def run(): graph, ep = loadFromFile() ui = UI() utils = Utils() ui.clear() while True: opt = ui.mainMenu() if opt == 0: ui.clear() break elif opt == 1: ui.clear() startVertex = ui.readVertex("Enter start vertex: ", graph.getVertices()) if startVertex != -1: endVertex = ui.readVertex("Enter end vertex: ", graph.getVertices()) if endVertex != -1: utils.BellmanFord(graph, ep, startVertex, endVertex) ui.wait4enter() elif opt == 2: ui.showG_or_EP(graph) elif opt == 3: ui.showG_or_EP(ep)
def run(): loadFromFile() copyGraph = deepcopy(graph) copyEP = deepcopy(ep) ui = UI() ui.clear() while True: opt = ui.mainMenu() if opt == 0: ui.clear() break elif opt == 1: ui.clear() ui.numberVertices(graph.getNbrVertices()) ui.wait4enter() elif opt == 2: ui.clear() startVertex = ui.readVertex("Enter start vertex: ", graph.getDictKeys()) if startVertex != -1: endVertex = ui.readVertex("Enter end vertex: ", graph.getDictKeys()) if endVertex != -1: if graph.isEdge(startVertex, endVertex): print "Yes. There is an edge from", startVertex, "to", endVertex else: print "No. There dosen't exists an edge from", startVertex, "to", endVertex ui.wait4enter() else: ui.clear() else: ui.clear() elif opt == 3: ui.clear() vertex = ui.readVertex("Enter vertex: ", graph.getDictKeys()) if vertex != -1: x = graph.vertexDegree(vertex) print "In degree:",x[0] print "Out degree:", x[1] ui.wait4enter() else: ui.clear() elif opt == 4: ui.clear() vertex = ui.readVertex("Enter vertex: ", graph.getDictKeys()) if vertex != -1: print graph.outbound(vertex) ui.wait4enter() else: ui.clear() elif opt == 5: ui.clear() vertex = ui.readVertex("Enter vertex: ", graph.getDictKeys()) if vertex != -1: print graph.inbound(vertex) ui.wait4enter() else: ui.clear() elif opt == 6: ui.clear() startVertex = ui.readVertex("Enter start vertex: ", graph.getDictKeys()) if startVertex != -1: endVertex = ui.readVertex("Enter end vertex: ", graph.getDictKeys()) if endVertex != -1: if graph.isEdge(startVertex, endVertex): ep.retrieveProperty(startVertex, endVertex) ui.wait4enter() else: print "That edge does not exist!" ui.wait4enter() else: ui.clear() else: ui.clear() elif opt == 7: ui.clear() startVertex = ui.readVertex("Enter start vertex: ", graph.getDictKeys()) if startVertex != -1: endVertex = ui.readVertex("Enter end vertex: ", graph.getDictKeys()) if endVertex != -1: if graph.isEdge(startVertex, endVertex): value = raw_input("Enter value: ").strip() ep.modifyProperty(startVertex, endVertex, value) ui.clear() else: print "That edge does not exist!" ui.wait4enter() else: ui.clear() else: ui.clear() elif opt == 8: ui.clear() startVertex = ui.readVertex("Enter start vertex: ", graph.getDictKeys()) if startVertex != -1: endVertex = ui.readVertex("Enter end vertex: ", graph.getDictKeys()) if endVertex != -1: if graph.isEdge(startVertex, endVertex): print "That edge already exists!" ui.wait4enter() else: value = raw_input("Enter value: ").strip() graph.addEdge(startVertex, endVertex) ep.addEP((startVertex, endVertex), value) ui.clear() else: ui.clear() else: ui.clear() elif opt == 9: ui.clear() startVertex = ui.readVertex("Enter start vertex: ", graph.getDictKeys()) if startVertex != -1: endVertex = ui.readVertex("Enter end vertex: ", graph.getDictKeys()) if endVertex != -1: if graph.isEdge(startVertex, endVertex): graph.removeEdge(startVertex, endVertex) toBeRemovedEdges = [] toBeRemovedEdges.append((startVertex, endVertex)) ep.removeEdges(toBeRemovedEdges) else: print "There dosen't exists an edge from", startVertex, "to", endVertex ui.wait4enter() ui.clear() elif opt == 10: ui.clear() vertex = ui.readNewVertex("Enter vertex (positive integer): ", graph.getDictKeys()) if vertex != -1: graph.addVertex(vertex) ui.clear() elif opt == 11: ui.clear() vertex = ui.readVertex("Enter vertex: ", graph.getDictKeys()) if vertex != -1: toBeRemovedEdges = graph.removeVertex(vertex) ep.removeEdges(toBeRemovedEdges) ui.clear() elif opt == 12: ui.clear() ui.showG_or_EP(copyGraph) ui.wait4enter() elif opt == 13: ui.clear() ui.showG_or_EP(copyEP) ui.wait4enter() elif opt == 14: ui.clear() ui.showG_or_EP(graph) ui.wait4enter() elif opt == 15: ui.showG_or_EP(ep) ui.wait4enter()