forked from UNN/2026-rff_mp
82 lines
3.2 KiB
Python
82 lines
3.2 KiB
Python
|
|
import matplotlib.pyplot as plt
|
|||
|
|
import os
|
|||
|
|
|
|||
|
|
os.makedirs('docs/data', exist_ok=True)
|
|||
|
|
|
|||
|
|
|
|||
|
|
algorithms = ['BFS', 'DFS', 'A*']
|
|||
|
|
simple_time = [0.020, 0.012, 0.020]
|
|||
|
|
simple_visited = [11, 9, 9]
|
|||
|
|
simple_path = [6, 8, 6]
|
|||
|
|
|
|||
|
|
|
|||
|
|
fig, ax = plt.subplots(figsize=(8, 5))
|
|||
|
|
bars = ax.bar(algorithms, simple_time, color=['#3498db', '#e74c3c', '#2ecc71'])
|
|||
|
|
ax.set_ylabel('Время (мс)')
|
|||
|
|
ax.set_title('Время выполнения алгоритмов (простой лабиринт)')
|
|||
|
|
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')
|
|||
|
|
plt.savefig('docs/data/maze_time_graph.png', dpi=150, bbox_inches='tight')
|
|||
|
|
plt.close()
|
|||
|
|
|
|||
|
|
|
|||
|
|
fig, ax = plt.subplots(figsize=(8, 5))
|
|||
|
|
bars = ax.bar(algorithms, simple_visited, color=['#3498db', '#e74c3c', '#2ecc71'])
|
|||
|
|
ax.set_ylabel('Количество клеток')
|
|||
|
|
ax.set_title('Посещённые клетки при поиске')
|
|||
|
|
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')
|
|||
|
|
plt.savefig('docs/data/maze_visited_graph.png', dpi=150, bbox_inches='tight')
|
|||
|
|
plt.close()
|
|||
|
|
|
|||
|
|
|
|||
|
|
fig, ax = plt.subplots(figsize=(8, 5))
|
|||
|
|
bars = ax.bar(algorithms, simple_path, color=['#3498db', '#e74c3c', '#2ecc71'])
|
|||
|
|
ax.set_ylabel('Длина пути (шагов)')
|
|||
|
|
ax.set_title('Длина найденного пути')
|
|||
|
|
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')
|
|||
|
|
plt.savefig('docs/data/maze_path_graph.png', dpi=150, bbox_inches='tight')
|
|||
|
|
plt.close()
|
|||
|
|
|
|||
|
|
|
|||
|
|
fig, ax = plt.subplots(figsize=(12, 5))
|
|||
|
|
ax.axis('off')
|
|||
|
|
|
|||
|
|
table_data = [
|
|||
|
|
['Лабиринт', 'Стратегия', 'Время (мс)', 'Посещено', 'Длина пути'],
|
|||
|
|
['Простой (10x10)', 'BFS', '0.020', '11', '6'],
|
|||
|
|
['Простой (10x10)', 'DFS', '0.012', '9', '8'],
|
|||
|
|
['Простой (10x10)', 'A*', '0.020', '9', '6'],
|
|||
|
|
['С тупиками (20x20)', 'BFS', '0.492', '306', '35'],
|
|||
|
|
['С тупиками (20x20)', 'DFS', '0.234', '198', '81'],
|
|||
|
|
['С тупиками (20x20)', 'A*', '0.456', '225', '35'],
|
|||
|
|
['Пустой (50x50)', 'BFS', '3.486', '2304', '95'],
|
|||
|
|
['Пустой (50x50)', 'DFS', '10.452', '2304', '1129'],
|
|||
|
|
['Пустой (50x50)', 'A*', '5.743', '2304', '95'],
|
|||
|
|
['Без выхода', 'BFS', '0.010', '1', 'нет пути'],
|
|||
|
|
['Без выхода', 'DFS', '0.003', '1', 'нет пути'],
|
|||
|
|
['Без выхода', 'A*', '0.004', '1', 'нет пути'],
|
|||
|
|
]
|
|||
|
|
|
|||
|
|
table = ax.table(cellText=table_data, loc='center', cellLoc='center', colWidths=[0.2, 0.13, 0.13, 0.13, 0.13])
|
|||
|
|
table.auto_set_font_size(False)
|
|||
|
|
table.set_fontsize(10)
|
|||
|
|
table.scale(1, 1.8)
|
|||
|
|
|
|||
|
|
|
|||
|
|
for i in range(5):
|
|||
|
|
table[(0, i)].set_facecolor('#4472C4')
|
|||
|
|
table[(0, i)].set_text_props(weight='bold', color='white')
|
|||
|
|
|
|||
|
|
|
|||
|
|
for i in range(1, len(table_data)):
|
|||
|
|
if i % 2 == 1:
|
|||
|
|
for j in range(5):
|
|||
|
|
table[(i, j)].set_facecolor('#E8F0FE')
|
|||
|
|
|
|||
|
|
plt.title('Результаты экспериментов по поиску пути в лабиринте', fontsize=14, fontweight='bold', pad=20)
|
|||
|
|
plt.savefig('docs/data/maze_table_results.png', dpi=200, bbox_inches='tight', facecolor='white')
|
|||
|
|
plt.close()
|
|||
|
|
|