本文整理汇总了Python中apgl.graph.DictGraph.DictGraph.edgeExists方法的典型用法代码示例。如果您正苦于以下问题:Python DictGraph.edgeExists方法的具体用法?Python DictGraph.edgeExists怎么用?Python DictGraph.edgeExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apgl.graph.DictGraph.DictGraph
的用法示例。
在下文中一共展示了DictGraph.edgeExists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testGetSparseWeightMatrix
# 需要导入模块: from apgl.graph.DictGraph import DictGraph [as 别名]
# 或者: from apgl.graph.DictGraph.DictGraph import edgeExists [as 别名]
def testGetSparseWeightMatrix(self):
graph = DictGraph()
graph.addEdge("a", "b")
graph.addEdge("a", "c")
graph.addEdge("a", "d", "blah")
graph.addEdge("d", "e", -1.1)
graph.addEdge("c", "b", 2)
W = graph.getSparseWeightMatrix()
keys = graph.getAllVertexIds()
for i in range(len(keys)):
for j in range(len(keys)):
if graph.edgeExists(keys[i], keys[j]) and not isinstance(graph.getEdge(keys[i], keys[j]), numbers.Number):
self.assertEquals(1, W[i, j])
elif W[i, j] != 0:
self.assertEquals(graph.getEdge(keys[i], keys[j]), W[i, j])
else:
self.assertEquals(graph.getEdge(keys[i], keys[j]), None)
#Try a directed graph
graph = DictGraph(False)
graph.addEdge("a", "b")
graph.addEdge("a", "c", "test")
graph.addEdge("a", "d")
graph.addEdge("d", "e")
graph.addEdge("c", "a", 0.1)
W = graph.getSparseWeightMatrix()
for i in range(len(keys)):
for j in range(len(keys)):
if graph.edgeExists(keys[i], keys[j]) and not isinstance(graph.getEdge(keys[i], keys[j]), numbers.Number):
self.assertEquals(1, W[i, j])
elif W[i, j] != 0:
self.assertEquals(graph.getEdge(keys[i], keys[j]), W[i, j])
else:
self.assertEquals(graph.getEdge(keys[i], keys[j]), None)
示例2: testAdjacencyList
# 需要导入模块: from apgl.graph.DictGraph import DictGraph [as 别名]
# 或者: from apgl.graph.DictGraph.DictGraph import edgeExists [as 别名]
def testAdjacencyList(self):
graph = DictGraph()
graph.addEdge("a", "b", 1)
graph.addEdge("b", "c", 1)
graph.addEdge("b", "d", 1)
graph.addEdge("c", "e", 1)
graph.setVertex("f", 1)
neighbourIndices, neighbourWeights = graph.adjacencyList()
vertexIds = graph.getAllVertexIds()
for i in range(len(neighbourIndices)):
for k, j in enumerate(neighbourIndices[i]):
self.assertTrue(graph.edgeExists(vertexIds[i], vertexIds[j]))
self.assertEquals(graph[vertexIds[i], vertexIds[j]], neighbourWeights[i][k])
示例3: testRemoveVertex
# 需要导入模块: from apgl.graph.DictGraph import DictGraph [as 别名]
# 或者: from apgl.graph.DictGraph.DictGraph import edgeExists [as 别名]
def testRemoveVertex(self):
graph = DictGraph()
graph.addEdge(0, 1)
graph.addEdge(0, 2)
graph.addEdge(0, 3)
graph.addEdge(1, 2)
graph.addEdge(2, 3)
graph.addEdge(3, 4)
graph.removeVertex(4)
self.assertFalse(graph.vertexExists(4))
self.assertFalse(graph.edgeExists(3, 4))
graph.removeVertex(3)
self.assertFalse(graph.vertexExists(3))
self.assertFalse(graph.edgeExists(2, 3))
self.assertFalse(graph.edgeExists(0, 3))
graph.removeVertex(2)
self.assertFalse(graph.vertexExists(2))
self.assertFalse(graph.edgeExists(1, 2))
self.assertFalse(graph.edgeExists(0, 2))
self.assertTrue(graph.getAllVertexIds() == [0, 1])
self.assertTrue(graph.getAllEdges() == [(0, 1)])
#Try directed graph
graph = DictGraph(False)
graph.addEdge(0, 1)
graph.addEdge(1, 0)
graph.addEdge(0, 3)
graph.addEdge(1, 2)
graph.addEdge(2, 3)
graph.addEdge(3, 4)
graph.removeVertex(0)
self.assertFalse(graph.vertexExists(0))
self.assertFalse(graph.edgeExists(0, 1))
self.assertFalse(graph.edgeExists(0, 3))
self.assertFalse(graph.edgeExists(1, 0))
graph.removeVertex(2)
self.assertFalse(graph.vertexExists(2))
self.assertFalse(graph.edgeExists(1, 2))
self.assertFalse(graph.edgeExists(2, 3))
self.assertTrue(graph.getAllVertexIds() == [1, 3, 4])
self.assertTrue(graph.getAllEdges() == [(3, 4)])