Advertisement
Guest User

project_menu

a guest
May 23rd, 2019
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.60 KB | None | 0 0
  1. import airSpace
  2. import graph
  3. import path
  4. import testgraph
  5.  
  6. def loadSimpleGraph():
  7. return testgraph.crearGrafo()
  8.  
  9. def plotGraph(simpleGraph):
  10. if len(simpleGraph.nodes) > 0:
  11. graph.plot(simpleGraph)
  12. else:
  13. return None
  14.  
  15. def plotNode(simpleGraph, nodeName):
  16. if len(simpleGraph.nodes) > 0:
  17. graph.plotNode(simpleGraph, nodeName)
  18. else:
  19. return None
  20.  
  21. def plotPath(simpleGraph, thePath):
  22. if len(simpleGraph.nodes) > 0:
  23. graph.plotPath(simpleGraph, thePath)
  24. else:
  25. return None
  26.  
  27. def plotMinPath(simpleGraph, nameOrg, nameDst):
  28. if len(simpleGraph.nodes) > 0:
  29. thePath = graph.findShortestPath(simpleGraph, nameOrg, nameDst)
  30. if thePath != None:
  31. graph.plotPath(simpleGraph, thePath)
  32. else:
  33. print "There are not any path between " + nameOrg + " and " + nameDst
  34. return None
  35. else:
  36. return None
  37.  
  38. def loadAirSpace():
  39. nameAirSpace = raw_input("Please, give me the name of the airspace: ")
  40. if nameAirSpace == "Cat" or nameAirSpace == "ECAC" or nameAirSpace == "Spain":
  41. ns = airSpace.buildAirSpace(nameAirSpace)
  42. return ns
  43. else:
  44. print "You gived Invalid AirSpace"
  45. return None
  46.  
  47.  
  48. def listAirports(airSp):
  49. if len(airSp.airports) == 0:
  50. return False
  51. else:
  52. i = 0
  53. while i < len(airSp.airports):
  54. print airSp.airports[i].name
  55. i += 1
  56. return True
  57.  
  58.  
  59. def createAirports(air, nameFile):
  60. airSpace.airportsToKML(air, nameFile)
  61.  
  62.  
  63. def createRoute(p, nameFile):
  64. path.PathtoKml(p,nameFile)
  65.  
  66.  
  67. print (" ")
  68. print ("Main menu")
  69. print ("======================================================================")
  70. print ("a - Load simple graph (i.e. the first week graph)")
  71. print ("b - Plot graph")
  72. print ("c - Plot node (ask node name)")
  73. print ("d . Plot path (ask list of nodes to form the path)")
  74. print ("e - Plot min path (ask origin node and destination node)")
  75. print ("----------------------------------------------------------------------")
  76. print ("f - Load airspace (ask airspace name)")
  77. print ("g - List airports")
  78. print ("h - Create airports.kml (ask name of the output file)")
  79. print ("i - Create route.kml (ask name of the output file)")
  80. print ("======================================================================")
  81. print ("z - Exit")
  82. print (" ")
  83.  
  84. G = graph.Graph()
  85. airSp = airSpace.airSpace()
  86.  
  87. A = raw_input("Please select the option you want to execute, from the Main Menu: ")
  88. while A != "z":
  89.  
  90. if A == "a":
  91. G = loadSimpleGraph()
  92. if len(G.nodes) > 0:
  93. print "You loaded correctly the graph!"
  94.  
  95. elif A == "b":
  96. if len(G.nodes) > 0:
  97. plotGraph(G)
  98. else:
  99. print "The graph is not loaded. Please, select previously the option a in the Menu."
  100.  
  101. elif A == "c":
  102. nodeName = raw_input("Please give me the name of the Node: ")
  103. if len(G.nodes) > 0:
  104. node = graph.buscarNodo(G.nodes, nodeName)
  105. if node != None:
  106. plotNode(G, nodeName)
  107. else:
  108. print "The node " + nodeName + " doesn't exists in the graph!"
  109. else:
  110. print "The graph is not loaded. Please, select previously the option a in the Menu."
  111.  
  112.  
  113. elif A == "d":
  114. p = path.Path()
  115. if len(G.nodes) > 0:
  116. nodeList = raw_input("Please give me the list of the nodes of the path that you want to visualise (separed with blank space. F.ex. A B): ")
  117. nodeListCorrect = True
  118. elementos = nodeList.split(" ")
  119. i = 0
  120. while i < len(elementos) and nodeListCorrect:
  121. #print str(i) + " de " + str(len(elementos))
  122. theNode = graph.buscarNodo(G.nodes, elementos[i])
  123. if theNode == None:
  124. print "The node " + elementos[i] + " doesn't exists in the graph!"
  125. nodeListCorrect = False
  126. else:
  127. if not(path.addNode(G, p, elementos[i])):
  128. print "The node " + elementos[i] + " it's not neighbor of the node " + elementos[i-1] + "."
  129. nodeListCorrect = False
  130. i += 1
  131. if nodeListCorrect:
  132. plotPath(G, p)
  133. else:
  134. print "You added nodes that doesn't exists in the graph or are not neighbors!"
  135.  
  136. else:
  137. print "The graph is not loaded. Please, select previously the option a in the Menu."
  138.  
  139. elif A == "e":
  140. minPath=path.Path()
  141. if len(G.nodes) > 0:
  142. nodeOrg = raw_input("Please give me the name of the node origin: ")
  143. theNode = graph.buscarNodo(G.nodes, nodeOrg)
  144. if theNode == None:
  145. print "The node " + nodeOrg + " don't exists in the graph!"
  146. else:
  147. nodeDst = raw_input("Please give me the name of the node destination: ")
  148. theNode = graph.buscarNodo(G.nodes, nodeDst)
  149. if theNode == None:
  150. print "The node " + nodeDst + " don't exists in the graph!"
  151. else:
  152. plotMinPath(G, nodeOrg, nodeDst)
  153. else:
  154. print "The graph is not loaded. Please, select previously the option a in the Menu."
  155.  
  156.  
  157. elif A == "f":
  158. airSp = loadAirSpace()
  159. if airSp != None:
  160. print "Airspace have been loaded correctly!"
  161.  
  162. elif A == "g":
  163. if listAirports(airSp):
  164. print "List of the airports extracted correctly."
  165. else:
  166. print "The airspace is not loaded. Please, select previously the option f in the Menu."
  167.  
  168. elif A == "h":
  169. if len(airSp.airports) > 0:
  170. nameFile = raw_input("Please, give me the nameFile do you want to create: ")
  171. createAirports(airSp,nameFile)
  172. else:
  173. print "The airspace is not loaded. Please, select previously the option f in the Menu."
  174.  
  175.  
  176. elif A == "i":
  177. if len(airSp.airports) > 0:
  178. airportOrg = raw_input("Please, give me the name of the airport origin: ")
  179. airportDst = raw_input("Please, give me the name of the airport destination: ")
  180. nameFile = raw_input("Please, give me the nameFile do you want to create: ")
  181. graphAirSpace = airSpace.buildAirGraph(airSp)
  182. nodoAeroportInicial = airSpace.buscarNomNodoAeroport(airSp, airportOrg)
  183. if nodoAeroportInicial != None:
  184. nodoAeroportFinal = airSpace.buscarNomNodoAeroport(airSp, airportDst)
  185. if nodoAeroportFinal != None:
  186. thePath = graph.findShortestPath(graphAirSpace, nodoAeroportInicial, nodoAeroportFinal)
  187. if thePath != None:
  188. createRoute(thePath, nameFile)
  189. print "Route created correctly."
  190. else:
  191. print "There are not any path between " + airportOrg + " and " + airportDst + "."
  192. else:
  193. print "There are not exist any airport called " + airportDst + " in the airspace loaded."
  194. else:
  195. print "There are not exist any airport called " + airportOrg + " in the airspace loaded."
  196.  
  197. else:
  198. print "The airspace is not loaded. Please, select previously the option f in the Menu."
  199.  
  200. else:
  201. print "Option not valid"
  202.  
  203. A = raw_input("Please select the option you want to execute, from the Main Menu: ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement