-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGraph.py
More file actions
72 lines (60 loc) · 2.03 KB
/
Graph.py
File metadata and controls
72 lines (60 loc) · 2.03 KB
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
66
67
68
69
70
71
72
"""
Graph
- Is a container for Nodes and edges.
- these nodes can be connected, with edges, or can be individual islands( nodes with edges, that are not all connected)
TODO:
- setup two graph evaluation types, 1. Directional eg.ICE, 2. All Node Evaluating eg.Dependency Graph
- a good way of finding islands in the nodes
"""
import Node as mNode
class Graph(object):
def __init__(self):
self.nodes = []
def createNode(self, classType):
"""
Creates a node of the class type passed in.
Returns:
mNode.Node: the newly created node
"""
node = classType()
self.nodes.append(node)
return node
def getNetworkHeads(self):
"""
Returns the head nodes of all the networks(islands) in this graph
Returns:
[]: of nodes
"""
nodesWithNoConnectedOutput = []
for node in self.nodes:
if not node.isConnected():
nodesWithNoConnectedOutput.append(node)
else:
connected = False
for port in node.portsOut:
if port.isConnected():
connected = True
if not connected:
nodesWithNoConnectedOutput.append(node)
return nodesWithNoConnectedOutput
def getNetworkTails(self):
"""
Returns the tail nodes of all the networks(islands) in this graph
Returns:
[]: of nodes
"""
nodesWithNoConnectedInput = []
for node in self.nodes:
if not node.isConnected():
nodesWithNoConnectedInput.append(node)
else:
connected = False
for port in node.portsIn:
if port.isConnected():
connected = True
if not connected:
nodesWithNoConnectedInput.append(node)
return nodesWithNoConnectedInput
def evaluate(self):
for head in self.getNetworkHeads():
head.evaluate()