Добавлены графики

This commit is contained in:
yanyaevaa 2026-05-21 16:30:23 +03:00
parent 06a8a01c7f
commit 3b072cee1c
3 changed files with 51 additions and 18 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

View File

@ -1,16 +1,16 @@
лабиринт,стратегия,время_мс,посещено_клеток,длина_пути лабиринт,стратегия,время_мс,посещено_клеток,длина_пути
10x10.txt,BFS,0.02810000005410984,30.0,29.0 10x10.txt,BFS,0.02643000007083174,30.0,29.0
10x10.txt,DFS,0.038610000046901405,43.0,29.0 10x10.txt,DFS,0.03684999974211678,43.0,29.0
10x10.txt,AStar,0.03273000111221336,30.0,29.0 10x10.txt,AStar,0.0320400002237875,30.0,29.0
50x50.txt,BFS,0.7084800003212877,799.0,316.0 50x50.txt,BFS,0.6697899993014289,799.0,316.0
50x50.txt,DFS,0.48563999953330494,562.0,350.0 50x50.txt,DFS,0.4721500004961854,562.0,350.0
50x50.txt,AStar,0.6310500000836328,539.0,316.0 50x50.txt,AStar,0.5986000000120839,539.0,316.0
100x100.txt,BFS,3.024820000428008,3576.0,196.0 100x100.txt,BFS,3.000480001355754,3576.0,196.0
100x100.txt,DFS,0.44655999954557046,595.0,364.0 100x100.txt,DFS,0.4453900000953581,595.0,364.0
100x100.txt,AStar,0.5645899997034576,522.0,196.0 100x100.txt,AStar,0.5786999998235842,522.0,196.0
empty.txt,BFS,0.2849799988325685,324.0,35.0 empty.txt,BFS,0.29044999937468674,324.0,35.0
empty.txt,DFS,0.1592799999343697,324.0,171.0 empty.txt,DFS,0.16180000056920107,324.0,171.0
empty.txt,AStar,0.4022000000986736,324.0,35.0 empty.txt,AStar,0.40738000025157817,324.0,35.0
without_exit.txt,BFS,0.041259999125031754,48.0,0.0 without_exit.txt,BFS,0.04074000025866553,48.0,0.0
without_exit.txt,DFS,0.040809998608892784,48.0,0.0 without_exit.txt,DFS,0.040809999700286426,48.0,0.0
without_exit.txt,AStar,0.052090000826865435,48.0,0.0 without_exit.txt,AStar,0.05192000025999732,48.0,0.0

1 лабиринт стратегия время_мс посещено_клеток длина_пути
2 10x10.txt BFS 0.02810000005410984 0.02643000007083174 30.0 29.0
3 10x10.txt DFS 0.038610000046901405 0.03684999974211678 43.0 29.0
4 10x10.txt AStar 0.03273000111221336 0.0320400002237875 30.0 29.0
5 50x50.txt BFS 0.7084800003212877 0.6697899993014289 799.0 316.0
6 50x50.txt DFS 0.48563999953330494 0.4721500004961854 562.0 350.0
7 50x50.txt AStar 0.6310500000836328 0.5986000000120839 539.0 316.0
8 100x100.txt BFS 3.024820000428008 3.000480001355754 3576.0 196.0
9 100x100.txt DFS 0.44655999954557046 0.4453900000953581 595.0 364.0
10 100x100.txt AStar 0.5645899997034576 0.5786999998235842 522.0 196.0
11 empty.txt BFS 0.2849799988325685 0.29044999937468674 324.0 35.0
12 empty.txt DFS 0.1592799999343697 0.16180000056920107 324.0 171.0
13 empty.txt AStar 0.4022000000986736 0.40738000025157817 324.0 35.0
14 without_exit.txt BFS 0.041259999125031754 0.04074000025866553 48.0 0.0
15 without_exit.txt DFS 0.040809998608892784 0.040809999700286426 48.0 0.0
16 without_exit.txt AStar 0.052090000826865435 0.05192000025999732 48.0 0.0

View File

@ -1,5 +1,8 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from collections import deque from collections import deque
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
import heapq import heapq
import time import time
import os import os
@ -221,7 +224,6 @@ class ConsoleView(Observer):
#Этап 6 #Этап 6
mazes = ["10x10.txt","50x50.txt","100x100.txt","empty.txt","without_exit.txt"] mazes = ["10x10.txt","50x50.txt","100x100.txt","empty.txt","without_exit.txt"]
results =[["лабиринт", results =[["лабиринт",
"стратегия", "стратегия",
"время_мс", "время_мс",
@ -235,6 +237,7 @@ strategies = {
builder = TextFileMazeBuilder() builder = TextFileMazeBuilder()
n=10 n=10
directory = os.path.join("docs", "data") directory = os.path.join("docs", "data")
for maze_name in mazes: for maze_name in mazes:
print(maze_name) print(maze_name)
file_name=os.path.join(directory, maze_name) file_name=os.path.join(directory, maze_name)
@ -258,9 +261,39 @@ for maze_name in mazes:
print(f"{maze_name} стратегия: {strategy_name} время_мс: {avg_time} посещено_клеток: {avg_visited} длина_пути: {avg_path_length}") print(f"{maze_name} стратегия: {strategy_name} время_мс: {avg_time} посещено_клеток: {avg_visited} длина_пути: {avg_path_length}")
results.append([maze_name, strategy_name, avg_time, avg_visited, avg_path_length]) results.append([maze_name, strategy_name, avg_time, avg_visited, avg_path_length])
path, _ = strategy.findPath(maze, maze.start, maze.exit) path, _ = strategy.findPath(maze, maze.start, maze.exit)
path=path[1:-1]
viewer.render(maze, path) viewer.render(maze, path)
csv_filename = os.path.join(directory, "maze_results.csv") csv_filename = os.path.join(directory, "maze_results.csv")
with open(csv_filename, "w", newline="", encoding="utf-8-sig") as f: with open(csv_filename, "w", newline="", encoding="utf-8-sig") as f:
writer = csv.writer(f) writer = csv.writer(f)
writer.writerows(results) writer.writerows(results)
#Графики
df = pd.read_csv(csv_filename)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(16, 6))
sns.barplot(data=df, x='лабиринт', y='время_мс', hue='стратегия', ax=ax1)
ax1.set_title('Время выполнения алгоритмов')
ax1.set_xlabel('Лабиринты')
ax1.set_ylabel('Время (мс)')
ax1.grid(axis='y', linestyle='--', alpha=0.7)
ax1.legend()
sns.barplot(data=df, x='лабиринт', y='посещено_клеток', hue='стратегия', ax=ax2)
ax2.set_title('Количество посещенных клеток')
ax2.set_xlabel('Лабиринты')
ax2.set_ylabel('Количество клеток')
ax2.grid(axis='y', linestyle='--', alpha=0.7)
ax2.legend()
plt.tight_layout()
sns.barplot(data=df, x='лабиринт', y='длина_пути', hue='стратегия', ax=ax3)
ax3.set_title('Длина пути')
ax3.set_xlabel('Лабиринты')
ax3.set_ylabel('Количество клеток')
ax3.grid(axis='y', linestyle='--', alpha=0.7)
ax3.legend()
plt.tight_layout()
img = os.path.join(directory, "maze_graphics.png")
plt.savefig(img, dpi=300)
plt.show()