-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (29 loc) · 774 Bytes
/
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
from graph import Node, W, dijkstra
from random import Random
from draw import drawGraph, drawDijkstraGraph
rng = Random()
rng.seed = "A"
# Gen random nodes
NODECOUNT = 20
EXTRAEDGECOUNT = 2
MAXX, MAXY = 1000,1000
nodes = []
for i in range(NODECOUNT):
nodes += [Node(rng.randint(0, MAXX), rng.randint(0, MAXY))]
edges = []
for i in nodes:
while True:
a = rng.choice(nodes)
if a != i:
break
edges += [(i,a)]
for i in range(EXTRAEDGECOUNT):
a, b = None, None
while a == b and not (a,b) in edges:
a, b = rng.choice(nodes), rng.choice(nodes)
edges += [(a, b)]
for n in nodes:
n.calc_adjacent(edges)
dijkstra(nodes, edges, nodes[0], nodes[-1])
drawDijkstraGraph(nodes,edges,nodes[-1].get_path_to_root())
input()