-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathILP_solver_tests.py
68 lines (56 loc) · 2.52 KB
/
ILP_solver_tests.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from ILP_solver.ILP_solver import solve_TCP_instance, solve_multi_destination_TCP_instance
from graph_tools.graph_generator import generate_graph
import networkx
def test_TCP_instance():
"""
Tests the TCP ILP solver on an instance of necessary edge reuse.
"""
graph = networkx.DiGraph()
graph.add_edge(2, 2, weight=0.001)
graph.add_edge(1, 2, weight=3)
graph.add_edge(2, 6, weight=6)
graph.add_edge(1, 3, weight=5)
graph.add_edge(3, 4, weight=1)
graph.add_edge(4, 5, weight=1)
graph.add_edge(5, 3, weight=1)
graph.add_edge(4, 6, weight=1)
existence_for_node_time = {
(1, 0): 1, (1, 1): 0, (1, 2): 0, (1, 3): 0, (1, 4): 0, (1, 5): 0, (1, 6): 0,
(2, 0): 0, (2, 1): 1, (2, 2): 1, (2, 3): 1, (2, 4): 1, (2, 5): 1, (2, 6): 0,
(3, 0): 0, (3, 1): 1, (3, 2): 1, (3, 3): 0, (3, 4): 1, (3, 5): 0, (3, 6): 0,
(4, 0): 0, (4, 1): 0, (4, 2): 1, (4, 3): 0, (4, 4): 0, (4, 5): 1, (4, 6): 0,
(5, 0): 0, (5, 1): 0, (5, 2): 1, (5, 3): 1, (5, 4): 0, (5, 5): 0, (5, 6): 0,
(6, 0): 0, (6, 1): 0, (6, 2): 0, (6, 3): 0, (6, 4): 0, (6, 5): 0, (6, 6): 1,
}
connectivity_demand = (1, 6)
solve_TCP_instance(graph, existence_for_node_time, connectivity_demand)
def test_mTCP_instance():
"""
Tests the mTCP ILP solver on an instance of necessary edge reuse.
"""
graph = networkx.DiGraph()
graph.add_edge(2, 2, weight=0.001)
graph.add_edge(1, 2, weight=3)
graph.add_edge(2, 6, weight=6)
graph.add_edge(1, 3, weight=5)
graph.add_edge(3, 4, weight=1)
graph.add_edge(4, 5, weight=1)
graph.add_edge(5, 3, weight=1)
graph.add_edge(4, 6, weight=1)
existence_for_node_time = {
(1, 0): 1, (1, 1): 0, (1, 2): 0, (1, 3): 0, (1, 4): 0, (1, 5): 0, (1, 6): 0,
(2, 0): 0, (2, 1): 1, (2, 2): 1, (2, 3): 1, (2, 4): 1, (2, 5): 1, (2, 6): 1,
(3, 0): 0, (3, 1): 1, (3, 2): 1, (3, 3): 0, (3, 4): 1, (3, 5): 0, (3, 6): 0,
(4, 0): 0, (4, 1): 0, (4, 2): 1, (4, 3): 0, (4, 4): 0, (4, 5): 1, (4, 6): 0,
(5, 0): 0, (5, 1): 0, (5, 2): 1, (5, 3): 1, (5, 4): 0, (5, 5): 0, (5, 6): 1,
(6, 0): 0, (6, 1): 0, (6, 2): 0, (6, 3): 0, (6, 4): 0, (6, 5): 0, (6, 6): 1,
}
solve_multi_destination_TCP_instance(graph, existence_for_node_time, source=1, destinations=[2, 5])
def test_generated_TCP():
graph, existence_for_node_time, connectivity_demand = generate_graph(num_nodes=10000, edge_connectivity=.001, max_time=3, active_time_percent=0.1)
solve_TCP_instance(graph, existence_for_node_time, connectivity_demand)
print "Connectivity Demand: " + str(connectivity_demand)
return existence_for_node_time, graph
#test_TCP_instance()
#test_mTCP_instance()
test_generated_TCP()