-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (28 loc) · 1.14 KB
/
main.py
File metadata and controls
36 lines (28 loc) · 1.14 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 time
from state import State
from a_star import a_star
# Παράδειγμα κλήσης με N, M και K
N = 3 # Αριθμός ιεραποστόλων και κανίβαλων.
M = 2 # Χωρητικότητα της βάρκας.
K = 100 # Μέγιστος αριθμός διασχίσεων.
initial_state = State(N,N,N, boat_capacity=M)
# Έναρξη μέτρησης χρόνου.
start_time = time.time()
solution = a_star(initial_state, max_crossings=K)
# Τέλος μέτρησης χρόνου.
end_time = time.time()
total_time = end_time - start_time
if solution:
print("Λύση βρέθηκε:")
path = []
while solution:
path.append(solution)
solution = solution._father
path.reverse()
for step in path:
step.print_state()
# Εμφάνιση του συνολικού αριθμού μετακινήσεων.
print(f"Συνολικές μετακινήσεις: {len(path) - 1}")
else:
print("Δεν βρέθηκε λύση.")
print(f"Συνολικός χρόνος ολοκλήρωσης: {total_time:.4f} δευτερόλεπτα")