【问题标题】:BGL - using flow algorithms with bundled propertiesBGL - 使用具有捆绑属性的流算法
【发布时间】:2016-01-25 20:03:48
【问题描述】:

我似乎无法弄清楚如何让 BGL 的 push-relabel 最大流量算法与捆绑属性一起使用。

这样设置图表:

struct VertexProperties{

};

struct EdgeProperties{
    int id;
    int capacity;
    int residual_capacity;
};

typedef boost::adjacency_list<vecS,vecS,directedS,VertexProperties,EdgeProperties> Graph;
typedef boost::graph_traits<Graph> Traits;
typedef Traits::vertex_descriptor Vertex;
typedef Traits::edge_descriptor Edge;

我创建一个

Graph g(nofNodes); // nofNodes > 2

然后选择

Vertex s = vertex(nofNodes-2,g); //source
Vertex t = vertex(nofNodes-1,g); //sink

然后我继续向图中添加边,并为每个插入的边添加容量为 0 的反向边。

使用地图

std::map<Edge,Edge> reverse_edge_of;

void do_add_edge(int& next_id, const Vertex& a, const Vertex& b, const int c, Graph& g,std::map<Edge,Edge>& reverse_edge_of){
    Edge e,re; bool success;

    std::tie(e,success) = add_edge(a,b,g);
    g[e].id = next_id;
    g[e].capacity = c;
    g[e].residual_capacity = c;

    //reverse edge
    std::tie(re,success) = add_edge(b,a,g);
    g[re].id = next_id + 1;
    g[re].capacity = 0;
    g[re].residual_capacity = 0;

    reverse_edge_of[e] = re;
    reverse_edge_of[re] = e;

    next_id += 2;
}

完成后,我尝试像这样调用库函数push_relabel_max_flow

push_relabel_max_flow(
    g,
    s,
    t,
    capacity_map(get(&EdgeProperties::capacity,g))
    .residual_capacity_map(get(&EdgeProperties::residual_capacity,g))
    .reverse_edge_map(make_assoc_property_map(reverse_edge_of))
    .vertex_index_map(get(vertex_index,g))
);

这无法编译(带有非常不可读的错误消息)。

不幸的是,文档提供的示例仍在使用其标记为已弃用的内部属性,因此我很难在我的方法中找到错误。有人碰巧看到了吗?

虽然我们正在处理它(并且很可能是相关的),我可以以某种方式使边缘的反向边缘成为(捆绑的一部分!)边缘属性吗?如果有,怎么做?

更新

不知道这里发生了什么,但事实证明

        int maxflow = push_relabel_max_flow(
            g,
            s,
            t,
            capacity_map(get(&EdgeProperties::capacity,g))
            .residual_capacity_map(get(&EdgeProperties::residual_capacity,g))
            .reverse_edge_map(make_assoc_property_map(reverse_edge_of))
            .vertex_index_map(get(vertex_index,g))
        );

会产生错误,而

        int maxflow = push_relabel_max_flow(
            g,
            s,
            t,
            get(&EdgeProperties::capacity,g),
            get(&EdgeProperties::residual_capacity,g),
            make_assoc_property_map(reverse_edge_of),
            get(vertex_index,g)
        );

没有。

(例如

按预期工作:http://ideone.com/U3O0p8

编译器错误:http://ideone.com/uUuiKc

)

【问题讨论】:

  • 你有一个独立的例子吗?我的意思是,我可以花 10 分钟解谜,也可以花 10 分钟回答。

标签: c++ c++11 boost boost-graph boost-property-map


【解决方案1】:

至少你必须在预期的地方传递属性映射:

.reverse_edge_map(make_assoc_property_map(reverse_edge_of))

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    相关资源
    最近更新 更多