main full ver, graphics unfinished

This commit is contained in:
gutovvm 2026-05-27 01:45:20 +03:00
parent 2360b42a88
commit bbd059e8b2
9 changed files with 394 additions and 3 deletions

View File

@ -0,0 +1,10 @@
##########
#S# #
# # #### #
# # # #
### # ## #
# # #
# ##### ##
# # #
##### ##E#
##########

View File

@ -0,0 +1,51 @@
###################################################
#S# # # # #
# # ##### # ######### # ##### # ################# #
# # # # # # # # # #
##### # ########### # ### # ############# ####### #
# # # # # # # # #
# ##### # ############# # # # ############# ##### #
# # # # # # # # # # #
# # ##### # ############# # # # ######### ##### # #
# # # # # # # # # # # # #
# # # ##### # ######### # # ##### ##### ##### # # #
# # # # # # # # # # # # #
# # ######### # ##### ########### # # # # ##### # #
# # # # # # # # # # #
# ############# ### # # ########### ##### # ##### #
# # # # # # #
############### # ### ########### ############### #
# # # # # # #
# ############# ### # # ##### # ######### # ##### #
# # # # # # # # # # # # # #
# # ############# ### # # # # # ####### # # # # # #
# # # # # # # # # # # #
# # ############### # ####### ####### # # ####### #
# # # # # # # # # #
# # # ############# ####### ####### # # ####### # #
# # # # # # # # # # # #
# # # # ######### ####### # # ##### # ####### # # #
# # # # # # # # # # # # # #
##### # # ##### ####### # ##### # # # # ### # #####
# # # # # # # # # # # # #
# ##### ##### # # ############# # # # ### # ##### #
# # # # # # # # # # # # #
##### ##### # # # # ############# # ### # ##### # #
# # # # # # # # # # # # #
# # ##### # # # # ################### # ### # ### #
# # # # # # # # # # # # # #
# ##### # # # # # # ############### # ### # ### # #
# # # # # # # # # # # # #
##### # ######### ############### # ### # # ### # #
# # # # # # # # #
# ############# ##################### ####### # # #
# # # # #
############# ######################### ###########
# # # #
# ########### # ####################### # ####### #
# # # # # # #
########### # # # ####################### ####### #
# # # # #
# ########### ################################### #
# E#
###################################################

View File

