Created
March 24, 2015 00:40
-
-
Save gchaturvedi/c45f0d352dd9712c6066 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Graph actualGraph = new SingleGraph("actualFlight"); | |
for(Airport airport: allAirports) { | |
actualGraph.addNode(airport.getCode()); | |
actualGraph.getNode(airport.getCode()).setAttribute("ui.label", airport.getCode()); | |
} | |
for(Flight flight: allFlights) { | |
String edgeCode = flight.getDepartureAirport().getCode() + "-" + flight.getArrivalAirport().getCode(); | |
if(actualGraph.getEdge(edgeCode) == null) { | |
actualGraph.addEdge(edgeCode, flight.getDepartureAirport().getCode(), flight.getArrivalAirport().getCode(), true); | |
Edge edge = actualGraph.getEdge(edgeCode); | |
edge.addAttribute("length", 1); | |
} | |
} | |
actualGraph.display(); | |
Dijkstra dijkstra = new Dijkstra(Dijkstra.Element.EDGE, "result", "length"); | |
dijkstra.init(actualGraph); | |
dijkstra.setSource(actualGraph.getNode("BOS")); | |
dijkstra.compute(); | |
List<String> lp = new ArrayList<String>(); | |
// Path d =dijkstra.getPath(actualGraph.getNode("SFO")); | |
// dijkstra.getAllPaths(actualGraph.getNode("SFO")); | |
for (Path p : dijkstra.getAllPaths(actualGraph.getNode("ORD"))) { | |
lp.add(p.toString()); | |
} | |
System.out.println(lp.toString()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment