forked from UNN/2026-rff_mp
36 lines
1.7 KiB
Python
36 lines
1.7 KiB
Python
|
|
import csv
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import matplotlib.pyplot as plt
|
||
|
|
|
||
|
|
|
||
|
|
def create_plot(csv_path="docs/data/maze_results_summary.csv", output_path="docs/data/maze_performance.png"):
|
||
|
|
with Path(csv_path).open(encoding="utf-8-sig") as file:
|
||
|
|
rows = list(csv.DictReader(file))
|
||
|
|
mazes = sorted({row["maze"] for row in rows})
|
||
|
|
strategies = ["BFS", "DFS", "A*"]
|
||
|
|
colors = {"BFS": "#4472C4", "DFS": "#ED7D31", "A*": "#70AD47"}
|
||
|
|
figure, axes = plt.subplots(2, 1, figsize=(12, 9))
|
||
|
|
positions = range(len(mazes))
|
||
|
|
width = 0.24
|
||
|
|
for index, strategy in enumerate(strategies):
|
||
|
|
selected = [next(row for row in rows if row["maze"] == maze and row["strategy"] == strategy) for maze in mazes]
|
||
|
|
offsets = [position + (index - 1) * width for position in positions]
|
||
|
|
axes[0].bar(offsets, [float(row["mean_time_ms"]) for row in selected], width, label=strategy, color=colors[strategy])
|
||
|
|
axes[1].bar(offsets, [float(row["mean_visited_cells"]) for row in selected], width, label=strategy, color=colors[strategy])
|
||
|
|
for axis, ylabel, title in zip(axes, ["Время, мс", "Посещено клеток"], ["Среднее время поиска", "Объём исследования лабиринта"]):
|
||
|
|
axis.set_xticks(list(positions), mazes, rotation=20, ha="right")
|
||
|
|
axis.set_ylabel(ylabel)
|
||
|
|
axis.set_title(title)
|
||
|
|
axis.grid(axis="y", alpha=0.25)
|
||
|
|
axis.legend()
|
||
|
|
figure.suptitle("Сравнение стратегий поиска (средние значения)")
|
||
|
|
figure.tight_layout()
|
||
|
|
figure.savefig(output_path, dpi=180)
|
||
|
|
plt.close(figure)
|
||
|
|
return Path(output_path)
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
print(f"График сохранён: {create_plot()}")
|