-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
65 lines (53 loc) · 1.51 KB
/
main.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
from Node import Node
from path import Path
from Graph import Graph
if __name__ == '__main__':
# defining nodes
a = Node('A')
b = Node('B')
c = Node('C')
d = Node('D')
e = Node('E')
f = Node('F')
g = Node('G')
h = Node('H')
# defining path
a.children.append(Path(b, 3))
a.children.append(Path(c, 4))
a.children.append(Path(d, 7))
b.children.append(Path(a, 3))
b.children.append(Path(c, 1))
b.children.append(Path(f, 5))
c.children.append(Path(a, 4))
c.children.append(Path(b, 1))
c.children.append(Path(d, 2))
c.children.append(Path(f, 6))
d.children.append(Path(a, 7))
d.children.append(Path(c, 2))
d.children.append(Path(e, 3))
d.children.append(Path(g, 6))
e.children.append(Path(d, 3))
e.children.append(Path(g, 3))
e.children.append(Path(h, 4))
e.children.append(Path(f, 1))
f.children.append(Path(b, 5))
f.children.append(Path(c, 6))
f.children.append(Path(e, 1))
f.children.append(Path(h, 8))
g.children.append(Path(d, 6))
g.children.append(Path(e, 3))
g.children.append(Path(h, 2))
h.children.append(Path(g, 2))
h.children.append(Path(e, 4))
h.children.append(Path(f, 8))
# Setting up the graph
graph = Graph()
graph.vertices.append(a)
graph.vertices.append(b)
graph.vertices.append(c)
graph.vertices.append(d)
graph.vertices.append(e)
graph.vertices.append(f)
graph.vertices.append(g)
graph.vertices.append(h)
graph.search(a, h)