wangsh 2011-11-18
PgRouting是开源路径分析算法库,其主要功能包含:
基于Dijkstra算法的最短路径(未使用启发式算法);
基于A star算法最短路径:使用启发式算法求解大数据量路径算法;
基于Shooting-Star算法的最短路径:使用启发式算法接球转向限制;
旅行商算法(TSP):使用遗传算法求解(最多求解40个点);
计算驾车距离(Isolines)(没有找到相关代码)。
编译pgrouting(参考5)
我分析相关代码,并贴出核心部分:pgrouting最短路径核心算法基于bgl实现:
dijkstra.c:
static int compute_shortest_path(char* sql, int start_vertex, int end_vertex, bool directed, bool has_reverse_cost, path_element_t **path, int *path_count)
{
//此处省略代码n行
ret = boost_dijkstra(edges, total_tuples, start_vertex, end_vertex,
directed, has_reverse_cost,
path, path_count, &err_msg);
//此处省略代码n行
}
astar.c:
static int compute_shortest_path_astar(char* sql, int source_vertex_id, int target_vertex_id, bool directed, bool has_reverse_cost, path_element_t **path, int *path_count)
{
//此处省略代码n行
// calling C++ A* function
ret = boost_astar(edges, total_tuples, source_vertex_id-v_min_id, target_vertex_id-v_min_id, directed, has_reverse_cost, path, path_count, &err_msg);
//此处省略代码n行
}
shooting_star.c
static int compute_shortest_path_shooting_star(char* sql, int source_edge_id, int target_edge_id, bool directed, bool has_reverse_cost, path_element_t **path, int *path_count)
{
//此处省略代码n行
ret = boost_shooting_star(edges, total_tuples, source_edge_id, target_edge_id, directed, has_reverse_cost, path, path_count, &err_msg, e_max_id);
//此处省略代码n行
}
tsp.c:
static int solve_tsp(char* sql, char* p_ids,
int source, path_element_t* path)
{
//此处省略代码n行
//使用gaul库解决最多40个网络节点旅行商问题
ret = find_tsp_solution(total_tuples, DISTANCE, ids,
source, &fit, err_msg);
//此处省略代码n行
}
pgrouting是依赖bgl完成路径分析的,这也许就是bgl的强大之处,也许是到了深入学习bgl的时候了。
参考资料
1. PgRouting: http://www.pgrouting.org/
2. PgRouting文档介绍 http://www.davidgis.fr/documentation/pgrouting-1.02/
3. 使用pgRouting进行路径分析 http://blog.csdn.net/warrenwyf/article/details/5703360
4. OSGEO pgrouting http://download.osgeo.org/pgrouting/
5. Windows编译 http://www.pgrouting.org/docs/howto/build_on_windows.html
6. 运用pgrouting求解最短路径 http://2007.foss4g.org/presentations/view.php?abstract_id=84
7. PostLBS http://en.giswiki.net/wiki/PostLBS
8. 测试数据地址:http://wiki.openstreetmap.org/wiki/Planet.osm