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


Python Graph.findPath方法代码示例

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


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

示例1: raw_input

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import findPath [as 别名]
                print "What else would you like to know?"
                print "0 = artists similar to a given artist"
                print "1 = if an artist is connected to another artist through similar artists"
                print "To exit, type 'exit' at any time"               
            else:
                print "I'm sorry, we aren't that hip."
                print "We don't have any information on that artist."
                print "Try another one?"

        elif cmnd == "1":
            cmnd = raw_input("Please specify the first artist: ")
            foo = raw_input("Please specify the second artist: ")

            if cmnd in artists and foo in artists:
                print "The path from %s to %s is: " % (cmnd, foo)
                path = g.findPath(cmnd, foo)
                for p in path: print p
            
                print ""
                print "What else would you like to know?"
                print "0 = artists similar to a given artist"
                print "1 = if an artist is connected to another artist through similar artists"
                print "To exit, type 'exit' at any time" 
            else:
                print "I'm sorry, we aren't that hip."
                print "We don't have any information on that artist."
                print "Try another one?"


        elif cmnd == "exit":
            sys.exit()
开发者ID:kellybreedlove,项目名称:proj6,代码行数:33,代码来源:Driver.py

示例2: Graph

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import findPath [as 别名]
'''

from Graph import *

folder_name1 = '../../Example Input/Graph1'
folder_name2 = '../Graph2'
g1 = Graph(folder_name1)
print g1
print "----------------------------------"
for i in g1.nodes:
    for j in g1.nodes:
        if i==j:
            continue
        print '\n'
        print "all paths between " + str(i) + " and " + str(j) + ":"
        print g1.findPath(i, j)
        print "shortest path between " + str(i) + " and " + str(j) + ":"
        print g1.findShortestPath(i, j)
print "----------------------------------"
print '\n\n'
g2 = Graph(folder_name2)
print g2
print "----------------------------------"
for i in g2.nodes:
    for j in g2.nodes:
        if i==j:
            continue
        print '\n'
        print "all paths between " + str(i) + " and " + str(j) + ":"
        print g2.findPath(i, j)
        print "shortest path between " + str(i) + " and " + str(j) + ":"
开发者ID:MattYi,项目名称:UW_Engineering_Computing,代码行数:33,代码来源:Main.py

示例3: Graph

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import findPath [as 别名]
'''
Created on Apr 24, 2009

@author: Peter
'''

from Graph import *

g = Graph('folder_name')

for nodeID in range(1,g.numNodes()): 
    path = g.findPath(0, node)    # path is a structure {‘nodepath’: […], ‘length’: float}
    print "The path goes through %s and has a length of %s"  \
                               % ( path['nodepath'], path['length'] )
开发者ID:MattYi,项目名称:UW_Engineering_Computing,代码行数:16,代码来源:Main.py


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