-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmazeGA_main.py
More file actions
43 lines (33 loc) · 1.66 KB
/
mazeGA_main.py
File metadata and controls
43 lines (33 loc) · 1.66 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
37
38
39
40
41
42
43
import numpy as np
from agent import GeneticAgent
def main():
source = np.array([0, 0])
destination = np.array([3, 3])
maze = np.array([[0, 0, 0, 0],
[0, 1, 0, 1],
[0, 0, 0, 1],
[1, 0, 0, 0]])
# maze = np.array([[0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
# [0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
# [0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
# [0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0],
# [0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0],
# [0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0],
# [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
# [0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0],
# [0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0],
# [0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0],
# [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
# [1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
# [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0],
# [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0],
# [1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0]])
ga_agent = GeneticAgent(source, destination, maze)
best_path = ga_agent.run_genetic_algorithm()
if best_path:
print(f"\nOptimal Path Found: {best_path}")
ga_agent.display_maze()
else:
print("\nNo optimal path found within the given generations.")
if __name__ == '__main__':
main()