-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaze_Components.py
More file actions
executable file
·67 lines (56 loc) · 1.73 KB
/
Maze_Components.py
File metadata and controls
executable file
·67 lines (56 loc) · 1.73 KB
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
from PHeap import PHeap
class Vertex:
def __init__(self, value):
self.value = value
self.label = "UNEXPLORED"
self.distance = 2**60
self.edges = []
self.prev = None
self.heuristic = -1
def connection(self, w):
for e in self.edges:
if e.opposite(self) == w:
return e
return None
def __eq__(self, v):
try:
return self.value == v.value
except AttributeError:
return False
class Edge:
def __init__(self, u, v, weight = 0):
self.ends = (u, v)
self.label = "UNEXPLORED"
self.weight = weight
self.middle = []
def opposite(self, node):
if self.ends[0] == node:
return self.ends[1]
else:
return self.ends[0]
class Graph:
'''
Class made of vertices and edges. vertices are stored in a dict, and ordered in a Priority Queue
'''
def __init__(self):
self.vertices = {}
self.edges = []
self.end = None
self.Heap = PHeap()
def smallest(self):
s_v = None
s_weight = 2**63 + 1
for k, v in self.vertices.items():
if(v.distance < s_weight and v.label == "UNEXPLORED"):
s_v = v
s_weight = v.distance
return s_v
def smallestHeap(self):
while not self.Heap.isEmpty():
value = self.Heap.removeMin()
retval = self.vertices.get(value[1])
if retval is not None:
return retval
return None
def __str__(self):
return "Vertices: {}\nEdges: {}".format(len(self.vertices), len(self.edges))