[Lemon-commits] [lemon_svn] marci: r128 - hugo/trunk/src/work
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:37:29 CET 2006
Author: marci
Date: Wed Feb 18 16:58:28 2004
New Revision: 128
Modified:
hugo/trunk/src/work/bfs_iterator.hh
hugo/trunk/src/work/iterator_bfs_demo.cc
hugo/trunk/src/work/makefile
Log:
dfs iterator: DfsIterator4 improved version
Modified: hugo/trunk/src/work/bfs_iterator.hh
==============================================================================
--- hugo/trunk/src/work/bfs_iterator.hh (original)
+++ hugo/trunk/src/work/bfs_iterator.hh Wed Feb 18 16:58:28 2004
@@ -283,7 +283,7 @@
bool finished() { return bfs_queue.empty(); }
operator OutEdgeIt () { return actual_edge; }
bool bNodeIsNewlyReached() { return b_node_newly_reached; }
- bool aNodeIsLeaved() { return !(actual_edge.valid()); }
+ bool aNodeIsExamined() { return !(actual_edge.valid()); }
};
template <typename Graph, typename OutEdgeIt, typename ReachedMap>
@@ -614,6 +614,72 @@
};
+ template <typename Graph, typename OutEdgeIt, typename ReachedMap>
+ struct DfsIterator4 {
+ typedef typename Graph::NodeIt NodeIt;
+ const Graph& G;
+ std::stack<OutEdgeIt> dfs_stack;
+ //ReachedMap& reached;
+ bool b_node_newly_reached;
+ OutEdgeIt actual_edge;
+ NodeIt actual_node;
+ ReachedMap reached;
+ DfsIterator4(const Graph& _G
+ /*, std::stack<OutEdgeIt>& _bfs_queue,
+ ReachedMap& _reached*/) :
+ G(_G), reached(G, false) /*, bfs_queue(_bfs_queue), reached(_reached)*/ {
+ //actual_edge=bfs_queue.top();
+ //if (actual_edge.valid()) {
+ // NodeIt w=G.bNode(actual_edge);
+ //if (!reached.get(w)) {
+ // bfs_queue.push(OutEdgeIt(G, w));
+ // reached.set(w, true);
+ // b_node_newly_reached=true;
+ //} else {
+ // ++(bfs_queue.top());
+ // b_node_newly_reached=false;
+ //}
+ //} else {
+ // bfs_queue.pop();
+ //}
+ }
+ void pushAndSetReached(NodeIt s) {
+ reached.set(s, true);
+ dfs_stack.push(G.template first<OutEdgeIt>(s));
+ }
+ DfsIterator4<Graph, OutEdgeIt, ReachedMap>&
+ operator++() {
+ actual_edge=dfs_stack.top();
+ //actual_node=G.aNode(actual_edge);
+ if (actual_edge.valid()) {
+ NodeIt w=G.bNode(actual_edge);
+ actual_node=w;
+ if (!reached.get(w)) {
+ dfs_stack.push(G.template first<OutEdgeIt>(w));
+ reached.set(w, true);
+ b_node_newly_reached=true;
+ } else {
+ ++(dfs_stack.top());
+ b_node_newly_reached=false;
+ }
+ } else {
+ //actual_node=G.aNode(dfs_stack.top());
+ dfs_stack.pop();
+ }
+ return *this;
+ }
+ bool finished() const { return dfs_stack.empty(); }
+ operator OutEdgeIt () const { return actual_edge; }
+ bool isBNodeNewlyReached() const { return b_node_newly_reached; }
+ bool isANodeExamined() const { return !(actual_edge.valid()); }
+ NodeIt aNode() const { return actual_node; }
+ NodeIt bNode() const { return G.bNode(actual_edge); }
+ const ReachedMap& getReachedMap() const { return reached; }
+ const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
+ };
+
+
+
template <typename GraphWrapper, typename ReachedMap>
class BfsIterator5 {
typedef typename GraphWrapper::NodeIt NodeIt;
Modified: hugo/trunk/src/work/iterator_bfs_demo.cc
==============================================================================
--- hugo/trunk/src/work/iterator_bfs_demo.cc (original)
+++ hugo/trunk/src/work/iterator_bfs_demo.cc Wed Feb 18 16:58:28 2004
@@ -79,6 +79,37 @@
}
}
+ {
+ std::cout << "iterator dfs demo 4 ..." << std::endl;
+ DfsIterator4< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap<bool> > dfs(G);
+ dfs.pushAndSetReached(s);
+ while (!dfs.finished()) {
+ ++dfs;
+ if (OutEdgeIt(dfs).valid()) {
+ std::cout << "OutEdgeIt: " << dfs;
+ std::cout << " aNode: " << G.aNode(dfs);
+ std::cout << " bNode: " << G.bNode(dfs) << " ";
+ } else {
+ std::cout << "OutEdgeIt: " << "invalid";
+ std::cout << " aNode: " << dfs.aNode();
+ std::cout << " bNode: " << "invalid" << " ";
+ }
+ if (dfs.isBNodeNewlyReached()) {
+ std::cout << "bNodeIsNewlyReached ";
+ } else {
+ std::cout << "bNodeIsNotNewlyReached ";
+ }
+ if (dfs.isANodeExamined()) {
+ std::cout << "aNodeIsExamined ";
+ } else {
+ std::cout << "aNodeIsNotExamined ";
+ }
+ std::cout<<std::endl;
+ //++dfs;
+ }
+ }
+
+
typedef ConstTrivGraphWrapper<ListGraph> CTGW;
CTGW wG(G);
Modified: hugo/trunk/src/work/makefile
==============================================================================
--- hugo/trunk/src/work/makefile (original)
+++ hugo/trunk/src/work/makefile Wed Feb 18 16:58:28 2004
@@ -1,7 +1,7 @@
INCLUDEDIRS=-I../include -I. -I./jacint
CXXFLAGS=-g -O -Wall $(INCLUDEDIRS) -ansi -pedantic
-BINARIES = bfsdemo bfsdemo2 bin_heap_demo marci_graph_demo iterator_bfs_dfs_demo graphdemo proba
+BINARIES = bin_heap_demo marci_graph_demo iterator_bfs_dfs_demo graphdemo bfsdemo bfsdemo2
# Hat, ez elismerem, hogy nagyon ronda, de mukodik minden altalam
# ismert rendszeren :-) (Misi)
More information about the Lemon-commits
mailing list