Boost logo

Boost Users :

Subject: [Boost-users] [BGL] Structure for BFSvisitor is in header file (visitor & property confusion)??
From: Trevor Bain (trevor.bain_at_[hidden])
Date: 2009-03-03 16:07:42


I have my graph working with BFS, and a BFSvisitor. But, I don't want the
BFSvisitor to be in the header file. Since, it is, I have to declare properties
I want to use in the visitor, but then I have to pass them in in the constructor
for the class that contains the graph and the visitor structure ...

Here is my visitor (in .hpp):

/* ... other code */

/*! Structure for creating BFSvisitor
*
* The property maps are being assigned in the constructor for the
* Ann object - I don't know how inneficient of a method that is.
* i.e. if I should be using references.
*/
struct propagate_node : public boost::base_visitor<propagate_node> {
                
        // getting the dynamically created VoltageMap
        boost::property_map<Digraph, vertex_voltage_t>::type voltmap;
        boost::property_map<Digraph, vertex_input_t>::type inputmap;
        boost::property_map<Digraph, vertex_output_t>::type outputmap;
                
          typedef boost::on_discover_vertex event_filter;
                
        /*
         * This is a functor For Breadth First Visit.
        */
        template <class Vertex, class Digraph>
        void operator()(Vertex v, Digraph& G) {
                        
                boost::graph_traits<Digraph>::out_edge_iterator ed;
                        
                // getting the dynamically created VoltageMap && InputMap
                double volt = boost::get(voltmap, v);
                bool in = boost::get(inputmap, v);
                bool out = boost::get(outputmap, v);
                        
                // mapping sigmoid (don't apply sigmoid to input/output layers)
                if (in == false && out == false) {
                        // justify this sigmoid ???
                        volt = 1/(1+pow(MYEXP,-volt));
                        boost::put(voltmap, v, volt);
                }
                        

                if (v != *vertices(G).first) {
                        for ( ed = boost::out_edges(v, G).first;
                              ed != boost::out_edges(v, G).second;
                              ed++)
                        {
                                boost::put( voltmap,
                                            target(*ed, G),
get(voltmap,target(*ed,G))+get(boost::edge_weight,G,*ed)* volt);
                                }
                        }
                  }
        } prop;

/* ... other code */

So in the c'tor I have to do (in .cpp):

/* ... in initializer list */
        VoltageMap(get(vertex_voltage_t(), net)),
        InputMap(get(vertex_input_t(), net)),
        OutputMap(get(vertex_output_t(), net)),

/* ... other code */

        prop.voltmap = VoltageMap;
        prop.inputmap = InputMap;
        prop.outputmap = OutputMap;

to pass my properties from the graph to the visitor ... there has to be a better
way to do this. How can I put the visitor definition into the .cpp, and only
declare it in the .hpp?


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