本文整理汇总了Python中Graph.Graph.getAdj方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.getAdj方法的具体用法?Python Graph.getAdj怎么用?Python Graph.getAdj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.getAdj方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GraphTest
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import getAdj [as 别名]
class GraphTest(unittest.TestCase):
graph = None
adj = None
mutex = 0
def setUp(self):
if self.mutex == 0:
self.graph = Graph([1,2,3,4,6])
self.graph.addEdge(1,3)
self.graph.addEdge(2,4)
self.graph.addEdge(2,6)
self.graph.addEdge(6,4)
self.adj = self.graph.getAdj()
self.mutex = 1
def tearDown(self):
self.graph = None
def testDegree (self):
assert self.graph.degree(1) == len(self.adj[0]), 'degree = x\n'
assert self.graph.degree(4) == len(self.adj[3]), 'degree = x\n'
def testMaxDegree(self):
assert self.graph.maxDegree() == len(self.adj[4]), 'max degree = x\n'
def testAvgDegree(self):
assert self.graph.avgDegree() == (sum(map(len,self.adj))/2), 'avg degree = \n'
def testSelfLoops(self):
#assert self.graph.selfLoops() == , 'self loops = %d' % self.graph.selfLoops()
return
示例2: count
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import getAdj [as 别名]
for i in graph.Adj(s):
if i == None:
return
if not self.__visited[graph.getIndex(i)]:
self.__depthFirst(g,i)
self.__components[graph.getIndex(i)] = self.__count
return
def count(self):
return self.__count
def componentsId(self):
return self.__components
def connected(self, v1, v2):
if v1 not in self.graph.vertices or v2 not in self.graph.vertices:
return False
return self.__components[self.graph.getIndex(v1)] == self.__components[self.graph.getIndex(v2)]
g = Graph([1,2,3,4,13,12,6])
g.addEdge(1,3)
g.addEdge(2,4)
g.addEdge(2,6)
g.addEdge(6,4)
g.addEdge(13,12)
print g.getAdj()
cc = GraphCC(g)
print cc.count()
print cc.componentsId()
print cc.connected(12,13)