@ -0,0 +1,97 @@
#####################################################################################################
#S# # # # # #
# # ##### # ################# # ######### # ################# # ################################### #
# # # # # # # # # # # # # #
##### # ############# ####### # # ##### # # # ############# # # # ################################# #
# # # # # # # # # # # # # # # # #
# ##### # ############# ####### # # # # # # # # ############# # # # ############################### #
# # # # # # # # # # # # # # # # # #
# # ##### # ######### ########### # # # # # # ############### # # # # ############################# #
# # # # # # # # # # # # # # # #
# # # ##### # ##### ############### ##### ################# # # # # # ############################# #
# # # # # # # # # # #
# # ############# ######################### ############### # ##### # ############################# #
# # # # # # # # #
# ############### # ####################### # ############# # # ##### # ########################### #
# # # # # # # # # # # #
############### # # # ##################### # # ############# # # ##### # ######################### #
# # # # # # # # # # # # # #
# ############# # # # # ################### # # # ############# # # ##### # ####################### #
# # # # # # # # # # # # # # # # #
# # ############# # # # # ################# # # # # ############# # ##### # # ##################### #
# # # # # # # # # # # # # # # # # #
# # # ############# # # # # ############### # # # ############### # ##### # # # ################### #
# # # # # # # # # # # # # # # #
# # # # ############# ##################### # # ######################### # # # # ################# #
# # # # # # # # # # # # #
# # # # # ################################# # ########################### # # # # # ############### #
# # # # # # # # # # #
# # # ####### ############################### ############################# ####### ############### #
# # # # # # # #
# # ######### # ############################# # ########################### ####### # ############# #
# # # # # # # # # #
# ########### # # ########################### # # ######################### ####### # ############# #
# # # # # # # # # #
############# # # # ######################### # ########################### # ##### # ############# #
# # # # # # # # # # #
# ########### # # # # ####################### ############################# # # ##### # #############
# # # # # # # # # # # # #
# # ######### # # # # # ##################### # ########################### # # # ##### ########### #
# # # # # # # # # # # # # # # # #
# # # ####### # # # # # # ################### # # ######################### # # # # ##### ######### #
# # # # # # # # # # # # # # # # # # #
# # # # ##### # ##### # # # ################# # ########################### # # # # # ##### ####### #
# # # # # # # # # # # # # # # # # # #
# ##### # # # # # ##### # # # ############### ############################# ####### # # ##### ##### #
# # # # # # # # # # # # # # # # # # #
# # ##### # # # # # ##### # # # ############################################# ####### # # # # # ### #
# # # # # # # # # # # # # # # #
# ######### ####### ########### # ############################################# ####### ### # ### # #
# # # # # # # # # # #
########### # ####### ########### # ########################################### ######### # ### # # #
# # # # # # # # # # # #
# ########### # ##### # ########### # ######################################### # ######### ### # # #
# # # # # # # # # # # # # # # #
# # ######### # # # # # # ######### # ######################################### # # ##### ### # # # #
# # # # # # # # # # # # # # # # # # # # #
# # # ####### # # # # # # # ####### # ######################################### # # # # ### # # # # #
# # # # # # # # # # # # # # # # # # #
# ##### ####### ######### # # ##### ########################################### # # # ### # ### # # #
# # # # # # # # # # # # # # #
####### # ############### # # ##### # ######################################### # # ### # ### # # # #
# # # # # # # # # # # # # # # #
# ####### # ############# # ### # ### # ######################################### ### # ### # ### # #
# # # # # # # # # # # # # # # # #
# # ##### # ############### ### # # ### # ######################################### # # ### # ### # #
# # # # # # # # # # # # # # # # #
# # # # ##### ############### # # ##### # # ####################################### # # ### # ### # #
# # # # # # # # # # # # # # # # #
# # # ######### ############# # # # ##### # # ##################################### ##### # ### # # #
# # # # # # # # # # # # # # #
# # ############# ############### # # ##### # # ################################### # ##### ### # # #
# # # # # # # # # # # # # #
# ############### # ############# # # # ##### # # ################################# # # ##### ##### #
# # # # # # # # # # # # # # #
# ################# # ########### # # # # ##### # # ############################### # # # ##### ### #
# # # # # # # # # # # # # # # # #
# # ############### # # ######### # ##### # ##### # # ############################# # # # # ##### # #
# # # # # # # # # # # # # # # # # #
# # # ############# # # # ####### ######### # ##### # # ########################### ####### # ##### #
# # # # # # # # # # # # # # # # # #
# # # # ############# # # # ##### # ####### # # ##### # # ######################### # ####### # #####
# # # # # # # # # # # # # # # # # # # # # # #
# # # # # ########### # # # # # # # # ##### # # # ##### # # ####################### # # ##### # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # ##### # ######### # ##### # # # # # # # # # # # ##### # # ##################### # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # #
# ######### # ######### ############### ######### # ##### # # ##################### ##### # ##### # #
# # # # # # # # # # # # # # # #
########### # ######### # ##################### # # # ##### # # ################### # ##### # # # # #
# # # # # # # # # # # # # # # # # #
# ####################### # ################### # # # # ##### # # ################# # # ##### # # # #
# # # # # # # # # # # # # # # # #
# # ##################### # # ################# ##### # # ##### # # ############### # # # ##### ### #
# # # # # # # # # # # # # # # # # # #
# # # ################### # # # ############### # ##### # # ##### # # ############# # # # # ##### # #
# # # # # # # # # # # # # # # # E
#####################################################################################################

View File

@ -0,0 +1,50 @@
S
E

View File

@ -0,0 +1,51 @@
###################################################
#S# # # # #
# # ##### # ######### # ##### # ################# #
# # # # # # # # # #
##### # ########### # ### # ############# ####### #
# # # # # # # # #
# ##### # ############# # # # ############# ##### #
# # # # # # # # # # #
# # ##### # ############# # # # ######### ##### # #
# # # # # # # # # # # # #
# # # ##### # ######### # # ##### ##### ##### # # #
# # # # # # # # # # # # #
# # ######### # ##### ########### # # # # ##### # #
# # # # # # # # # # #
# ############# ### # # ########### ##### # ##### #
# # # # # # #
############### # ### ########### ############### #
# # # # # # #
# ############# ### # # ##### # ######### # ##### #
# # # # # # # # # # # # # #
# # ############# ### # # # # # ####### # # # # # #
# # # # # # # # # # # #
# # ############### # ####### ####### # # ####### #
# # # # # # # # # #
# # # ############# ####### ####### # # ####### # #
# # # # # # # # # # # #
# # # # ######### ####### # # ##### # ####### # # #
# # # # # # # # # # # # # #
##### # # ##### ####### # ##### # # # # ### # #####
# # # # # # # # # # # # #
# ##### ##### # # ############# # # # ### # ##### #
# # # # # # # # # # # # #
##### ##### # # # # ############# # ### # ##### # #
# # # # # # # # # # # # #
# # ##### # # # # ################### # ### # ### #
# # # # # # # # # # # # # #
# ##### # # # # # # ############### # ### # ### # #
# # # # # # # # # # # # #
##### # ######### ############### # ### # # ### # #
# # # # # # # # #
# ############# ##################### ####### # # #
# # # # #
############# ######################### ###########
# # # #
# ########### # ####################### # ####### #
# # # # # # #
########### # # # ####################### ####### #
# # # # ### #
# ########### ########################### #E# #
# ### #
###################################################

