[Lemon-commits] [lemon_svn] marci: r448 - in hugo/trunk/src/work: athos jacint marci
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:39:30 CET 2006
Author: marci
Date: Thu Apr 15 16:41:20 2004
New Revision: 448
Added:
hugo/trunk/src/work/marci/for_each_macros.h
hugo/trunk/src/work/marci/macro_test.cc
Modified:
hugo/trunk/src/work/athos/minlengthpaths.h
hugo/trunk/src/work/jacint/preflow.h
hugo/trunk/src/work/marci/edmonds_karp.h
hugo/trunk/src/work/marci/edmonds_karp_demo.cc
hugo/trunk/src/work/marci/graph_wrapper.h
hugo/trunk/src/work/marci/makefile
Log:
In the resgraphwrapper interface, and in the constructor,
the order of FlowMap and CapacityMap is changed.
Modified: hugo/trunk/src/work/athos/minlengthpaths.h
==============================================================================
--- hugo/trunk/src/work/athos/minlengthpaths.h (original)
+++ hugo/trunk/src/work/athos/minlengthpaths.h Thu Apr 15 16:41:20 2004
@@ -37,7 +37,7 @@
typedef ConstMap<Edge,int> ConstMap;
- typedef ResGraphWrapper<const Graph,int,EdgeIntMap,ConstMap> ResGraphType;
+ typedef ResGraphWrapper<const Graph,int,ConstMap,EdgeIntMap> ResGraphType;
class ModLengthMap {
@@ -92,7 +92,7 @@
ConstMap const1map(1);
//We need a residual graph, in which some of the edges are reversed
- ResGraphType res_graph(G, reversed, const1map);
+ ResGraphType res_graph(G, const1map, reversed);
//Initialize the copy of the Dijkstra potential to zero
typename ResGraphType::NodeMap<Length> dijkstra_dist(res_graph);
Modified: hugo/trunk/src/work/jacint/preflow.h
==============================================================================
--- hugo/trunk/src/work/jacint/preflow.h (original)
+++ hugo/trunk/src/work/jacint/preflow.h Thu Apr 15 16:41:20 2004
@@ -43,8 +43,8 @@
namespace hugo {
template <typename Graph, typename T,
- typename FlowMap=typename Graph::EdgeMap<T>,
- typename CapMap=typename Graph::EdgeMap<T> >
+ typename CapMap=typename Graph::EdgeMap<T>,
+ typename FlowMap=typename Graph::EdgeMap<T> >
class Preflow {
typedef typename Graph::Node Node;
@@ -56,15 +56,14 @@
const Graph& G;
Node s;
Node t;
- FlowMap& flow;
const CapMap& capacity;
+ FlowMap& flow;
T value;
public:
Preflow(const Graph& _G, Node _s, Node _t, const CapMap& _capacity,
FlowMap& _flow ) :
- G(_G), s(_s), t(_t), flow(_flow), capacity(_capacity) {}
-
+ G(_G), s(_s), t(_t), capacity(_capacity), flow(_flow) {}
void run() {
Modified: hugo/trunk/src/work/marci/edmonds_karp.h
==============================================================================
--- hugo/trunk/src/work/marci/edmonds_karp.h (original)
+++ hugo/trunk/src/work/marci/edmonds_karp.h Thu Apr 15 16:41:20 2004
@@ -13,243 +13,243 @@
namespace hugo {
- template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
- class ResGraph {
- public:
- typedef typename Graph::Node Node;
- typedef typename Graph::NodeIt NodeIt;
- private:
- typedef typename Graph::SymEdgeIt OldSymEdgeIt;
- const Graph& G;
- FlowMap& flow;
- const CapacityMap& capacity;
- public:
- ResGraph(const Graph& _G, FlowMap& _flow,
- const CapacityMap& _capacity) :
- G(_G), flow(_flow), capacity(_capacity) { }
-
- class Edge;
- class OutEdgeIt;
- friend class Edge;
- friend class OutEdgeIt;
+// template<typename Graph, typename Number, typename CapacityMap, typename FlowMap>
+// class ResGraph {
+// public:
+// typedef typename Graph::Node Node;
+// typedef typename Graph::NodeIt NodeIt;
+// private:
+// typedef typename Graph::SymEdgeIt OldSymEdgeIt;
+// const Graph& G;
+// const CapacityMap& capacity;
+// FlowMap& flow;
+// public:
+// ResGraph(const Graph& _G, const CapacityMap& _capacity, FlowMap& _flow) :
+// G(_G), capacity(_capacity), flow(_flow) { }
- class Edge {
- friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
- protected:
- const ResGraph<Graph, Number, FlowMap, CapacityMap>* resG;
- OldSymEdgeIt sym;
- public:
- Edge() { }
- //Edge(const Edge& e) : resG(e.resG), sym(e.sym) { }
- Number free() const {
- if (resG->G.aNode(sym)==resG->G.tail(sym)) {
- return (resG->capacity.get(sym)-resG->flow.get(sym));
- } else {
- return (resG->flow.get(sym));
- }
- }
- bool valid() const { return sym.valid(); }
- void augment(Number a) const {
- if (resG->G.aNode(sym)==resG->G.tail(sym)) {
- resG->flow.set(sym, resG->flow.get(sym)+a);
- //resG->flow[sym]+=a;
- } else {
- resG->flow.set(sym, resG->flow.get(sym)-a);
- //resG->flow[sym]-=a;
- }
- }
- };
+// class Edge;
+// class OutEdgeIt;
+// friend class Edge;
+// friend class OutEdgeIt;
+
+// class Edge {
+// friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
+// protected:
+// const ResGraph<Graph, Number, FlowMap, CapacityMap>* resG;
+// OldSymEdgeIt sym;
+// public:
+// Edge() { }
+// //Edge(const Edge& e) : resG(e.resG), sym(e.sym) { }
+// Number free() const {
+// if (resG->G.aNode(sym)==resG->G.tail(sym)) {
+// return (resG->capacity.get(sym)-resG->flow.get(sym));
+// } else {
+// return (resG->flow.get(sym));
+// }
+// }
+// bool valid() const { return sym.valid(); }
+// void augment(Number a) const {
+// if (resG->G.aNode(sym)==resG->G.tail(sym)) {
+// resG->flow.set(sym, resG->flow.get(sym)+a);
+// //resG->flow[sym]+=a;
+// } else {
+// resG->flow.set(sym, resG->flow.get(sym)-a);
+// //resG->flow[sym]-=a;
+// }
+// }
+// };
- class OutEdgeIt : public Edge {
- friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
- public:
- OutEdgeIt() { }
- //OutEdgeIt(const OutEdgeIt& e) { resG=e.resG; sym=e.sym; }
- private:
- OutEdgeIt(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) {
- resG=&_resG;
- sym=resG->G.template first<OldSymEdgeIt>(v);
- while( sym.valid() && !(free()>0) ) { ++sym; }
- }
- public:
- OutEdgeIt& operator++() {
- ++sym;
- while( sym.valid() && !(free()>0) ) { ++sym; }
- return *this;
- }
- };
+// class OutEdgeIt : public Edge {
+// friend class ResGraph<Graph, Number, FlowMap, CapacityMap>;
+// public:
+// OutEdgeIt() { }
+// //OutEdgeIt(const OutEdgeIt& e) { resG=e.resG; sym=e.sym; }
+// private:
+// OutEdgeIt(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) {
+// resG=&_resG;
+// sym=resG->G.template first<OldSymEdgeIt>(v);
+// while( sym.valid() && !(free()>0) ) { ++sym; }
+// }
+// public:
+// OutEdgeIt& operator++() {
+// ++sym;
+// while( sym.valid() && !(free()>0) ) { ++sym; }
+// return *this;
+// }
+// };
- void /*getF*/first(OutEdgeIt& e, Node v) const {
- e=OutEdgeIt(*this, v);
- }
- void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
+// void /*getF*/first(OutEdgeIt& e, Node v) const {
+// e=OutEdgeIt(*this, v);
+// }
+// void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
- template< typename It >
- It first() const {
- It e;
- /*getF*/first(e);
- return e;
- }
+// template< typename It >
+// It first() const {
+// It e;
+// /*getF*/first(e);
+// return e;
+// }
- template< typename It >
- It first(Node v) const {
- It e;
- /*getF*/first(e, v);
- return e;
- }
+// template< typename It >
+// It first(Node v) const {
+// It e;
+// /*getF*/first(e, v);
+// return e;
+// }
- Node tail(Edge e) const { return G.aNode(e.sym); }
- Node head(Edge e) const { return G.bNode(e.sym); }
+// Node tail(Edge e) const { return G.aNode(e.sym); }
+// Node head(Edge e) const { return G.bNode(e.sym); }
- Node aNode(OutEdgeIt e) const { return G.aNode(e.sym); }
- Node bNode(OutEdgeIt e) const { return G.bNode(e.sym); }
+// Node aNode(OutEdgeIt e) const { return G.aNode(e.sym); }
+// Node bNode(OutEdgeIt e) const { return G.bNode(e.sym); }
- int id(Node v) const { return G.id(v); }
+// int id(Node v) const { return G.id(v); }
- template <typename S>
- class NodeMap {
- typename Graph::NodeMap<S> node_map;
- public:
- NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
- NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
- void set(Node nit, S a) { node_map.set(nit, a); }
- S get(Node nit) const { return node_map.get(nit); }
- S& operator[](Node nit) { return node_map[nit]; }
- const S& operator[](Node nit) const { return node_map[nit]; }
- };
+// template <typename S>
+// class NodeMap {
+// typename Graph::NodeMap<S> node_map;
+// public:
+// NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
+// NodeMap(const ResGraph<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
+// void set(Node nit, S a) { node_map.set(nit, a); }
+// S get(Node nit) const { return node_map.get(nit); }
+// S& operator[](Node nit) { return node_map[nit]; }
+// const S& operator[](Node nit) const { return node_map[nit]; }
+// };
- };
+// };
- template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
- class ResGraph2 {
- public:
- typedef typename Graph::Node Node;
- typedef typename Graph::NodeIt NodeIt;
- private:
- //typedef typename Graph::SymEdgeIt OldSymEdgeIt;
- typedef typename Graph::OutEdgeIt OldOutEdgeIt;
- typedef typename Graph::InEdgeIt OldInEdgeIt;
+// template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
+// class ResGraph2 {
+// public:
+// typedef typename Graph::Node Node;
+// typedef typename Graph::NodeIt NodeIt;
+// private:
+// //typedef typename Graph::SymEdgeIt OldSymEdgeIt;
+// typedef typename Graph::OutEdgeIt OldOutEdgeIt;
+// typedef typename Graph::InEdgeIt OldInEdgeIt;
- const Graph& G;
- FlowMap& flow;
- const CapacityMap& capacity;
- public:
- ResGraph2(const Graph& _G, FlowMap& _flow,
- const CapacityMap& _capacity) :
- G(_G), flow(_flow), capacity(_capacity) { }
-
- class Edge;
- class OutEdgeIt;
- friend class Edge;
- friend class OutEdgeIt;
-
- class Edge {
- friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
- protected:
- const ResGraph2<Graph, Number, FlowMap, CapacityMap>* resG;
- //OldSymEdgeIt sym;
- OldOutEdgeIt out;
- OldInEdgeIt in;
- bool out_or_in; //true, iff out
- public:
- Edge() : out_or_in(true) { }
- Number free() const {
- if (out_or_in) {
- return (resG->capacity.get(out)-resG->flow.get(out));
- } else {
- return (resG->flow.get(in));
- }
- }
- bool valid() const {
- return out_or_in && out.valid() || in.valid(); }
- void augment(Number a) const {
- if (out_or_in) {
- resG->flow.set(out, resG->flow.get(out)+a);
- } else {
- resG->flow.set(in, resG->flow.get(in)-a);
- }
- }
- };
+// const Graph& G;
+// FlowMap& flow;
+// const CapacityMap& capacity;
+// public:
+// ResGraph2(const Graph& _G, FlowMap& _flow,
+// const CapacityMap& _capacity) :
+// G(_G), flow(_flow), capacity(_capacity) { }
+
+// class Edge;
+// class OutEdgeIt;
+// friend class Edge;
+// friend class OutEdgeIt;
+
+// class Edge {
+// friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
+// protected:
+// const ResGraph2<Graph, Number, FlowMap, CapacityMap>* resG;
+// //OldSymEdgeIt sym;
+// OldOutEdgeIt out;
+// OldInEdgeIt in;
+// bool out_or_in; //true, iff out
+// public:
+// Edge() : out_or_in(true) { }
+// Number free() const {
+// if (out_or_in) {
+// return (resG->capacity.get(out)-resG->flow.get(out));
+// } else {
+// return (resG->flow.get(in));
+// }
+// }
+// bool valid() const {
+// return out_or_in && out.valid() || in.valid(); }
+// void augment(Number a) const {
+// if (out_or_in) {
+// resG->flow.set(out, resG->flow.get(out)+a);
+// } else {
+// resG->flow.set(in, resG->flow.get(in)-a);
+// }
+// }
+// };
- class OutEdgeIt : public Edge {
- friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
- public:
- OutEdgeIt() { }
- private:
- OutEdgeIt(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) {
- resG=&_resG;
- out=resG->G.template first<OldOutEdgeIt>(v);
- while( out.valid() && !(free()>0) ) { ++out; }
- if (!out.valid()) {
- out_or_in=0;
- in=resG->G.template first<OldInEdgeIt>(v);
- while( in.valid() && !(free()>0) ) { ++in; }
- }
- }
- public:
- OutEdgeIt& operator++() {
- if (out_or_in) {
- Node v=resG->G.aNode(out);
- ++out;
- while( out.valid() && !(free()>0) ) { ++out; }
- if (!out.valid()) {
- out_or_in=0;
- in=resG->G.template first<OldInEdgeIt>(v);
- while( in.valid() && !(free()>0) ) { ++in; }
- }
- } else {
- ++in;
- while( in.valid() && !(free()>0) ) { ++in; }
- }
- return *this;
- }
- };
+// class OutEdgeIt : public Edge {
+// friend class ResGraph2<Graph, Number, FlowMap, CapacityMap>;
+// public:
+// OutEdgeIt() { }
+// private:
+// OutEdgeIt(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _resG, Node v) {
+// resG=&_resG;
+// out=resG->G.template first<OldOutEdgeIt>(v);
+// while( out.valid() && !(free()>0) ) { ++out; }
+// if (!out.valid()) {
+// out_or_in=0;
+// in=resG->G.template first<OldInEdgeIt>(v);
+// while( in.valid() && !(free()>0) ) { ++in; }
+// }
+// }
+// public:
+// OutEdgeIt& operator++() {
+// if (out_or_in) {
+// Node v=resG->G.aNode(out);
+// ++out;
+// while( out.valid() && !(free()>0) ) { ++out; }
+// if (!out.valid()) {
+// out_or_in=0;
+// in=resG->G.template first<OldInEdgeIt>(v);
+// while( in.valid() && !(free()>0) ) { ++in; }
+// }
+// } else {
+// ++in;
+// while( in.valid() && !(free()>0) ) { ++in; }
+// }
+// return *this;
+// }
+// };
- void /*getF*/first(OutEdgeIt& e, Node v) const {
- e=OutEdgeIt(*this, v);
- }
- void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
+// void /*getF*/first(OutEdgeIt& e, Node v) const {
+// e=OutEdgeIt(*this, v);
+// }
+// void /*getF*/first(NodeIt& v) const { G./*getF*/first(v); }
- template< typename It >
- It first() const {
- It e;
- /*getF*/first(e);
- return e;
- }
+// template< typename It >
+// It first() const {
+// It e;
+// /*getF*/first(e);
+// return e;
+// }
- template< typename It >
- It first(Node v) const {
- It e;
- /*getF*/first(e, v);
- return e;
- }
+// template< typename It >
+// It first(Node v) const {
+// It e;
+// /*getF*/first(e, v);
+// return e;
+// }
- Node tail(Edge e) const {
- return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
- Node head(Edge e) const {
- return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
-
- Node aNode(OutEdgeIt e) const {
- return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
- Node bNode(OutEdgeIt e) const {
- return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
-
- int id(Node v) const { return G.id(v); }
-
- template <typename S>
- class NodeMap {
- typename Graph::NodeMap<S> node_map;
- public:
- NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
- NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
- void set(Node nit, S a) { node_map.set(nit, a); }
- S get(Node nit) const { return node_map.get(nit); }
- };
- };
+// Node tail(Edge e) const {
+// return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
+// Node head(Edge e) const {
+// return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
+
+// Node aNode(OutEdgeIt e) const {
+// return ((e.out_or_in) ? G.aNode(e.out) : G.aNode(e.in)); }
+// Node bNode(OutEdgeIt e) const {
+// return ((e.out_or_in) ? G.bNode(e.out) : G.bNode(e.in)); }
+
+// int id(Node v) const { return G.id(v); }
+
+// template <typename S>
+// class NodeMap {
+// typename Graph::NodeMap<S> node_map;
+// public:
+// NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G) : node_map(_G.G) { }
+// NodeMap(const ResGraph2<Graph, Number, FlowMap, CapacityMap>& _G, S a) : node_map(_G.G, a) { }
+// void set(Node nit, S a) { node_map.set(nit, a); }
+// S get(Node nit) const { return node_map.get(nit); }
+// };
+// };
- template <typename Graph, typename Number, typename FlowMap, typename CapacityMap>
+ template <typename Graph, typename Number,
+ typename CapacityMap, typename FlowMap>
class MaxFlow {
protected:
typedef typename Graph::Node Node;
@@ -260,18 +260,19 @@
const Graph* g;
Node s;
Node t;
- FlowMap* flow;
const CapacityMap* capacity;
- typedef ResGraphWrapper<const Graph, Number, FlowMap, CapacityMap > ResGW;
+ FlowMap* flow;
+ typedef ResGraphWrapper<const Graph, Number, CapacityMap, FlowMap> ResGW;
typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
typedef typename ResGW::Edge ResGWEdge;
public:
- MaxFlow(const Graph& _g, Node _s, Node _t, FlowMap& _flow, const CapacityMap& _capacity) :
- g(&_g), s(_s), t(_t), flow(&_flow), capacity(&_capacity) { }
+ MaxFlow(const Graph& _g, Node _s, Node _t, const CapacityMap& _capacity,
+ FlowMap& _flow) :
+ g(&_g), s(_s), t(_t), capacity(&_capacity), flow(&_flow) { }
bool augmentOnShortestPath() {
- ResGW res_graph(*g, *flow, *capacity);
+ ResGW res_graph(*g, *capacity, *flow);
bool _augment=false;
BfsIterator5< ResGW, typename ResGW::NodeMap<bool> > bfs(res_graph);
@@ -336,7 +337,7 @@
typedef MutableGraph MG;
bool _augment=false;
- ResGW res_graph(*g, *flow, *capacity);
+ ResGW res_graph(*g, *capacity, *flow);
BfsIterator5< ResGW, typename ResGW::NodeMap<bool> > bfs(res_graph);
@@ -445,7 +446,7 @@
typedef MutableGraph MG;
bool _augment=false;
- ResGW res_graph(*g, *flow, *capacity);
+ ResGW res_graph(*g, *capacity, *flow);
//bfs for distances on the residual graph
BfsIterator5< ResGW, typename ResGW::NodeMap<bool> > bfs(res_graph);
@@ -550,7 +551,7 @@
bool augmentOnBlockingFlow2() {
bool _augment=false;
- ResGW res_graph(*g, *flow, *capacity);
+ ResGW res_graph(*g, *capacity, *flow);
BfsIterator5< ResGW, typename ResGW::NodeMap<bool> > bfs(res_graph);
Modified: hugo/trunk/src/work/marci/edmonds_karp_demo.cc
==============================================================================
--- hugo/trunk/src/work/marci/edmonds_karp_demo.cc (original)
+++ hugo/trunk/src/work/marci/edmonds_karp_demo.cc Thu Apr 15 16:41:20 2004
@@ -104,7 +104,7 @@
ts.reset();
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
- max_flow_test(G, s, t, flow, cap);
+ max_flow_test(G, s, t, cap, flow);
int i=0;
while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) {
// for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
@@ -132,7 +132,7 @@
ts.reset();
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
- max_flow_test(G, s, t, flow, cap);
+ max_flow_test(G, s, t, cap, flow);
int i=0;
while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) {
// for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
@@ -160,7 +160,7 @@
ts.reset();
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
- max_flow_test(G, s, t, flow, cap);
+ max_flow_test(G, s, t, cap, flow);
int i=0;
while (max_flow_test.augmentOnBlockingFlow2()) {
// for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
@@ -188,7 +188,7 @@
ts.reset();
MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
- max_flow_test(G, s, t, flow, cap);
+ max_flow_test(G, s, t, cap, flow);
int i=0;
while (max_flow_test.augmentOnShortestPath()) {
// for(EdgeIt e=G.template first<EdgeIt>(); e.valid(); ++e) {
Added: hugo/trunk/src/work/marci/for_each_macros.h
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/marci/for_each_macros.h Thu Apr 15 16:41:20 2004
@@ -0,0 +1,85 @@
+// -*- c++ -*-
+#ifndef FOR_EACH_MACROS_H
+#define FOR_EACH_MACROS_H
+
+namespace hugo {
+
+#define FOR_EACH(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
+#define FOR_EACH_INC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
+
+#define FOR_EACH_EDGE(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
+#define FOR_EACH_NODE(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
+#define FOR_EACH_INEDGE(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
+#define FOR_EACH_OUTEDGE(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
+
+// template<typename It, typename Graph>
+// It loopFirst(const Graph& g) const {
+// It e; g.first(e); return e;
+// }
+
+// template<typename It, typename Graph>
+// It loopFirst(const Graph& g, const Node& v) const {
+// It e; g.first(e, v); return e;
+// }
+
+// template<typename Graph>
+// typename Graph::NodeIt loopFirstNode(const Graph& g) const {
+// typename Graph::NodeIt e; g.first(e); return e;
+// }
+// template<typename Graph>
+// typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
+// typename Graph::EdgeIt e; g.first(e); return e;
+// }
+// template<typename Graph>
+// typename Graph::OutEdgeIt
+// loopFirstOutEdge(const Graph& g, const Node& n) const {
+// typename Graph::OutEdgeIt e; g.first(e, n); return e;
+// }
+// template<typename Graph>
+// typename Graph::InEdgeIt
+// loopFirstIn Edge(const Graph& g, const Node& n) const {
+// typename Graph::InEdgeIt e; g.first(e, n); return e;
+// }
+
+//FIXME ezt hogy a gorcsbe birja levezetni. Csak ugy leveszi a const-ot??
+ template<typename It, typename Graph>
+ It loopFirst(const It& i, const Graph& g) {
+ It e=i; g.first(e); return e;
+ }
+
+ template<typename It, typename Graph, typename Node>
+ It loopFirst(const It& i, const Graph& g, const Node& v) {
+ It e=i; g.first(e, v); return e;
+ }
+
+// template<typename Graph>
+// typename Graph::NodeIt loopFirstNode(const Graph& g) const {
+// typename Graph::NodeIt e; g.first(e); return e;
+// }
+// template<typename Graph>
+// typename Graph::EdgeIt loopFirstEdge(const Graph& g) const {
+// typename Graph::EdgeIt e; g.first(e); return e;
+// }
+// template<typename Graph>
+// typename Graph::OutEdgeIt
+// loopFirstOutEdge(const Graph& g, const Node& n) const {
+// typename Graph::OutEdgeIt e; g.first(e, n); return e;
+// }
+// template<typename Graph>
+// typename Graph::InEdgeIt
+// loopFirstIn Edge(const Graph& g, const Node& n) const {
+// typename Graph::InEdgeIt e; g.first(e, n); return e;
+// }
+
+#define FOR_EACH_LOC(Ittype, e, g) for(Ittype (e)=loopFirst(Ittype(), (g)); (g).valid((e)); (g).next((e)))
+#define FOR_EACH_INC_LOC(Ittype, e, g, v) for(Ittype (e)=loopFirst(Ittype(), (g), (v)); (g).valid((e)); (g).next((e)))
+
+// #define FOR_EACH_EDGE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
+// #define FOR_EACH_NODE_LOC(e, g) for((g).first((e)); (g).valid((e)); (g).next((e)))
+// #define FOR_EACH_INEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
+// #define FOR_EACH_OUTEDGE_LOC(e, g, v) for((g).first((e), (v)); (g).valid((e)); (g).next((e)))
+
+
+} //namespace hugo
+
+#endif //FOR_EACH_MACROS_H
Modified: hugo/trunk/src/work/marci/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/work/marci/graph_wrapper.h (original)
+++ hugo/trunk/src/work/marci/graph_wrapper.h Thu Apr 15 16:41:20 2004
@@ -896,19 +896,20 @@
- template<typename Graph, typename Number, typename FlowMap, typename CapacityMap>
+ template<typename Graph, typename Number,
+ typename CapacityMap, typename FlowMap>
class ResGraphWrapper : public GraphWrapper<Graph> {
protected:
// typedef typename Graph::OutEdgeIt GraphOutEdgeIt;
// typedef typename Graph::InEdgeIt GraphInEdgeIt;
// typedef typename Graph::Edge GraphEdge;
- FlowMap* flow;
const CapacityMap* capacity;
+ FlowMap* flow;
public:
- ResGraphWrapper(Graph& _graph, FlowMap& _flow,
- const CapacityMap& _capacity) :
- GraphWrapper<Graph>(_graph), flow(&_flow), capacity(&_capacity) { }
+ ResGraphWrapper(Graph& _graph, const CapacityMap& _capacity,
+ FlowMap& _flow) :
+ GraphWrapper<Graph>(_graph), capacity(&_capacity), flow(&_flow) { }
class Edge;
class OutEdgeIt;
@@ -918,7 +919,7 @@
typedef typename GraphWrapper<Graph>::Node Node;
typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
class Edge : public Graph::Edge {
- friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+ friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
protected:
bool forward; //true, iff forward
// typename Graph::Edge e;
@@ -940,7 +941,7 @@
}
};
// class Edge {
-// friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+// friend class ResGraphWrapper<Graph, Number,lksd FlowMap, CapacityMap>;
// protected:
// bool out_or_in; //true, iff out
// GraphOutEdgeIt out;
@@ -967,7 +968,7 @@
// }
// };
class OutEdgeIt {
- friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+ friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
protected:
typename Graph::OutEdgeIt out;
typename Graph::InEdgeIt in;
@@ -978,7 +979,7 @@
// OutEdgeIt(const Edge& e) : Edge(e) { }
OutEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { }
//the unique invalid iterator
- OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) {
+ OutEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) {
forward=true;
resG.graph->first(out, v);
while( resG.graph->valid(out) && !(resG.resCap(*this)>0) ) { resG.graph->next(out); }
@@ -1000,13 +1001,13 @@
}
};
// class OutEdgeIt : public Edge {
-// friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+// friend class ResGraphWrapper<Graph, Number, FkklowMap, CapacityMap>;
// public:
// OutEdgeIt() { }
// //FIXME
// OutEdgeIt(const Edge& e) : Edge(e) { }
// OutEdgeIt(const Invalid& i) : Edge(i) { }
-// OutEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) : Edge() {
+// OutEdgeIt(const ResGraphWrapper<Graph, Number, FdfvlowMap, CapacityMap>& resG, Node v) : Edge() {
// resG.graph->first(out, v);
// while( resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); }
// if (!resG.graph->valid(out)) {
@@ -1038,7 +1039,7 @@
// class InEdgeIt : public Edge { };
class InEdgeIt {
- friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+ friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
protected:
typename Graph::OutEdgeIt out;
typename Graph::InEdgeIt in;
@@ -1049,7 +1050,7 @@
// OutEdgeIt(const Edge& e) : Edge(e) { }
InEdgeIt(const Invalid& i) : out(i), in(i), forward(false) { }
//the unique invalid iterator
- InEdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG, Node v) {
+ InEdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG, Node v) {
forward=true;
resG.graph->first(in, v);
while( resG.graph->valid(in) && !(resG.resCap(*this)>0) ) { resG.graph->next(in); }
@@ -1072,14 +1073,14 @@
};
class EdgeIt {
- friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+ friend class ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>;
protected:
typename Graph::EdgeIt e;
bool forward;
public:
EdgeIt() { }
EdgeIt(const Invalid& i) : e(i), forward(false) { }
- EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) {
+ EdgeIt(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& resG) {
forward=true;
resG.graph->first(e);
while (resG.graph->valid(e) && !(resG.resCap(*this)>0)) resG.graph->next(e);
@@ -1094,13 +1095,13 @@
}
};
// class EdgeIt : public Edge {
-// friend class ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>;
+// friend class ResGraphWrapper<Graph, Number, FflowMap, CapacityMap>;
// NodeIt v;
// public:
// EdgeIt() { }
// //EdgeIt(const EdgeIt& e) : Edge(e), v(e.v) { }
// EdgeIt(const Invalid& i) : Edge(i) { }
-// EdgeIt(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& resG) : Edge() {
+// EdgeIt(const ResGraphWrapper<Graph, Number, FlfowMap, CapacityMap>& resG) : Edge() {
// resG.graph->first(v);
// if (resG.graph->valid(v)) resG.graph->first(out, v); else out=INVALID;
// while (resG.graph->valid(out) && !(resG.resCap(out)>0) ) { resG.graph->next(out); }
@@ -1317,9 +1318,9 @@
// template<typename T> class NodeMap : public Graph::NodeMap<T> {
// public:
-// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G)
+// NodeMap(const ResGraphWrapper<Graph, Number, FlovwMap, CapacityMap>& _G)
// : Graph::NodeMap<T>(_G.gw) { }
-// NodeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G,
+// NodeMap(const ResGraphWrapper<Graph, Number, FlowvMap, CapacityMap>& _G,
// T a) : Graph::NodeMap<T>(_G.gw, a) { }
// };
@@ -1337,8 +1338,8 @@
class EdgeMap {
typename Graph::EdgeMap<T> forward_map, backward_map;
public:
- EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
- EdgeMap(const ResGraphWrapper<Graph, Number, FlowMap, CapacityMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
+ EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
+ EdgeMap(const ResGraphWrapper<Graph, Number, CapacityMap, FlowMap>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
void set(Edge e, T a) {
if (e.forward)
forward_map.set(e.out, a);
Added: hugo/trunk/src/work/marci/macro_test.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/src/work/marci/macro_test.cc Thu Apr 15 16:41:20 2004
@@ -0,0 +1,28 @@
+// -*- c++ -*-
+#include <iostream>
+#include <fstream>
+
+#include <list_graph.h>
+#include <for_each_macros.h>
+
+using namespace hugo;
+
+int main()
+{
+ typedef ListGraph Graph;
+ Graph g;
+ Graph::Node n1=g.addNode();
+ Graph::Node n2=g.addNode();
+ Graph::NodeIt n;
+ FOR_EACH(n, g) {
+ std::cout << g.id(n) << " ";
+ }
+ std::cout << std::endl;
+ FOR_EACH_LOC(Graph::NodeIt, m, g) {
+ std::cout << g.id(m) << " ";
+ }
+ std::cout << std::endl;
+
+
+ return 0;
+}
Modified: hugo/trunk/src/work/marci/makefile
==============================================================================
--- hugo/trunk/src/work/marci/makefile (original)
+++ hugo/trunk/src/work/marci/makefile Thu Apr 15 16:41:20 2004
@@ -12,7 +12,7 @@
CXXFLAGS = -g -O -W -Wall $(INCLUDEDIRS) -ansi -pedantic -ftemplate-depth-30
LEDABINARIES = lg_vs_sg leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
-BINARIES = edmonds_karp_demo iterator_bfs_demo
+BINARIES = edmonds_karp_demo iterator_bfs_demo macro_test
#gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
all: $(BINARIES)
More information about the Lemon-commits
mailing list