示例#1
0
    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)
示例#2
0
"""
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)

示例#3
0
# -*- 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)