Dijsktra with contrains

Hi folks, im implementing a program to find a train route from one city to another. All information about direct train between cities is in the database. Problem is: providing users want to go from one city to another, and they'd like to depart not earlier than departureTime and arrive no later than arriveTime.

I used Dijsktra to find the best route which will take users to their destination at earliest time.

But now, there's one more constrain: users want the best route which take them there as soon as possible IN CONDITION that they don't have to change train maxChanges time. And that is when i got lost. Because the answer i found previously is not neccessarily the route statifies the second requirement.

Eg: User wants to go from A-->C, depart at or after 10.00 and arrive before or at 19.00

Dijsktra without second requirement, i found a best route A-->B-->C which departs at A at 10.30 and arrive at C at 16.00

But if user wants no train changes, the best route would be A-->C directly, departs at A at 12.30 and arrive at C at 17.30

I dont know if using Dijsktra can help solving this problem.

Any ideas, Please !!!!

Cheers

[1219 byte] By [csbham] at [2007-9-30 21:39:21]
# 1

> I dont know if using Dijsktra can help solving this problem.

Dijkstra's shortest path algorithm still aplies: Arriving at a vertex (a railway station), there's the choice

for hopping off of a train or staying seated in that train. Hopping off means traveling in time, i.e. the

time needed waiting for another train. Time is your only concern here so time is your only cost factor.

The node where you could hop off a train is in the set (or heap or priority queue of whatever) of

temporarily labeled nodes, i.e. you don't know the shortest path to this vertex yet. You do know how

you arrived to that node (vertex, railway station).

Solving from A to B using Dijkstra's shortest path algorithm gives you the path from B to A (backwards).

Simply follow the path back from the station where you hopped off a train (potentially) and add a

humongous cost factor (they call it 'big M costs') if you've hopped off a (any) train more often than wanted.

kind regards,

Jos

JosAH at 2007-7-7 3:09:35 > top of Java-index,Other Topics,Algorithms...
# 2
Sorry, I dont really get it.
csbham at 2007-7-7 3:09:35 > top of Java-index,Other Topics,Algorithms...
# 3
Problem solved. i've been so stupidThanks anyway
csbham at 2007-7-7 3:09:35 > top of Java-index,Other Topics,Algorithms...