forked from UNN/2026-rff_mp
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
|
|
import csv
|
||
|
|
import time
|
||
|
|
from maze import MazeBuilder
|
||
|
|
from solver import BfsStrategy, DfsStrategy, AstarStrategy, MazeSolver
|
||
|
|
|
||
|
|
MAPS = ["simple.txt", "medium.txt", "hard.txt"]
|
||
|
|
REPEATS = 5
|
||
|
|
|
||
|
|
def run_one(filename, strategy):
|
||
|
|
maze = MazeBuilder().from_file("raskatovia/docs/data/task2/maps/" + filename).build()
|
||
|
|
solver = MazeSolver(strategy)
|
||
|
|
start = time.perf_counter()
|
||
|
|
result = solver.solve(maze)
|
||
|
|
work_time = time.perf_counter() - start
|
||
|
|
return result, work_time
|
||
|
|
|
||
|
|
def main():
|
||
|
|
rows = [["map", "algorithm", "try", "time", "visited", "length"]]
|
||
|
|
strategies = [BfsStrategy(), DfsStrategy(), AstarStrategy()]
|
||
|
|
|
||
|
|
for filename in MAPS:
|
||
|
|
for strategy in strategies:
|
||
|
|
for number in range(1, REPEATS + 1):
|
||
|
|
result, work_time = run_one(filename, strategy)
|
||
|
|
rows.append([
|
||
|
|
filename,
|
||
|
|
result["name"],
|
||
|
|
number,
|
||
|
|
work_time,
|
||
|
|
result["visited"],
|
||
|
|
result["length"]
|
||
|
|
])
|
||
|
|
|
||
|
|
with open("raskatovia/docs/data/task2/results.csv", "w", newline="", encoding="utf-8") as file:
|
||
|
|
writer = csv.writer(file)
|
||
|
|
writer.writerows(rows)
|
||
|
|
|
||
|
|
print("results saved")
|
||
|
|
|
||
|
|
main()
|