Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import airSpace
- import graph
- import path
- import testgraph
- def loadSimpleGraph():
- return testgraph.crearGrafo()
- def plotGraph(simpleGraph):
- if len(simpleGraph.nodes) > 0:
- graph.plot(simpleGraph)
- else:
- return None
- def plotNode(simpleGraph, nodeName):
- if len(simpleGraph.nodes) > 0:
- graph.plotNode(simpleGraph, nodeName)
- else:
- return None
- def plotPath(simpleGraph, thePath):
- if len(simpleGraph.nodes) > 0:
- graph.plotPath(simpleGraph, thePath)
- else:
- return None
- def plotMinPath(simpleGraph, nameOrg, nameDst):
- if len(simpleGraph.nodes) > 0:
- thePath = graph.findShortestPath(simpleGraph, nameOrg, nameDst)
- if thePath != None:
- graph.plotPath(simpleGraph, thePath)
- else:
- print "There are not any path between " + nameOrg + " and " + nameDst
- return None
- else:
- return None
- def loadAirSpace():
- nameAirSpace = raw_input("Please, give me the name of the airspace: ")
- if nameAirSpace == "Cat" or nameAirSpace == "ECAC" or nameAirSpace == "Spain":
- ns = airSpace.buildAirSpace(nameAirSpace)
- return ns
- else:
- print "You gived Invalid AirSpace"
- return None
- def listAirports(airSp):
- if len(airSp.airports) == 0:
- return False
- else:
- i = 0
- while i < len(airSp.airports):
- print airSp.airports[i].name
- i += 1
- return True
- def createAirports(air, nameFile):
- airSpace.airportsToKML(air, nameFile)
- def createRoute(p, nameFile):
- path.PathtoKml(p,nameFile)
- print (" ")
- print ("Main menu")
- print ("======================================================================")
- print ("a - Load simple graph (i.e. the first week graph)")
- print ("b - Plot graph")
- print ("c - Plot node (ask node name)")
- print ("d . Plot path (ask list of nodes to form the path)")
- print ("e - Plot min path (ask origin node and destination node)")
- print ("----------------------------------------------------------------------")
- print ("f - Load airspace (ask airspace name)")
- print ("g - List airports")
- print ("h - Create airports.kml (ask name of the output file)")
- print ("i - Create route.kml (ask name of the output file)")
- print ("======================================================================")
- print ("z - Exit")
- print (" ")
- G = graph.Graph()
- airSp = airSpace.airSpace()
- A = raw_input("Please select the option you want to execute, from the Main Menu: ")
- while A != "z":
- if A == "a":
- G = loadSimpleGraph()
- if len(G.nodes) > 0:
- print "You loaded correctly the graph!"
- elif A == "b":
- if len(G.nodes) > 0:
- plotGraph(G)
- else:
- print "The graph is not loaded. Please, select previously the option a in the Menu."
- elif A == "c":
- nodeName = raw_input("Please give me the name of the Node: ")
- if len(G.nodes) > 0:
- node = graph.buscarNodo(G.nodes, nodeName)
- if node != None:
- plotNode(G, nodeName)
- else:
- print "The node " + nodeName + " doesn't exists in the graph!"
- else:
- print "The graph is not loaded. Please, select previously the option a in the Menu."
- elif A == "d":
- p = path.Path()
- if len(G.nodes) > 0:
- 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): ")
- nodeListCorrect = True
- elementos = nodeList.split(" ")
- i = 0
- while i < len(elementos) and nodeListCorrect:
- #print str(i) + " de " + str(len(elementos))
- theNode = graph.buscarNodo(G.nodes, elementos[i])
- if theNode == None:
- print "The node " + elementos[i] + " doesn't exists in the graph!"
- nodeListCorrect = False
- else:
- if not(path.addNode(G, p, elementos[i])):
- print "The node " + elementos[i] + " it's not neighbor of the node " + elementos[i-1] + "."
- nodeListCorrect = False
- i += 1
- if nodeListCorrect:
- plotPath(G, p)
- else:
- print "You added nodes that doesn't exists in the graph or are not neighbors!"
- else:
- print "The graph is not loaded. Please, select previously the option a in the Menu."
- elif A == "e":
- minPath=path.Path()
- if len(G.nodes) > 0:
- nodeOrg = raw_input("Please give me the name of the node origin: ")
- theNode = graph.buscarNodo(G.nodes, nodeOrg)
- if theNode == None:
- print "The node " + nodeOrg + " don't exists in the graph!"
- else:
- nodeDst = raw_input("Please give me the name of the node destination: ")
- theNode = graph.buscarNodo(G.nodes, nodeDst)
- if theNode == None:
- print "The node " + nodeDst + " don't exists in the graph!"
- else:
- plotMinPath(G, nodeOrg, nodeDst)
- else:
- print "The graph is not loaded. Please, select previously the option a in the Menu."
- elif A == "f":
- airSp = loadAirSpace()
- if airSp != None:
- print "Airspace have been loaded correctly!"
- elif A == "g":
- if listAirports(airSp):
- print "List of the airports extracted correctly."
- else:
- print "The airspace is not loaded. Please, select previously the option f in the Menu."
- elif A == "h":
- if len(airSp.airports) > 0:
- nameFile = raw_input("Please, give me the nameFile do you want to create: ")
- createAirports(airSp,nameFile)
- else:
- print "The airspace is not loaded. Please, select previously the option f in the Menu."
- elif A == "i":
- if len(airSp.airports) > 0:
- airportOrg = raw_input("Please, give me the name of the airport origin: ")
- airportDst = raw_input("Please, give me the name of the airport destination: ")
- nameFile = raw_input("Please, give me the nameFile do you want to create: ")
- graphAirSpace = airSpace.buildAirGraph(airSp)
- nodoAeroportInicial = airSpace.buscarNomNodoAeroport(airSp, airportOrg)
- if nodoAeroportInicial != None:
- nodoAeroportFinal = airSpace.buscarNomNodoAeroport(airSp, airportDst)
- if nodoAeroportFinal != None:
- thePath = graph.findShortestPath(graphAirSpace, nodoAeroportInicial, nodoAeroportFinal)
- if thePath != None:
- createRoute(thePath, nameFile)
- print "Route created correctly."
- else:
- print "There are not any path between " + airportOrg + " and " + airportDst + "."
- else:
- print "There are not exist any airport called " + airportDst + " in the airspace loaded."
- else:
- print "There are not exist any airport called " + airportOrg + " in the airspace loaded."
- else:
- print "The airspace is not loaded. Please, select previously the option f in the Menu."
- else:
- print "Option not valid"
- 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