def test_SpecifyThatGraphNodeCanBeModified(self): graphNode = GraphNode(index=10) self.assertEqual(10, graphNode.Index, "Index 1") graphNode.Index = 20 self.assertEqual(20, graphNode.Index, "Index 2")
def test_SpecifyThatANodeCanAddedInplaceOfACurrentlyDeactivatedNode(self): sparseGraph = SparseGraph(isDigraph=False) nodeIndex = sparseGraph.GetNextFreeNodeIndex() node = GraphNode(nodeIndex) sparseGraph.AddNode(node) self.assertEqual(1, len(sparseGraph._nodes), "_nodes 1") self.assertEqual(0, sparseGraph._nodes[nodeIndex].Index, "node.Index 1") # Deactivate the node node.Index = NodeType.InvalidNodeIndex self.assertEqual(NodeType.InvalidNodeIndex.value, sparseGraph._nodes[nodeIndex].Index, "node.Index 2") # Add a new node in place of a deactivate node in the graph newNode = GraphNode(nodeIndex) sparseGraph.AddNode(newNode) self.assertEqual(1, len(sparseGraph._nodes), "_nodes 3") self.assertEqual(0, sparseGraph._nodes[nodeIndex].Index, "node.Index 3")
def CreateDigraph(): from HorizonCore.Graph.SparseGraph import SparseGraph from HorizonCore.Graph.GraphEdge import GraphEdge from HorizonCore.Graph.GraphNode import GraphNode sparseGraph = SparseGraph(isDigraph=True) node0 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node0) node0.Index = -1 node1 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node1) node2 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node2) node3 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node3) node4 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node4) node5 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node5) node6 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node6) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node1.Index, toNodeIndex=node5.Index, cost=2.9)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node1.Index, toNodeIndex=node6.Index, cost=1.0)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node2.Index, toNodeIndex=node3.Index, cost=3.1)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node3.Index, toNodeIndex=node5.Index, cost=0.8)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node4.Index, toNodeIndex=node3.Index, cost=3.7)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node5.Index, toNodeIndex=node2.Index, cost=1.9)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node5.Index, toNodeIndex=node6.Index, cost=3.0)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node6.Index, toNodeIndex=node4.Index, cost=1.1)) return sparseGraph
def CreateUniGraph(): from HorizonCore.Graph.SparseGraph import SparseGraph from HorizonCore.Graph.GraphEdge import GraphEdge from HorizonCore.Graph.GraphNode import GraphNode sparseGraph = SparseGraph(isDigraph=False) node0 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node0) node0.Index = -1 node1 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node1) node2 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node2) node3 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node3) node4 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node4) node5 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node5) node6 = GraphNode(index=sparseGraph.GetNextFreeNodeIndex()) sparseGraph.AddNode(node6) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node1.Index, toNodeIndex=node5.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node1.Index, toNodeIndex=node6.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node2.Index, toNodeIndex=node3.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node2.Index, toNodeIndex=node5.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node3.Index, toNodeIndex=node2.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node3.Index, toNodeIndex=node4.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node3.Index, toNodeIndex=node5.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node4.Index, toNodeIndex=node3.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node4.Index, toNodeIndex=node6.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node5.Index, toNodeIndex=node1.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node5.Index, toNodeIndex=node2.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node5.Index, toNodeIndex=node3.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node5.Index, toNodeIndex=node6.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node6.Index, toNodeIndex=node1.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node6.Index, toNodeIndex=node4.Index)) sparseGraph.AddEdge( GraphEdge(fromNodeIndex=node6.Index, toNodeIndex=node5.Index)) return sparseGraph