def testGetAllEdgeIndices(self): graph = DictGraph() graph.addEdge("a", "b") graph.addEdge("a", "c") graph.addEdge("a", "d") graph.addEdge("d", "e") edgeIndices = graph.getAllEdgeIndices() keys = graph.getAllVertexIds() self.assertEquals(edgeIndices.shape[0], graph.getNumEdges()) for i in range(edgeIndices.shape[0]): self.assertTrue(graph.getEdge(keys[int(edgeIndices[i, 0])], keys[edgeIndices[i, 1]]) == 1) graph = DictGraph(False) graph.addEdge("a", "b") graph.addEdge("b", "a") graph.addEdge("a", "c") graph.addEdge("a", "d") graph.addEdge("d", "e") edgeIndices = graph.getAllEdgeIndices() keys = graph.getAllVertexIds() self.assertEquals(edgeIndices.shape[0], graph.getNumEdges()) for i in range(edgeIndices.shape[0]): self.assertTrue(graph.getEdge(keys[int(edgeIndices[i, 0])], keys[edgeIndices[i, 1]]) == 1)
""" Name: Generate Graph: Author: Jia_qiu Wang(王佳秋) Data: December, 2016 function: """ from apgl.graph.DictGraph import DictGraph from apgl.graph.SparseGraph import SparseGraph from apgl.graph.GeneralVertexList import GeneralVertexList graph = DictGraph() graph.addEdge("a", "b") graph.addEdge("a", "c") graph.addEdge("a", "d") edgeIndices = graph.getAllEdgeIndices() graph2 = SparseGraph(GeneralVertexList(graph.getNumVertices())) graph2.addEdges(edgeIndices)
# -*- coding: utf-8 -*- from apgl.graph.DictGraph import DictGraph from apgl.graph.SparseGraph import SparseGraph from apgl.graph.GeneralVertexList import GeneralVertexList graph = DictGraph() graph.addEdge("a", "b") graph.addEdge("a", "c") graph.addEdge("a", "d") edgeIndices = graph.getAllEdgeIndices() graph2 = SparseGraph(GeneralVertexList(graph.getNumVertices())) graph2.addEdges(edgeIndices)