[Lemon-commits] [lemon_svn] marci: r594 - hugo/trunk/src/work/marci/leda
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:40:26 CET 2006
Author: marci
Date: Tue Apr 27 16:10:19 2004
New Revision: 594
Added:
hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc
- copied, changed from r589, /hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc
Modified:
hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc
hugo/trunk/src/work/marci/leda/leda_graph_wrapper.h
hugo/trunk/src/work/marci/leda/makefile
Log:
comparison for matchings with leda
Modified: hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc
==============================================================================
--- hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc (original)
+++ hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc Tue Apr 27 16:10:19 2004
@@ -7,6 +7,7 @@
#include <LEDA/graph.h>
#include <LEDA/mcb_matching.h>
#include <LEDA/list.h>
+#include <LEDA/graph_gen.h>
#include <leda_graph_wrapper.h>
#include <list_graph.h>
@@ -89,88 +90,15 @@
for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false);
for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true);
-// Graph::Node u;
-// std::cout << "These nodes will be in S:\n";
-// //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen
-// //irni 1etlen FOR_EACH-csel.
-// for (bipartite_map.first(u, false); g.valid(u); bipartite_map.next(u))
-// std::cout << u << " ";
-// std::cout << "\n";
-// std::cout << "These nodes will be in T:\n";
-// for (bipartite_map.first(u, true); g.valid(u); bipartite_map.next(u))
-// std::cout << u << " ";
-// std::cout << "\n";
-
typedef BipartiteGraphWrapper<Graph> BGW;
BGW bgw(g, bipartite_map);
-// std::cout << "Nodes by NodeIt:\n";
-// FOR_EACH_LOC(BGW::NodeIt, n, bgw) {
-// std::cout << n << " ";
-// }
-// std::cout << "\n";
-// std::cout << "Nodes in S by ClassNodeIt:\n";
-// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) {
-// std::cout << n << " ";
-// }
-// std::cout << "\n";
-// std::cout << "Nodes in T by ClassNodeIt:\n";
-// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) {
-// std::cout << n << " ";
-// }
-// std::cout << "\n";
-// std::cout << "Edges of the bipartite graph:\n";
-// FOR_EACH_LOC(BGW::EdgeIt, e, bgw) {
-// std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl;
-// }
-
BGW::NodeMap<int> dbyj(bgw);
BGW::EdgeMap<int> dbyxcj(bgw);
typedef stGraphWrapper<BGW> stGW;
stGW stgw(bgw);
ConstMap<stGW::Edge, int> const1map(1);
-// stGW::NodeMap<int> ize(stgw);
-
-// BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
-// Graph::NodeIt si;
-// Graph::Node s;
-// s=g.first(si);
-// bfs.pushAndSetReached(BGW::Node(s));
-// while (!bfs.finished()) { ++bfs; }
-
-// FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
-// std::cout << "out-edges of " << n << ":\n";
-// FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) {
-// std::cout << " " << e << "\n";
-// std::cout << " aNode: " << stgw.aNode(e) << "\n";
-// std::cout << " bNode: " << stgw.bNode(e) << "\n";
-// }
-// std::cout << "in-edges of " << n << ":\n";
-// FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) {
-// std::cout << " " << e << "\n";
-// std::cout << " aNode: " << stgw.aNode(e) << "\n";
-// std::cout << " bNode: " << stgw.bNode(e) << "\n";
-// }
-// }
-// std::cout << "Edges of the stGraphWrapper:\n";
-// FOR_EACH_LOC(stGW::EdgeIt, n, stgw) {
-// std::cout << " " << n << "\n";
-// }
-
-// stGW::NodeMap<bool> b(stgw);
-// FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
-// std::cout << n << ": " << b[n] <<"\n";
-// }
-
-// std::cout << "Bfs from s: \n";
-// BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
-// bfs_stgw.pushAndSetReached(stgw.S_NODE);
-// while (!bfs_stgw.finished()) {
-// std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n";
-// ++bfs_stgw;
-// }
-
Timer ts;
ts.reset();
Copied: hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc (from r589, /hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc)
==============================================================================
--- /hugo/trunk/src/work/marci/leda/bipartite_matching_leda.cc (original)
+++ hugo/trunk/src/work/marci/leda/bipartite_matching_leda_gen.cc Tue Apr 27 16:10:19 2004
@@ -7,6 +7,7 @@
#include <LEDA/graph.h>
#include <LEDA/mcb_matching.h>
#include <LEDA/list.h>
+#include <LEDA/graph_gen.h>
#include <leda_graph_wrapper.h>
#include <list_graph.h>
@@ -73,134 +74,55 @@
int m;
std::cout << "number of edges=";
std::cin >> m;
-
-
- for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode());
- for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode());
-
- random_init();
- for(int i=0; i<m; ++i) {
- g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
- }
+ int k;
+ std::cout << "number of groups in LEDA random group graph=";
+ std::cin >> k;
+
+ leda_list<leda_node> lS;
+ leda_list<leda_node> lT;
+ random_bigraph(lg, a, b, m, lS, lT, k);
+
+// for (int i=0; i<a; ++i) s_nodes.push_back(g.addNode());
+// for (int i=0; i<b; ++i) t_nodes.push_back(g.addNode());
+
+// random_init();
+// for(int i=0; i<m; ++i) {
+// g.addEdge(s_nodes[random(a)], t_nodes[random(b)]);
+// }
Graph::NodeMap<int> ref_map(g, -1);
IterableBoolMap< Graph::NodeMap<int> > bipartite_map(ref_map);
- for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false);
- for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true);
-
-// Graph::Node u;
-// std::cout << "These nodes will be in S:\n";
-// //FIXME azert kellene ++, es invalid vizsgalat u-bol, hogy ezt le lehessen
-// //irni 1etlen FOR_EACH-csel.
-// for (bipartite_map.first(u, false); g.valid(u); bipartite_map.next(u))
-// std::cout << u << " ";
-// std::cout << "\n";
-// std::cout << "These nodes will be in T:\n";
-// for (bipartite_map.first(u, true); g.valid(u); bipartite_map.next(u))
-// std::cout << u << " ";
-// std::cout << "\n";
+// for (int i=0; i<a; ++i) bipartite_map.insert(s_nodes[i], false);
+// for (int i=0; i<b; ++i) bipartite_map.insert(t_nodes[i], true);
+ leda_node ln;
+ forall(ln, lS) bipartite_map.insert(ln, false);
+ forall(ln, lT) bipartite_map.insert(ln, true);
typedef BipartiteGraphWrapper<Graph> BGW;
BGW bgw(g, bipartite_map);
-// std::cout << "Nodes by NodeIt:\n";
-// FOR_EACH_LOC(BGW::NodeIt, n, bgw) {
-// std::cout << n << " ";
-// }
-// std::cout << "\n";
-// std::cout << "Nodes in S by ClassNodeIt:\n";
-// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.S_CLASS) {
-// std::cout << n << " ";
-// }
-// std::cout << "\n";
-// std::cout << "Nodes in T by ClassNodeIt:\n";
-// FOR_EACH_INC_LOC(BGW::ClassNodeIt, n, bgw, bgw.T_CLASS) {
-// std::cout << n << " ";
-// }
-// std::cout << "\n";
-// std::cout << "Edges of the bipartite graph:\n";
-// FOR_EACH_LOC(BGW::EdgeIt, e, bgw) {
-// std::cout << bgw.tail(e) << "->" << bgw.head(e) << std::endl;
-// }
-
- BGW::NodeMap<int> dbyj(bgw);
- BGW::EdgeMap<int> dbyxcj(bgw);
+ // BGW::NodeMap<int> dbyj(bgw);
+ // BGW::EdgeMap<int> dbyxcj(bgw);
typedef stGraphWrapper<BGW> stGW;
stGW stgw(bgw);
ConstMap<stGW::Edge, int> const1map(1);
-// stGW::NodeMap<int> ize(stgw);
-
-// BfsIterator< BGW, BGW::NodeMap<bool> > bfs(bgw);
-// Graph::NodeIt si;
-// Graph::Node s;
-// s=g.first(si);
-// bfs.pushAndSetReached(BGW::Node(s));
-// while (!bfs.finished()) { ++bfs; }
-
-// FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
-// std::cout << "out-edges of " << n << ":\n";
-// FOR_EACH_INC_LOC(stGW::OutEdgeIt, e, stgw, n) {
-// std::cout << " " << e << "\n";
-// std::cout << " aNode: " << stgw.aNode(e) << "\n";
-// std::cout << " bNode: " << stgw.bNode(e) << "\n";
-// }
-// std::cout << "in-edges of " << n << ":\n";
-// FOR_EACH_INC_LOC(stGW::InEdgeIt, e, stgw, n) {
-// std::cout << " " << e << "\n";
-// std::cout << " aNode: " << stgw.aNode(e) << "\n";
-// std::cout << " bNode: " << stgw.bNode(e) << "\n";
-// }
-// }
-// std::cout << "Edges of the stGraphWrapper:\n";
-// FOR_EACH_LOC(stGW::EdgeIt, n, stgw) {
-// std::cout << " " << n << "\n";
-// }
-
-// stGW::NodeMap<bool> b(stgw);
-// FOR_EACH_LOC(stGW::NodeIt, n, stgw) {
-// std::cout << n << ": " << b[n] <<"\n";
-// }
-
-// std::cout << "Bfs from s: \n";
-// BfsIterator< stGW, stGW::NodeMap<bool> > bfs_stgw(stgw);
-// bfs_stgw.pushAndSetReached(stgw.S_NODE);
-// while (!bfs_stgw.finished()) {
-// std::cout << " " << stGW::OutEdgeIt(bfs_stgw) << "\n";
-// ++bfs_stgw;
-// }
-
+ stGW::EdgeMap<int> flow(stgw);
Timer ts;
+ FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
ts.reset();
- stGW::EdgeMap<int> max_flow(stgw);
- MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
- max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, max_flow);
-// while (max_flow_test.augmentOnShortestPath()) { }
- typedef ListGraph MutableGraph;
-// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
- while (max_flow_test.augmentOnBlockingFlow2()) {
- std::cout << max_flow_test.flowValue() << std::endl;
- }
- std::cout << "max flow value: " << max_flow_test.flowValue() << std::endl;
- std::cout << "elapsed time: " << ts << std::endl;
-// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
-// std::cout << e << ": " << max_flow[e] << "\n";
-// }
-// std::cout << "\n";
-
- ts.reset();
- stGW::EdgeMap<int> pre_flow(stgw);
+ // stGW::EdgeMap<int> pre_flow(stgw);
Preflow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
- pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true);
+ pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow, true);
pre_flow_test.run();
- std::cout << "pre flow value: " << max_flow_test.flowValue() << std::endl;
+ std::cout << "HUGO pre flow value: " << pre_flow_test.flowValue() << std::endl;
std::cout << "elapsed time: " << ts << std::endl;
// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
// std::cout << e << ": " << pre_flow[e] << "\n";
// }
-// std::cout << "\n";
+ std::cout << "\n";
ts.reset();
leda_list<leda_edge> ml=MAX_CARD_BIPARTITE_MATCHING(lg);
@@ -208,11 +130,28 @@
//Preflow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
// pre_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, pre_flow, true);
//pre_flow_test.run();
- std::cout << "leda matching value: " << ml.size() << std::endl;
+ std::cout << "LEDA matching value: " << ml.size() << std::endl;
std::cout << "elapsed time: " << ts << std::endl;
// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
// std::cout << e << ": " << pre_flow[e] << "\n";
// }
+ std::cout << "\n";
+
+ FOR_EACH_LOC(stGW::EdgeIt, e, stgw) flow.set(e, 0);
+ ts.reset();
+ MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
+ max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
+// while (max_flow_test.augmentOnShortestPath()) { }
+ typedef ListGraph MutableGraph;
+// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
+ while (max_flow_test.augmentOnBlockingFlow2()) {
+ std::cout << max_flow_test.flowValue() << std::endl;
+ }
+ std::cout << "HUGO blocking flow value: " << max_flow_test.flowValue() << std::endl;
+ std::cout << "elapsed time: " << ts << std::endl;
+// FOR_EACH_LOC(stGW::EdgeIt, e, stgw) {
+// std::cout << e << ": " << max_flow[e] << "\n";
+// }
// std::cout << "\n";
return 0;
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 Tue Apr 27 16:10:19 2004
@@ -63,6 +63,7 @@
protected:
template <typename T> friend class NodeMap;
leda_node _n;
+ public: //FIXME
Node(leda_node __n) : _n(__n) { }
public:
/// @warning The default constructor sets the iterator
@@ -95,6 +96,7 @@
protected:
template <typename T> friend class EdgeMap;
leda_edge _e;
+ public: //FIXME
Edge(leda_edge __e) : _e(__e) { }
public:
/// @warning The default constructor sets the iterator
Modified: hugo/trunk/src/work/marci/leda/makefile
==============================================================================
--- hugo/trunk/src/work/marci/leda/makefile (original)
+++ hugo/trunk/src/work/marci/leda/makefile Tue Apr 27 16:10:19 2004
@@ -4,7 +4,7 @@
INCLUDEDIRS ?= -I../../../include -I../.. -I../../{marci,jacint,alpar,klao,akos,athos} -I$(LEDAROOT)/incl -I.
LDFLAGS = -L$(LEDAROOT) -lG -lL -lm
-BINARIES = bipartite_matching_leda
+BINARIES = bipartite_matching_leda bipartite_matching_leda_gen
include ../../makefile
More information about the Lemon-commits
mailing list