当前位置: 首页>>代码示例>>Python>>正文


Python Graph.getAdj方法代码示例

本文整理汇总了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
开发者ID:SaadTalaat,项目名称:Algorithms-bag,代码行数:33,代码来源:Graph-Test.py

示例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)
开发者ID:SaadTalaat,项目名称:Algorithms-bag,代码行数:32,代码来源:GraphCC.py


注:本文中的Graph.Graph.getAdj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。