-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_minimum_steiner_tree.py
More file actions
36 lines (29 loc) · 1.15 KB
/
test_minimum_steiner_tree.py
File metadata and controls
36 lines (29 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
from graph_tool.generation import lattice
from minimum_steiner_tree import min_steiner_tree
from graph_helpers import is_tree
def test_unweighted():
g = lattice((5, 5))
for n, c in [(10, 5), (g.num_vertices(), 1)]:
# repeat `c` rounds, using `n` terminals
for _ in range(c):
obs = np.random.choice(np.arange(g.num_vertices()), n,
replace=False)
t = min_steiner_tree(g, obs)
assert is_tree(t)
assert set(obs).issubset(set(map(int, t.vertices())))
def test_weighted():
g = lattice((5, 5))
# assign some random weight
p = g.new_edge_property('float')
weights = np.random.random(g.num_edges())
p.a = (-np.log(weights))
for n, c in [(10, 5), (g.num_vertices(), 1)]:
# repeat `c` rounds, using `n` terminals
for _ in range(c):
obs = np.random.choice(np.arange(g.num_vertices()), n,
replace=False)
t = min_steiner_tree(g, obs, p)
# print(t)
assert is_tree(t)
assert set(obs).issubset(set(map(int, t.vertices())))