本文整理汇总了Python中Graph.Graph.find_shortest_path方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.find_shortest_path方法的具体用法?Python Graph.find_shortest_path怎么用?Python Graph.find_shortest_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.find_shortest_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import find_shortest_path [as 别名]
# print("Adding "+ elem.name+" to "+element.name)
# print("Adding "+ element.name+" to "+elem.name)
# print("Element already exists"+"\n")
does_elem_2_exist = True
elem.add_neighbors([element])
element.add_neighbors([elem])
if(not does_elem_2_exist):
# print("Elem1 name: "+element_builder_name_2)
# print("Adding "+ element_builder_name_2+" to "+element.name)
# print("Adding "+ element.name+" to "+element_builder_name_2)
# print("Element does not already exist"+"\n")
element_2 = Node(element_builder_name_2)
element_2.add_neighbors([element])
element.add_neighbors([element_2])
graph.add_node(element_2)
counter += 1
# print(counter)
# print constructed_amount
# print graph.print_nodes()
thaum_data.close()
print "Closing file"
while(True):
print("Enter aspects or \"quit\" to exit the program")
input1 = raw_input("Aspect 1: ")
if input1 in ("exit", "e", "q", "quit"):
break
input2 = raw_input("Aspect 2: ")
if input2 in ("exit", "e", "q", "quit"):
break
graph.find_shortest_path(input1, input2)
print("Exiting Program")
示例2: str
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import find_shortest_path [as 别名]
cost_and_time = x.get_route_info_GUI(list)
msg = "Cost of trip: " + str(cost_and_time[0]) + "\n Time trip will take: " +\
str(cost_and_time[1]) + " hours.\n"
eg.msgbox(msg)
if str(choice) == "Find Shortest Path Between Cities":
msg = "Enter the CODE of the home city."
title = "Home"
home = eg.enterbox(msg, title)
msg = "Enter the CODE of the dest city."
title = "Destination"
dest = eg.enterbox(msg, title)
list = [home, dest]
msg = "Shortest path between " + str(list[0]) + " and " + str(list[1]) +\
" is: " + str(x.find_shortest_path(home,dest,list))
eg.msgbox(msg)
if str(choice) == "Statistics":
msg = "Longest Flight: " + x.get_longest_flight().home +" to " + x.get_longest_flight().dest +\
"\nDistance: " + str(x.get_longest_flight().distance)+ "\n\n" +\
"Shortest Flight: " + x.get_shortest_flight().home+" to " + x.get_shortest_flight().dest +\
"\nDistance: " + str(x.get_shortest_flight().distance) + "\n\n" +\
"Distance of Average Flight: "+ str(x.get_avg_flight())+"\n\n" +\
"Largest City: " + x.get_big_city().name + "\nPopulation: " + str(x.get_big_city().population)+ " \n\n" +\
"Smallest City: " + x.get_small_city().name + "\nPopulation: " + str(x.get_small_city().population)+ " \n\n" +\
"Average City Size: " + str(x.get_avg_city()) + "\n\n"+\
"Cities w/ Most Connections: " + str(x.get_hub_city()) + " "+"\n\n"
eg.msgbox(msg)