BGL - 使用具有捆绑属性的流算法

时间:2015-10-26 16:15:32

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

我似乎无法弄清楚如何使用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

1 个答案:

答案 0 :(得分:1)

至少你必须传递预期的属性图:

.reverse_edge_map(make_assoc_property_map(reverse_edge_of))
相关问题