Boost graph - 理解编译错误和最小属性

Boost graph - understanding compilation errors and minimal properties

following 代码(片段 1)编译良好:

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/boykov_kolmogorov_max_flow.hpp>
#include <boost/graph/graph_utility.hpp>

using namespace boost;

typedef adjacency_list_traits<vecS, vecS, directedS> Traits_vvd;
typedef adjacency_list_traits<vecS, vecS, undirectedS> Traits_vvu;

typedef adjacency_list<
    vecS, vecS, directedS,
    property<
    vertex_index_t, int,
    property<vertex_color_t, boost::default_color_type,
    property<vertex_distance_t, double,
    property<vertex_predecessor_t, Traits_vvd::edge_descriptor>
    > > >,
    property<
    edge_index_t, int,
    property<edge_capacity_t, double,
    property<edge_weight_t, double,
    property<edge_residual_capacity_t, double,
    property<edge_reverse_t, Traits_vvd::edge_descriptor>
> > > > >
Graph_vvd;

class MAXFLOW_ {
public:
    double solve_max_flow(int s, int t){
        double retval = boykov_kolmogorov_max_flow(g, s, t);
        return retval;
    }
private:
    Graph_vvd g;
};

int main(){
    return 0;
}

但是,从图表中删除 vertex_distance_tvertex_predecessor_t 后,我们有 this 无法编译的代码(代码段 2):

#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/boykov_kolmogorov_max_flow.hpp>
#include <boost/graph/graph_utility.hpp>

using namespace boost;

typedef adjacency_list_traits<vecS, vecS, directedS> Traits_vvd;
typedef adjacency_list_traits<vecS, vecS, undirectedS> Traits_vvu;

typedef adjacency_list<
    vecS, vecS, directedS,
    property<
    vertex_index_t, int,
    property<vertex_color_t, boost::default_color_type
    > >,
    property<
    edge_index_t, int,
    property<edge_capacity_t, double,
    property<edge_weight_t, double,
    property<edge_residual_capacity_t, double,
    property<edge_reverse_t, Traits_vvd::edge_descriptor>
> > > > >
Graph_vvd;

class MAXFLOW_ {
public:
    double solve_max_flow(int s, int t){
        double retval = boykov_kolmogorov_max_flow(g, s, t);
        return retval;
    }
private:
    Graph_vvd g;
};

int main(){
    return 0;
}

片段 1 和片段 2 之间的唯一区别是在第二个片段中,没有与 vertex_distance_tvertex_predecessor_t 相关的顶点属性。

我的问题是:

(1)编译错误here看不懂。有没有一种方法可以开始理解错误并随后找出错误指定算法正常运行所需的属性,在这种情况下算法使用 boykov_kolmogorov 方法找到最大流量?

(2) 在查看此算法的 boost 文档中提供的代码示例时,可用 here,确实顶点具有所需的属性:

property < vertex_name_t, std::string,
    property < vertex_index_t, long,
    property < vertex_color_t, boost::default_color_type,
    property < vertex_distance_t, long,
    property < vertex_predecessor_t, Traits::edge_descriptor > > > > >,

但是这段代码也有一些不必要的属性,例如 vertex_name_t 没有这些属性,代码段 1 编译得很好。有没有办法找出最少的属性集来指定 boost 算法的正常运行?

算法记录了所需的属性:https://www.boost.org/doc/libs/1_76_0/libs/graph/doc/boykov_kolmogorov_max_flow.html

您可以看到哪些参数是 IN/OUT 或 UTIL,以及哪些参数具有默认值(使它们成为非强制性的,除非默认表达式对您的图形类型无效)。

我已经针对你之前的问题反复这样做了:

  • 其中我已经减少到最小的属性集¹并且还展示了如何将它们作为命名参数传递,而不是依赖内部属性“神奇地”获取它们.

    ¹ 也许 edge-id 除外,因为我认为它们对于您周围的代码是必不可少的,因为您已经付出了相当大的努力来为它生成值 属性

  • 这个较旧的答案我基本上做了同样的工作 (but still kept the name property uncommented), and also pointed out the known issue with boykov_kolmogorov_max_flow:

简而言之:

  • 编译器消息令人生畏。阅读它们需要一些图书馆经验。遗憾的是,这是将 C++03 与高度通用的模板一起使用的必然结果。如果您不需要这种通用库的原始功能,那么那里可能有更多用户友好的图形算法库。

    I say C++03 because newer standards would allow for better diagnostics. Specifically, I'd be thrilled to have a concepts-enabled version of BGL. "Unfortunately" (?) BGL remains C++03 compatible.

  • 基本上,您可以专注于文档,而不是编译器消息。如果你“搞砸”了特定于 C++ 而非特定于库的东西(或 运行 变成

    ,你仍然需要理解这些消息
  • 如果您对最低要求感兴趣,请关注 API 参考,而不是示例。示例经常随着时间的推移而演变,或者从其他示例中重复使用 data/models,因此不能假定它们是最小的。 (有时甚至可能取决于您的选择和偏好)。