Boost logo

Boost Users :

Subject: Re: [Boost-users] [Graph] newbie to graph (Andrew Sutton) (Phillip Jones)
From: Lior Weizman (lior.weizman_at_[hidden])
Date: 2008-11-03 05:29:47


Hello,
Applying the suggestion below:

>
>
> struct Node {
> std::string name;
> long index;
> boost::default_color_type color;
> long distance;
> graph_traits<Graph>::edge_descriptor predecessor;
> };
>
> struct Arc {
> long capacity;
> long residual;
> graph_traits<Graph>::edge_descriptor rev;
> };
>
> With the following call:
>
> flow = kolmogorov_max_flow(g, s, t,
> capacity_map(get(&Arc::capacity, g)).
> residual_capacity_map(get(&Arc::residual, g)).
> reverse_edge_map(get(&Arc::rev, g)).
> predecessor_map(get(&Node::predecessor, g)).
> color_map(get(&Node::color, g)).
> distance_map(get(&Node::distance, g)).
> vertex_index_map(get(&Node::index, g))
> );
>
> Resulted with many errors.But I think I found the right way. The following
code compiles without errors or warnings:
----------------CODE----------------------------
#include <boost/config.hpp>
#include <iostream>
#include <string>
#include <boost/graph/kolmogorov_max_flow.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/write_dimacs.hpp>
#include <boost/graph/read_dimacs.hpp>
using namespace boost;
struct Arc;
struct Node;
typedef adjacency_list<vecS,vecS,directedS,Node,Arc> Graph;
struct Arc {
    long capacity;
    long residual_capacity;
    Graph::edge_descriptor reverse;
};
struct Node {
    std::string name;
    Graph::edge_descriptor predecessor;
    default_color_type color;
    long distance;
    long index;
};
int
main()
{
    typedef Graph::vertex_descriptor vertex_descriptor;
    typedef Graph::edge_descriptor edge_descriptor;
    typedef std::pair<edge_descriptor, bool> EdgePair;
    typedef std::pair<int,int> Pair;
    Graph g;

    property_map<Graph, long Arc::*>::type capacity
        = get(&Arc::capacity, g);
    property_map<Graph, long Arc::*>::type res_capacity
        = get(&Arc::residual_capacity, g);
    property_map<Graph, Graph::edge_descriptor Arc::*>::type reverse
        = get(&Arc::reverse,g);
    property_map<Graph,Graph::edge_descriptor Node::*>::type predecessor
        = get(&Node::predecessor,g);
    property_map<Graph,default_color_type Node::*>::type color
        = get(&Node::color,g);
    property_map<Graph,long Node::*>::type distance
        = get(&Node::distance,g);
    property_map<Graph,long Node::*>::type index
        = get(&Node::index,g);
    long flow;
    vertex_descriptor s, t;
    Pair edge_array[6] = { Pair(0,1), Pair(0,2), Pair(0,3),
                           Pair(2,4),
                           Pair(1,3), Pair(4,3),
    };
    EdgePair edge_desc_obj;
    EdgePair
edge_from_first=add_edge(edge_array[0].first,edge_array[0].second,g);
    g[edge_from_first.first].capacity=1;

    for (int i = 1; i < 5; ++i){
        edge_desc_obj=add_edge(edge_array[i].first, edge_array[i].second,g);
        g[edge_desc_obj.first].capacity=i+1;
    }
     EdgePair
edge_to_last=add_edge(edge_array[5].first,edge_array[5].second,g);
    g[edge_to_last.first].capacity=4;
    char str[2];
    int i=0;
    vertex_descriptor v1=*vertices(g).first,v2=*vertices(g).second;
    while (v1!=v2)
    {
        sprintf(str,"%d",i);
        g[v1].name=str;
        v1++;
        i++;
    }
    edge_descriptor from_s,to_t;
    from_s=edge_from_first.first;
    to_t=edge_to_last.first;
    s=source(from_s,g);
    t=target(to_t,g);
    flow =
kolmogorov_max_flow(g,capacity,res_capacity,reverse,predecessor,color,distance,index,s,t);
    return 0;
}
-----------------------------END OFCODE-----------------

However when trying to run this code I receive "Segmentation error". (this
error does not appear when I remove the call to kolmogorov)
I work under linux and I tried to compile with both g++ and g++-3.3
The valgrind output can be found at:
http://www.cs.huji.ac.il/~lweizm45/valgring_output.txt

Any suggestions?

Lior



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net