# HG changeset patch # User marci # Date 1084982817 0 # Node ID bd7a69231cf888d340fa8ddb5969b262d49f2ecf # Parent d93d8b9906d1ca4b35e656fa970d30b70a7239f9 max_flow.h: status flags for actMinCut leda_graph_wrapper.h: NodeMapWrapper, EdgeMapWrapper diff -r d93d8b9906d1 -r bd7a69231cf8 src/work/marci/bfs_dfs.h --- a/src/work/marci/bfs_dfs.h Mon May 17 15:11:05 2004 +0000 +++ b/src/work/marci/bfs_dfs.h Wed May 19 16:06:57 2004 +0000 @@ -106,19 +106,19 @@ } return *this; } - /// Guess what? + /// Returns true iff the algorithm is finished. bool finished() const { return bfs_queue.empty(); } /// The conversion operator makes for converting the bfs-iterator /// to an \c out-edge-iterator. ///\bug Edge have to be in HUGO 0.2 operator OutEdgeIt() const { return actual_edge; } - /// Guess what? + /// Returns if b-node has been reached just now. bool isBNodeNewlyReached() const { return b_node_newly_reached; } - /// Guess what? + /// Returns if a-node is examined. bool isANodeExamined() const { return !(graph->valid(actual_edge)); } - /// Guess what? + /// Returns a-node of the actual edge, so does if the edge is invalid. Node aNode() const { return bfs_queue.front(); } - /// Guess what? + /// \pre The actual edge have to be valid. Node bNode() const { return graph->bNode(actual_edge); } /// Guess what? const ReachedMap& getReachedMap() const { return reached; } @@ -249,17 +249,20 @@ } return *this; } - /// Guess what? + /// Returns true iff the algorithm is finished. bool finished() const { return dfs_stack.empty(); } - /// Guess what? + /// The conversion operator makes for converting the bfs-iterator + /// to an \c out-edge-iterator. + ///\bug Edge have to be in HUGO 0.2 operator OutEdgeIt() const { return actual_edge; } - /// Guess what? + /// Returns if b-node has been reached just now. bool isBNodeNewlyReached() const { return b_node_newly_reached; } - /// Guess what? + /// Returns if a-node is examined. bool isANodeExamined() const { return !(graph->valid(actual_edge)); } - /// Guess what? + /// Returns a-node of the actual edge, so does if the edge is invalid. Node aNode() const { return actual_node; /*FIXME*/} - /// Guess what? + /// Returns b-node of the actual edge. + /// \pre The actual edge have to be valid. Node bNode() const { return graph->bNode(actual_edge); } /// Guess what? const ReachedMap& getReachedMap() const { return reached; } diff -r d93d8b9906d1 -r bd7a69231cf8 src/work/marci/leda/leda_graph_wrapper.h --- a/src/work/marci/leda/leda_graph_wrapper.h Mon May 17 15:11:05 2004 +0000 +++ b/src/work/marci/leda/leda_graph_wrapper.h Wed May 19 16:06:57 2004 +0000 @@ -40,6 +40,8 @@ template class NodeMap; template class EdgeMap; + template class NodeMapWrapper; + template class EdgeMapWrapper; class Node; class NodeIt; @@ -291,6 +293,49 @@ //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); } //FIXME: Is it necessary }; + + ///Read/write map from the nodes to type \c T. + template class NodeMapWrapper + { + leda_node_map* leda_stuff; + public: + typedef T ValueType; + typedef Node KeyType; + + NodeMapWrapper(leda_node_map& _leda_stuff) : + leda_stuff(&_leda_stuff) { } + //NodeMap(leda_node_map& &G, T t) : leda_stuff(*(G.l_graph), t) {} + + void set(Node i, T t) { (*leda_stuff)[i.l_n]=t; } + T get(Node i) const { return (*leda_stuff)[i.l_n]; } //FIXME: Is it necessary + T &operator[](Node i) { return (*leda_stuff)[i.l_n]; } + const T &operator[](Node i) const { return (*leda_stuff)[i.l_n]; } + + void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ } + //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); } //FIXME: Is it necessary + }; + + ///Read/write map from the edges to type \c T. + template class EdgeMapWrapper + { + leda_edge_map* leda_stuff; + public: + typedef T ValueType; + typedef Edge KeyType; + + EdgeMapWrapper(leda_edge_map& _leda_stuff) : + leda_stuff(_leda_stuff) { } + //EdgeMap(const LedaGraphWrapper &G, T t) : leda_stuff(*(G.l_graph), t) {} + + void set(Edge i, T t) { (*leda_stuff)[i.l_e]=t; } + T get(Edge i) const { return (*leda_stuff)[i.l_e]; } //FIXME: Is it necessary + T &operator[](Edge i) { return (*leda_stuff)[i.l_e]; } + const T &operator[](Edge i) const { return (*leda_stuff)[i.l_e]; } + + void update() { /*leda_stuff.init(leda_stuff.get_graph());*/ } + //void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); } //FIXME: Is it necessary + }; + }; diff -r d93d8b9906d1 -r bd7a69231cf8 src/work/marci/max_flow_demo.cc --- a/src/work/marci/max_flow_demo.cc Mon May 17 15:11:05 2004 +0000 +++ b/src/work/marci/max_flow_demo.cc Wed May 19 16:06:57 2004 +0000 @@ -72,6 +72,7 @@ Graph::EdgeMap flow(g); //0 flow MaxFlow, Graph::EdgeMap > max_flow_test(g, s, t, cap, flow); + Graph::NodeMap cut(g); { std::cout << "preflow ..." << std::endl; @@ -79,6 +80,14 @@ max_flow_test.run(); std::cout << "elapsed time: " << ts << std::endl; std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + max_flow_test.actMinCut(cut); + + FOR_EACH_LOC(Graph::EdgeIt, e, g) { + if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) + std::cout << "Slackness does not hold!" << std::endl; + if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) + std::cout << "Slackness does not hold!" << std::endl; + } } { @@ -88,6 +97,13 @@ max_flow_test.preflow(MaxFlow, Graph::EdgeMap >::GEN_FLOW); std::cout << "elapsed time: " << ts << std::endl; std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + + FOR_EACH_LOC(Graph::EdgeIt, e, g) { + if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) + std::cout << "Slackness does not hold!" << std::endl; + if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) + std::cout << "Slackness does not hold!" << std::endl; + } } // { @@ -108,6 +124,13 @@ std::cout << "elapsed time: " << ts << std::endl; std::cout << "number of augmentation phases: " << i << std::endl; std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + + FOR_EACH_LOC(Graph::EdgeIt, e, g) { + if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) + std::cout << "Slackness does not hold!" << std::endl; + if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) + std::cout << "Slackness does not hold!" << std::endl; + } } // { @@ -130,6 +153,13 @@ std::cout << "elapsed time: " << ts << std::endl; std::cout << "number of augmentation phases: " << i << std::endl; std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + + FOR_EACH_LOC(Graph::EdgeIt, e, g) { + if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) + std::cout << "Slackness does not hold!" << std::endl; + if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) + std::cout << "Slackness does not hold!" << std::endl; + } } { @@ -141,8 +171,32 @@ std::cout << "elapsed time: " << ts << std::endl; std::cout << "number of augmentation phases: " << i << std::endl; std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + + FOR_EACH_LOC(Graph::EdgeIt, e, g) { + if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) + std::cout << "Slackness does not hold!" << std::endl; + if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) + std::cout << "Slackness does not hold!" << std::endl; + } } + { + std::cout << "on-the-fly shortest path augmentation ..." << std::endl; + FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0); + ts.reset(); + int i=0; + while (max_flow_test.augmentOnShortestPath2()) { ++i; } + std::cout << "elapsed time: " << ts << std::endl; + std::cout << "number of augmentation phases: " << i << std::endl; + std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl; + + FOR_EACH_LOC(Graph::EdgeIt, e, g) { + if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e]) + std::cout << "Slackness does not hold!" << std::endl; + if (!cut[g.tail(e)] && cut[g.head(e)] && flow[e]>0) + std::cout << "Slackness does not hold!" << std::endl; + } + } return 0; }