[Lemon-commits] [lemon_svn] marci: r1031 - in hugo/trunk/src/work/marci: . leda lp
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:42:51 CET 2006
Author: marci
Date: Mon Aug 23 13:06:00 2004
New Revision: 1031
Modified:
hugo/trunk/src/work/marci/bipartite_graph_wrapper.h
hugo/trunk/src/work/marci/bipartite_graph_wrapper_test.cc
hugo/trunk/src/work/marci/bipartite_matching_try.cc
hugo/trunk/src/work/marci/bipartite_matching_try_3.cc
hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc
hugo/trunk/src/work/marci/leda/comparison.cc
hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h
hugo/trunk/src/work/marci/max_bipartite_matching.h
hugo/trunk/src/work/marci/max_bipartite_matching_demo.cc
Log:
stGraphWrapper modifications
Modified: hugo/trunk/src/work/marci/bipartite_graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_graph_wrapper.h (original)
+++ hugo/trunk/src/work/marci/bipartite_graph_wrapper.h Mon Aug 23 13:06:00 2004
@@ -30,9 +30,10 @@
/// \author Marton Makai
template<typename Graph>
class BipartiteGraphWrapper : public GraphWrapper<Graph> {
- protected:
+ public:
typedef IterableBoolMap< typename Graph::template NodeMap<int> >
SFalseTTrueMap;
+ protected:
SFalseTTrueMap* s_false_t_true_map;
BipartiteGraphWrapper() : GraphWrapper<Graph>()/*,
@@ -46,6 +47,12 @@
//FIXME vhogy igy kellene, csak az en forditom nem eszi meg
static const bool S_CLASS;
static const bool T_CLASS;
+
+ /// This method is to reach the iterable maps of the bipartite graph or
+ /// bipartite graph wrapper.
+ const SFalseTTrueMap& sFalseTTrueMap() const {
+ return *s_false_t_true_map;
+ }
//bool S_CLASS;
//bool T_CLASS;
@@ -211,13 +218,13 @@
/// does not work well.
template<typename Graph>
class BipartiteGraph : public BipartiteGraphWrapper<Graph> {
- typedef IterableBoolMap< typename Graph::template NodeMap<int> >
- SFalseTTrueMap;
+// typedef IterableBoolMap< typename Graph::template NodeMap<int> >
+// SFalseTTrueMap;
typedef BipartiteGraphWrapper<Graph> Parent;
protected:
Graph gr;
typename Graph::template NodeMap<int> bipartite_map;
- SFalseTTrueMap s_false_t_true_map;
+ typename Parent::SFalseTTrueMap s_false_t_true_map;
public:
typedef typename Parent::Node Node;
typedef typename Parent::Edge Edge;
@@ -258,9 +265,20 @@
}
};
+ template<typename Graph, typename sIterableMap, typename tIterableMap>
+ class stGraphWrapper;
+ /// Easier stuff for bipartite graphs.
template<typename Graph>
- class stGraphWrapper;
+ class stBipartiteGraphWrapper : public
+ stGraphWrapper<Graph, typename Graph::SFalseTTrueMap,
+ typename Graph::SFalseTTrueMap> {
+ public:
+ typedef stGraphWrapper<Graph, typename Graph::SFalseTTrueMap,
+ typename Graph::SFalseTTrueMap> Parent;
+ stBipartiteGraphWrapper(Graph& _graph) :
+ Parent(_graph, _graph.sFalseTTrueMap(), _graph.sFalseTTrueMap()) { }
+ };
// template<typename Graph>
// std::ostream&
@@ -287,13 +305,16 @@
/// graph have to be oriented from S to T.
///
/// \author Marton Makai
- template<typename Graph>
+ template<typename Graph, typename sIterableMap, typename tIterableMap>
class stGraphWrapper : public GraphWrapper<Graph> {
+ protected:
+ const sIterableMap* s_iterable_map;
+ const tIterableMap* t_iterable_map;
public:
class Node;
friend class Node;
//GN, int
-//0 normalis, 1 s, 2, true, ez az iteralasi sorrend,
+//0 normalis, 1 s, 2 t, ez az iteralasi sorrend,
//es a vege a false azaz (invalid, 3)
class NodeIt;
friend class NodeIt;
@@ -334,9 +355,15 @@
static const bool S_CLASS=false;
static const bool T_CLASS=true;
- stGraphWrapper(Graph& _graph) : GraphWrapper<Graph>(_graph) ,
- S_NODE(INVALID, 1),
- T_NODE(INVALID, 2) { }
+ // \bug not too nice constructor.
+ stGraphWrapper(Graph& _graph,
+ const sIterableMap& _s_iterable_map,
+ const tIterableMap& _t_iterable_map) :
+ GraphWrapper<Graph>(_graph),
+ s_iterable_map(&_s_iterable_map),
+ t_iterable_map(&_t_iterable_map),
+ S_NODE(INVALID, 1),
+ T_NODE(INVALID, 2) { }
// std::ostream&
@@ -349,7 +376,7 @@
class Node : public Graph::Node {
protected:
friend class GraphWrapper<Graph>;
- friend class stGraphWrapper<Graph>;
+ friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
template <typename T> friend class NodeMap;
friend class Edge;
friend class OutEdgeIt;
@@ -380,7 +407,7 @@
class NodeIt {
friend class GraphWrapper<Graph>;
- friend class stGraphWrapper<Graph>;
+ friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
typename Graph::NodeIt n;
int spec;
public:
@@ -388,7 +415,8 @@
NodeIt(const typename Graph::NodeIt& _n, int _spec) :
n(_n), spec(_spec) { }
NodeIt(const Invalid& i) : n(i), spec(3) { }
- NodeIt(const stGraphWrapper<Graph>& _G) : n(*(_G.graph)), spec(0) {
+ NodeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G)
+ : n(*(_G.graph)), spec(0) {
if (!_G.graph->valid(n)) spec=1;
}
operator Node() const { return Node(n, spec); }
@@ -396,7 +424,7 @@
class Edge : public Graph::Edge {
friend class GraphWrapper<Graph>;
- friend class stGraphWrapper<Graph>;
+ friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
template <typename T> friend class EdgeMap;
int spec;
typename Graph::Node n;
@@ -429,7 +457,7 @@
class OutEdgeIt {
friend class GraphWrapper<Graph>;
- friend class stGraphWrapper<Graph>;
+ friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
typename Graph::OutEdgeIt e;
int spec;
typename Graph::ClassNodeIt n;
@@ -440,7 +468,8 @@
e(_e), spec(_spec), n(_n) {
}
OutEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
- OutEdgeIt(const stGraphWrapper<Graph>& _G, const Node& _n) {
+ OutEdgeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G,
+ const Node& _n) {
switch (_n.spec) {
case 0 :
if (_G.graph->inSClass(_n)) { //S, van normalis kiel
@@ -473,7 +502,7 @@
class InEdgeIt {
friend class GraphWrapper<Graph>;
- friend class stGraphWrapper<Graph>;
+ friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
typename Graph::InEdgeIt e;
int spec;
typename Graph::ClassNodeIt n;
@@ -484,7 +513,8 @@
e(_e), spec(_spec), n(_n) {
}
InEdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
- InEdgeIt(const stGraphWrapper<Graph>& _G, const Node& _n) {
+ InEdgeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G,
+ const Node& _n) {
switch (_n.spec) {
case 0 :
if (_G.graph->inTClass(_n)) { //T, van normalis beel
@@ -517,7 +547,7 @@
class EdgeIt {
friend class GraphWrapper<Graph>;
- friend class stGraphWrapper<Graph>;
+ friend class stGraphWrapper<Graph, sIterableMap, tIterableMap>;
typename Graph::EdgeIt e;
int spec;
typename Graph::ClassNodeIt n;
@@ -527,7 +557,7 @@
const typename Graph::ClassNodeIt& _n) :
e(_e), spec(_spec), n(_n) { }
EdgeIt(const Invalid& i) : e(i), spec(3), n(i) { }
- EdgeIt(const stGraphWrapper<Graph>& _G) :
+ EdgeIt(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G) :
e(*(_G.graph)), spec(0), n(INVALID) {
if (!_G.graph->valid(e)) {
spec=1;
@@ -718,12 +748,14 @@
protected:
T s_value, t_value;
public:
- NodeMap(const stGraphWrapper<Graph>& _G) : Parent(_G),
- s_value(),
- t_value() { }
- NodeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a),
- s_value(a),
- t_value(a) { }
+ NodeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G) :
+ Parent(_G),
+ s_value(),
+ t_value() { }
+ NodeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G, T a)
+ : Parent(_G, a),
+ s_value(a),
+ t_value(a) { }
T operator[](const Node& n) const {
switch (n.spec) {
case 0:
@@ -753,7 +785,7 @@
/// This class is to wrap a node-map of \c Graph and two variables
/// storing values for \c S_NODE and \c T_NODE to a node-map of
- /// stGraphWrapper<Graph>.
+ /// stGraphWrapper<Graph, sIterableMap, tIterableMap>.
template<typename NM> class NodeMapWrapper {
public:
typedef Node KeyType;
@@ -797,10 +829,12 @@
protected:
typename GraphWrapper<Graph>::template NodeMap<T> node_value;
public:
- EdgeMap(const stGraphWrapper<Graph>& _G) : Parent(_G),
- node_value(_G) { }
- EdgeMap(const stGraphWrapper<Graph>& _G, T a) : Parent(_G, a),
- node_value(_G, a) { }
+ EdgeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G)
+ : Parent(_G),
+ node_value(_G) { }
+ EdgeMap(const stGraphWrapper<Graph, sIterableMap, tIterableMap>& _G, T a)
+ : Parent(_G, a),
+ node_value(_G, a) { }
T operator[](const Edge& e) const {
switch (e.spec) {
case 0:
@@ -829,7 +863,7 @@
};
/// This class is to wrap an edge-map and a node-map of \c Graph
- /// to an edge-map of stGraphWrapper<Graph>.
+ /// to an edge-map of stGraphWrapper<Graph, sIterableMap, tIterableMap>.
template<typename EM, typename NM>
class EdgeMapWrapper {
public:
Modified: hugo/trunk/src/work/marci/bipartite_graph_wrapper_test.cc
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_graph_wrapper_test.cc (original)
+++ hugo/trunk/src/work/marci/bipartite_graph_wrapper_test.cc Mon Aug 23 13:06:00 2004
@@ -89,7 +89,7 @@
BGW::NodeMap<int> dbyj(bgw);
BGW::EdgeMap<int> dbyxcj(bgw);
- typedef stGraphWrapper<BGW> stGW;
+ typedef stBipartiteGraphWrapper<BGW> stGW;
stGW stgw(bgw);
ConstMap<stGW::Edge, int> const1map(1);
stGW::NodeMap<int> ize(stgw);
Modified: hugo/trunk/src/work/marci/bipartite_matching_try.cc
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_matching_try.cc (original)
+++ hugo/trunk/src/work/marci/bipartite_matching_try.cc Mon Aug 23 13:06:00 2004
@@ -116,7 +116,7 @@
// BGW::NodeMap<int> dbyj(bgw);
// BGW::EdgeMap<int> dbyxcj(bgw);
- typedef stGraphWrapper<BGW> stGW;
+ typedef stBipartiteGraphWrapper<BGW> stGW;
stGW stgw(bgw);
ConstMap<stGW::Edge, int> const1map(1);
// stGW::NodeMap<int> ize(stgw);
Modified: hugo/trunk/src/work/marci/bipartite_matching_try_3.cc
==============================================================================
--- hugo/trunk/src/work/marci/bipartite_matching_try_3.cc (original)
+++ hugo/trunk/src/work/marci/bipartite_matching_try_3.cc Mon Aug 23 13:06:00 2004
@@ -17,6 +17,9 @@
using namespace hugo;
+using std::cout;
+using std::endl;
+
int main() {
//typedef UndirListGraph Graph;
typedef BipartiteGraph<SageGraph> Graph;
@@ -30,53 +33,54 @@
Graph g;
int a;
- std::cout << "number of nodes in the first color class=";
+ cout << "number of nodes in the first color class=";
std::cin >> a;
int b;
- std::cout << "number of nodes in the second color class=";
+ cout << "number of nodes in the second color class=";
std::cin >> b;
int m;
- std::cout << "number of edges=";
+ cout << "number of edges=";
std::cin >> m;
- std::cout << "Generatig a random bipartite graph..." << std::endl;
+ cout << "Generatig a random bipartite graph..." << endl;
random_init();
randomBipartiteGraph(g, a, b, m);
-// std::cout << "Edges of the bipartite graph:" << std::endl;
-// FOR_EACH_LOC(EdgeIt, e, g) std::cout << e << " ";
-// std::cout << std::endl;
-
-// std::cout << "Nodes:" << std::endl;
-// FOR_EACH_LOC(Graph::NodeIt, v, g) std::cout << v << " ";
-// std::cout << std::endl;
-// std::cout << "Nodes in T:" << std::endl;
-// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " ";
-// std::cout << std::endl;
-// std::cout << "Nodes in S:" << std::endl;
-// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " ";
-// std::cout << std::endl;
+// cout << "Edges of the bipartite graph:" << endl;
+// FOR_EACH_LOC(EdgeIt, e, g) cout << e << " ";
+// cout << endl;
+
+// cout << "Nodes:" << endl;
+// FOR_EACH_LOC(Graph::NodeIt, v, g) cout << v << " ";
+// cout << endl;
+// cout << "Nodes in T:" << endl;
+// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
+// cout << endl;
+// cout << "Nodes in S:" << endl;
+// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
+// cout << endl;
-// std::cout << "Erasing the first node..." << std::endl;
+// cout << "Erasing the first node..." << endl;
// NodeIt n;
// g.first(n);
// g.erase(n);
-// std::cout << "Nodes of the bipartite graph:" << std::endl;
-// FOR_EACH_GLOB(n, g) std::cout << n << " ";
-// std::cout << std::endl;
-
-// std::cout << "Nodes in T:" << std::endl;
-// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) std::cout << v << " ";
-// std::cout << std::endl;
-// std::cout << "Nodes in S:" << std::endl;
-// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) std::cout << v << " ";
-// std::cout << std::endl;
+// cout << "Nodes of the bipartite graph:" << endl;
+// FOR_EACH_GLOB(n, g) cout << n << " ";
+// cout << endl;
+
+// cout << "Nodes in T:" << endl;
+// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::T_CLASS) cout << v << " ";
+// cout << endl;
+// cout << "Nodes in S:" << endl;
+// FOR_EACH_INC_LOC(Graph::ClassNodeIt, v, g, Graph::S_CLASS) cout << v << " ";
+// cout << endl;
- typedef stGraphWrapper<Graph> stGW;
+ typedef stBipartiteGraphWrapper<Graph> stGW;
stGW stgw(g);
ConstMap<stGW::Edge, int> const1map(1);
Timer ts;
+ cout << "max bipartite matching with stGraphWrapper..." << endl;
ts.reset();
stGW::EdgeMap<int> flow(stgw);
MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
@@ -86,14 +90,14 @@
// typedef ListGraph MutableGraph;
// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
// while (max_flow_test.augmentOnBlockingFlow2()) {
-// std::cout << max_flow_test.flowValue() << std::endl;
+// cout << max_flow_test.flowValue() << endl;
// }
- std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
- std::cout << "elapsed time: " << ts << std::endl;
+ cout << "matching value: " << max_flow_test.flowValue() << endl;
+ cout << "elapsed time: " << ts << endl;
// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
-// if (flow[e]) std::cout << e << std::endl;
+// if (flow[e]) cout << e << endl;
// }
- std::cout << std::endl;
+ cout << endl;
typedef ConstMap<Graph::Edge, int> EdgeCap;
EdgeCap ge1(1);
@@ -104,12 +108,13 @@
typedef Graph::NodeMap<int> NodeFlow;
NodeFlow gnf(g); //0
- typedef stGraphWrapper<Graph>::EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
- typedef stGraphWrapper<Graph>::EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
+ typedef stGW::EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
+ typedef stGW::EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
CapMap cm(ge1, gn1);
FlowMap fm(gef, gnf);
//Timer ts;
+ cout << "max bipartite matching with stGraphWrapper..." << endl;
ts.reset();
//stGW::EdgeMap<int> flow(stgw);
MaxFlow<stGW, int, CapMap, FlowMap>
@@ -119,15 +124,16 @@
// typedef ListGraph MutableGraph;
// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
// while (max_flow_test.augmentOnBlockingFlow2()) {
-// std::cout << max_flow_test.flowValue() << std::endl;
+// cout << max_flow_test.flowValue() << endl;
// }
- std::cout << "max flow value: " << max_flow_test1.flowValue() << std::endl;
- std::cout << "elapsed time: " << ts << std::endl;
+ cout << "matching value: " << max_flow_test1.flowValue() << endl;
+ cout << "elapsed time: " << ts << endl;
// FOR_EACH_LOC(Graph::EdgeIt, e, g) {
-// if (gef[e]) std::cout << e << std::endl;
+// if (gef[e]) cout << e << endl;
// }
- std::cout << std::endl;
+ cout << endl;
+ cout << "max bipartite matching with stGraphWrapper..." << endl;
ts.reset();
FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
@@ -136,27 +142,41 @@
matching_test(g, ge1, gn1, gef, gnf);
matching_test.run();
- std::cout << "max flow value: " << matching_test.matchingValue() << std::endl;
- std::cout << "elapsed time: " << ts << std::endl;
+ cout << "matching value: " << matching_test.matchingValue() << endl;
+ cout << "elapsed time: " << ts << endl;
// FOR_EACH_LOC(Graph::EdgeIt, e, g) {
-// if (gef[e]) std::cout << e << std::endl;
+// if (gef[e]) cout << e << endl;
// }
- std::cout << std::endl;
+ cout << endl;
+ cout << "max bipartite matching with MaxBipartiteMatching..." << endl;
ts.reset();
FOR_EACH_LOC(Graph::EdgeIt, e, g) gef.set(e, 0);
//FOR_EACH_LOC(Graph::NodeIt, n, g) gnf.set(n, 0);
- MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>, ConstMap<Graph::Node, int>,
- Graph::EdgeMap<int>, Graph::NodeMap<int> >
- matching_test_1(g, ge1, gn1, gef/*, gnf*/);
+ typedef MaxBipartiteMatching<Graph, ConstMap<Graph::Edge, int>,
+ ConstMap<Graph::Node, int>,
+ Graph::EdgeMap<int>, Graph::NodeMap<int> > MaxBipartiteMatching;
+ MaxBipartiteMatching matching_test_1(g, ge1, gn1, gef/*, gnf*/);
matching_test_1.run();
- std::cout << "max flow value: " << matching_test_1.matchingValue() << std::endl;
- std::cout << "elapsed time: " << ts << std::endl;
+ cout << "matching value: " << matching_test_1.matchingValue() << endl;
+ cout << "elapsed time: " << ts << endl;
// FOR_EACH_LOC(Graph::EdgeIt, e, g) {
-// if (gef[e]) std::cout << e << std::endl;
+// if (gef[e]) cout << e << endl;
// }
- std::cout << std::endl;
+ cout << endl;
+
+ cout << "testing optimality with MaxBipartiteMatching..." << endl;
+ ts.reset();
+ matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING);
+ cout << "matching value: " << matching_test_1.matchingValue() << endl;
+ cout << "elapsed time: " << ts << endl;
+
+ cout << "testing optimality with MaxBipartiteMatching..." << endl;
+ ts.reset();
+ matching_test_1.run(MaxBipartiteMatching::GEN_MATCHING_WITH_GOOD_NODE_FLOW);
+ cout << "matching value: " << matching_test_1.matchingValue() << endl;
+ cout << "elapsed time: " << ts << endl;
return 0;
}
Modified: hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc
==============================================================================
--- hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc (original)
+++ hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc Mon Aug 23 13:06:00 2004
@@ -97,7 +97,7 @@
//st-wrapper
- typedef stGraphWrapper<BGW> stGW;
+ typedef stBipartiteGraphWrapper<BGW> stGW;
stGW stgw(bgw);
ConstMap<stGW::Edge, int> const1map(1);
stGW::EdgeMap<int> flow(stgw);
Modified: hugo/trunk/src/work/marci/leda/comparison.cc
==============================================================================
--- hugo/trunk/src/work/marci/leda/comparison.cc (original)
+++ hugo/trunk/src/work/marci/leda/comparison.cc Mon Aug 23 13:06:00 2004
@@ -97,7 +97,7 @@
//st-wrapper
- typedef stGraphWrapper<BGW> stGW;
+ typedef stBipartiteGraphWrapper<BGW> stGW;
stGW stgw(bgw);
ConstMap<stGW::Edge, int> const1map(1);
stGW::EdgeMap<int> flow(stgw);
Modified: hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h (original)
+++ hugo/trunk/src/work/marci/lp/lp_solver_wrapper.h Mon Aug 23 13:06:00 2004
@@ -331,8 +331,8 @@
lpx_set_col_bnds(lp, col_iter_map[col_it], bound_type, lo, up);
}
///.
- void setObjCoef(const ColIt& col_it, double obj_coef) {
- lpx_set_obj_coef(lp, col_iter_map[col_it], obj_coef);
+ double getObjCoef(const ColIt& col_it) {
+ return lpx_get_obj_coef(lp, col_iter_map[col_it]);
}
///.
void setRowBounds(const RowIt& row_it, int bound_type,
Modified: hugo/trunk/src/work/marci/max_bipartite_matching.h
==============================================================================
--- hugo/trunk/src/work/marci/max_bipartite_matching.h (original)
+++ hugo/trunk/src/work/marci/max_bipartite_matching.h Mon Aug 23 13:06:00 2004
@@ -59,18 +59,25 @@
// NodeCap* node_cap;
// EdgeFlow* edge_flow;
// NodeFlow* node_flow;
- typedef stGraphWrapper<Graph> stGW;
+ typedef stBipartiteGraphWrapper<Graph> stGW;
stGW stgw;
typedef typename stGW::template EdgeMapWrapper<EdgeCap, NodeCap> CapMap;
CapMap cap;
NodeFlow* node_flow;
typedef typename stGW::template EdgeMapWrapper<EdgeFlow, NodeFlow> FlowMap;
FlowMap flow;
- MaxFlow<stGW, int, CapMap, FlowMap> mf;
+ typedef MaxFlow<stGW, int, CapMap, FlowMap> MaxFlow;
+ MaxFlow mf;
//graph* g;
//EdgeCap* edge_cap;
//EdgeFlow* edge_flow;
public:
+ enum MatchingEnum{
+ ZERO_MATCHING,
+ GEN_MATCHING,
+ GEN_MATCHING_WITH_GOOD_NODE_FLOW,
+ NO_MATCHING
+ };
/// For capacitated b-matchings, edge-caoacities and node-capacities
/// have to be given. After running \c run the matching is is given
/// back in the edge-map \c _edge_flow and \c _node_map can be used
@@ -98,9 +105,34 @@
/// The class have a nontrivial destructor.
~MaxBipartiteMatching() { if (node_flow) delete node_flow; }
/// run computes the max matching.
- void run() { mf.run(); }
+ void run(MatchingEnum me=ZERO_MATCHING) {
+ switch (me) {
+ case ZERO_MATCHING:
+ mf.run(MaxFlow::ZERO_FLOW);
+ break;
+ case GEN_MATCHING:
+ {
+ typename stGW::OutEdgeIt e;
+ for (stgw.first(e, stgw.S_NODE); stgw.valid(e); stgw.next(e))
+ flow.set(e, cap[e]);
+ }
+ {
+ typename stGW::InEdgeIt e;
+ for (stgw.first(e, stgw.T_NODE); stgw.valid(e); stgw.next(e))
+ flow.set(e, 0);
+ }
+ mf.run(MaxFlow::PRE_FLOW);
+ break;
+ case GEN_MATCHING_WITH_GOOD_NODE_FLOW:
+ mf.run(MaxFlow::GEN_FLOW);
+ break;
+ case NO_MATCHING:
+ mf.run(MaxFlow::NO_FLOW);
+ break;
+ }
+ }
/// The matching value after running \c run.
- int matchingValue() { return mf.flowValue(); }
+ int matchingValue() const { return mf.flowValue(); }
};
} //namespace hugo
Modified: hugo/trunk/src/work/marci/max_bipartite_matching_demo.cc
==============================================================================
--- hugo/trunk/src/work/marci/max_bipartite_matching_demo.cc (original)
+++ hugo/trunk/src/work/marci/max_bipartite_matching_demo.cc Mon Aug 23 13:06:00 2004
@@ -70,8 +70,7 @@
cin >> b;
int m;
cout << "number of edges=";
- cin >> m;
-
+ cin >> m;
for(int i=0; i<a; ++i) {
s_nodes.push_back(G.addNode());
More information about the Lemon-commits
mailing list