[Lemon-commits] [lemon_svn] alpar: r1065 - in hugo/branches/hugo++/src: demo hugo work work/marci work/marci/leda work/marci/lp
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:43:03 CET 2006
Author: alpar
Date: Mon Aug 30 13:17:15 2004
New Revision: 1065
Added:
hugo/branches/hugo++/src/demo/
- copied from r1064, /hugo/trunk/src/demo/
hugo/branches/hugo++/src/work/marci/bipartite_matching_demo.cc
- copied unchanged from r1064, /hugo/trunk/src/work/marci/bipartite_matching_demo.cc
hugo/branches/hugo++/src/work/marci/graph_wrapper_time.cc
- copied unchanged from r1064, /hugo/trunk/src/work/marci/graph_wrapper_time.cc
hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_comparison.cc
- copied unchanged from r1064, /hugo/trunk/src/work/marci/leda/bipartite_matching_comparison.cc
hugo/branches/hugo++/src/work/marci/leda/max_bipartite_matching_demo.cc
- copied unchanged from r1064, /hugo/trunk/src/work/marci/leda/max_bipartite_matching_demo.cc
Removed:
hugo/branches/hugo++/src/work/marci/bipartite_matching_try.cc
hugo/branches/hugo++/src/work/marci/bipartite_matching_try_3.cc
hugo/branches/hugo++/src/work/marci/leda/comparison.cc
hugo/branches/hugo++/src/work/marci/max_bipartite_matching_demo.cc
Modified:
hugo/branches/hugo++/src/hugo/max_flow.h
hugo/branches/hugo++/src/work/makefile
hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper.h
hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper_test.cc
hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda.cc
hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda_gen.cc
hugo/branches/hugo++/src/work/marci/leda/makefile
hugo/branches/hugo++/src/work/marci/lp/lp_solver_wrapper.h
hugo/branches/hugo++/src/work/marci/makefile
hugo/branches/hugo++/src/work/marci/max_bipartite_matching.h
Log:
branches/hugo++: ported -r1029:1064 from trunk.
Modified: hugo/branches/hugo++/src/hugo/max_flow.h
==============================================================================
--- hugo/branches/hugo++/src/hugo/max_flow.h (original)
+++ hugo/branches/hugo++/src/hugo/max_flow.h Mon Aug 30 13:17:15 2004
@@ -792,14 +792,15 @@
//putting the active nodes into the stack
int lev=level[w];
- if ( exc > 0 && lev < n && w != t )
+ if ( exc > 0 && lev < n && Node(w) != t )
+ ///\bug if ( exc > 0 && lev < n && w != t ) temporarily for working with wrappers.
{
next.set(w,first[lev]);
first[lev]=w;
}
}
break;
- }
+ } //switch
} //preflowPreproc
@@ -808,7 +809,7 @@
NNMap& right, int& b, int& k, bool what_heur )
{
- Num lev=level[w];
+ int lev=level[w];
Node right_n=right[w];
Node left_n=left[w];
Modified: hugo/branches/hugo++/src/work/makefile
==============================================================================
--- hugo/branches/hugo++/src/work/makefile (original)
+++ hugo/branches/hugo++/src/work/makefile Mon Aug 30 13:17:15 2004
@@ -1,5 +1,5 @@
INCLUDEDIRS ?= -I.. -I. -I./{marci,jacint,alpar,klao,akos}
-CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
+CXXFLAGS = -g -O3 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
BINARIES ?= bin_heap_demo
Modified: hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper.h
==============================================================================
--- hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper.h (original)
+++ hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper.h Mon Aug 30 13:17:15 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/branches/hugo++/src/work/marci/bipartite_graph_wrapper_test.cc
==============================================================================
--- hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper_test.cc (original)
+++ hugo/branches/hugo++/src/work/marci/bipartite_graph_wrapper_test.cc Mon Aug 30 13:17:15 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/branches/hugo++/src/work/marci/leda/bipartite_matching_leda.cc
==============================================================================
--- hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda.cc (original)
+++ hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda.cc Mon Aug 30 13:17:15 2004
@@ -14,11 +14,11 @@
//#include <smart_graph.h>
//#include <dimacs.h>
#include <hugo/time_measure.h>
-#include <hugo/for_each_macros.h>
+#include <for_each_macros.h>
#include <hugo/graph_wrapper.h>
#include <bipartite_graph_wrapper.h>
#include <hugo/maps.h>
-#include <max_flow.h>
+#include <hugo/max_flow.h>
/**
* Inicializalja a veletlenszamgeneratort.
@@ -95,7 +95,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);
@@ -109,9 +109,10 @@
// while (max_flow_test.augmentOnShortestPath()) { }
typedef SageGraph MutableGraph;
// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
- while (max_flow_test.augmentOnBlockingFlow2()) {
- std::cout << max_flow_test.flowValue() << std::endl;
- }
+// while (max_flow_test.augmentOnBlockingFlow2()) {
+// std::cout << max_flow_test.flowValue() << std::endl;
+// }
+ max_flow_test.run();
std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
std::cout << "elapsed time: " << ts << std::endl;
Modified: hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda_gen.cc
==============================================================================
--- hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda_gen.cc (original)
+++ hugo/branches/hugo++/src/work/marci/leda/bipartite_matching_leda_gen.cc Mon Aug 30 13:17:15 2004
@@ -14,11 +14,12 @@
//#include <smart_graph.h>
//#include <dimacs.h>
#include <hugo/time_measure.h>
-#include <hugo/for_each_macros.h>
+#include <for_each_macros.h>
#include <hugo/graph_wrapper.h>
#include <bipartite_graph_wrapper.h>
#include <hugo/maps.h>
-#include <max_flow.h>
+#include <hugo/max_flow.h>
+#include <augmenting_flow.h>
/**
* Inicializalja a veletlenszamgeneratort.
@@ -97,7 +98,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);
@@ -125,10 +126,12 @@
ts.reset();
FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
typedef SageGraph MutableGraph;
- while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { }
+ AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
+ max_flow_test_1(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow/*, true*/);
+ while (max_flow_test_1.augmentOnBlockingFlow<MutableGraph>()) { }
std::cout << "HUGO max matching algorithm based on blocking flow augmentation."
<< std::endl << "Matching size: "
- << max_flow_test.flowValue() << std::endl;
+ << max_flow_test_1.flowValue() << std::endl;
std::cout << "elapsed time: " << ts << std::endl;
return 0;
Modified: hugo/branches/hugo++/src/work/marci/leda/makefile
==============================================================================
--- hugo/branches/hugo++/src/work/marci/leda/makefile (original)
+++ hugo/branches/hugo++/src/work/marci/leda/makefile Mon Aug 30 13:17:15 2004
@@ -4,7 +4,7 @@
INCLUDEDIRS ?= -I. -I../.. -I../../{marci,jacint,alpar,klao,akos,athos} -I$(LEDAROOT)/incl -I../../..
LDFLAGS = -L$(LEDAROOT) -lG -lL -lm
-BINARIES = bipartite_matching_leda bipartite_matching_leda_gen comparison
+BINARIES = bipartite_matching_leda bipartite_matching_leda_gen bipartite_matching_comparison
include ../../makefile
Modified: hugo/branches/hugo++/src/work/marci/lp/lp_solver_wrapper.h
==============================================================================
--- hugo/branches/hugo++/src/work/marci/lp/lp_solver_wrapper.h (original)
+++ hugo/branches/hugo++/src/work/marci/lp/lp_solver_wrapper.h Mon Aug 30 13:17:15 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/branches/hugo++/src/work/marci/makefile
==============================================================================
--- hugo/branches/hugo++/src/work/marci/makefile (original)
+++ hugo/branches/hugo++/src/work/marci/makefile Mon Aug 30 13:17:15 2004
@@ -4,7 +4,7 @@
INCLUDEDIRS ?= -I../{jacint,marci,alpar,klao,akos,athos} -I../.. -I.. -I$(BOOSTROOT)
LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
-BINARIES = max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_try bipartite_matching_try_3 top_sort_test max_flow_1
+BINARIES = graph_wrapper_time max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_demo top_sort_test max_flow_1 proba7
#BINARIES = preflow_bug
#gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
Modified: hugo/branches/hugo++/src/work/marci/max_bipartite_matching.h
==============================================================================
--- hugo/branches/hugo++/src/work/marci/max_bipartite_matching.h (original)
+++ hugo/branches/hugo++/src/work/marci/max_bipartite_matching.h Mon Aug 30 13:17:15 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
More information about the Lemon-commits
mailing list