Custom heuristic on pgrouting pgr_astar function

55 Views Asked by At

So i'm using pgrouting to compute shortest path on transit network, The cost of my graph is time, but the graph isn't "time dependent" - which means my arcs are available at every hour everyday, the cost is not the distance between station but the time it take to move from one point to another. I figured by doing the computation that pgr_astar (and even pgr_bdAstar) is slower than pgr_dijkstra. I thought it might be a heuristic problem. My questions is :

Is there a way to edit pgr_astar to insert your own heuristi

1

There are 1 best solutions below

0
Zegarek On

It's open-source, so yes you can, as long as you don't mind some C/C++: here. Still, what you likely want is one of the 6 built-in options:

             switch (m_heuristic) {
                 case 0:
                     current = 0;
                     break;
                 case 1:
                     current = std::fabs((std::max)(dx, dy)) * m_factor;
                     break;
                 case 2:
                     current = std::fabs((std::min)(dx, dy)) * m_factor;
                     break;
                 case 3:
                     current = (dx * dx + dy * dy) * m_factor * m_factor;
                     break;
                 case 4:
                     current = std::sqrt(dx * dx + dy * dy) * m_factor;
                     break;
                 case 5:
                     current = (std::fabs(dx) + std::fabs(dy)) * m_factor;
                     break;
                 default:
                     current = 0;
             }

All of which are fairly simple as it is.