c++ - How to modify properties while proceeding BFS in Boost Graph Library? -
i'm using bundled property graph. definitions follows:
class node {     void assignplane(plane& p)     plane* dp;     double errors; }  void node::assignplane(plane& p) {     dp=&p;     errors=p.a+p.b+p.c;// simplified }  typedef adjacency_list<vecs,vecs,bidirectionals,node,float> ngraph;  //...  struct nvisitor: default_bfs_visitor {     void discover_vertex(vertexdesc u, const ngraph& g) const     {         // can't modify g     } } but can't call g[u].assignplane(p) modify vertex, nor can pointer vertex, both vital me. 
 though question may seem stupid, novice of boost, , have fought 2 weeks adapt convoluted style of boost codes, need help. 
 not try answer "you need use other bgl", please, can find nothing support work other bgl. 
 , must say, official documentation not intended explain great work in simpler way. since have read documentation dozens of times, not suggest me reread documentation. 
 appreciate useful help, , thank in advance. 
you make fields mutable
class node {     void assignplane(plane& p) const;     plane* mutable dp;     double mutable errors; }  void node::assignplane(plane& p) const {     dp=&p;     errors=p.a+p.b+p.c;// simplified } otherwise, consider holding non-const "reference" graph inside visitor:
struct nvisitor: default_bfs_visitor {     ngraph* gref_;     nvisitor(ngraph& g) : gref_(&g) {}      void discover_vertex(vertexdesc u, const ngraph& g) const     {         plane* p = /*get somewhere*/;         (*gref_)[u].assignplane(p);     } } be careful not break invariants bfs (like, don't edit edges while traversing).
Comments
Post a Comment