сделаны все графики

This commit is contained in:
konnovaea 2026-05-22 17:43:21 +03:00
parent 58b2b73c8a
commit 9f9158b0c4
17 changed files with 97 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 132 KiB

After

Width:  |  Height:  |  Size: 142 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View File

@ -1,46 +1,130 @@
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import os import os
os.makedirs('docs/data', exist_ok=True) os.makedirs('lab2/docs/data', exist_ok=True)
algorithms = ['BFS', 'DFS', 'A*'] algorithms = ['BFS', 'DFS', 'A*']
simple_time = [0.020, 0.012, 0.020] simple_time = [0.020, 0.012, 0.020]
simple_visited = [11, 9, 9] simple_visited = [11, 9, 9]
simple_path = [6, 8, 6] simple_path = [6, 8, 6]
fig, ax = plt.subplots(figsize=(8, 5)) fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, simple_time, color=['#3498db', '#e74c3c', '#2ecc71']) bars = ax.bar(algorithms, simple_time, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Время (мс)') ax.set_ylabel('Время (мс)')
ax.set_title('Время выполнения алгоритмов (простой лабиринт)') ax.set_title('Время выполнения (простой лабиринт 10x10)')
for bar, val in zip(bars, simple_time): for bar, val in zip(bars, simple_time):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.001, f'{val:.3f}', ha='center', va='bottom') ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.001, f'{val:.3f}', ha='center', va='bottom')
plt.savefig('docs/data/maze_time_graph.png', dpi=150, bbox_inches='tight') plt.savefig('docs/data/simple_time_graph.png', dpi=150, bbox_inches='tight')
plt.close() plt.close()
fig, ax = plt.subplots(figsize=(8, 5)) fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, simple_visited, color=['#3498db', '#e74c3c', '#2ecc71']) bars = ax.bar(algorithms, simple_visited, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Количество клеток') ax.set_ylabel('Количество клеток')
ax.set_title('Посещённые клетки при поиске') ax.set_title('Посещённые клетки (простой лабиринт)')
for bar, val in zip(bars, simple_visited): for bar, val in zip(bars, simple_visited):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, str(val), ha='center', va='bottom') ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, str(val), ha='center', va='bottom')
plt.savefig('docs/data/maze_visited_graph.png', dpi=150, bbox_inches='tight') plt.savefig('docs/data/simple_visited_graph.png', dpi=150, bbox_inches='tight')
plt.close() plt.close()
fig, ax = plt.subplots(figsize=(8, 5)) fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, simple_path, color=['#3498db', '#e74c3c', '#2ecc71']) bars = ax.bar(algorithms, simple_path, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Длина пути (шагов)') ax.set_ylabel('Длина пути (шагов)')
ax.set_title('Длина найденного пути') ax.set_title('Длина найденного пути (простой лабиринт)')
for bar, val in zip(bars, simple_path): for bar, val in zip(bars, simple_path):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, str(val), ha='center', va='bottom') ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, str(val), ha='center', va='bottom')
plt.savefig('docs/data/maze_path_graph.png', dpi=150, bbox_inches='tight') plt.savefig('docs/data/simple_path_graph.png', dpi=150, bbox_inches='tight')
plt.close() plt.close()
fig, ax = plt.subplots(figsize=(12, 5)) dead_time = [0.492, 0.234, 0.456]
dead_visited = [306, 198, 225]
dead_path = [35, 81, 35]
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, dead_time, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Время (мс)')
ax.set_title('Время выполнения (лабиринт с тупиками)')
for bar, val in zip(bars, dead_time):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.01, f'{val:.3f}', ha='center', va='bottom')
plt.savefig('docs/data/dead_time_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, dead_visited, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Количество клеток')
ax.set_title('Посещённые клетки (лабиринт с тупиками)')
for bar, val in zip(bars, dead_visited):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 10, str(val), ha='center', va='bottom')
plt.savefig('docs/data/dead_visited_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, dead_path, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Длина пути (шагов)')
ax.set_title('Длина найденного пути (лабиринт с тупиками)')
for bar, val in zip(bars, dead_path):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 3, str(val), ha='center', va='bottom')
plt.savefig('docs/data/dead_path_graph.png', dpi=150, bbox_inches='tight')
plt.close()
empty_time = [3.486, 10.452, 5.743]
empty_visited = [2304, 2304, 2304]
empty_path = [95, 1129, 95]
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, empty_time, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Время (мс)')
ax.set_title('Время выполнения (пустой лабиринт 50x50)')
for bar, val in zip(bars, empty_time):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.3, f'{val:.3f}', ha='center', va='bottom')
plt.savefig('docs/data/empty_time_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, empty_visited, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Количество клеток')
ax.set_title('Посещённые клетки (пустой лабиринт)')
for bar, val in zip(bars, empty_visited):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 50, str(val), ha='center', va='bottom')
plt.savefig('docs/data/empty_visited_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, empty_path, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Длина пути (шагов)')
ax.set_title('Длина найденного пути (пустой лабиринт)')
for bar, val in zip(bars, empty_path):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 50, str(val), ha='center', va='bottom')
plt.savefig('docs/data/empty_path_graph.png', dpi=150, bbox_inches='tight')
plt.close()
noexit_time = [0.010, 0.003, 0.004]
noexit_visited = [1, 1, 1]
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, noexit_time, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Время (мс)')
ax.set_title('Время выполнения (лабиринт без выхода)')
for bar, val in zip(bars, noexit_time):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.0005, f'{val:.3f}', ha='center', va='bottom')
plt.savefig('docs/data/noexit_time_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(8, 5))
bars = ax.bar(algorithms, noexit_visited, color=['#3498db', '#e74c3c', '#2ecc71'])
ax.set_ylabel('Количество клеток')
ax.set_title('Посещённые клетки (лабиринт без выхода)')
for bar, val in zip(bars, noexit_visited):
ax.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.05, str(val), ha='center', va='bottom')
plt.savefig('docs/data/noexit_visited_graph.png', dpi=150, bbox_inches='tight')
plt.close()
fig, ax = plt.subplots(figsize=(14, 8))
ax.axis('off') ax.axis('off')
table_data = [ table_data = [
@ -64,12 +148,10 @@ table.auto_set_font_size(False)
table.set_fontsize(10) table.set_fontsize(10)
table.scale(1, 1.8) table.scale(1, 1.8)
for i in range(5): for i in range(5):
table[(0, i)].set_facecolor('#4472C4') table[(0, i)].set_facecolor('#4472C4')
table[(0, i)].set_text_props(weight='bold', color='white') table[(0, i)].set_text_props(weight='bold', color='white')
for i in range(1, len(table_data)): for i in range(1, len(table_data)):
if i % 2 == 1: if i % 2 == 1:
for j in range(5): for j in range(5):
@ -78,4 +160,3 @@ for i in range(1, len(table_data)):
plt.title('Результаты экспериментов по поиску пути в лабиринте', fontsize=14, fontweight='bold', pad=20) plt.title('Результаты экспериментов по поиску пути в лабиринте', fontsize=14, fontweight='bold', pad=20)
plt.savefig('docs/data/maze_table_results.png', dpi=200, bbox_inches='tight', facecolor='white') plt.savefig('docs/data/maze_table_results.png', dpi=200, bbox_inches='tight', facecolor='white')
plt.close() plt.close()

View File

@ -1,7 +1,7 @@
import time import time
import csv import csv
import os import os
from maze_solver import TextFileMazeBuilder, BFSStrategy, DFSStrategy, AStarStrategy, MazeSolver from lab2.maze_solver import TextFileMazeBuilder, BFSStrategy, DFSStrategy, AStarStrategy, MazeSolver
def save_maze_to_file(maze, filename): def save_maze_to_file(maze, filename):
with open(filename, 'w') as f: with open(filename, 'w') as f: