forked from UNN/2026-rff_mp
2th task is absolutly completed
This commit is contained in:
parent
5dc9777c5a
commit
e8418bd446
76
SolovevDS/docs/data/data_for_task2/diagrams.py
Normal file
76
SolovevDS/docs/data/data_for_task2/diagrams.py
Normal file
|
|
@ -0,0 +1,76 @@
|
||||||
|
import pandas as pd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
df = pd.read_csv("results.csv")
|
||||||
|
|
||||||
|
maze_order = ["small_10", "medium_50", "large_100", "empty", "no_path"]
|
||||||
|
strategy_order = ["BFS", "DFS", "AStar"]
|
||||||
|
|
||||||
|
maze_labels = {
|
||||||
|
"small_10": "10×10",
|
||||||
|
"medium_50": "50×50",
|
||||||
|
"large_100": "100×100",
|
||||||
|
"empty": "Пустой",
|
||||||
|
"no_path": "Без выхода"
|
||||||
|
}
|
||||||
|
|
||||||
|
df["maze"] = pd.Categorical(df["maze"], categories=maze_order, ordered=True)
|
||||||
|
df["strategy"] = pd.Categorical(df["strategy"], categories=strategy_order, ordered=True)
|
||||||
|
df = df.sort_values(["maze", "strategy"])
|
||||||
|
|
||||||
|
|
||||||
|
def plot_grouped_bar(df, value_col, ylabel, title, filename):
|
||||||
|
mazes = maze_order
|
||||||
|
strategies = strategy_order
|
||||||
|
|
||||||
|
x = np.arange(len(mazes))
|
||||||
|
width = 0.25
|
||||||
|
|
||||||
|
plt.figure(figsize=(11, 6))
|
||||||
|
|
||||||
|
for i, strategy in enumerate(strategies):
|
||||||
|
values = []
|
||||||
|
|
||||||
|
for maze in mazes:
|
||||||
|
row = df[(df["maze"] == maze) & (df["strategy"] == strategy)]
|
||||||
|
values.append(row[value_col].values[0])
|
||||||
|
|
||||||
|
plt.bar(x + (i - 1) * width, values, width, label=strategy)
|
||||||
|
|
||||||
|
plt.xlabel("Лабиринт")
|
||||||
|
plt.ylabel(ylabel)
|
||||||
|
plt.title(title)
|
||||||
|
|
||||||
|
plt.xticks(x, [maze_labels[m] for m in mazes], rotation=20)
|
||||||
|
plt.legend(title="Стратегия")
|
||||||
|
plt.grid(axis="y", alpha=0.3)
|
||||||
|
|
||||||
|
plt.tight_layout()
|
||||||
|
plt.savefig(filename, format="svg")
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
plot_grouped_bar(
|
||||||
|
df,
|
||||||
|
value_col="time_ms",
|
||||||
|
ylabel="Время, мс",
|
||||||
|
title="Сравнение времени выполнения BFS, DFS и A*",
|
||||||
|
filename="time_comparison.svg"
|
||||||
|
)
|
||||||
|
|
||||||
|
plot_grouped_bar(
|
||||||
|
df,
|
||||||
|
value_col="cells_visited",
|
||||||
|
ylabel="Количество посещённых клеток",
|
||||||
|
title="Сравнение количества посещённых клеток",
|
||||||
|
filename="visited_cells_comparison.svg"
|
||||||
|
)
|
||||||
|
|
||||||
|
plot_grouped_bar(
|
||||||
|
df,
|
||||||
|
value_col="way_len",
|
||||||
|
ylabel="Длина пути, клеток",
|
||||||
|
title="Сравнение длины найденного пути",
|
||||||
|
filename="path_length_comparison.svg"
|
||||||
|
)
|
||||||
10
SolovevDS/docs/data/data_for_task2/maze10.txt
Normal file
10
SolovevDS/docs/data/data_for_task2/maze10.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
##########
|
||||||
|
#S ###
|
||||||
|
###### ###
|
||||||
|
# ###
|
||||||
|
# #### ###
|
||||||
|
# # ###
|
||||||
|
# # ######
|
||||||
|
# # #
|
||||||
|
# ######E#
|
||||||
|
##########
|
||||||
100
SolovevDS/docs/data/data_for_task2/maze100.txt
Normal file
100
SolovevDS/docs/data/data_for_task2/maze100.txt
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
####################################################################################################
|
||||||
|
#S # # # # # # # # # ##
|
||||||
|
## ############### # ## ## ###### # ### ### ### ########### ### # ## # ####### # ### # # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### # ##### # #### ##### ######### # ##### # ##### # ### ##### ### # # ### # ####### ##### # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### ### ##### ##### # # ### # ##### # ##### # ####### ######### ##### # # # # ### ### # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # ### # # # ### # ##### ### ### # # ##### # # # ### # # ##### ### ##### ### ########### ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ### ########### # # ### # ### # # ### # ### # ##### # ####### #### ## # ### ######### ####### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ####### ### # # # ### # ### ################# ############# # ### ## ### ## # ### ### # # # # ####
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
####### ### ### ##### ### # # ########### # ####### ### # ### # ##### # # ##### ### # ### ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### # # ### ####### # # ##### ### # ### ### # ### # # # # ##### # # ########### # ##### # # ######
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ##### #### # # # # # # ## ## # # ### ##### ### # ####### ### ####### # # # # ### # # ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ## # # # ### ####### # # # ##### # # ## # # # ######### ### ####### # ### ### # # # ### # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### ### # # ##### # ### ##### # ### ### ### ##### # # # ### ###### ##### # # # # ##### ### # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### # ######### # ######### ### # ## #### ### ############### # ########### ######### ## # # ##
|
||||||
|
# # # # # # # # # # # # # # # # ##
|
||||||
|
# ####### # # ##### ### # #### # ### # ### # # # ############# # # # # # # # ####### ### # # ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
####### ### ### # # ##### # # ### # # ### ##### ########### # ### ####### ####### # # ### # # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### ## ##### ###### ## # ##### ### ### ##### ### ############# # ### # ##### ####### ### ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ### ## ###### # # # #### ### ### # # # ####### # ##### # ### # ####### ### ### ### ### ######
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### # # ##### # ###### #### # # ### # # # # ### # # # ######### # ### ### # # ## ## # ### # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ### ### # ##### # ## # # # ### ##### # # # # # # # ### #### # ### # # ####### # # # ### # ####
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### ### ### # ### # ####### # ### # # ##### # ### # ### # ##### ### ### # ##### # ### # ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### ### # # ### # # # #### ## # # # ### # # ### # ### ### ### # # # # # ####### ######### # ####
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # # # ##### # # ### # ### # # ### # ### # # # ### ### ############# # ### # ######### # ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### # # # # # ##### ### # # # # # # ##### # # # ##### # ##### # # ## # ### # # # ### ##### ####
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
### ##### ### ### # # # ### # ### # # ### # ### # # # # ### ### # # # ### ####### ## ## ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # # ## ### # ##### # # ### # # ##### # ### ### # # ### ### ##### ### # ##### ## ### ####### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ####### ### ### # ####### ####### # # ### # # ####### ### ### # # # ##### ##### ### ### # # ####
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ####### ####### ### # ### ### # # # ##### ########## # # # ####### # # ######### # # ### # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # # # ##### # ### ##### ### ##### # ##### ### # # # ### # ### # ### # # #### ## ### ### # # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # ##### ### ####### ##### ### # ### ## ### # # # ####### # # # # # ##### ##### # ### # ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
##### # # ### ### # # # ##### # # # ### # # # # ##### ### # ### # # # # ##### # ### # ### # # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ### # # ##### # ############ # ##### # #### ## # ##### # # ######### # ####### ## # # # # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### # ##### # ### ### # # ##### # ############### # # ### ######### # ### # ##### ### # ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # # ### # # # # ## ### ##### # ### ## ######## ### ########## # # ### # # ####### ### ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### # # # ### ##### ##### # # # ############### ######### ### # # ################ # # ### ######
|
||||||
|
# # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # ### ### ######### # # # ####### ### #### # ### ##### ######### # # # ##### # ##### # ########
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
### # # # ##### # # # # # # # ### # # ### # ### # ## # ## # ####### ######### ##### # # # ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### ##### # # ### ### ### # ##### # # # ### # ############ ## ######### ### # ### ### # # # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ##### # # ##### # ### # #### ### # ######### ### # # ##### # ### ### # ### ### #### ## # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ##### ### #### # # ########### ### # # # # # # # ### # # # # # # ### # ### ##### ### # ### # # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # # # ### # ### # # ####### #### ######### ####### ### ####### # # ####### ### ### # ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ##### ##### # ####### ### ################# # # ### # # ### # # ### # # ### # ######### ##### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
### # ### # # ##### # # # # ### ### # ##### ####### ### ### # # ### ####### ####### ### ##########
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ######### # ##### ### ############# # ####### ##### ### ### # # ### # ### ##### # # ### ### # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # # # # ##### ##### # ######### # ### ### ### # ####### # # ### # ####### ##### ### # ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### # # # ##### # ###### #### # ##### # ### # # ### ######### ### ####### # ### ### ### ####### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # ########### ### # ##### # # # # # ### # ### ### ### ##### ### ##### # ####### # ###### # # ####
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# # # ###### # ### # # ########### ## ### ##### # # # # # # # # # ########### ### ######### ### ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
# ### ### # ### # ### # # ### # # ### # ### # ### # ##### # # # # ### # # ###### # ### # # ### # ##
|
||||||
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # ##
|
||||||
|
### # # ##### ##### ### # # ####### ##### # # # ########### ######### ### # # ### ##### # # # # ##
|
||||||
|
# # # # # # # # E##
|
||||||
|
####################################################################################################
|
||||||
|
####################################################################################################
|
||||||
50
SolovevDS/docs/data/data_for_task2/maze50.txt
Normal file
50
SolovevDS/docs/data/data_for_task2/maze50.txt
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
##################################################
|
||||||
|
#S # # # # # ##
|
||||||
|
##### ##### ### ######### ### ### # ### # ### # ##
|
||||||
|
# # # # # # # # # # # # ##
|
||||||
|
### ######### ############# ### # # # ##### ### ##
|
||||||
|
# # # # # # # # # # ##
|
||||||
|
# ########### # ### # # ##### # ##### # ### # ##
|
||||||
|
# # # # # # # # # # # ##
|
||||||
|
### # # ### ### # ### # ######### # ####### ### ##
|
||||||
|
# # # # # # # # # # ##
|
||||||
|
# ##### # ### ##### # ##### ##### ########### ####
|
||||||
|
# # # # # # # # # # ##
|
||||||
|
##### # ### ##### # ########### ##### ##### ### ##
|
||||||
|
# # # # # # # # # # ##
|
||||||
|
# ####### # ####### # ####### ### # ### # ### # ##
|
||||||
|
# # # # # # # # # # # # ##
|
||||||
|
# # # # ################### # # ### # # # ### # ##
|
||||||
|
# # # # # # # # # # # # # ##
|
||||||
|
### # ### ### # # ########### ### # # # ### ### ##
|
||||||
|
# # # # # # # # # # # # # # ##
|
||||||
|
# ##### ### ######### ##### ### # ### # # ### # ##
|
||||||
|
# # # # # # # # # # # # # ##
|
||||||
|
# # # ####### ### ### # ### # # ### # # # # # ####
|
||||||
|
# # # # # # # # # # # # # # ##
|
||||||
|
# # ########### ####### # ### # # ######### ### ##
|
||||||
|
# # # # # # # # ##
|
||||||
|
# ### ####### # ##### ##### # ####### ### ### ####
|
||||||
|
# # # # # # # # # # # # ##
|
||||||
|
# ######### ####### # # # # ### # ####### # ### ##
|
||||||
|
# # # # # # # # # # # # ##
|
||||||
|
### # ### ##### ####### # # # # ### # # ####### ##
|
||||||
|
# # # # # # # # # # # # # # ##
|
||||||
|
# # # # ### # ####### # # # ##### # # ### ### # ##
|
||||||
|
# # # # # # # # # # # # # # # # ##
|
||||||
|
# # # ######### # # # ### ### ### ### # ### # # ##
|
||||||
|
# # # # # # # # # # # # # ##
|
||||||
|
# ### # ####### # ######### # ####### ### # ### ##
|
||||||
|
# # # # # # # # # # # # # ##
|
||||||
|
# ##### # # # ##### # # ####### ### # # ### # ####
|
||||||
|
# # # # # # # # # # # # # # ##
|
||||||
|
##### ### # # # ##### ########### # # # # # ### ##
|
||||||
|
# # # # # # # # # # # ##
|
||||||
|
# ############# # ### ##### ##### # ### # ##### ##
|
||||||
|
# # # # # # # # # # # ##
|
||||||
|
# # ####### ### # # ### # ### ### ### # ##### # ##
|
||||||
|
# # # # # # # # # # # # # ##
|
||||||
|
# ##### ##### ### # # ##### ### ### ##### ##### ##
|
||||||
|
# # # # # # E##
|
||||||
|
##################################################
|
||||||
|
##################################################
|
||||||
50
SolovevDS/docs/data/data_for_task2/maze_empty.txt
Normal file
50
SolovevDS/docs/data/data_for_task2/maze_empty.txt
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
S
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
E
|
||||||
10
SolovevDS/docs/data/data_for_task2/maze_no_path.txt
Normal file
10
SolovevDS/docs/data/data_for_task2/maze_no_path.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
##########
|
||||||
|
#S #
|
||||||
|
# ###### #
|
||||||
|
# # # #
|
||||||
|
# # ## # #
|
||||||
|
# # ## # #
|
||||||
|
# # # #
|
||||||
|
# ########
|
||||||
|
# #E#
|
||||||
|
##########
|
||||||
1536
SolovevDS/docs/data/data_for_task2/path_length_comparison.svg
Normal file
1536
SolovevDS/docs/data/data_for_task2/path_length_comparison.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 38 KiB |
16
SolovevDS/docs/data/data_for_task2/results.csv
Normal file
16
SolovevDS/docs/data/data_for_task2/results.csv
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
maze,strategy,time_ms,cells_visited,way_len
|
||||||
|
small_10,BFS,0.00724,31.00000,21.00000
|
||||||
|
small_10,DFS,0.00360,31.00000,21.00000
|
||||||
|
small_10,AStar,0.00519,24.00000,21.00000
|
||||||
|
medium_50,BFS,0.04465,505.00000,145.00000
|
||||||
|
medium_50,DFS,0.03666,385.00000,361.00000
|
||||||
|
medium_50,AStar,0.05370,319.00000,145.00000
|
||||||
|
large_100,BFS,0.44010,4534.00000,245.00000
|
||||||
|
large_100,DFS,0.09760,816.00000,703.00000
|
||||||
|
large_100,AStar,0.37331,1298.00000,245.00000
|
||||||
|
empty,BFS,0.15303,2500.00000,99.00000
|
||||||
|
empty,DFS,0.09335,1275.00000,1275.00000
|
||||||
|
empty,AStar,0.17047,341.00000,99.00000
|
||||||
|
no_path,BFS,0.00259,25.00000,0.00000
|
||||||
|
no_path,DFS,0.00244,25.00000,0.00000
|
||||||
|
no_path,AStar,0.00494,25.00000,0.00000
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <chrono> /*мерит время*/
|
#include <chrono> /*мерит время*/
|
||||||
#include <cstdlib> /*волшебная отрисовка*/
|
#include <cstdlib> /*волшебная отрисовка*/
|
||||||
|
#include <iomanip>
|
||||||
|
#include <windows.h>
|
||||||
|
#include <clocale>
|
||||||
|
|
||||||
class cell{
|
class cell{
|
||||||
private:
|
private:
|
||||||
|
|
@ -41,7 +44,6 @@ class cell{
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class maze{
|
class maze{
|
||||||
private:
|
private:
|
||||||
int width;
|
int width;
|
||||||
|
|
@ -174,8 +176,6 @@ class TextFileMazeBuilder : public MazeBuilder {
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
|
|
||||||
// ДОБАВИЛ: первый проход по файлу.
|
|
||||||
// Здесь узнаём ширину и высоту лабиринта.
|
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
if (height == 0) {
|
if (height == 0) {
|
||||||
width = line.length();
|
width = line.length();
|
||||||
|
|
@ -248,13 +248,7 @@ class TextFileMazeBuilder : public MazeBuilder {
|
||||||
if (!hasExit)
|
if (!hasExit)
|
||||||
throw std::runtime_error("Ошибка: в лабиринте нет выхода!");
|
throw std::runtime_error("Ошибка: в лабиринте нет выхода!");
|
||||||
return labirint;
|
return labirint;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// прочитать символы
|
|
||||||
// создать клетки
|
|
||||||
// вернуть готовый Maze
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -640,7 +634,6 @@ class MazeSolver{
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
std::chrono::duration<double, std::milli> duration = end - start;
|
std::chrono::duration<double, std::milli> duration = end - start;
|
||||||
|
|
||||||
|
|
||||||
int pathLength = 0;
|
int pathLength = 0;
|
||||||
|
|
||||||
if (path[0] != nullptr)
|
if (path[0] != nullptr)
|
||||||
|
|
@ -847,9 +840,95 @@ class ConsolController{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Benchmark {
|
||||||
|
private:
|
||||||
|
int RUNS = 10;
|
||||||
|
public:
|
||||||
|
Benchmark(int runs) {this->RUNS = runs;}
|
||||||
|
void benchmark(){
|
||||||
|
std::string mazeFiles[] = {
|
||||||
|
"SolovevDS/docs/data/data_for_task2/maze10.txt",
|
||||||
|
"SolovevDS/docs/data/data_for_task2/maze50.txt",
|
||||||
|
"SolovevDS/docs/data/data_for_task2/maze100.txt",
|
||||||
|
"SolovevDS/docs/data/data_for_task2/maze_empty.txt",
|
||||||
|
"SolovevDS/docs/data/data_for_task2/maze_no_path.txt"
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string mazeNames[] = {
|
||||||
|
"small_10",
|
||||||
|
"medium_50",
|
||||||
|
"large_100",
|
||||||
|
"empty",
|
||||||
|
"no_path"
|
||||||
|
};
|
||||||
|
|
||||||
|
std::ofstream csv("SolovevDS/docs/data/data_for_task2/results.csv");
|
||||||
|
|
||||||
|
if (!csv.is_open())
|
||||||
|
throw std::runtime_error("Ошибка: не удалось создать results.csv!");
|
||||||
|
|
||||||
|
csv << "maze,strategy,time_ms,cells_visited,way_len\n";
|
||||||
|
|
||||||
|
TextFileMazeBuilder builder;
|
||||||
|
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
maze* labirint = builder.buildFromFile(mazeFiles[i]);
|
||||||
|
|
||||||
|
MazeSolver solver(labirint);
|
||||||
|
|
||||||
|
BFSStrategy bfs;
|
||||||
|
DFSStrategy dfs;
|
||||||
|
AStarStrategy astar;
|
||||||
|
|
||||||
|
PathFindingStrategy* strategies[] = {&bfs, &dfs, &astar};
|
||||||
|
std::string strategyNames[] = {"BFS", "DFS", "AStar"};
|
||||||
|
|
||||||
|
for (int s = 0; s < 3; s++) {
|
||||||
|
double sumTime = 0;
|
||||||
|
double sumVisited = 0;
|
||||||
|
double sumPathLength = 0;
|
||||||
|
|
||||||
|
for (int run = 0; run < RUNS; run++) {
|
||||||
|
solver.setStrategy(strategies[s]);
|
||||||
|
|
||||||
|
SearchStats stats = solver.solve();
|
||||||
|
|
||||||
|
sumTime += stats.timeMs;
|
||||||
|
sumVisited += stats.visitedCells;
|
||||||
|
sumPathLength += stats.pathLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
double avgTime = sumTime / RUNS;
|
||||||
|
double avgVisited = sumVisited / RUNS;
|
||||||
|
double avgPathLength = sumPathLength / RUNS;
|
||||||
|
|
||||||
|
csv << mazeNames[i] << ","
|
||||||
|
<< strategyNames[s] << ","
|
||||||
|
<< std::fixed << std::setprecision(5) << avgTime << ","
|
||||||
|
<< avgVisited << ","
|
||||||
|
<< avgPathLength << "\n";
|
||||||
|
}
|
||||||
|
delete labirint;
|
||||||
|
}
|
||||||
|
|
||||||
|
csv.close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
SetConsoleCP(CP_UTF8);
|
||||||
|
SetConsoleOutputCP(CP_UTF8);
|
||||||
|
setlocale(LC_ALL, ".UTF-8");
|
||||||
|
Benchmark ben(10);
|
||||||
|
ben.benchmark();
|
||||||
|
|
||||||
}
|
TextFileMazeBuilder builder;
|
||||||
|
maze* labirint = builder.buildFromFile("SolovevDS/docs/data/data_for_task2/maze10.txt");
|
||||||
|
Player player(labirint->getStart());
|
||||||
|
ConsolController controller(labirint, &player);
|
||||||
|
controller.run();
|
||||||
|
delete labirint;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
1582
SolovevDS/docs/data/data_for_task2/time_comparison.svg
Normal file
1582
SolovevDS/docs/data/data_for_task2/time_comparison.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 41 KiB |
1530
SolovevDS/docs/data/data_for_task2/visited_cells_comparison.svg
Normal file
1530
SolovevDS/docs/data/data_for_task2/visited_cells_comparison.svg
Normal file
File diff suppressed because it is too large
Load Diff
|
After Width: | Height: | Size: 39 KiB |
BIN
SolovevDS/docs/laba_2_report.pdf
Normal file
BIN
SolovevDS/docs/laba_2_report.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user