Boost logo

Boost Users :

From: Aaron Windsor (aaron.windsor_at_[hidden])
Date: 2007-02-21 21:26:15


On 2/21/07, Shufei Fan <fansf_at_[hidden]> wrote:

<snip>

> Somewhere in my program, I construct it using add_edge() method. What I want
> is, I allow parallel edges, but I all parallel ones being merged(weight
> summed together). Can I add edges one by one, and use an general method to
> 'magically' merge them?(is there a function doing merging?)

Hi Shufei,

No, there's no general method in the BGL to merge edges as you
describe.

If you want all parallel edges merged, you probably don't want to add
parallel edges to begin with. I would suggest defining your graph as

typedef boost::adjacency_list<
    boost::setS, boost::vecS, boost::undirectedS,
    Node, Edge> Graph;

which disallows parallel edges. add_edge(u,v,g) returns a std::pair
consisting of an edge descriptor and a bool signalling whether the edge
u,v was added. So check that bool and, if it's false, increment the weight
rather than assigning it.

> My second question is, where should I find a complete list of usage of all
> the library methods(say, manual for add_edge)

The online manual is very thorough - in your case, I'd suggest starting here:

http://www.boost.org/libs/graph/doc/graph_concepts.html

Regards,
Aaron


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