[Lemon-commits] [lemon_svn] marci: r596 - hugo/trunk/src/work/marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:40:27 CET 2006
Author: marci
Date: Tue Apr 27 18:27:08 2004
New Revision: 596
Modified:
hugo/trunk/src/work/marci/bfs_iterator.h
Log:
bfs, dfs, bfsiterator, dfsiterator for alpar's sake of being much more standardized.
Modified: hugo/trunk/src/work/marci/bfs_iterator.h
==============================================================================
--- hugo/trunk/src/work/marci/bfs_iterator.h (original)
+++ hugo/trunk/src/work/marci/bfs_iterator.h Tue Apr 27 18:27:08 2004
@@ -28,9 +28,10 @@
graph(&_graph), reached(*(new ReachedMap(*graph /*, false*/))),
own_reached_map(true) { }
~BfsIterator() { if (own_reached_map) delete &reached; }
- //s is marcked reached.
- //if the queue is empty, then the its is pushed ant the first OutEdgeIt is processe.
- //is the queue is not empty, then is it pushed.
+ /// This method markes s reached.
+ /// If the queue is empty, then s is pushed in the bfs queue
+ /// and the first OutEdgeIt is processed.
+ /// If the queue is not empty, then s is simply pushed.
void pushAndSetReached(Node s) {
reached.set(s, true);
if (bfs_queue.empty()) {
@@ -50,6 +51,8 @@
bfs_queue.push(s);
}
}
+ /// As \c BfsIterator<Graph, ReachedMap> works as an edge-iterator,
+ /// its \c operator++() iterates on the edges in a bfs order.
BfsIterator<Graph, /*OutEdgeIt,*/ ReachedMap>&
operator++() {
if (graph->valid(actual_edge)) {
@@ -83,6 +86,8 @@
return *this;
}
bool finished() const { return bfs_queue.empty(); }
+ /// The conversion operator makes for converting the bfs-iterator
+ /// to an \c out-edge-iterator.
operator OutEdgeIt() const { return actual_edge; }
bool isBNodeNewlyReached() const { return b_node_newly_reached; }
bool isANodeExamined() const { return !(graph->valid(actual_edge)); }
@@ -93,7 +98,9 @@
};
/// Bfs searches from s for the nodes wich are not marked in
- /// reachedmap
+ /// \c reached_map
+ /// Reached is a read-write bool-map, Pred is a write-nodemap
+ /// and dist is an rw-nodemap, have to be.
template <typename Graph,
typename ReachedMap=typename Graph::template NodeMap<bool>,
typename PredMap
@@ -107,11 +114,11 @@
DistMap& dist;
public:
Bfs<Graph, ReachedMap, PredMap, DistMap>(const Graph& _graph, ReachedMap& _reached, PredMap& _pred, DistMap& _dist) : BfsIterator<Graph, ReachedMap>(_graph, _reached), pred(&_pred), dist(&_dist) { }
- //s is marked to be reached and pushed in the bfs queue.
- //if the queue is empty, then the first out-edge is processed
- //If s was not marked previously, then
- //in addition its pred is set to be INVALID, and dist to 0.
- //if s was marked previuosly, then it is simply pushed.
+ /// s is marked to be reached and pushed in the bfs queue.
+ /// If the queue is empty, then the first out-edge is processed.
+ /// If s was not marked previously, then
+ /// in addition its pred is set to be INVALID, and dist to 0.
+ /// if s was marked previuosly, then it is simply pushed.
void push(Node s) {
if (this->reached[s]) {
Parent::pushAndSetReached(s);
@@ -121,6 +128,7 @@
dist.set(s, 0);
}
}
+ /// A bfs is processed from s.
void run(Node s) {
push(s);
while (!this->finished()) this->operator++();
@@ -200,6 +208,50 @@
const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
};
+ /// Dfs searches from s for the nodes wich are not marked in
+ /// \c reached_map
+ /// Reached is a read-write bool-map, Pred is a write-nodemap, have to be.
+ template <typename Graph,
+ typename ReachedMap=typename Graph::template NodeMap<bool>,
+ typename PredMap
+ =typename Graph::template NodeMap<typename Graph::Edge> >
+ class Dfs : public DfsIterator<Graph, ReachedMap> {
+ typedef DfsIterator<Graph, ReachedMap> Parent;
+ protected:
+ typedef typename Parent::Node Node;
+ PredMap& pred;
+ public:
+ Dfs<Graph, ReachedMap, PredMap>(const Graph& _graph, ReachedMap& _reached, PredMap& _pred) : DfsIterator<Graph, ReachedMap>(_graph, _reached), pred(&_pred) { }
+ /// s is marked to be reached and pushed in the bfs queue.
+ /// If the queue is empty, then the first out-edge is processed.
+ /// If s was not marked previously, then
+ /// in addition its pred is set to be INVALID.
+ /// if s was marked previuosly, then it is simply pushed.
+ void push(Node s) {
+ if (this->reached[s]) {
+ Parent::pushAndSetReached(s);
+ } else {
+ Parent::pushAndSetReached(s);
+ pred.set(s, INVALID);
+ }
+ }
+ /// A bfs is processed from s.
+ void run(Node s) {
+ push(s);
+ while (!this->finished()) this->operator++();
+ }
+ Dfs<Graph, ReachedMap, PredMap> operator++() {
+ Parent::operator++();
+ if (this->graph->valid(this->actual_edge) && this->b_node_newly_reached)
+ {
+ pred.set(this->bNode(), this->actual_edge);
+ }
+ return *this;
+ }
+ const PredMap& getPredMap() const { return pred; }
+ };
+
+
} // namespace hugo
#endif //HUGO_BFS_ITERATOR_H
More information about the Lemon-commits
mailing list