forked from gabriel301/DiscreteOptimizationCoursera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTree.py
37 lines (28 loc) · 1.01 KB
/
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
37
from Preprocessing import Preprocessing
class Tree:
def __init__(self,treeRoot):
self.Root = None
self.Nodes = {}
self.Cost = 0
self.setRoot(treeRoot)
def setRoot(self,newRoot):
if self.Root is not None:
self.Cost = self.Cost - self.Root.setup_cost
self.Root = newRoot
self.Cost = self.Cost + self.Root.setup_cost
def addNode(self,node):
self.Nodes[node.index] = node
self.Cost = self.Cost + Preprocessing.getEuclideanDistance(self.Root.location,node.location)
def removeNode(self,node):
if node.index in self.Nodes.keys():
self.Cost = self.Cost - Preprocessing.getEuclideanDistance(self.Root.location,node.location)
self.Nodes.pop(node.index, None)
def clearNodes(self):
self.Nodes.clear()
self.Cost = self.Root.setup_cost
def getRoot(self):
return self.Root
def getCost(self):
return self.Cost
def getNodes(self):
return self.Nodes