<div dir="ltr"><div><div><div>The code below implements the deletion of parts of a DAG not reachable from a certain node. The DAG (ListDigraph) represents a Game Tree with Transpositions in a "Monte Carlo Tree Search"-implementation. So the code below does a depth first traversal of the tree (dag), using a std::stack, marks the visited nodes as visited and deletes the nodes not visited. I found that deletion of a node invalidates the iterator, so I store the nodes temporarily in a std::vector and then delete all afterwards. The code is as follows:<br><br>void dag_slice ( Graph& dag_, const Node& node_ ) {<br><br>    stack<Node> stk_;<br><br>    stk_.push ( node_ );<br><br>    IterableBoolNodeMap ibm_ ( dag_ );<br><br>    while ( not ( stk_.empty ( ) ) ) {<br><br>        const Node n_ ( stk_.top ( ) );<br><br>        stk_.pop ( );<br><br>        ibm_.set ( n_, true );<br><br>        for ( OutArcIt a_ ( dag_, n_ ); a_ != lemon::INVALID; ++a_ ) {<br><br>            const Node t_ ( dag_.target ( a_ ) );<br><br>            if ( not ( ibm_ [ t_ ] ) ) {<br>            <br>                stk_.push ( t_ );<br>            }<br>        }<br>    }<br><br>    vector<Node> ns_;<br><br>    for ( IterableBoolNodeMap::FalseIt n_ ( ibm_ ); n_ != lemon::INVALID; ++n_ ) {<br>    <br>        ns_.push_back ( n_ );<br>    }<br><br>    for ( auto n_ : ns_ ) {<br>    <br>        dag_.erase ( n_ );<br>    }<br>}<br><br></div>My questions are as follows: Is this a reasonable way to do this? Are there better suited tools in the lemon library? Should one store Id's instead of Nodes, and why, if so? Do you have any other suggestions?<br><br></div>Thank you in advance,<br><br></div>Degski<br></div>