-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (38 loc) · 1.27 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
from random import randint
class Node:
def __init__(self, idx=0, x=0, y=0, z=0):
self.idx = idx
self.x = x
self.y = y
self.z = z
def __str__(self):
return "%d, %d, %d\n" % (self.x, self.y, self.z)
class Edge:
def __init__(self, node1, node2):
self.node1 = node1
self.node2 = node2
def __str__(self):
return "%d, %d\n" % (self.node1.idx, self.node2.idx)
class RoadNetwork:
def __init__(self):
node_first = Node(0, 1, 1, 1)
node_second = Node(1, 2, 2, 2)
self.nodes = [node_first, node_second]
self.edges = [Edge(node_first, node_second)]
def add_edge(self):
start_node = self.nodes[randint(0, len(self.nodes)-1)]
end_node = Node(len(self.nodes), randint(1,20), randint(1,20), randint(1,20))
self.nodes.append(end_node)
self.edges.append(Edge(start_node, end_node))
def __str__(self):
ret_string = ''
for node in self.nodes:
ret_string += str(node)
for edge in self.edges:
ret_string += str(edge)
return ret_string
if __name__ == '__main__':
road_network = RoadNetwork()
for n in range(10):
road_network.add_edge()
print road_network