-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynchronous_movement_test.py
52 lines (43 loc) · 1.52 KB
/
synchronous_movement_test.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
from utils.environments import *
from solvers.model_cp import solving_MAPF, run_CPLEX
import networkx as nx
import matplotlib.pyplot as plt
from solvers.model_smt import run_Z3
"""
Run this file to replicate the experiment described in Synchronization and collision avoidance subsection of the report.
This test was performed by considering a graph with a number of nodes equal to the number of agents in order to show
the possible synchronous movement of agents
"""
edges = [{0, 1, 2}, {0, 1, 2}, {0, 1, 2}]
agents = [(0, 1), (1, 2), (2, 0)]
UPPER_BOUND = 1
graph = nx.uniform_random_intersection_graph(len(edges), len(edges), 1)
min_shortest_path, makespan = min_max_shortest_path(graph, agents)
print("ENVIRONMENT: ")
[print(str(node) + ": " + str(neighbors)) for node, neighbors in enumerate(edges)]
print("AGENTS: ")
print(agents)
sep = "=" * 50
print(sep)
print("Z3")
check, _, _, _, _, _ = run_Z3(edges, agents, makespan)
while not check and makespan <= UPPER_BOUND:
makespan += 1
check, _, _, _, _, _ = run_Z3(edges, agents, makespan)
if not check and makespan >= UPPER_BOUND:
print("Unsatisfiable")
print(sep)
print("CPLEX")
print("Step 1) Searching for optimal number of layers")
check, RET, num_layers, _, _, _, _ = \
solving_MAPF(agents, edges, UPPER_BOUND, min_shortest_path)
print(sep)
print("Step 2) Solving with %d layers" % num_layers)
print(sep)
if check:
_, mksp, _, _, _, _, _ = \
run_CPLEX(edges, agents, RET, num_layers)
else:
print("Unsatisfiable")
nx.draw(graph, with_labels=True)
plt.show()