2026-rff_mp/konnovaea/lab2/make_lab2_plots.py

163 lines
7.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import matplotlib.pyplot as plt
import os
os.makedirs('lab2/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('Время выполнения (простой лабиринт 10x10)')
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/simple_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/simple_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/simple_path_graph.png', dpi=150, bbox_inches='tight')
plt.close()
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')
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()