-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForwardCheckMap.py
71 lines (51 loc) · 2.04 KB
/
ForwardCheckMap.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
69
70
71
from CSP import *
from Map import *
import time
problem = Problem()
problem2 = Problem()
problem3 = Problem()
new_map = Map()
new_map.generate_points(13)
new_map.connect_points()
color = [1, 2, 3, 4]
for i in range(len(new_map.points)):
problem.add_variable(i, color[:])
problem2.add_variable(i, color[:])
problem3.add_variable(i, color[:])
for line in new_map.lines:
problem.add_double_constraint(lambda p1, p2: p1 != p2,
(new_map.points.index(line.point1), new_map.points.index(line.point2)))
problem2.add_double_constraint(lambda p1, p2: p1 != p2,
(new_map.points.index(line.point1), new_map.points.index(line.point2)))
problem3.add_double_constraint(lambda p1, p2: p1 != p2,
(new_map.points.index(line.point1), new_map.points.index(line.point2)))
start = time.time()
problem.variable_heuristic = 0
problem.value_heuristic = 0
problem.solve_backtracking()
# print(problem.solutions)
end = time.time()
print(f"czas: {end - start}\nnodes: {problem.nodes_visited}")
print(f"czas pierwsze rozwiązanie: {problem.end_time - problem.start_time}\nnodes: {problem.nodes_to_first_sol}")
start = time.time()
problem2.variable_heuristic = 0
problem2.value_heuristic = 0
problem2.solve_forward_check()
# print(problem.solutions)
end = time.time()
print(f"czas: {end - start}\nnodes: {problem2.nodes_visited}")
print(f"czas pierwsze rozwiązanie: {problem2.end_time - problem2.start_time}\nnodes: {problem2.nodes_to_first_sol}")
start = time.time()
problem3.variable_heuristic = 0
problem3.value_heuristic = 1
problem3.solve_forward_check()
# print(problem.solutions)
end = time.time()
print(f"czas: {end - start}\nnodes: {problem3.nodes_visited}")
print(f"czas pierwsze rozwiązanie: {problem3.end_time - problem3.start_time}\nnodes: {problem3.nodes_to_first_sol}")
solutions = problem.solutions
print(f"Znaleziono {len(solutions)} rozwiązań:")
print(solutions[0])
for key, value in solutions[0]:
new_map.points[key].color = value
# new_map.draw()