Boost logo

Boost Users :

From: Eric Fowler (eric.fowler_at_[hidden])
Date: 2006-09-06 23:30:20


I am writing a simple graph app. The edges have an unsigned integer property
that is incremented every time I "add" an edge from one given node to
another, thus, any given edge has an "instance" of at least one, but if
there are, say, three edges from node A to node B, edge A->B has nInstances
== 3.

To do this I would like to attempt to add an edge between nodes, and if the
edge has already been added, just bump the counter for that edge, otherwise,
set the counter to 1. My basic approach is to call tie(edge_iter, boolflag)
= add_edge(v0, v1, graph). If boolvar is set to false then the edge already
was in the graph.

The problem is that add_edge() never clears boolvar - it is always true,
even when I coerce redundant edges, as in the following code:

#include "stdafx.h"
#include <boost/graph/adjacency_list.hpp>
#include <boost/property_map.hpp>

using namespace boost;
using namespace std;

//Don't worry about the vertex property, it is irrelevant ...
struct vertex_char_t
{
    typedef vertex_property_tag kind;
};
typedef property<vertex_char_t, char> VertexCharProperty;

typedef adjacency_list<vecS, vecS, directedS, VertexCharProperty> Graph;

int _tmain(int argc, _TCHAR* argv[])
{

    Graph g(256);
    property_map<Graph, vertex_char_t>::type vert_char =
get(vertex_char_t(), g);
    typedef graph_traits<Graph>::vertex_descriptor Vertex;
    Vertex va, vb;
    typedef graph_traits<Graph>::edge_descriptor Edge;
    Edge ei;

    bool bNotPresent = false;
    for(unsigned i = 0; i < 256; ++i)
    {
        va = vertex(0, g);
        vb = vertex(1, g);

/*
***ADD REDUNDANT EDGES BETWEEN NODES 0, 1
*/
        tie(ei, bNotPresent) = add_edge(va, vb, g);

//BUT MY FLAG ALWAYS == true, why?
        if(!bNotPresent)
            break;
    }

    return 0;
}



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