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


Python Graph.findVertex方法代码示例

本文整理汇总了Python中Graph.findVertex方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.findVertex方法的具体用法?Python Graph.findVertex怎么用?Python Graph.findVertex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.findVertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import findVertex [as 别名]
class Application:

    #. Contructor .#
    def __init__ (self):
        self.interface = Interface(self.ButtonCallBack)    # Create an interface
        self.graph = Graph()                               # Create a graph
        self.graph.formGraph()                             # Form the graph
        
    #. Call back function when button is pressed .#
    def ButtonCallBack(self):
        startName = self.interface.getStartEntry().encode('gbk')
        destName = self.interface.getDestEntry().encode('gbk')
        start = self.graph.findVertex(startName)           # Find the start vertex
        dest = self.graph.findVertex(destName)             # Find the dest vertex
        # If start or dest are not found
        if start == None:
            result = startName.encode('utf8') + ' doesn\'t exist'
        elif dest == None:
            result = destName.encode('utf8') + ' doesn\'t exist'
        else:    # Normal case
            self.graph.BFS(start)
            result = self.graph.shortestPath(dest).encode('utf8')
        self.interface.updateText(result)

    #. Run the program .#
    def run(self):
        mainloop()
开发者ID:Irving-cl,项目名称:ShanghaiSubwayShortestPath,代码行数:29,代码来源:Application.py

示例2: Stack

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import findVertex [as 别名]
#Creates a stack and tests a stack of 10 integers. Implements LIFO 0 goes in first up to 9 then nine comes out first
sizeofstack = 10
i = 0;
stack = Stack()
while i < sizeofstack:
	stack.push(i)
	i += 1
print "testing stack"
while stack.checkSize() != 0:
	print stack.pop()
print " "

#Graph
#creates a Graph intially with 10 unconnected nodes then randomly connects the nodes
#then randomly searches for 5 nodes
graph = Graph()
i = 0
while i < 10:
	graph.addVertex(i)
	i += 1
i = 0
while i < 20:
	graph.addEdge(randint(0,9), randint(0,9))
	i += 1
i = 0
while i < 5:
	graph.findVertex(randint(0,10))
	i += 1


开发者ID:jupu1234,项目名称:Purtell_CSCI3202_Assignment1,代码行数:30,代码来源:Purtell_Assignment1.py


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