-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
76 lines (60 loc) · 2.18 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from heapq import heappop, heappush
import itertools
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
class PriorityQueue():
REMOVED = '<removed-task>'
def __init__(self):
self.pq = []
self.entry_finder = {}
self.counter = itertools.count()
def add_task(self, task, priority=0):
if task in self.entry_finder:
self.remove_task(task)
count = next(self.counter)
entry = [priority, count, task]
self.entry_finder[task] = entry
heappush(self.pq, entry)
def remove_task(self, task):
entry = self.entry_finder.pop(task)
entry[-1] = self.REMOVED
def pop_task(self):
while self.pq:
priority, count, task = heappop(self.pq)
if task is not self.REMOVED:
del self.entry_finder[task]
return task
return None
class ComputationProgress():
def __init__(self):
self.latest_iteration = st.empty()
self.bar = st.progress(0)
def update(self, iteration, maximum):
self.latest_iteration.text(f'Discovered {iteration} out of {maximum} states in the search space')
self.bar.progress(int(iteration*100/maximum))
def done(self):
self.latest_iteration.markdown('## Done')
self.bar.progress(100)
def fail(self):
self.latest_iteration.text('No Path is found')
class AnalysisGraph():
filename = "./analysis.csv"
def __init__(self, name):
self.name = name
try:
self.df = pd.read_csv(self.filename)
except FileNotFoundError:
self.df = pd.DataFrame({"name": [], "depth_len": [], "visited_len": []})
def update(self, depth_len, visited_len):
self.df = self.df.append(
{"name": self.name, "depth_len": depth_len, "visited_len": visited_len},
ignore_index=True
)
self.df.to_csv(self.filename, index=False)
def done(self):
st.write("Performance report:")
st.write(self.name)
self.df[self.df["name"] == self.name]\
.plot(kind='scatter', x='depth_len',y='visited_len',color='blue')
st.pyplot(plt)