forked from UNN/2026-rff_mp
lab_2 graphics, doc finished
This commit is contained in:
parent
bbd059e8b2
commit
19f9b5403c
|
|
@ -1,59 +1,29 @@
|
|||
#Графики
|
||||
import csv
|
||||
import matplotlib.pyplot as plt
|
||||
import pandas as pd
|
||||
|
||||
data = []
|
||||
df = pd.read_csv('results.csv', header=None, names=['lab','strategy','timeMs','cellsVisited','pathLength'])
|
||||
|
||||
with open('results.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
for row in reader:
|
||||
data.append(row)
|
||||
print(df)
|
||||
|
||||
print(data)
|
||||
df_time = df.pivot(index='lab', columns='strategy', values=['timeMs','cellsVisited','pathLength'])
|
||||
|
||||
labs = ['10x10','50x50','100x100','empty','no exit']
|
||||
algorythms = ['BFS','DFS','Astar']
|
||||
valuetypes = ['timeMs','cellsVisited','passLength']
|
||||
print(df_time)
|
||||
|
||||
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()
|
||||
# 1. График только для Времени
|
||||
df_time["timeMs"].plot(kind="bar", figsize=(10, 5), rot=0)
|
||||
plt.title("Время работы стратегий (мс)")
|
||||
plt.ylabel("timeMs")
|
||||
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()
|
||||
# 2. График для Посещенных клеток
|
||||
df_time["cellsVisited"].plot(kind="bar", figsize=(10, 5), rot=0)
|
||||
plt.title("Количество посещенных клеток")
|
||||
plt.ylabel("cellsVisited")
|
||||
plt.show()
|
||||
|
||||
# 3. График для Длины пути
|
||||
df_time["pathLength"].plot(kind="bar", figsize=(10, 5), rot=0)
|
||||
plt.title("Длина найденного пути")
|
||||
plt.ylabel("pathLength")
|
||||
plt.show()
|
||||
|
|
@ -266,7 +266,7 @@ class Astar(PathFindingStrategy):
|
|||
cell = pathmap[cell.coords]
|
||||
path.append(st)
|
||||
path = path[::-1]
|
||||
self.visited = self.g_score #экий костыль
|
||||
self.visited = set(self.g_score.keys()) #экий костыль
|
||||
return path
|
||||
|
||||
for n in maze.getNeighbors(cell):
|
||||
|
|
@ -287,7 +287,7 @@ class Astar(PathFindingStrategy):
|
|||
heapq.heappush(hp_queue, (full_score, c, n))
|
||||
hp_queue_coords.add(n.coords)
|
||||
|
||||
self.visited = self.g_score #экий костыль 2: возвращение ситхов
|
||||
self.visited = set(self.g_score.keys()) #экий костыль 2: возвращение ситхов
|
||||
return None
|
||||
|
||||
# path = Astar().findPath(maze,maze.st,maze.ex)
|
||||
|
|
@ -339,7 +339,7 @@ class MazeSolver():
|
|||
for observer in self.observers:
|
||||
observer.update(MazeEvent('path_found',self.maze,None,path))
|
||||
|
||||
return SearchStats(elapsed, visitedCells, pathLength)
|
||||
return SearchStats(elapsed*1000, visitedCells, pathLength)
|
||||
|
||||
# MS = MazeSolver(maze, DFS())
|
||||
# Stats = MS.solve()
|
||||
|
|
@ -581,13 +581,13 @@ for strategy in range(3):
|
|||
|
||||
MS = MazeSolver(maze, strategyList[strategy])
|
||||
|
||||
for j in range(5):
|
||||
for j in range(10):
|
||||
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.])
|
||||
res.append([labNamesList[i-1],sNamesList[strategy],sum(subres1)/10., sum(subres2)/10., sum(subres3)/10.])
|
||||
|
||||
print(res)
|
||||
|
||||
|
|
|
|||
128
GutovVM/docs/data/lab_2_data/mermaid diagram.txt
Normal file
128
GutovVM/docs/data/lab_2_data/mermaid diagram.txt
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
classDiagram
|
||||
|
||||
class Cell{
|
||||
+tuple coords
|
||||
+bool isWall
|
||||
+bool isStart
|
||||
+bool isExit
|
||||
+isPassable(): bool
|
||||
}
|
||||
|
||||
class Maze{
|
||||
+np.array cells
|
||||
+int width
|
||||
+int height
|
||||
+Cell st
|
||||
+Cell ex
|
||||
+getCell(x,y): Cell
|
||||
+getNeighbors(cell): List~Cell~
|
||||
}
|
||||
|
||||
class MazeBuilder{
|
||||
<<interface>>
|
||||
+buildFromFile(filename): Maze
|
||||
}
|
||||
|
||||
class TextFileMazeBuilder{
|
||||
+buildFromFile(filename): Maze
|
||||
}
|
||||
|
||||
MazeBuilder <|.. TextFileMazeBuilder
|
||||
|
||||
class PathFindingStrategy{
|
||||
<<interface>>
|
||||
+findPath(maze,st,ex): list~Cell~
|
||||
}
|
||||
|
||||
class BFS{
|
||||
+set~tuple~ visited
|
||||
+findPath(maze,st,ex): list~Cell~
|
||||
}
|
||||
|
||||
class DFS{
|
||||
+set~tuple~ visited
|
||||
+findPath(maze,st,ex): list~Cell~
|
||||
}
|
||||
|
||||
class Astar{
|
||||
+dict~tuple, int~
|
||||
+set~tuple~ visited
|
||||
+findPath(maze,st,ex): list~Cell~
|
||||
}
|
||||
|
||||
PathFindingStrategy <|.. BFS
|
||||
PathFindingStrategy <|.. DFS
|
||||
PathFindingStrategy <|.. Astar
|
||||
|
||||
class SearchStats{
|
||||
+float timeMs
|
||||
+int visitedCells
|
||||
+int pathLength
|
||||
}
|
||||
|
||||
class MazeSolver{
|
||||
+Maze maze
|
||||
+PathFindingStrategy strategy
|
||||
+list~ConsoleView~ observers
|
||||
+setStrategy(strategy)
|
||||
+solve(): SearchStats
|
||||
}
|
||||
|
||||
class MazeEvent{
|
||||
+string event_type
|
||||
+Maze maze
|
||||
+tuple player_position
|
||||
+list~tuple~ path
|
||||
}
|
||||
|
||||
class Observer{
|
||||
<<interface>>
|
||||
+update(event)
|
||||
}
|
||||
|
||||
class ConsoleView{
|
||||
+Maze maze
|
||||
+tuple player_position
|
||||
+list~tuple~ path
|
||||
+update(event)
|
||||
+render(maze,player_position,path)
|
||||
}
|
||||
|
||||
class Command{
|
||||
<<interface>>
|
||||
+execute()
|
||||
+undo()
|
||||
}
|
||||
|
||||
class MoveCommand{
|
||||
+tuple previousCell
|
||||
+execute(player,direction)
|
||||
+undo(player)
|
||||
}
|
||||
|
||||
Command <|.. MoveCommand
|
||||
|
||||
class Player{
|
||||
+tuple currentCell
|
||||
+moveTo(cell)
|
||||
}
|
||||
|
||||
class Direction{
|
||||
+tuple dir
|
||||
}
|
||||
|
||||
MazeSolver --> PathFindingStrategy: uses
|
||||
MazeBuilder --> Maze: creates
|
||||
Maze --> Cell: contains
|
||||
ConsoleView ..|> Observer
|
||||
MazeSolver --> Observer: notifies
|
||||
MazeSolver --> MazeEvent: creates
|
||||
Observer --> MazeEvent: accepts
|
||||
MoveCommand --> Player: moves
|
||||
MoveCommand --> Direction: uses
|
||||
ConsoleView --> Player: accepts position
|
||||
ConsoleView --> Maze: renders
|
||||
MazeSolver --> SearchStats: returns
|
||||
MazeSolver --> Maze: accepts
|
||||
MazeEvent --> Player: stores position
|
||||
Player --> Cell: saves coords
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 777 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 92 KiB |
|
|
@ -1,15 +0,0 @@
|
|||
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
|
||||
|
16
GutovVM/docs/data/lab_2_data/results copy 28 05 26.csv
Normal file
16
GutovVM/docs/data/lab_2_data/results copy 28 05 26.csv
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
ëàáèðèíò;ñòðàòåãèÿ;âðåìÿ_ìñ;ïîñåùåíî_êëåòîê (ñð);äëèíà_ïóòè (ñð)
|
||||
10x10;BFS;0.08966999594122171;36;21
|
||||
50x50;BFS;2.187670022249222;1020;501
|
||||
100x100;BFS;8.31503001973033;4172;414
|
||||
empty;BFS;5.047210049815476;2500;99
|
||||
no exit;BFS;2.197379991412163;1072;0
|
||||
10x10;DFS;0.09059999138116837;37;21
|
||||
50x50;DFS;1.264189975336194;593;581
|
||||
100x100;DFS;5.151620041579008;2384;1122
|
||||
empty;DFS;3.3813500544056296;2500;1275
|
||||
no exit;DFS;2.2671299753710628;1072;0
|
||||
10x10;Astar;0.11618996504694223;33;21
|
||||
50x50;Astar;2.8455600142478943;973;501
|
||||
100x100;Astar;9.197140019387007;2980;414
|
||||
empty;Astar;7.771430024877191;2500;99
|
||||
no exit;Astar;3.192879958078265;1072;0
|
||||
|
|
|
@ -1,15 +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
|
||||
10x10,BFS,0.08966999594122171,36.0,21.0
|
||||
50x50,BFS,2.187670022249222,1020.0,501.0
|
||||
100x100,BFS,8.31503001973033,4172.0,414.0
|
||||
empty,BFS,5.047210049815476,2500.0,99.0
|
||||
no exit,BFS,2.197379991412163,1072.0,0.0
|
||||
10x10,DFS,0.09059999138116837,37.0,21.0
|
||||
50x50,DFS,1.264189975336194,593.0,581.0
|
||||
100x100,DFS,5.151620041579008,2384.0,1122.0
|
||||
empty,DFS,3.3813500544056296,2500.0,1275.0
|
||||
no exit,DFS,2.2671299753710628,1072.0,0.0
|
||||
10x10,Astar,0.11618996504694223,33.0,21.0
|
||||
50x50,Astar,2.8455600142478943,973.0,501.0
|
||||
100x100,Astar,9.197140019387007,2980.0,414.0
|
||||
empty,Astar,7.771430024877191,2500.0,99.0
|
||||
no exit,Astar,3.192879958078265,1072.0,0.0
|
||||
|
|
|
|||
|
BIN
GutovVM/docs/otchet2.docx
Normal file
BIN
GutovVM/docs/otchet2.docx
Normal file
Binary file not shown.
BIN
GutovVM/docs/otchet2.pdf
Normal file
BIN
GutovVM/docs/otchet2.pdf
Normal file
Binary file not shown.
BIN
GutovVM/docs/~$tchet1.docx
Normal file
BIN
GutovVM/docs/~$tchet1.docx
Normal file
Binary file not shown.
BIN
GutovVM/docs/~$tchet2.docx
Normal file
BIN
GutovVM/docs/~$tchet2.docx
Normal file
Binary file not shown.
BIN
GutovVM/docs/~WRL0005.tmp
Normal file
BIN
GutovVM/docs/~WRL0005.tmp
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user