Skip to content

Commit 65d7528

Browse files
committed
test: added clique percolation benchmark
1 parent c8c4cbd commit 65d7528

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from itertools import combinations
2+
from random import seed
3+
4+
from igraph import Graph as LegacyGraph
5+
6+
from igraph_ctypes.constructors import (
7+
create_graph_from_edge_list,
8+
create_geometric_random_graph,
9+
)
10+
from igraph_ctypes.conversion import get_edge_list
11+
from igraph_ctypes.paths import components
12+
from igraph_ctypes._internal.functions import maximal_cliques
13+
14+
seed(42)
15+
16+
n, r, k = 1600, 0.0625, 4
17+
18+
new_g = create_geometric_random_graph(n, r)
19+
old_g = LegacyGraph(get_edge_list(new_g).tolist())
20+
21+
22+
def _gen_pairs(sets, threshold: int):
23+
return (
24+
(u, v)
25+
for u, v in combinations(range(len(sets)), 2)
26+
if u != v and len(sets[u] & sets[v]) >= threshold
27+
)
28+
29+
30+
def _find_edgelist_pairs(sets, threshold: int):
31+
return list(_gen_pairs(sets, threshold))
32+
33+
34+
def _find_edgelist(sets, threshold: int):
35+
result = []
36+
for pair in _gen_pairs(sets, threshold):
37+
result.extend(pair)
38+
return result
39+
40+
41+
def clique_percolation_with_old_igraph():
42+
cliques = [set(cl) for cl in old_g.maximal_cliques(min=k)]
43+
el = _find_edgelist_pairs(cliques, k - 1)
44+
clique_g = LegacyGraph(el, directed=False)
45+
clique_g.components()
46+
47+
48+
def clique_percolation_with_new_igraph():
49+
cliques = [set(cl) for cl in maximal_cliques(new_g, min_size=4)]
50+
el = _find_edgelist(cliques, k - 1)
51+
clique_g = create_graph_from_edge_list(el, directed=False)
52+
components(clique_g)
53+
54+
55+
__benchmarks__ = [
56+
(
57+
clique_percolation_with_old_igraph,
58+
clique_percolation_with_new_igraph,
59+
"Clique percolation method",
60+
)
61+
]

benchmarks/bench_shortest_path.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717
new_g = create_square_lattice([n, n], directed=False, periodic=False)
1818

1919

20-
def with_old_igraph():
20+
def shortest_path_with_old_igraph():
2121
for u, v in pairs:
2222
old_g.get_shortest_paths(u, v)
2323

2424

25-
def with_new_igraph():
25+
def shortest_path_with_new_igraph():
2626
for u, v in pairs:
2727
get_shortest_path(new_g, u, v)
2828

2929

3030
__benchmarks__ = [
31-
(with_old_igraph, with_new_igraph, "Finding shortest path in grid graph")
31+
(
32+
shortest_path_with_old_igraph,
33+
shortest_path_with_new_igraph,
34+
"Finding shortest path in grid graph",
35+
)
3236
]

0 commit comments

Comments
 (0)