I'm looking for a solution since days but can't find a way to solve it.
My goal is to find the shortest way between 2 bus stops, based on the time the bus takes between them.
So I have bus lines, and time tables for each of them. The cost is represented by the difference of time between the actual bus stop and the next bus stop (in seconds). the source and targets are the ID's of the bus stops
The problem is: I have some parallel links because each bus do his line many times a day, running the same way everytime.
I've tried with pgrouting's shortest_path function, but itt returns many times a wrong solution because of parallel links.
I've seen about shooting_star, but I don't think I can use it in my case, without geometry.
I've got PostGreSQL 9.1.9 with PostGIS 2.0.1. Here are an example of my database extraction:
id | idcourse | source | target | cost |
1 | 1 | 62 | 34 | 60 |
2 | 1 | 34 | 16 | 360 |
3 | 1 | 16 | 61 | 60 |
4 | 1 | 61 | 60 | 120 |
5 | 2 | 62 | 34 | 60 |
the last row here is the same bus line as others (with idcourse = 1) but one hour later
and here is the request to get this:
select hc.idhorairecourse as id, c.idcourse,
hc.idarret as source,
(select hc2.idarret from horairecourse hc2 where hc2.idcourse = c.idcourse and hc2.heure > hc.heure order by hc2.heure limit 1) as target,
(extract(epoch from ((select horairecourse.heure from horairecourse where horairecourse.idcourse = c.idcourse and horairecourse.heure > hc.heure order by horairecourse.heure limit 1) - hc.heure))) as cost
from course c
inner join horairecourse hc on c.idcourse = hc.idcourse
where (select horairecourse.idarret from horairecourse where horairecourse.idcourse = c.idcourse and horairecourse.heure > hc.heure order by horairecourse.heure limit 1) is not null
order by c.idcourse, hc.heure