View File

@ -0,0 +1,59 @@
#Графики
import csv
import matplotlib.pyplot as plt
data = []
with open('results.csv', 'r') as f:
reader = csv.reader(f)
for row in reader:
data.append(row)
print(data)
labs = ['10x10','50x50','100x100','empty','no exit']
algorythms = ['BFS','DFS','Astar']
valuetypes = ['timeMs','cellsVisited','passLength']
for lab in labs:
for vtp in range(len(valuetypes)):
X = algorythms
Y = [0.,0.,0.]
for row in data:
if row[0] == lab:
alg = row[1]
if alg == X[0]:
Y[0] = row[2+vtp]
elif alg == X[1]:
Y[1] = row[2+vtp]
elif alg == X[2]:
Y[2] = row[2+vtp]
plt.bar(X,Y)
plt.title(lab + valuetypes[vtp])
plt.ylabel(valuetypes[vtp])
plt.show()
# for dt in types:
# for at in algorythms:
# X = operations
# Y = [0.,0.,0.]
# for row in data:
# if row[1] == dt and row[0] == at:
# if row[2] == X[0]:
# Y[0] = float(row[3])
# elif row[2] == X[1]:
# Y[1] = float(row[3])
# elif row[2] == X[2]:
# Y[2] = float(row[3])
# plt.bar(X,Y,color='g')
# plt.title(dt + at)
# plt.ylabel('Время')
# plt.show()

View File

@ -5,6 +5,7 @@ import heapq
import time
import os
import keyboard
import csv
#Классы клетки и лабиринта
@ -327,10 +328,16 @@ class MazeSolver():
visitedCells = len(self.strategy.visited)
pathLength = len(path)
if path is not None:
pathLength = len(path)
for observer in self.observers:
observer.update(MazeEvent('path_found',self.maze,path[-1].coords,path))
for observer in self.observers:
observer.update(MazeEvent('path_found',self.maze,path[-1].coords,path))
else:
pathLength = 0
for observer in self.observers:
observer.update(MazeEvent('path_found',self.maze,None,path))
return SearchStats(elapsed, visitedCells, pathLength)
@ -504,6 +511,8 @@ class Direction():
def __init__(self, x,y):
self.dir = (x,y)
#Тест системы перемещения клавиатурой :D
builder = TextFileMazeBuilder
maze = builder.buildFromFile('maze1.txt')
@ -551,3 +560,37 @@ keyboard.wait('x')
keyboard.unhook_all()
#Эксперимент
res = []
strategyList = [BFS(),DFS(),Astar()]
sNamesList = ['BFS','DFS','Astar']
labNamesList = ['10x10','50x50','100x100','empty','no exit']
for strategy in range(3):
for i in range(1,6):
subres1 = []
subres2 = []
subres3 = []
maze_name = 'expmaze' + str(i) + '.txt'
maze = TextFileMazeBuilder.buildFromFile(maze_name)
MS = MazeSolver(maze, strategyList[strategy])
for j in range(5):
Stats = MS.solve()
subres1.append(Stats.timeMs)
subres2.append(Stats.visitedCells)
subres3.append(Stats.pathLength)
res.append([labNamesList[i-1],sNamesList[strategy],sum(subres1)/5., sum(subres2)/5., sum(subres3)/5.])
print(res)
with open("results.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerows(res)

View File

@ -0,0 +1,15 @@
10x10;BFS;8.80999956279993e-05;36.0;21.0
50x50;BFS;0.0021232399623841046;1020.0;501.0
100x100;BFS;0.008321480033919216;4172.0;414.0
empty;BFS;0.005303340032696724;2500.0;99.0
no exit;BFS;0.002201080042868853;1072.0;0.0
10x10;DFS;9.08199232071638e-05;37.0;21.0
50x50;DFS;0.0012574800755828619;593.0;581.0
100x100;DFS;0.004624999966472388;2384.0;1122.0
empty;DFS;0.003010439919307828;2500.0;1275.0
no exit;DFS;0.0021919400431215765;1072.0;0.0
10x10;Astar;0.00011409996077418327;33.0;21.0
50x50;Astar;0.002919959928840399;973.0;501.0
100x100;Astar;0.009005780052393674;2980.0;414.0
empty;Astar;0.00798685997724533;2500.0;99.0
no exit;Astar;0.0031794799026101826;1072.0;0.0
Internal Server Error - DRE.lab repo

Internal Server Error

Gitea Version: 1.22.0