0

I discovered this lib this week, and my first project works, I modelize simple flight booking.

As edge I have created an Flight Class As vertex I have created an Airport Class

I put duration for each flight and succeed to associate dijsktra algorithm (DijkstraShortestPath)

class Airport {
    String name;
}

class Flight {
    String flight;        
    int duration;
}

g = new DirectedSparseMultigraph<Airport, Flight>();
Flight AXXX = new Flight("A57",3);
Flight AYYY = new Flight("A53",1);

ORY = new Airport("ORY");
LYS = new Airport("LYS");

g.addEdge(AXXX, ORY, LYS);
g.addEdge(AYYY, LYS, ORY); 

Transformer<Flight, Integer> wtTransformer = new Transformer<Flight, Integer>() {
        @Override
        public Integer transform(Flight link) {
                return link.duration;                
        }            
    };

DijkstraShortestPath<Airport, Flight> alg = new DijkstraShortestPath(g, wtTransformer);        
Number dist = alg.getDistance(ORY, LYS);

This simple case works well, but now I would to calculate duration as: Flight1 start 12/01/13 at 12:00 and arrival at 13/01/13 at 14h Flight2 start 13/01/13 at 18:00 and arrival at 13/01/13 at 20h

In this case I want to calculate duration of flight AND between flight. Cause to get shortest path from one to another flight we need to take care about time to wait between flight and not only flight duration. But DiskstraShortestPath allow only Transformer as: Transformer so I can’t get reference to previous flight to calculate total duration (wait + flight).

So my question is: what is the best way for my case ? Create new algorithm (inherit DijsktraShortestPath…) Create new GraphType (inherit DirectedSparseMultigraph…)

Thanks for you answer guy ;) !

Zuzu
  • 1
  • 2

1 Answers1

0

If you are trying to minimize total travel time, then this is, indeed, not a shortest path problem, but a different kind of discrete optimization problem. JUNG does not provide a general solver for discrete optimization problems.

Even if you're trying to minimize flight time only (that is, time spent in the air) then you need to be able to filter the graph (more precisely, the outgoing edges) at each step, because only flights that depart after the previous flight arrives are relevant, i.e., the local topology is a function of time.

Joshua O'Madadhain
  • 2,704
  • 1
  • 14
  • 18