本文整理汇总了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()
示例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