
This is again a newbie question. I want to create a graph based on some input file. I parse this file and in the code I want to check whether the link already exists int current=strToInt(tokens[0]); int numedges=strToInt(tokens[1]); for(int i=0;i<numedges;i++){ Vertex first=vertex(current,*g); int other=strToInt(tokens[3+i]); Vertex second=vertex(other,*g); pair<Edge, bool> result=boost::edge(first,second,*g); if(!result.second){ boost::add_edge(first,second,*g); } } tokens[0] is the id of the node, tokens[1] contains the number of edges this node is pointing to. From tokens[3] until the end, one gets the nodes to which the current node is connected (stored in other) As you can see I call the function boost::edge() to check whether there is already a link between first and second. As soon as I do this I get an error in Xcode. Does anyone know what I'm doing wrong here. It probably something very simple but I don't see it. Thanks in advance Tom

Hi Tom, 2006/9/18, Tom Lenaerts <tlenaert@vub.ac.be>: [snip] :)
As you can see I call the function boost::edge() to check whether there is already a link between first and second. As soon as I do this I get an error in Xcode.
I think you need to specify your error more precisely. What error do you get? A runtime or compile-time error? And please add the error message. Another good thing is to post a(n extracted) test case (including main). So one can easily try to compile your program and see what type Vertex, Edge, and especially the Graph is. There are several reasons for this, the one you will like most is, that more people will help you ;) I just added the sourrounding code how I'd do it, and that worked for me: #include <boost/graph/adjacency_list.hpp> #include <boost/lexical_cast.hpp> #include <string> #include <iostream> int main(){ using namespace boost; using namespace std; typedef adjacency_list<vecS, vecS, directedS> tGraph; tGraph g(1); typedef graph_traits<tGraph>::vertex_descriptor Vertex; typedef graph_traits<tGraph>::edge_descriptor Edge; string tokens[] = {"0", "3", "1", "2", "2"}; //test case int current = lexical_cast<int>(tokens[0]); int numedges = lexical_cast<int>(tokens[1]); Vertex first=vertex(current,g); //moved that out of the loop for(int i = 0; i < numedges; ++i){ int other = lexical_cast<int>(tokens[2+i]); //<---- should be 2 instead of 3?! Vertex second = vertex(other, g); pair<Edge, bool> result = edge(first, second, g); if(!result.second){ add_edge(first, second, g); } } cout << "Number of edges in tokens: " << numedges << "\n"; cout << "Number of edges in graph: " << num_edges(g) << "\n"; } HTH, Stephan
participants (2)
-
Stephan Diederich
-
Tom Lenaerts