How to convert graphtraits<Graph>::in_edge to graphtraits<Graph>::edge
hi, i have stored some bundled properties for an edge. * class EdgeProperties { public: int targetI;// Terminal No. interms of target node int sourceI;// Terminal No. interms of source node EdgeProperties(int s,int t):sourceI(s-1),targetI(t-1) { } };* my Graph is : *typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, EdgeProperties *> Graph; Graph g; * Now iam iterating through in_edges of some vertex v; *graphtraits<Graph>::in_edge_iterator iedge_s,iedge_end; for(boost::tie(iedge_s,iedge_end) = boost::in_edges(v,g); iedge_s!=iedge_end; ++iedge_s){ EdgeProperties *ep = g[*iedge_s]; // <==== **Line 10** cout << ep->sourceI << endl; // <==== **This is giving segmentation fault;** } * I checked the *ep* pointer. it is coming out as null in line 10; is there any problem while using *in_edge_descriptor* as *edge_descriptor**( for g[edge_descriptor]* ) in *Line 10* ?? * *please help. - Phani. * *
The same code is working fine if i use boost::target(*iedge_s,g) or boost::source(*iedge_s,g); i mean that source and target of the edge that it is returning are the right ones. here i think iam able to use *in_edge_descriptor* as *edge_descriptor* - Phani. On Tue, Mar 24, 2009 at 11:35 PM, Phani Deepak <phanidee@gmail.com> wrote:
hi, i have stored some bundled properties for an edge. * class EdgeProperties { public: int targetI;// Terminal No. interms of target node int sourceI;// Terminal No. interms of source node EdgeProperties(int s,int t):sourceI(s-1),targetI(t-1) { } };*
my Graph is : *typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, EdgeProperties *> Graph; Graph g; * Now iam iterating through in_edges of some vertex v; *graphtraits<Graph>::in_edge_iterator iedge_s,iedge_end; for(boost::tie(iedge_s,iedge_end) = boost::in_edges(v,g); iedge_s!=iedge_end; ++iedge_s){ EdgeProperties *ep = g[*iedge_s]; // <==== **Line 10** cout << ep->sourceI << endl; // <==== **This is giving segmentation fault;** } * I checked the *ep* pointer. it is coming out as null in line 10;
is there any problem while using *in_edge_descriptor* as *edge_descriptor* *( for g[edge_descriptor]* ) in *Line 10* ?? * *please help.
- Phani. * *
The same code is working fine if i use
boost::target(*iedge_s,g) or boost::source(*iedge_s,g);
That's because these functions return a vertex_descriptor. my Graph is :
*typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, EdgeProperties *> Graph; *
Your graph doesn't seem to have edge properties. The EdgeProprties* type appears to be substituted for the VertexProperties parameter, not EdgeProperties. Andrew Sutton andrew.n.sutton@gmail.com
hi Andrew, On Wed, Mar 25, 2009 at 6:53 AM, Andrew Sutton <andrew.n.sutton@gmail.com>wrote:
my Graph is :
*typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, EdgeProperties *> Graph; *
Your graph doesn't seem to have edge properties. The EdgeProprties* type appears to be substituted for the VertexProperties parameter, not EdgeProperties.
Sorry for the typo, The actual declaration was *typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, NodeProperties*, EdgeProperties *> Graph; **** class Node{ public: string id; }; class EdgeProperties { public: int targetI;// Terminal No. interms of target node int sourceI;// Terminal No. interms of source node EdgeProperties(int s,int t):sourceI(s-1),targetI(t-1) { } }; Graph g; typedef graphtraits<Graph>::vertex_descriptor Vertex; for(boost::tie(iedge_s,iedge_* *end) = boost::in_edges(v,g); iedge_s!=iedge_end; ++iedge_s) { Vertex src = boost::source(*iedge_s,g); Vertex target = boost::target(*iedge_s,g); cout << g[src]->id << "-->" << g[target]->id << endl; EdgeProperties *ep = g[*iedge_s]; // <==== Line 10; g[*iedge_s] is returning null cout << ep->sourceI << endl; // <==== This is giving segmentation fault; } ** ***here g[*iedge_s] is returning null** is it the problem because iam using (*iedge_s) as (edge_descriptor) or the problem somewhere in my code where in i had not properly assigned the property object to that specific edge. i just wanted to know whether both of these are same *graphtraits<Graph>::in_edge_iterator *iedge_iter; graphtraits<Graph>::edge_iterator *edge_iter; **(*edge_iter)* -> this becomes edge_descriptor *(*iedge_iter) -> ***whether this will also become edge_descriptor** pardon me if iam really missing any basic concept in here.
Andrew Sutton andrew.n.sutton@gmail.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Wed, Mar 25, 2009 at 12:01 PM, Phani Deepak <phanidee@gmail.com> wrote:
hi Andrew,
On Wed, Mar 25, 2009 at 6:53 AM, Andrew Sutton <andrew.n.sutton@gmail.com>wrote:
my Graph is :
*typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, EdgeProperties *> Graph; *
Your graph doesn't seem to have edge properties. The EdgeProprties* type appears to be substituted for the VertexProperties parameter, not EdgeProperties.
Sorry for the typo, The actual declaration was
*typedef boost::adjacency_list<boost::listS,boost::listS,boost::bidirectionalS, NodeProperties*, EdgeProperties *> Graph; *****
class NodeProperties {} instead of class Node
* class Node{ public: string id; }; class EdgeProperties { public: int targetI;// Terminal No. interms of target node int sourceI;// Terminal No. interms of source node EdgeProperties(int s,int t):sourceI(s-1),targetI(t-1) { } };
Graph g; typedef graphtraits<Graph>::vertex_descriptor Vertex; for(boost::tie(iedge_s,iedge_ * *end) = boost::in_edges(v,g); iedge_s!=iedge_end; ++iedge_s) { Vertex src = boost::source(*iedge_s,g); Vertex target = boost::target(*iedge_s,g); cout << g[src]->id << "-->" << g[target]->id << endl; EdgeProperties *ep = g[*iedge_s]; // <==== Line 10; g[*iedge_s] is returning null cout << ep->sourceI << endl; // <==== This is giving segmentation fault; } ** ***here g[*iedge_s] is returning null** is it the problem because iam using (*iedge_s) as (edge_descriptor) or the problem somewhere in my code where in i had not properly assigned the property object to that specific edge.
i just wanted to know whether both of these are same *graphtraits<Graph>::in_edge_iterator *iedge_iter; graphtraits<Graph>::edge_iterator *edge_iter; **(*edge_iter)* -> this becomes edge_descriptor *(*iedge_iter) -> ***whether this will also become edge_descriptor**
pardon me if iam really missing any basic concept in here.
Andrew Sutton andrew.n.sutton@gmail.com
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
* for(boost::tie(iedge_s,iedge_ * *end) = boost::in_edges(v,g); iedge_s!=iedge_end; ++iedge_s) { Vertex src = boost::source(*iedge_s,g); Vertex target = boost::target(*iedge_s,g); cout << g[src]->id << "-->" << g[target]->id << endl; EdgeProperties *ep = g[*iedge_s]; // <==== Line 10; g[*iedge_s] is returning null cout << ep->sourceI << endl; // <==== This is giving segmentation fault; } ** ***here g[*iedge_s] is returning null** is it the problem because iam using (*iedge_s) as (edge_descriptor) or the problem somewhere in my code where in i had not properly assigned the property object to that specific edge.
Any kind of edge iterator (in, out, etc.) dereferences to an edge descriptor, so you're not missing anything. You're not actually modifying the edge set in that loop are you? That will cause some serious problems. Otherwise, it looks like you may have missed an initialization. Andrew Sutton andrew.n.sutton@gmail.com
participants (2)
-
Andrew Sutton
-
Phani Deepak