Boost logo

Boost Users :

Subject: [Boost-users] Seg fault while adding 2nd edge to the graph
From: Phani Deepak (phanidee_at_[hidden])
Date: 2009-03-22 10:03:57

      i started using BGL for my project.
      strangely all the examples i tried to learn BGL worked fine. But when
i write the
      actual code for my project, it started giving me this error.

             While adding second edge to the boost graph using
      it is giving out a seg fault.

Please help with this prob.

Iam also attaching the code that's giving the error

/*********Code that's giving this error****************/

class Node{

        std::string id;
        double Energy;
        Node() {}


class EdgeProperties {
    int targetI;
    int sourceI;
    EdgeProperties(int s,int t):sourceI(s),targetI(t) { }

                                Node *,EdgeProperties *> Graph;

typedef boost::graph_traits<Graph> GraphTraits;
typedef GraphTraits::vertex_descriptor Vertex;
typedef GraphTraits::edge_descriptor Edge;

namespace boost {

    Vertex getVertexbyId(std::string id,Graph g){
        std::cout << "getVID called for " << id << std::endl;
        GraphTraits::vertex_iterator vstart,vend;
        for(boost::tie(vstart,vend) = boost::vertices(g); vstart!=vend;
vstart++) {
            if(g[*vstart]->id == (id)) return *vstart;
        std::cout << "Critical Error: |" << id << "| referencing node not
present in graph " << std::endl;
        return NULL;

int main(){

    Graph g;

    // populate Graph with all the vertices and edges.
    std::cout << "* Populating graph with Vertices and Edges " << std::endl;

    Vertex v = boost::add_vertex(g);
    g[v] = new Node();
    g[v]->id = "xor_1";
    g[v]->Energy = 2.3;

    std::cout << "Inserted xor_1" << std::endl;

    v = boost::add_vertex(g);
    g[v] = (new Node());
    g[v]->id = "and_1";
    g[v]->Energy = 1.9;

    std::cout << "Inserted and_1" << std::endl;

    v = boost::add_vertex(g);
    g[v] = (new Node());
    g[v]->id = "i_1";
    std::cout << "Inserted i_1" << std::endl;

    // add Edges

    std::pair<Edge,bool> e;

    EdgeProperties *ep = new EdgeProperties(1,1);
    e =
    std::cout << "Inserted Edge 1" << std::endl;

    ep = new EdgeProperties(1,2);
    e =
    std::cout << "Inserted Edge 2" << std::endl;




Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at