Boost logo

Boost Users :

Subject: Re: [Boost-users] [Graph] newbie to graph (Andrew Sutton)
From: Lior Weizman (lior.weizman_at_[hidden])
Date: 2008-11-02 06:32:11


Hello,

Thank you for your reply.

I implemented your suggestions but the problem persists. Below is the
current version of my code:
--------------------------------------------------------------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;
};
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, Graph::edge_descriptor Arc::*>::type rev
        = get(&Arc::reverse,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;
        std::cout << 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, s, t);
    return 0;
}
-------------------------------------------------------------------END OF
CODE------------------------------------------------------------------

The compilation output of the code above includes errors and can be found
here:

http://www.cs.huji.ac.il/~lweizm45/compile_output2.txt>

Again, if I remove the call to kolmogorv_max_flow, everyting is fine. If I
replace
the call to kolmogorov_max_flow with the line:

write_dimacs_max_flow(g, capacity, identity_property_map(),s, t, std::cout);

The output is:
-------------------------------------- OUTPUT
------------------------------------------------------
c DIMACS max-flow file generated from boost::write_dimacs_max_flow
p max 5 6
n 1 s
n 4 t
a 1 2 1
a 1 3 2
a 1 4 3
a 2 4 5
a 3 5 4
a 5 4 4
---------------------------------------- END OF OUTPUT
--------------------------------------------------
Which means that the graph was created correctly.

Any suggestions?

Thanks,

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