我应该如何从访问者内部修改顶点的捆绑属性?
我想使用简单的下标图形的方法,但是传递给访问者的图形参数是 const,因此编译器不允许更改。
我可以在访问者中存储对图表的引用,但这似乎很奇怪。
/**
A visitor which identifies vertices as leafs or trees
*/
class bfs_vis_leaf_finder:public default_bfs_visitor {
public:
/**
Constructor
@param[in] total reference to int variable to store total number of leaves
@param[in] g reference to graph ( used to modify bundled properties )
*/
bfs_vis_leaf_finder( int& total, graph_t& g ) :
myTotal( total ), myGraph( g )
{
myTotal = 0;
}
/**
Called when the search finds a new vertex
If the vertex has no children, it is a leaf and the total leaf count is incremented
*/
template <typename Vertex, typename Graph>
void discover_vertex( Vertex u, Graph& g)
{
if( out_edges( u, g ).first == out_edges( u, g ).second ) {
myTotal++;
//g[u].myLevel = s3d::cV::leaf;
myGraph[u].myLevel = s3d::cV::leaf;
} else {
//g[u].myLevel = s3d::cV::tree;
myGraph[u].myLevel = s3d::cV::tree;
}
}
int& myTotal;
graph_t& myGraph;
};