Skip to content

Instantly share code, notes, and snippets.

@gchaturvedi
Created March 24, 2015 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gchaturvedi/c45f0d352dd9712c6066 to your computer and use it in GitHub Desktop.
Save gchaturvedi/c45f0d352dd9712c6066 to your computer and use it in GitHub Desktop.
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