如何定义在加速Dijkstra算法定制的距离? [英] How do I define a custom distance in Boost Dijkstra?

查看:174
本文介绍了如何定义在加速Dijkstra算法定制的距离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我期待在加速Dijkstra算法的文档 - 的 http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/dijkstra_shortest_paths.html ;我的目的是修改结合起来,得到一个最大,而不是加计算时,我距离的距离。该医生说这样的:

I'm currently looking at the documentation of Boost Dijkstra - http://www.boost.org/doc/libs/1_52_0/libs/graph/doc/dijkstra_shortest_paths.html; my objective is to modify the distance combining to get a "max" instead of a "plus" when computing my distances. The doc says this:

IN: distance_combine(CombineFunction cmb)
This function is used to combine distances to compute the distance of a path. The
CombineFunction type must be a model of Binary Function. The first argument typ
of the binary function must match the value type of the DistanceMap property map
and the second argument type must match the value type of the WeightMap property
map. The result type must be the same type as the distance value type.
Default: closed_plus<D> with D=typename property_traits<DistanceMap>::value_type

什么是语法定义这样的合并功能?我试着摸索与周围的std ::最大的,但我的编译器似乎并不乐意用它。

What's the syntax to define such a Combine function? I've tried fumbling around with std::max, but my compiler doesn't seem to be happy with it.

推荐答案

也许有它的参数是模板是可能使事情变得有点困难......

Probably having its arguments be templates is might make things a bit difficult...

TRY(其中T是你的距离的类型)

Try (where T is the type of your distances)

T comb(T& a, T& b) { return std::max(a, b); }

和通过梳理。

这篇关于如何定义在加速Dijkstra算法定制的距离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