boost::graph自定义权重类型:numeric_limits必需
boost::graph custom weight type: numeric_limits necessary?
我在boost图中有一个自定义边属性(MyWeight
),并且希望应用Dijkstra最短路径搜索。
在boost的帮助下,我的权重类型是:运算符、可加、可减、小于可比和相等可比。
因为我知道搜索必须从某个东西开始,我需要一个零的等价物,并找出一个节点是否可以到达,一个非常大的节点。
MyWeight weight_zero(...), weight_inf(...);
// now, weight_zero is less than all other weights, weight_inf greater than all other weights.
boost::dijkstra_shortest_paths( G, target_idx, boost::predecessor_map(&predecessors[0])
.distance_map(&distances[0])
.distance_inf(weight_inf)
.distance_zero(weight_zero)
);
这就是我使用自定义重量的原则。它与gcc 4.8.1一起编译(似乎工作正常),但与gcc 4.7.3一起,我得到了以下错误(稍微缩短了一点):
/usr/include/c++/4.7/limits:-1: In instantiation of 'static constexpr _Tp std::numeric_limits<_Tp>::max() [with _Tp = MyWeight<2, MyEvaluator>]':
/usr/include/c++/4.7/limits:313: error: no matching function for call to 'MyWeight<2, MyEvaluator>::MyWeight(int)'
(MyWeight
实际上是一个模板)
我将此消息解释为"您的类型没有std::numeric_limit",另一方面,我告诉BGL要使用哪个极值,不明白它为什么试图调用数字限制。我认为在这里最好的尝试是让numeric_limits
识别我的自定义数据类型。
有人能告诉我如何做到这一点吗?
我在这里找到了第一个提示,但这个例子使用了digits
和digits10
这样的成员,我想知道它们来自哪里。
编辑
这是一个和我一样的例子。无法编译它,有关错误,请参阅上文。
这似乎是命名参数包装中的一个错误(或缺陷;我不确定它是否可以修复),即使不使用默认值,它也会扩展默认值。如果使用位置参数重载并手动填写中的所有参数,则不需要numeric_limits
。
相关文章:
- "迭代器"和"const_iterator"不是 STL 容器的必需成员?
- <limits> 使用 VSC2019 编译旧代码时出错
- 类型别名允许分配任意指针,尽管 int* 是必需的
- 合并 2 个排序的链表。必需的成员函数 bool Merge(List342 &list1):
- 为什么常量变量是模板特殊化所必需的,而不是常量
- limits.h中未确认的值
- 是防止原子存储部分读取所必需的"memory_order_relaxed"
- OpenCV make error: limits.h 没有这样的目录文件
- 标头包含不是 .c 程序所必需的,而是.cpp程序需要的
- 如何检查每个头文件是否包含必需的包含文件?
- 这->...在模板包装类中必需
- 在没有 <limits.h> 或 <values.h> 的系统上查找SHRT_MAX
- 在ROS中,C++和Python都是必需的吗?
- 如何将必需的 protobuf 字段设置为其默认值?
- std::function, Clang 6.0 & MSVC (10.0017134.12) - 可能的 ABI 错误或必需的编译器标志
- Python 包 cx_Oracle==5.1.3 Microsoft Visual C++ 9.0 是必需的
- 为什么 std::integral_constant 在爆炸 std::tuple 时是必需的?
- 通过为每个线程独占使用对象(不在线程之间共享)是保护该类的成员函数所必需的
- 假设包含所有必需的头文件,输出将是什么
- static_cast 使用 std::get 与枚举类时必需的