-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tree.py
36 lines (32 loc) · 919 Bytes
/
Tree.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
import helper
#MAKE SEARCH TREE
class Node:
def __init__(self, name, time, successors = None, path = []):
self.name = name
self.time = time
self.successors = successors
self.path = path
def add_path(self, old_path, node):
self.path = old_path[:]
self.path.append(node.time)
def add_successors(self, successors):
self.successors = successors
def makeTree(pieces):
#create start node
start = Node('start', None)
current = [start]
#order the domain
ordered = helper.time_counts(pieces)
number_nodes = 1
for p in helper.order(pieces):
successors = []
times = sorted(p.times, key = lambda x: ordered[x])
for t in times:
new_node = Node(p.choreographer, t)
successors.append(new_node)
for c in current:
c.add_successors(successors)
number_nodes *= len(successors)
current = successors
print ('This tree has a total of {} nodes to explore'.format(number_nodes))
return start