|
Boost Users : |
From: Stephan Diederich (stephan.diederich_at_[hidden])
Date: 2006-09-18 17:13:09
Hi Tom,
2006/9/18, Tom Lenaerts <tlenaert_at_[hidden]>:
[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
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