[Lemon-commits] [lemon_svn] marci: r846 - in hugo/trunk/src/work/marci: . leda
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:41:49 CET 2006
Author: marci
Date: Wed May 19 18:06:57 2004
New Revision: 846
Modified:
hugo/trunk/src/work/marci/bfs_dfs.h
hugo/trunk/src/work/marci/leda/leda_graph_wrapper.h
hugo/trunk/src/work/marci/max_flow_demo.cc
Log:
max_flow.h: status flags for actMinCut
leda_graph_wrapper.h: NodeMapWrapper, EdgeMapWrapper
Modified: hugo/trunk/src/work/marci/bfs_dfs.h
==============================================================================
--- hugo/trunk/src/work/marci/bfs_dfs.h (original)
+++ hugo/trunk/src/work/marci/bfs_dfs.h Wed May 19 18:06:57 2004
@@ -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; }
Modified: hugo/trunk/src/work/marci/leda/leda_graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/leda/leda_graph_wrapper.h (original)
+++ hugo/trunk/src/work/marci/leda/leda_graph_wrapper.h Wed May 19 18:06:57 2004
@@ -40,6 +40,8 @@
template <typename T> class NodeMap;
template <typename T> class EdgeMap;
+ template <typename T> class NodeMapWrapper;
+ template <typename T> 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<typename T> class NodeMapWrapper
+ {
+ leda_node_map<T>* leda_stuff;
+ public:
+ typedef T ValueType;
+ typedef Node KeyType;
+
+ NodeMapWrapper(leda_node_map<T>& _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<typename T> class EdgeMapWrapper
+ {
+ leda_edge_map<T>* leda_stuff;
+ public:
+ typedef T ValueType;
+ typedef Edge KeyType;
+
+ EdgeMapWrapper(leda_edge_map<T>& _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
+ };
+
};
Modified: hugo/trunk/src/work/marci/max_flow_demo.cc
==============================================================================
--- hugo/trunk/src/work/marci/max_flow_demo.cc (original)
+++ hugo/trunk/src/work/marci/max_flow_demo.cc Wed May 19 18:06:57 2004
@@ -72,6 +72,7 @@
Graph::EdgeMap<int> flow(g); //0 flow
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
max_flow_test(g, s, t, cap, flow);
+ Graph::NodeMap<bool> 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, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::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;
}
More information about the Lemon-commits
mailing list