[Lemon-commits] [lemon_svn] marci: r850 - in hugo/trunk/src: hugo work/jacint work/marci work/marci/leda
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:41:51 CET 2006
Author: marci
Date: Thu May 20 17:40:59 2004
New Revision: 850
Modified:
hugo/trunk/src/hugo/graph_wrapper.h
hugo/trunk/src/work/jacint/max_flow.h
hugo/trunk/src/work/marci/bfs_dfs.h
hugo/trunk/src/work/marci/leda/leda_graph_wrapper.h
Log:
a
Modified: hugo/trunk/src/hugo/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/hugo/graph_wrapper.h (original)
+++ hugo/trunk/src/hugo/graph_wrapper.h Thu May 20 17:40:59 2004
@@ -11,6 +11,7 @@
///\author Marton Makai
#include <hugo/invalid.h>
+#include <hugo/maps.h>
//#include <iter_map.h>
namespace hugo {
@@ -103,6 +104,10 @@
public:
Node() { }
Node(const typename Graph::Node& _n) : Graph::Node(_n) { }
+ // /// \bug construction throughrthr multiple levels should be
+ // /// handled better
+ // Node(const typename ParentGraph::ParentGraph::Node& _n) :
+ // Graph::Node(_n) { }
Node(const Invalid& i) : Graph::Node(i) { }
};
class NodeIt {
@@ -202,6 +207,11 @@
void clear() const { graph->clear(); }
+ bool forward(const Edge& e) const { graph->forward(e); }
+ bool backward(const Edge& e) const { graph->backward(e); }
+
+ Edge opposite(const Edge& e) const { Edge(graph->opposite(e)); }
+
template<typename T> class NodeMap : public Graph::template NodeMap<T> {
typedef typename Graph::template NodeMap<T> Parent;
public:
@@ -227,6 +237,8 @@
///\author Marton Makai
template<typename Graph>
class RevGraphWrapper : public GraphWrapper<Graph> {
+ public:
+ typedef GraphWrapper<Graph> Parent;
protected:
RevGraphWrapper() : GraphWrapper<Graph>() { }
public:
@@ -307,6 +319,8 @@
template<typename Graph, typename NodeFilterMap,
typename EdgeFilterMap>
class SubGraphWrapper : public GraphWrapper<Graph> {
+ public:
+ typedef GraphWrapper<Graph> Parent;
protected:
NodeFilterMap* node_filter_map;
EdgeFilterMap* edge_filter_map;
@@ -321,7 +335,6 @@
}
public:
-
SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map,
EdgeFilterMap& _edge_filter_map) :
GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map),
@@ -496,6 +509,8 @@
/// \author Marton Makai
template<typename Graph>
class UndirGraphWrapper : public GraphWrapper<Graph> {
+ public:
+ typedef GraphWrapper<Graph> Parent;
protected:
UndirGraphWrapper() : GraphWrapper<Graph>() { }
@@ -591,34 +606,44 @@
};
- ///\brief A wrapper for composing bidirected graph from a directed one.
+
+ ///\brief A wrapper for composing a subgraph of a
+ /// bidirected graph composed from a directed one.
/// experimental, for fezso's sake.
///
- /// A wrapper for composing bidirected graph from a directed one.
+ /// A wrapper for composing a subgraps of a
+ /// bidirected graph composed from a directed one.
/// experimental, for fezso's sake.
/// A bidirected graph is composed over the directed one without physical
/// storage. As the oppositely directed edges are logically different ones
/// the maps are able to attach different values for them.
- template<typename Graph>
- class BidirGraphWrapper : public GraphWrapper<Graph> {
+ template<typename Graph,
+ typename ForwardFilterMap, typename BackwardFilterMap>
+ class SubBidirGraphWrapper : public GraphWrapper<Graph> {
+ public:
+ typedef GraphWrapper<Graph> Parent;
protected:
//const CapacityMap* capacity;
//FlowMap* flow;
- BidirGraphWrapper() : GraphWrapper<Graph>()/*,
+ ForwardFilterMap* forward_filter;
+ BackwardFilterMap* backward_filter;
+
+ SubBidirGraphWrapper() : GraphWrapper<Graph>()/*,
capacity(0), flow(0)*/ { }
-// void setCapacityMap(const CapacityMap& _capacity) {
-// capacity=&_capacity;
-// }
-// void setFlowMap(FlowMap& _flow) {
-// flow=&_flow;
-// }
+ void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
+ forward_filter=&_forward_filter;
+ }
+ void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
+ backward_filter=&_backward_filter;
+ }
public:
- BidirGraphWrapper(Graph& _graph/*, const CapacityMap& _capacity,
- FlowMap& _flow*/) :
- GraphWrapper<Graph>(_graph)/*, capacity(&_capacity), flow(&_flow)*/ { }
+ SubBidirGraphWrapper(Graph& _graph, ForwardFilterMap& _forward_filter,
+ BackwardFilterMap& _backward_filter) :
+ GraphWrapper<Graph>(_graph),
+ forward_filter(&_forward_filter), backward_filter(&_backward_filter) { }
class Edge;
class OutEdgeIt;
@@ -632,7 +657,8 @@
typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
class Edge : public Graph::Edge {
- friend class BidirGraphWrapper<Graph>;
+ friend class SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>;
///\bug ez nem is kell
//template<typename T> friend class NodeMap;
template<typename T> friend class EdgeMap;
@@ -659,7 +685,8 @@
};
class OutEdgeIt {
- friend class BidirGraphWrapper<Graph>;
+ friend class SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>;
protected:
typename Graph::OutEdgeIt out;
typename Graph::InEdgeIt in;
@@ -670,14 +697,15 @@
// OutEdgeIt(const Edge& e) : Edge(e) { }
OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
//the unique invalid iterator
- OutEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) {
+ OutEdgeIt(const SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>& _G, Node v) {
backward=false;
_G.graph->first(out, v);
- while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
+ while(_G.graph->valid(out) && !(*_G.forward_filter)[*this]) { _G.graph->next(out); }
if (!_G.graph->valid(out)) {
backward=true;
_G.graph->first(in, v);
- while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
+ while(_G.graph->valid(in) && !(*_G.backward_filter)[*this]) { _G.graph->next(in); }
}
}
operator Edge() const {
@@ -693,7 +721,8 @@
};
class InEdgeIt {
- friend class BidirGraphWrapper<Graph>;
+ friend class SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>;
protected:
typename Graph::OutEdgeIt out;
typename Graph::InEdgeIt in;
@@ -704,14 +733,15 @@
// OutEdgeIt(const Edge& e) : Edge(e) { }
InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
//the unique invalid iterator
- InEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) {
+ InEdgeIt(const SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>& _G, Node v) {
backward=false;
_G.graph->first(in, v);
- while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
+ while(_G.graph->valid(in) && !(*_G.forward_filter)[*this]) { _G.graph->next(in); }
if (!_G.graph->valid(in)) {
backward=true;
_G.graph->first(out, v);
- while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
+ while(_G.graph->valid(out) && !(*_G.backward_filter)[*this]) { _G.graph->next(out); }
}
}
operator Edge() const {
@@ -727,21 +757,23 @@
};
class EdgeIt {
- friend class BidirGraphWrapper<Graph>;
+ friend class SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>;
protected:
typename Graph::EdgeIt e;
bool backward;
public:
EdgeIt() { }
EdgeIt(const Invalid& i) : e(i), backward(true) { }
- EdgeIt(const BidirGraphWrapper<Graph>& _G) {
+ EdgeIt(const SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>& _G) {
backward=false;
_G.graph->first(e);
- while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
+ while (_G.graph->valid(e) && !(*_G.forward_filter)[*this]) _G.graph->next(e);
if (!_G.graph->valid(e)) {
backward=true;
_G.graph->first(e);
- while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
+ while (_G.graph->valid(e) && !(*_G.backward_filter)[*this]) _G.graph->next(e);
}
}
operator Edge() const {
@@ -770,17 +802,17 @@
if (!e.backward) {
Node v=this->graph->aNode(e.out);
this->graph->next(e.out);
- while(this->graph->valid(e.out) && !enabled(e)) {
+ while(this->graph->valid(e.out) && !(*forward_filter)[e]) {
this->graph->next(e.out); }
if (!this->graph->valid(e.out)) {
e.backward=true;
this->graph->first(e.in, v);
- while(this->graph->valid(e.in) && !enabled(e)) {
+ while(this->graph->valid(e.in) && !(*backward_filter)[e]) {
this->graph->next(e.in); }
}
} else {
this->graph->next(e.in);
- while(this->graph->valid(e.in) && !enabled(e)) {
+ while(this->graph->valid(e.in) && !(*backward_filter)[e]) {
this->graph->next(e.in); }
}
return e;
@@ -790,17 +822,17 @@
if (!e.backward) {
Node v=this->graph->aNode(e.in);
this->graph->next(e.in);
- while(this->graph->valid(e.in) && !enabled(e)) {
+ while(this->graph->valid(e.in) && !(*forward_filter)[e]) {
this->graph->next(e.in); }
if (!this->graph->valid(e.in)) {
e.backward=true;
this->graph->first(e.out, v);
- while(this->graph->valid(e.out) && !enabled(e)) {
+ while(this->graph->valid(e.out) && !(*backward_filter)[e]) {
this->graph->next(e.out); }
}
} else {
this->graph->next(e.out);
- while(this->graph->valid(e.out) && !enabled(e)) {
+ while(this->graph->valid(e.out) && !(*backward_filter)[e]) {
this->graph->next(e.out); }
}
return e;
@@ -808,17 +840,17 @@
EdgeIt& next(EdgeIt& e) const {
if (!e.backward) {
this->graph->next(e.e);
- while(this->graph->valid(e.e) && !enabled(e)) {
+ while(this->graph->valid(e.e) && !(*forward_filter)[e]) {
this->graph->next(e.e); }
if (!this->graph->valid(e.e)) {
e.backward=true;
this->graph->first(e.e);
- while(this->graph->valid(e.e) && !enabled(e)) {
+ while(this->graph->valid(e.e) && !(*backward_filter)[e]) {
this->graph->next(e.e); }
}
} else {
this->graph->next(e.e);
- while(this->graph->valid(e.e) && !enabled(e)) {
+ while(this->graph->valid(e.e) && !(*backward_filter)[e]) {
this->graph->next(e.e); }
}
return e;
@@ -876,16 +908,16 @@
// flow->set(e, (*flow)[e]-a);
// }
- bool enabled(const Edge& e) const {
- if (!e.backward)
-// return (capacity->get(e.out)-flow->get(e.out));
- //return ((*capacity)[e]-(*flow)[e]);
- return true;
- else
-// return (flow->get(e.in));
- //return ((*flow)[e]);
- return true;
- }
+// bool enabled(const Edge& e) const {
+// if (!e.backward)
+// // return (capacity->get(e.out)-flow->get(e.out));
+// //return ((*capacity)[e]-(*flow)[e]);
+// return true;
+// else
+// // return (flow->get(e.in));
+// //return ((*flow)[e]);
+// return true;
+// }
// Number enabled(typename Graph::OutEdgeIt out) const {
// // return (capacity->get(out)-flow->get(out));
@@ -903,8 +935,12 @@
public:
typedef T ValueType;
typedef Edge KeyType;
- EdgeMap(const BidirGraphWrapper<Graph>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
- EdgeMap(const BidirGraphWrapper<Graph>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
+ EdgeMap(const SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>& _G) :
+ forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
+ EdgeMap(const SubBidirGraphWrapper<Graph,
+ ForwardFilterMap, BackwardFilterMap>& _G, T a) :
+ forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
void set(Edge e, T a) {
if (!e.backward)
forward_map.set(e/*.out*/, a);
@@ -930,6 +966,393 @@
};
};
+
+
+ ///\brief A wrapper for composing bidirected graph from a directed one.
+ /// experimental, for fezso's sake.
+ ///
+ /// A wrapper for composing bidirected graph from a directed one.
+ /// experimental, for fezso's sake.
+ /// A bidirected graph is composed over the directed one without physical
+ /// storage. As the oppositely directed edges are logically different ones
+ /// the maps are able to attach different values for them.
+ template<typename Graph>
+ class BidirGraphWrapper :
+ public SubBidirGraphWrapper<
+ Graph,
+ ConstMap<typename Graph::Edge, bool>,
+ ConstMap<typename Graph::Edge, bool> > {
+ public:
+ typedef SubBidirGraphWrapper<
+ Graph,
+ ConstMap<typename Graph::Edge, bool>,
+ ConstMap<typename Graph::Edge, bool> > Parent;
+ protected:
+ ConstMap<typename Graph::Edge, bool> cm;
+ //const CapacityMap* capacity;
+ //FlowMap* flow;
+
+ BidirGraphWrapper() : Parent(), cm(true) { }
+// void setCapacityMap(const CapacityMap& _capacity) {
+// capacity=&_capacity;
+// }
+// void setFlowMap(FlowMap& _flow) {
+// flow=&_flow;
+// }
+
+ public:
+
+ BidirGraphWrapper(Graph& _graph) : Parent() {
+ Parent::setGraph(_graph);
+ Parent::setForwardFilterMap(cm);
+ Parent::setBackwardFilterMap(cm);
+ }
+ };
+
+
+
+
+// ///\brief A wrapper for composing bidirected graph from a directed one.
+// /// experimental, for fezso's sake.
+// ///
+// /// A wrapper for composing bidirected graph from a directed one.
+// /// experimental, for fezso's sake.
+// /// A bidirected graph is composed over the directed one without physical
+// /// storage. As the oppositely directed edges are logically different ones
+// /// the maps are able to attach different values for them.
+// template<typename Graph>
+// class BidirGraphWrapper : public GraphWrapper<Graph> {
+// public:
+// typedef GraphWrapper<Graph> Parent;
+// protected:
+// //const CapacityMap* capacity;
+// //FlowMap* flow;
+
+// BidirGraphWrapper() : GraphWrapper<Graph>()/*,
+// capacity(0), flow(0)*/ { }
+// // void setCapacityMap(const CapacityMap& _capacity) {
+// // capacity=&_capacity;
+// // }
+// // void setFlowMap(FlowMap& _flow) {
+// // flow=&_flow;
+// // }
+
+// public:
+
+// BidirGraphWrapper(Graph& _graph/*, const CapacityMap& _capacity,
+// FlowMap& _flow*/) :
+// GraphWrapper<Graph>(_graph)/*, capacity(&_capacity), flow(&_flow)*/ { }
+
+// class Edge;
+// class OutEdgeIt;
+// friend class Edge;
+// friend class OutEdgeIt;
+
+// //template<typename T> class NodeMap;
+// template<typename T> class EdgeMap;
+
+// typedef typename GraphWrapper<Graph>::Node Node;
+// typedef typename GraphWrapper<Graph>::NodeIt NodeIt;
+
+// class Edge : public Graph::Edge {
+// friend class BidirGraphWrapper<Graph>;
+// ///\bug ez nem is kell
+// //template<typename T> friend class NodeMap;
+// template<typename T> friend class EdgeMap;
+// protected:
+// bool backward; //true, iff backward
+// // typename Graph::Edge e;
+// public:
+// Edge() { }
+// ///\bug =false kell-e? zsoltnak kell az addEdge miatt
+// Edge(const typename Graph::Edge& _e, bool _backward=false) :
+// Graph::Edge(_e), backward(_backward) { }
+// Edge(const Invalid& i) : Graph::Edge(i), backward(true) { }
+// //the unique invalid iterator
+// friend bool operator==(const Edge& u, const Edge& v) {
+// return (v.backward==u.backward &&
+// static_cast<typename Graph::Edge>(u)==
+// static_cast<typename Graph::Edge>(v));
+// }
+// friend bool operator!=(const Edge& u, const Edge& v) {
+// return (v.backward!=u.backward ||
+// static_cast<typename Graph::Edge>(u)!=
+// static_cast<typename Graph::Edge>(v));
+// }
+// };
+
+// class OutEdgeIt {
+// friend class BidirGraphWrapper<Graph>;
+// protected:
+// typename Graph::OutEdgeIt out;
+// typename Graph::InEdgeIt in;
+// bool backward;
+// public:
+// OutEdgeIt() { }
+// //FIXME
+// // OutEdgeIt(const Edge& e) : Edge(e) { }
+// OutEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
+// //the unique invalid iterator
+// OutEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) {
+// backward=false;
+// _G.graph->first(out, v);
+// while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
+// if (!_G.graph->valid(out)) {
+// backward=true;
+// _G.graph->first(in, v);
+// while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
+// }
+// }
+// operator Edge() const {
+// // Edge e;
+// // e.forward=this->forward;
+// // if (this->forward) e=out; else e=in;
+// // return e;
+// if (this->backward)
+// return Edge(in, this->backward);
+// else
+// return Edge(out, this->backward);
+// }
+// };
+
+// class InEdgeIt {
+// friend class BidirGraphWrapper<Graph>;
+// protected:
+// typename Graph::OutEdgeIt out;
+// typename Graph::InEdgeIt in;
+// bool backward;
+// public:
+// InEdgeIt() { }
+// //FIXME
+// // OutEdgeIt(const Edge& e) : Edge(e) { }
+// InEdgeIt(const Invalid& i) : out(i), in(i), backward(true) { }
+// //the unique invalid iterator
+// InEdgeIt(const BidirGraphWrapper<Graph>& _G, Node v) {
+// backward=false;
+// _G.graph->first(in, v);
+// while(_G.graph->valid(in) && !_G.enabled(*this)) { _G.graph->next(in); }
+// if (!_G.graph->valid(in)) {
+// backward=true;
+// _G.graph->first(out, v);
+// while(_G.graph->valid(out) && !_G.enabled(*this)) { _G.graph->next(out); }
+// }
+// }
+// operator Edge() const {
+// // Edge e;
+// // e.forward=this->forward;
+// // if (this->forward) e=out; else e=in;
+// // return e;
+// if (this->backward)
+// return Edge(out, this->backward);
+// else
+// return Edge(in, this->backward);
+// }
+// };
+
+// class EdgeIt {
+// friend class BidirGraphWrapper<Graph>;
+// protected:
+// typename Graph::EdgeIt e;
+// bool backward;
+// public:
+// EdgeIt() { }
+// EdgeIt(const Invalid& i) : e(i), backward(true) { }
+// EdgeIt(const BidirGraphWrapper<Graph>& _G) {
+// backward=false;
+// _G.graph->first(e);
+// while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
+// if (!_G.graph->valid(e)) {
+// backward=true;
+// _G.graph->first(e);
+// while (_G.graph->valid(e) && !_G.enabled(*this)) _G.graph->next(e);
+// }
+// }
+// operator Edge() const {
+// return Edge(e, this->backward);
+// }
+// };
+
+// using GraphWrapper<Graph>::first;
+// // NodeIt& first(NodeIt& i) const {
+// // i=NodeIt(*this); return i;
+// // }
+// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
+// i=OutEdgeIt(*this, p); return i;
+// }
+// // FIXME not tested
+// InEdgeIt& first(InEdgeIt& i, const Node& p) const {
+// i=InEdgeIt(*this, p); return i;
+// }
+// EdgeIt& first(EdgeIt& i) const {
+// i=EdgeIt(*this); return i;
+// }
+
+// using GraphWrapper<Graph>::next;
+// // NodeIt& next(NodeIt& n) const { GraphWrapper<Graph>::next(n); return n; }
+// OutEdgeIt& next(OutEdgeIt& e) const {
+// if (!e.backward) {
+// Node v=this->graph->aNode(e.out);
+// this->graph->next(e.out);
+// while(this->graph->valid(e.out) && !enabled(e)) {
+// this->graph->next(e.out); }
+// if (!this->graph->valid(e.out)) {
+// e.backward=true;
+// this->graph->first(e.in, v);
+// while(this->graph->valid(e.in) && !enabled(e)) {
+// this->graph->next(e.in); }
+// }
+// } else {
+// this->graph->next(e.in);
+// while(this->graph->valid(e.in) && !enabled(e)) {
+// this->graph->next(e.in); }
+// }
+// return e;
+// }
+// // FIXME Not tested
+// InEdgeIt& next(InEdgeIt& e) const {
+// if (!e.backward) {
+// Node v=this->graph->aNode(e.in);
+// this->graph->next(e.in);
+// while(this->graph->valid(e.in) && !enabled(e)) {
+// this->graph->next(e.in); }
+// if (!this->graph->valid(e.in)) {
+// e.backward=true;
+// this->graph->first(e.out, v);
+// while(this->graph->valid(e.out) && !enabled(e)) {
+// this->graph->next(e.out); }
+// }
+// } else {
+// this->graph->next(e.out);
+// while(this->graph->valid(e.out) && !enabled(e)) {
+// this->graph->next(e.out); }
+// }
+// return e;
+// }
+// EdgeIt& next(EdgeIt& e) const {
+// if (!e.backward) {
+// this->graph->next(e.e);
+// while(this->graph->valid(e.e) && !enabled(e)) {
+// this->graph->next(e.e); }
+// if (!this->graph->valid(e.e)) {
+// e.backward=true;
+// this->graph->first(e.e);
+// while(this->graph->valid(e.e) && !enabled(e)) {
+// this->graph->next(e.e); }
+// }
+// } else {
+// this->graph->next(e.e);
+// while(this->graph->valid(e.e) && !enabled(e)) {
+// this->graph->next(e.e); }
+// }
+// return e;
+// }
+
+// Node tail(Edge e) const {
+// return ((!e.backward) ? this->graph->tail(e) : this->graph->head(e)); }
+// Node head(Edge e) const {
+// return ((!e.backward) ? this->graph->head(e) : this->graph->tail(e)); }
+
+// Node aNode(OutEdgeIt e) const {
+// return ((!e.backward) ? this->graph->aNode(e.out) :
+// this->graph->aNode(e.in)); }
+// Node bNode(OutEdgeIt e) const {
+// return ((!e.backward) ? this->graph->bNode(e.out) :
+// this->graph->bNode(e.in)); }
+
+// Node aNode(InEdgeIt e) const {
+// return ((!e.backward) ? this->graph->aNode(e.in) :
+// this->graph->aNode(e.out)); }
+// Node bNode(InEdgeIt e) const {
+// return ((!e.backward) ? this->graph->bNode(e.in) :
+// this->graph->bNode(e.out)); }
+
+// /// Gives back the opposite edge.
+// Edge opposite(const Edge& e) const {
+// Edge f=e;
+// f.backward=!f.backward;
+// return f;
+// }
+
+// // int nodeNum() const { return graph->nodeNum(); }
+// //FIXME
+// void edgeNum() const { }
+// //int edgeNum() const { return graph->edgeNum(); }
+
+
+// // int id(Node v) const { return graph->id(v); }
+
+// bool valid(Node n) const { return GraphWrapper<Graph>::valid(n); }
+// bool valid(Edge e) const {
+// return this->graph->valid(e);
+// //return e.forward ? graph->valid(e.out) : graph->valid(e.in);
+// }
+
+// bool forward(const Edge& e) const { return !e.backward; }
+// bool backward(const Edge& e) const { return e.backward; }
+
+// // void augment(const Edge& e, Number a) const {
+// // if (!e.backward)
+// // // flow->set(e.out, flow->get(e.out)+a);
+// // flow->set(e, (*flow)[e]+a);
+// // else
+// // // flow->set(e.in, flow->get(e.in)-a);
+// // flow->set(e, (*flow)[e]-a);
+// // }
+
+// bool enabled(const Edge& e) const {
+// if (!e.backward)
+// // return (capacity->get(e.out)-flow->get(e.out));
+// //return ((*capacity)[e]-(*flow)[e]);
+// return true;
+// else
+// // return (flow->get(e.in));
+// //return ((*flow)[e]);
+// return true;
+// }
+
+// // Number enabled(typename Graph::OutEdgeIt out) const {
+// // // return (capacity->get(out)-flow->get(out));
+// // return ((*capacity)[out]-(*flow)[out]);
+// // }
+
+// // Number enabled(typename Graph::InEdgeIt in) const {
+// // // return (flow->get(in));
+// // return ((*flow)[in]);
+// // }
+
+// template <typename T>
+// class EdgeMap {
+// typename Graph::template EdgeMap<T> forward_map, backward_map;
+// public:
+// typedef T ValueType;
+// typedef Edge KeyType;
+// EdgeMap(const BidirGraphWrapper<Graph>& _G) : forward_map(*(_G.graph)), backward_map(*(_G.graph)) { }
+// EdgeMap(const BidirGraphWrapper<Graph>& _G, T a) : forward_map(*(_G.graph), a), backward_map(*(_G.graph), a) { }
+// void set(Edge e, T a) {
+// if (!e.backward)
+// forward_map.set(e/*.out*/, a);
+// else
+// backward_map.set(e/*.in*/, a);
+// }
+// T operator[](Edge e) const {
+// if (!e.backward)
+// return forward_map[e/*.out*/];
+// else
+// return backward_map[e/*.in*/];
+// }
+// void update() {
+// forward_map.update();
+// backward_map.update();
+// }
+// // T get(Edge e) const {
+// // if (e.out_or_in)
+// // return forward_map.get(e.out);
+// // else
+// // return backward_map.get(e.in);
+// // }
+// };
+// };
+
/// \brief A bidirected graph template.
///
/// A bidirected graph template.
@@ -941,6 +1364,7 @@
/// \ingroup graphs
template<typename Graph>
class BidirGraph : public BidirGraphWrapper<Graph> {
+ public:
typedef UndirGraphWrapper<Graph> Parent;
protected:
Graph gr;
@@ -951,12 +1375,161 @@
};
+
+ /// An experiment for ResGraphWrapper.
+ template<typename Graph, typename Number,
+ typename CapacityMap, typename FlowMap>
+ class ForwardFilter {
+ const Graph* graph;
+ const CapacityMap* capacity;
+ const FlowMap* flow;
+ public:
+ ForwardFilter(const Graph& _graph,
+ const CapacityMap& _capacity, const FlowMap& _flow) :
+ graph(&_graph), capacity(&_capacity), flow(&_flow) { }
+ bool operator[](const typename Graph::Edge& e) const {
+ return ((*flow)[e] < (*capacity)[e]);
+ }
+ };
+
+ /// An experiment for ResGraphWrapper.
+ template<typename Graph, typename Number,
+ typename CapacityMap, typename FlowMap>
+ class BackwardFilter {
+ const Graph* graph;
+ const CapacityMap* capacity;
+ const FlowMap* flow;
+ public:
+ BackwardFilter(const Graph& _graph,
+ const CapacityMap& _capacity, const FlowMap& _flow) :
+ graph(&_graph), capacity(&_capacity), flow(&_flow) { }
+ bool operator[](const typename Graph::Edge& e) const {
+ return (0 < (*flow)[e]);
+ }
+ };
+
+
+ /// An experiment for ResGraphWrapper.
+ template<typename Graph, typename Number,
+ typename CapacityMap, typename FlowMap>
+ class ExpResGraphWrapper :
+ public SubBidirGraphWrapper<
+ Graph,
+ ForwardFilter<Graph, Number, CapacityMap, FlowMap>,
+ BackwardFilter<Graph, Number, CapacityMap, FlowMap> > {
+ public:
+ typedef SubBidirGraphWrapper<
+ Graph,
+ ForwardFilter<Graph, Number, CapacityMap, FlowMap>,
+ BackwardFilter<Graph, Number, CapacityMap, FlowMap> > Parent;
+ protected:
+ const CapacityMap* capacity;
+ FlowMap* flow;
+ ForwardFilter<Graph, Number, CapacityMap, FlowMap> forward_filter;
+ BackwardFilter<Graph, Number, CapacityMap, FlowMap> backward_filter;
+ public:
+ ExpResGraphWrapper(Graph& _graph, const CapacityMap& _capacity,
+ FlowMap& _flow) :
+ Parent(), capacity(&_capacity), flow(&_flow),
+ forward_filter(_graph, _capacity, _flow),
+ backward_filter(_graph, _capacity, _flow) {
+ Parent::setGraph(_graph);
+ Parent::setForwardFilterMap(forward_filter);
+ Parent::setBackwardFilterMap(backward_filter);
+ }
+
+ // bool forward(const Parent::Edge& e) const { return Parent::forward(e); }
+ //bool backward(const Edge& e) const { return e.backward; }
+
+ void augment(const typename Parent::Edge& e, Number a) const {
+ if (Parent::forward(e))
+// flow->set(e.out, flow->get(e.out)+a);
+ flow->set(e, (*flow)[e]+a);
+ else
+ //flow->set(e.in, flow->get(e.in)-a);
+ flow->set(e, (*flow)[e]-a);
+ }
+
+ Number resCap(const typename Parent::Edge& e) const {
+ if (Parent::forward(e))
+// return (capacity->get(e.out)-flow->get(e.out));
+ return ((*capacity)[e]-(*flow)[e]);
+ else
+// return (flow->get(e.in));
+ return ((*flow)[e]);
+ }
+
+ };
+
+
+
+
+// /// An experiment for ResGraphWrapper.
+// template<typename Graph, typename Number,
+// typename CapacityMap, typename FlowMap>
+// class ExpResGraphWrapper :
+// public SubGraphWrapper< BidirGraphWrapper<Graph>,
+// ConstMap<typename BidirGraphWrapper<Graph>::Node,
+// bool>,
+// EdgeFilter< BidirGraphWrapper<Graph>,
+// CapacityMap, FlowMap> > {
+// public:
+// typedef SubGraphWrapper< BidirGraphWrapper<Graph>,
+// ConstMap<typename BidirGraphWrapper<Graph>::Node,
+// bool>,
+// EdgeFilter< BidirGraphWrapper<Graph>,
+// CapacityMap, FlowMap> > Parent;
+// protected:
+// const CapacityMap* capacity;
+// FlowMap* flow;
+// BidirGraphWrapper<Graph> bidir_graph;
+// ConstMap<typename BidirGraphWrapper<Graph>::Node, bool> node_filter;
+// EdgeFilter< BidirGraphWrapper<Graph>, CapacityMap, FlowMap> edge_filter;
+// public:
+// ExpResGraphWrapper(Graph& _graph, const CapacityMap& _capacity,
+// FlowMap& _flow) :
+// Parent(), capacity(&_capacity), flow(&_flow),
+// bidir_graph(_graph),
+// node_filter(true),
+// edge_filter(bidir_graph, *capacity, *flow) {
+// Parent::setGraph(bidir_graph);
+// Parent::setNodeFilterMap(node_filter);
+// Parent::setEdgeFilterMap(edge_filter);
+// }
+
+// // bool forward(const Parent::Edge& e) const { return Parent::forward(e); }
+// //bool backward(const Edge& e) const { return e.backward; }
+
+// void augment(const typename Parent::Edge& e, Number a) const {
+// if (Parent::forward(e))
+// // flow->set(e.out, flow->get(e.out)+a);
+// flow->set(e, (*flow)[e]+a);
+// else
+// // flow->set(e.in, flow->get(e.in)-a);
+// flow->set(e, (*flow)[e]-a);
+// }
+
+// Number resCap(const typename Parent::Edge& e) const {
+// if (Parent::forward(e))
+// // return (capacity->get(e.out)-flow->get(e.out));
+// return ((*capacity)[e]-(*flow)[e]);
+// else
+// // return (flow->get(e.in));
+// return ((*flow)[e]);
+// }
+
+// };
+
+
+
/// A wrapper for composing the residual graph for directed flow and circulation problems.
/// A wrapper for composing the residual graph for directed flow and circulation problems.
template<typename Graph, typename Number,
typename CapacityMap, typename FlowMap>
class ResGraphWrapper : public GraphWrapper<Graph> {
+ public:
+ typedef GraphWrapper<Graph> Parent;
protected:
const CapacityMap* capacity;
FlowMap* flow;
@@ -1283,6 +1856,8 @@
///\author Marton Makai
template<typename Graph, typename FirstOutEdgesMap>
class ErasingFirstGraphWrapper : public GraphWrapper<Graph> {
+ public:
+ typedef GraphWrapper<Graph> Parent;
protected:
FirstOutEdgesMap* first_out_edges;
public:
Modified: hugo/trunk/src/work/jacint/max_flow.h
==============================================================================
--- hugo/trunk/src/work/jacint/max_flow.h (original)
+++ hugo/trunk/src/work/jacint/max_flow.h Thu May 20 17:40:59 2004
@@ -63,7 +63,8 @@
const CapMap* capacity;
FlowMap* flow;
int n; //the number of nodes of G
- typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
+ // typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
+ typedef ExpResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
typedef typename ResGW::Edge ResGWEdge;
//typedef typename ResGW::template NodeMap<bool> ReachedMap;
@@ -139,7 +140,10 @@
TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) :
map(&_map), number_of_augmentations(&_number_of_augmentations) { }
void set(const Node& n, bool b) {
- map->set(n, *number_of_augmentations);
+ if (b)
+ map->set(n, *number_of_augmentations);
+ else
+ map->set(n, *number_of_augmentations-1);
}
bool operator[](const Node& n) const {
return (*map)[n]==*number_of_augmentations;
@@ -941,8 +945,8 @@
bool _augment=false;
if (status!=AFTER_AUGMENTING) {
- FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, -1);
- number_of_augmentations=0;
+ FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 3*n);
+ number_of_augmentations=3*n+1;
} else {
++number_of_augmentations;
}
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 Thu May 20 17:40:59 2004
@@ -20,7 +20,7 @@
/// Bfs searches for the nodes wich are not marked in
/// \c reached_map
- /// Reached have to work as read-write bool Node-map.
+ /// Reached have to be a read-write bool node-map.
/// \ingroup galgs
template <typename Graph, /*typename OutEdgeIt,*/
typename ReachedMap/*=typename Graph::NodeMap<bool>*/ >
@@ -36,13 +36,15 @@
bool own_reached_map;
public:
/// In that constructor \c _reached have to be a reference
- /// for a bool Node-map. The algorithm will search in a bfs order for
- /// the nodes which are \c false initially
+ /// for a bool bode-map. The algorithm will search for the
+ /// initially \c false nodes
+ /// in a bfs order.
BfsIterator(const Graph& _graph, ReachedMap& _reached) :
graph(&_graph), reached(_reached),
own_reached_map(false) { }
/// The same as above, but the map storing the reached nodes
/// is constructed dynamically to everywhere false.
+ /// \deprecated
BfsIterator(const Graph& _graph) :
graph(&_graph), reached(*(new ReachedMap(*graph /*, false*/))),
own_reached_map(true) { }
@@ -121,16 +123,18 @@
/// \pre The actual edge have to be valid.
Node bNode() const { return graph->bNode(actual_edge); }
/// Guess what?
+ /// \deprecated
const ReachedMap& getReachedMap() const { return reached; }
/// Guess what?
+ /// \deprecated
const std::queue<Node>& getBfsQueue() const { return bfs_queue; }
};
/// Bfs searches for the nodes wich are not marked in
/// \c reached_map
/// Reached have to work as a read-write bool Node-map,
- /// Pred is a write Edge Node-map and
- /// Dist is a read-write Node-map of integral value, have to be.
+ /// Pred is a write edge node-map and
+ /// Dist is a read-write node-map of integral value, have to be.
/// \ingroup galgs
template <typename Graph,
typename ReachedMap=typename Graph::template NodeMap<bool>,
@@ -179,8 +183,10 @@
return *this;
}
/// Guess what?
+ /// \deprecated
const PredMap& getPredMap() const { return pred; }
/// Guess what?
+ /// \deprecated
const DistMap& getDistMap() const { return dist; }
};
@@ -203,7 +209,7 @@
bool own_reached_map;
public:
/// In that constructor \c _reached have to be a reference
- /// for a bool Node-map. The algorithm will search in a dfs order for
+ /// for a bool node-map. The algorithm will search in a dfs order for
/// the nodes which are \c false initially
DfsIterator(const Graph& _graph, ReachedMap& _reached) :
graph(&_graph), reached(_reached),
@@ -265,15 +271,17 @@
/// \pre The actual edge have to be valid.
Node bNode() const { return graph->bNode(actual_edge); }
/// Guess what?
+ /// \deprecated
const ReachedMap& getReachedMap() const { return reached; }
/// Guess what?
+ /// \deprecated
const std::stack<OutEdgeIt>& getDfsStack() const { return dfs_stack; }
};
/// Dfs searches for the nodes wich are not marked in
/// \c reached_map
- /// Reached is a read-write bool Node-map,
- /// Pred is a write Node-map, have to be.
+ /// Reached is a read-write bool node-map,
+ /// Pred is a write node-map, have to be.
/// \ingroup galgs
template <typename Graph,
typename ReachedMap=typename Graph::template NodeMap<bool>,
@@ -318,6 +326,7 @@
return *this;
}
/// Guess what?
+ /// \deprecated
const PredMap& getPredMap() const { return pred; }
};
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 Thu May 20 17:40:59 2004
@@ -33,10 +33,11 @@
LedaGraphWrapper() : l_graph(0) { }
void setGraph(Graph& _l_graph) { l_graph=&_l_graph; }
public:
-
- //LedaGraphWrapper() { }
+
+ /// Constructor for wrapping LEDA graphs.
LedaGraphWrapper(Graph& _l_graph) : l_graph(&_l_graph) { }
- LedaGraphWrapper(const LedaGraphWrapper &G) : l_graph(G.l_graph) { }
+ /// Copy constructor
+ LedaGraphWrapper(const LedaGraphWrapper &g) : l_graph(g.l_graph) { }
template <typename T> class NodeMap;
template <typename T> class EdgeMap;
@@ -50,7 +51,7 @@
class OutEdgeIt;
class InEdgeIt;
- /// The base type of the node iterators.
+ /// Trivial node-iterator
class Node {
friend class LedaGraphWrapper<Graph>;
//friend class Edge;
@@ -65,7 +66,7 @@
public:
/// @warning The default constructor sets the iterator
/// to an undefined value.
- Node() {} //FIXME
+ Node() { } //FIXME
/// Initialize the iterator to be invalid
Node(Invalid) : l_n(0) { }
//Node(const Node &) {}
@@ -79,15 +80,15 @@
public:
/// @warning The default constructor sets the iterator
/// to an undefined value.
- NodeIt() {} //FIXME
+ NodeIt() { } //FIXME
/// Initialize the iterator to be invalid
- NodeIt(Invalid i) : Node(i) {}
+ NodeIt(Invalid i) : Node(i) { }
/// Sets the iterator to the first node of \c G.
NodeIt(const LedaGraphWrapper &G) : Node(G.l_graph->first_node()) { }
//NodeIt(const NodeIt &) {} //FIXME
};
- /// The base type of the edge iterators.
+ /// Trivial edge-iterator.
class Edge {
friend class LedaGraphWrapper;
protected:
@@ -98,24 +99,23 @@
public:
/// @warning The default constructor sets the iterator
/// to an undefined value.
- Edge() {} //FIXME
+ Edge() { } //FIXME
/// Initialize the iterator to be invalid
- Edge(Invalid) : l_e(0) {}
+ Edge(Invalid) : l_e(0) { }
//Edge(const Edge &) {}
bool operator==(Edge e) const { return l_e==e.l_e; } //FIXME
bool operator!=(Edge e) const { return l_e!=e.l_e; } //FIXME
operator leda_edge () { return l_e; }
};
- /// This iterator goes trought the outgoing edges of a certain graph.
-
+ /// This iterator goes trought the outgoing edges of a certain node.
class OutEdgeIt : public Edge {
public:
/// @warning The default constructor sets the iterator
/// to an undefined value.
- OutEdgeIt() {}
+ OutEdgeIt() { }
/// Initialize the iterator to be invalid
- OutEdgeIt(Invalid i) : Edge(i) {}
+ OutEdgeIt(Invalid i) : Edge(i) { }
/// This constructor sets the iterator to first outgoing edge.
/// This constructor set the iterator to the first outgoing edge of
@@ -125,29 +125,32 @@
OutEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G.l_graph->first_adj_edge(n.l_n)) { }
};
+ /// This iterator goes trought the incoming edges of a certain node.
class InEdgeIt : public Edge {
public:
/// @warning The default constructor sets the iterator
/// to an undefined value.
- InEdgeIt() {}
+ InEdgeIt() { }
/// Initialize the iterator to be invalid
- InEdgeIt(Invalid i) : Edge(i) {}
+ InEdgeIt(Invalid i) : Edge(i) { }
InEdgeIt(const LedaGraphWrapper & G, Node n) : Edge(G.l_graph->first_in_edge(n.l_n)) { }
};
// class SymEdgeIt : public Edge {};
+
+ /// This iterator goes trought the edges of the graph.
class EdgeIt : public Edge {
public:
/// @warning The default constructor sets the iterator
/// to an undefined value.
- EdgeIt() {}
+ EdgeIt() { }
/// Initialize the iterator to be invalid
- EdgeIt(Invalid i) : Edge(i) {}
+ EdgeIt(Invalid i) : Edge(i) { }
EdgeIt(const LedaGraphWrapper & G) : Edge(G.l_graph->first_edge()) { }
};
/// First node of the graph.
-
+ ///
/// \post \c i and the return value will be the first node.
///
NodeIt &first(NodeIt &i) const { i=NodeIt(*this); return i; }
@@ -163,7 +166,7 @@
return i;
}
// SymEdgeIt &first(SymEdgeIt &, Node) const { return i;}
- /// The first edge of the Graph.
+ /// The first edge of the graph.
EdgeIt &first(EdgeIt &i) const {
i=EdgeIt(*this);
return i; }
@@ -253,7 +256,7 @@
int nodeNum() const { return l_graph->number_of_nodes(); }
int edgeNum() const { return l_graph->number_of_edges(); }
- ///Read/write map from the nodes to type \c T.
+ /// Read/write map from the nodes to type \c T.
template<typename T> class NodeMap
{
leda_node_map<T> leda_stuff;
@@ -273,7 +276,7 @@
//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.
+ /// Read/write map from the edges to type \c T.
template<typename T> class EdgeMap
{
leda_edge_map<T> leda_stuff;
@@ -294,20 +297,21 @@
};
- ///Read/write map from the nodes to type \c T.
+ /// This class is to wrap existing
+ /// LEDA node-maps to HUGO ones.
template<typename T> class NodeMapWrapper
{
- leda_node_map<T>* leda_stuff;
+ leda_node_array<T>* leda_stuff;
public:
typedef T ValueType;
typedef Node KeyType;
- NodeMapWrapper(leda_node_map<T>& _leda_stuff) :
+ NodeMapWrapper(leda_node_array<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 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]; }
@@ -315,20 +319,21 @@
//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.
+ /// This class is to wrap existing
+ /// LEDA edge-maps to HUGO ones.
template<typename T> class EdgeMapWrapper
{
- leda_edge_map<T>* leda_stuff;
+ leda_edge_array<T>* leda_stuff;
public:
typedef T ValueType;
typedef Edge KeyType;
- EdgeMapWrapper(leda_edge_map<T>& _leda_stuff) :
+ EdgeMapWrapper(leda_edge_array<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 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]; }
@@ -336,6 +341,26 @@
//void update(T a) { leda_stuff.init(leda_stuff.get_graph()/**(G.l_graph)*/, a); } //FIXME: Is it necessary
};
+ /// This class is used for access node-data of
+ /// LEDA parametrized graphs.
+ template<typename T>
+ class NodeDataMap : public NodeMapWrapper<T>
+ {
+ public:
+ NodeDataMap(LedaGraphWrapper<Graph>& LGW) :
+ NodeMapWrapper<T>(*(LGW._g_graph).node_data()) { }
+ };
+
+ /// This class is used for access edge-data of
+ /// LEDA parametrized graphs.
+ template<typename T>
+ class EdgeDataMap : public EdgeMapWrapper<T>
+ {
+ public:
+ EdgeDataMap(LedaGraphWrapper<Graph>& LGW) :
+ EdgeMapWrapper<T>(*(LGW._g_graph).edge_data()) { }
+ };
+
};
More information about the Lemon-commits
mailing list