-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
158 lines (141 loc) · 4.43 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from BFSAgent import BFSAgent
from DFSAgent import DFSAgent
from GBFSAgent import GBFSAgent
from UCSAgent import UCSAgent
from IDSAgent import IDSAgent
from AStarAgent import AStarAgent
from HillClimbing import HillClimbingAgent
from QBot import QBot
from maze import Maze
from SimulatedAnnealing import SimulatedAnnealing
from Genetic_algorithmAgent import GeneticAlgorithmAgent
import tracemalloc
import time
maze = Maze()
maze.PutCoins()
maze.PutSlime()
maze.PrintMaze()
print("")
# STime = time.perf_counter()
# tracemalloc.start()
# bfs = BFSAgent(maze)
# path1 = bfs.bfs()
# maze.PrintPath(path1)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time BFS: {ETime-STime:.4f} seconds")
# print(f"BFS")
# tracemalloc.start()
# STime = time.perf_counter()
# dfs = DFSAgent(maze)
# path2 = dfs.dfs()
# maze.PrintPath(path2)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time DFS: {ETime-STime:.4f} seconds")
# print(f"DFS")
# STime = time.perf_counter()
# tracemalloc.start()
# UCS = UCSAgent(maze)
# path3= UCS.UCS()
# maze.PrintPath(path3)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed timee for ucs : {ETime-STime:.4f} seconds")
# print(f"UCS")
# STime = time.perf_counter()
# tracemalloc.start()
# AStar = AStarAgent(maze)
# path5 = AStar.AStar()
# maze.PrintPath(path5)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time A-star: {ETime-STime:.4f} seconds")
# print(f"A star")
# STime = time.perf_counter()
# tracemalloc.start()
# GBFS = GBFSAgent(maze)
# path4 = GBFS.GBFS()
# maze.PrintPath(path4)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time for greedy: {ETime-STime:.4f} seconds")
# print(f"Greedy")
# STime = time.perf_counter()
# tracemalloc.start()
# STime = time.perf_counter()
# HillClimbing = HillClimbingAgent(maze)
# result = HillClimbing.hill_climbing()
# x,y = result
# maze.PrintPath(result)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time for Hill Climbing: {ETime-STime:.4f} seconds")
# print(f"Hill Climbing")
# STime = time.perf_counter()
# tracemalloc.start()
# STime = time.perf_counter()
# ids = IDSAgent(maze)
# result = ids.IDS()
# maze.PrintPath(result)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time for IDS: {ETime-STime:.4f} seconds")
# print(f"IDS")
# print("")
# STime = time.perf_counter()
# tracemalloc.start()
# STime = time.perf_counter()
# sa = SimulatedAnnealing(maze)
# schedule = lambda t: max(0.01, min(1, 1 - 0.001 * t))
# result = sa.simulated_annealing(schedule)
# maze.PrintPath(result)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time for Simulated Annealing: {ETime-STime:.4f} seconds")
# print(f"Simulated Annealing")
# STime = time.perf_counter()
# tracemalloc.start()
# GA = GeneticAlgorithmAgent(maze)
# x, Thresh = path3
# #uses UCS path cost
# path5 = GA.genetic_algorithm(GA.fitness, maze.PathCost(Thresh)+300 )
# maze.PrintPath(path5)
# for I in path5:
# print(I)
# current, peak = tracemalloc.get_traced_memory()
# print(f"Peak memory usage: {peak / 10**6} MB")
# tracemalloc.stop()
# ETime = time.perf_counter()
# print(f"Elapsed time for GA: {ETime-STime:.4f} seconds")
# print(f"Genetic Algorithm")
STime = time.perf_counter()
tracemalloc.start()
qbot = QBot(maze, 0.105, 0.815)
qbot.q_episode_travesing(825)
pathQ = qbot.path_generation_test()
print("path generated")
filtered_path = [(x, y) for x, y, *_ in pathQ]
maze.PrintQPath(filtered_path)
current, peak = tracemalloc.get_traced_memory()
print(f"Peak memory usage: {peak / 10**6} MB")
tracemalloc.stop()
ETime = time.perf_counter()
print(f"Elapsed time for Q bot: {ETime-STime:.4f} seconds")
print(f"Qbot")