[Lemon-commits] [lemon_svn] marci: r1382 - in hugo/trunk/src: lemon test
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:44:59 CET 2006
Author: marci
Date: Mon Nov 15 13:25:39 2004
New Revision: 1382
Modified:
hugo/trunk/src/lemon/graph_wrapper.h
hugo/trunk/src/test/graph_wrapper_test.cc
Log:
GraphWrapper changes for factory
Modified: hugo/trunk/src/lemon/graph_wrapper.h
==============================================================================
--- hugo/trunk/src/lemon/graph_wrapper.h (original)
+++ hugo/trunk/src/lemon/graph_wrapper.h Mon Nov 15 13:25:39 2004
@@ -27,6 +27,7 @@
#include <lemon/invalid.h>
#include <lemon/maps.h>
+#include <lemon/iterable_graph_extender.h>
#include <lemon/map_defines.h>
#include <iostream>
@@ -123,7 +124,7 @@
public:
GraphWrapperBase(Graph& _graph) : graph(&_graph) { }
- GraphWrapperBase(const GraphWrapperBase<_Graph>& gw) : graph(gw.graph) { }
+// GraphWrapperBase(const GraphWrapperBase<_Graph>& gw) : graph(gw.graph) { }
typedef typename Graph::Node Node;
typedef typename Graph::Edge Edge;
@@ -299,7 +300,118 @@
};
+
+ template <typename _Graph, typename NodeFilterMap, typename EdgeFilterMap>
+ class SubGraphWrapperBase : public GraphWrapperBase<_Graph> {
+ public:
+ typedef _Graph Graph;
+ typedef GraphWrapperBase<_Graph> Parent;
+ protected:
+ NodeFilterMap* node_filter_map;
+ EdgeFilterMap* edge_filter_map;
+ SubGraphWrapperBase() : Parent(),
+ node_filter_map(0), edge_filter_map(0) { }
+
+ void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
+ node_filter_map=&_node_filter_map;
+ }
+ void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
+ edge_filter_map=&_edge_filter_map;
+ }
+
+ public:
+// SubGraphWrapperBase(Graph& _graph,
+// NodeFilterMap& _node_filter_map,
+// EdgeFilterMap& _edge_filter_map) :
+// Parent(&_graph),
+// node_filter_map(&node_filter_map),
+// edge_filter_map(&edge_filter_map) { }
+ typedef typename Parent::Node Node;
+ typedef typename Parent::Edge Edge;
+
+ void first(Node& i) const {
+ Parent::first(i);
+ while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
+ }
+ void first(Edge& i) const {
+ Parent::first(i);
+ while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i);
+ }
+ void firstIn(Edge& i, const Node& n) const {
+ Parent::firstIn(i, n);
+ while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i);
+ }
+ void firstOut(Edge& i, const Node& n) const {
+ Parent::firstOut(i, n);
+ while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i);
+ }
+
+ void next(Node& i) const {
+ Parent::next(i);
+ while (i!=INVALID && !(*node_filter_map)[i]) Parent::next(i);
+ }
+ void next(Edge& i) const {
+ Parent::next(i);
+ while (i!=INVALID && !(*edge_filter_map)[i]) Parent::next(i);
+ }
+ void nextIn(Edge& i) const {
+ Parent::nextIn(i);
+ while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextIn(i);
+ }
+ void nextOut(Edge& i) const {
+ Parent::nextOut(i);
+ while (i!=INVALID && !(*edge_filter_map)[i]) Parent::nextOut(i);
+ }
+
+ /// This function hides \c n in the graph, i.e. the iteration
+ /// jumps over it. This is done by simply setting the value of \c n
+ /// to be false in the corresponding node-map.
+ void hide(const Node& n) const { node_filter_map->set(n, false); }
+
+ /// This function hides \c e in the graph, i.e. the iteration
+ /// jumps over it. This is done by simply setting the value of \c e
+ /// to be false in the corresponding edge-map.
+ void hide(const Edge& e) const { edge_filter_map->set(e, false); }
+
+ /// The value of \c n is set to be true in the node-map which stores
+ /// hide information. If \c n was hidden previuosly, then it is shown
+ /// again
+ void unHide(const Node& n) const { node_filter_map->set(n, true); }
+
+ /// The value of \c e is set to be true in the edge-map which stores
+ /// hide information. If \c e was hidden previuosly, then it is shown
+ /// again
+ void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
+
+ /// Returns true if \c n is hidden.
+ bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
+
+ /// Returns true if \c n is hidden.
+ bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
+
+ /// \warning This is a linear time operation and works only if s
+ /// \c Graph::NodeIt is defined.
+ /// \todo assign tags.
+ int nodeNum() const {
+ int i=0;
+ Node n;
+ for (first(n); n!=INVALID; next(n)) ++i;
+ return i;
+ }
+
+ /// \warning This is a linear time operation and works only if
+ /// \c Graph::EdgeIt is defined.
+ /// \todo assign tags.
+ int edgeNum() const {
+ int i=0;
+ Edge e;
+ for (first(e); e!=INVALID; next(e)) ++i;
+ return i;
+ }
+
+
+ };
/*! \brief A graph wrapper for hiding nodes and edges from a graph.
@@ -347,195 +459,215 @@
\author Marton Makai
*/
- template<typename Graph, typename NodeFilterMap,
+ template<typename _Graph, typename NodeFilterMap,
typename EdgeFilterMap>
- class SubGraphWrapper : public GraphWrapper<Graph> {
+ class SubGraphWrapper :
+ public IterableGraphExtender<
+ SubGraphWrapperBase<_Graph, NodeFilterMap, EdgeFilterMap> > {
public:
- typedef GraphWrapper<Graph> Parent;
+ typedef _Graph Graph;
+ typedef IterableGraphExtender<
+ SubGraphWrapperBase<_Graph, NodeFilterMap, EdgeFilterMap> > Parent;
protected:
- NodeFilterMap* node_filter_map;
- EdgeFilterMap* edge_filter_map;
-
- SubGraphWrapper() : GraphWrapper<Graph>(),
- node_filter_map(0), edge_filter_map(0) { }
- void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
- node_filter_map=&_node_filter_map;
- }
- void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
- edge_filter_map=&_edge_filter_map;
- }
-
+ SubGraphWrapper() { }
public:
- SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map,
- EdgeFilterMap& _edge_filter_map) :
- GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map),
- edge_filter_map(&_edge_filter_map) { }
-
- typedef typename GraphWrapper<Graph>::Node Node;
- class NodeIt : public Node {
- const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
- friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
- public:
- NodeIt() { }
- NodeIt(Invalid i) : Node(i) { }
- NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) :
- Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) {
- while (*static_cast<Node*>(this)!=INVALID &&
- !(*(gw->node_filter_map))[*this])
- *(static_cast<Node*>(this))=
- ++(typename Graph::NodeIt(*(gw->graph), *this));
- }
- NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
- const Node& n) :
- Node(n), gw(&_gw) { }
- NodeIt& operator++() {
- *(static_cast<Node*>(this))=
- ++(typename Graph::NodeIt(*(gw->graph), *this));
- while (*static_cast<Node*>(this)!=INVALID &&
- !(*(gw->node_filter_map))[*this])
- *(static_cast<Node*>(this))=
- ++(typename Graph::NodeIt(*(gw->graph), *this));
- return *this;
- }
- };
- typedef typename GraphWrapper<Graph>::Edge Edge;
- class OutEdgeIt : public Edge {
- const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
- friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
- public:
- OutEdgeIt() { }
- OutEdgeIt(Invalid i) : Edge(i) { }
- OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) :
- Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) {
- while (*static_cast<Edge*>(this)!=INVALID &&
- !(*(gw->edge_filter_map))[*this])
- *(static_cast<Edge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- }
- OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
- const Edge& e) :
- Edge(e), gw(&_gw) { }
- OutEdgeIt& operator++() {
- *(static_cast<Edge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- while (*static_cast<Edge*>(this)!=INVALID &&
- !(*(gw->edge_filter_map))[*this])
- *(static_cast<Edge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- return *this;
- }
- };
- class InEdgeIt : public Edge {
- const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
- friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
- public:
- InEdgeIt() { }
- // InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { }
- InEdgeIt(Invalid i) : Edge(i) { }
- InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) :
- Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) {
- while (*static_cast<Edge*>(this)!=INVALID &&
- !(*(gw->edge_filter_map))[*this])
- *(static_cast<Edge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- }
- InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
- const Edge& e) :
- Edge(e), gw(&_gw) { }
- InEdgeIt& operator++() {
- *(static_cast<Edge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- while (*static_cast<Edge*>(this)!=INVALID &&
- !(*(gw->edge_filter_map))[*this])
- *(static_cast<Edge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- return *this;
- }
- };
- class EdgeIt : public Edge {
- const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
- friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
- public:
- EdgeIt() { }
- EdgeIt(Invalid i) : Edge(i) { }
- EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) :
- Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) {
- while (*static_cast<Edge*>(this)!=INVALID &&
- !(*(gw->edge_filter_map))[*this])
- *(static_cast<Edge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- }
- EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
- const Edge& e) :
- Edge(e), gw(&_gw) { }
- EdgeIt& operator++() {
- *(static_cast<Edge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- while (*static_cast<Edge*>(this)!=INVALID &&
- !(*(gw->edge_filter_map))[*this])
- *(static_cast<Edge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- return *this;
- }
- };
-
- NodeIt& first(NodeIt& i) const {
- i=NodeIt(*this); return i;
- }
- OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
- i=OutEdgeIt(*this, p); return i;
- }
- InEdgeIt& first(InEdgeIt& i, const Node& p) const {
- i=InEdgeIt(*this, p); return i;
+ SubGraphWrapper(_Graph& _graph, NodeFilterMap& _node_filter_map,
+ EdgeFilterMap& _edge_filter_map) {
+ setGraph(_graph);
+ setNodeFilterMap(_node_filter_map);
+ setEdgeFilterMap(_edge_filter_map);
}
- EdgeIt& first(EdgeIt& i) const {
- i=EdgeIt(*this); return i;
- }
-
- /// This function hides \c n in the graph, i.e. the iteration
- /// jumps over it. This is done by simply setting the value of \c n
- /// to be false in the corresponding node-map.
- void hide(const Node& n) const { node_filter_map->set(n, false); }
-
- /// This function hides \c e in the graph, i.e. the iteration
- /// jumps over it. This is done by simply setting the value of \c e
- /// to be false in the corresponding edge-map.
- void hide(const Edge& e) const { edge_filter_map->set(e, false); }
-
- /// The value of \c n is set to be true in the node-map which stores
- /// hide information. If \c n was hidden previuosly, then it is shown
- /// again
- void unHide(const Node& n) const { node_filter_map->set(n, true); }
-
- /// The value of \c e is set to be true in the edge-map which stores
- /// hide information. If \c e was hidden previuosly, then it is shown
- /// again
- void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
-
- /// Returns true if \c n is hidden.
- bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
+ };
- /// Returns true if \c n is hidden.
- bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
+// 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;
+
+// SubGraphWrapper() : GraphWrapper<Graph>(),
+// node_filter_map(0), edge_filter_map(0) { }
+// void setNodeFilterMap(NodeFilterMap& _node_filter_map) {
+// node_filter_map=&_node_filter_map;
+// }
+// void setEdgeFilterMap(EdgeFilterMap& _edge_filter_map) {
+// edge_filter_map=&_edge_filter_map;
+// }
+
+// public:
+// SubGraphWrapper(Graph& _graph, NodeFilterMap& _node_filter_map,
+// EdgeFilterMap& _edge_filter_map) :
+// GraphWrapper<Graph>(_graph), node_filter_map(&_node_filter_map),
+// edge_filter_map(&_edge_filter_map) { }
+
+// typedef typename GraphWrapper<Graph>::Node Node;
+// class NodeIt : public Node {
+// const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
+// friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
+// public:
+// NodeIt() { }
+// NodeIt(Invalid i) : Node(i) { }
+// NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) :
+// Node(typename Graph::NodeIt(*(_gw.graph))), gw(&_gw) {
+// while (*static_cast<Node*>(this)!=INVALID &&
+// !(*(gw->node_filter_map))[*this])
+// *(static_cast<Node*>(this))=
+// ++(typename Graph::NodeIt(*(gw->graph), *this));
+// }
+// NodeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
+// const Node& n) :
+// Node(n), gw(&_gw) { }
+// NodeIt& operator++() {
+// *(static_cast<Node*>(this))=
+// ++(typename Graph::NodeIt(*(gw->graph), *this));
+// while (*static_cast<Node*>(this)!=INVALID &&
+// !(*(gw->node_filter_map))[*this])
+// *(static_cast<Node*>(this))=
+// ++(typename Graph::NodeIt(*(gw->graph), *this));
+// return *this;
+// }
+// };
+// typedef typename GraphWrapper<Graph>::Edge Edge;
+// class OutEdgeIt : public Edge {
+// const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
+// friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
+// public:
+// OutEdgeIt() { }
+// OutEdgeIt(Invalid i) : Edge(i) { }
+// OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) :
+// Edge(typename Graph::OutEdgeIt(*(_gw.graph), n)), gw(&_gw) {
+// while (*static_cast<Edge*>(this)!=INVALID &&
+// !(*(gw->edge_filter_map))[*this])
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// }
+// OutEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
+// const Edge& e) :
+// Edge(e), gw(&_gw) { }
+// OutEdgeIt& operator++() {
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// while (*static_cast<Edge*>(this)!=INVALID &&
+// !(*(gw->edge_filter_map))[*this])
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// return *this;
+// }
+// };
+// class InEdgeIt : public Edge {
+// const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
+// friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
+// public:
+// InEdgeIt() { }
+// // InEdgeIt(const InEdgeIt& e) : Edge(e), gw(e.gw) { }
+// InEdgeIt(Invalid i) : Edge(i) { }
+// InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw, const Node& n) :
+// Edge(typename Graph::InEdgeIt(*(_gw.graph), n)), gw(&_gw) {
+// while (*static_cast<Edge*>(this)!=INVALID &&
+// !(*(gw->edge_filter_map))[*this])
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// }
+// InEdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
+// const Edge& e) :
+// Edge(e), gw(&_gw) { }
+// InEdgeIt& operator++() {
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// while (*static_cast<Edge*>(this)!=INVALID &&
+// !(*(gw->edge_filter_map))[*this])
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// return *this;
+// }
+// };
+// class EdgeIt : public Edge {
+// const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>* gw;
+// friend class SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>;
+// public:
+// EdgeIt() { }
+// EdgeIt(Invalid i) : Edge(i) { }
+// EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw) :
+// Edge(typename Graph::EdgeIt(*(_gw.graph))), gw(&_gw) {
+// while (*static_cast<Edge*>(this)!=INVALID &&
+// !(*(gw->edge_filter_map))[*this])
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// }
+// EdgeIt(const SubGraphWrapper<Graph, NodeFilterMap, EdgeFilterMap>& _gw,
+// const Edge& e) :
+// Edge(e), gw(&_gw) { }
+// EdgeIt& operator++() {
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// while (*static_cast<Edge*>(this)!=INVALID &&
+// !(*(gw->edge_filter_map))[*this])
+// *(static_cast<Edge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// return *this;
+// }
+// };
- /// \warning This is a linear time operation and works only if
- /// \c Graph::NodeIt is defined.
- int nodeNum() const {
- int i=0;
- for (NodeIt n(*this); n!=INVALID; ++n) ++i;
- return i;
- }
+// NodeIt& first(NodeIt& i) const {
+// i=NodeIt(*this); return i;
+// }
+// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
+// i=OutEdgeIt(*this, p); return i;
+// }
+// InEdgeIt& first(InEdgeIt& i, const Node& p) const {
+// i=InEdgeIt(*this, p); return i;
+// }
+// EdgeIt& first(EdgeIt& i) const {
+// i=EdgeIt(*this); return i;
+// }
+
+// /// This function hides \c n in the graph, i.e. the iteration
+// /// jumps over it. This is done by simply setting the value of \c n
+// /// to be false in the corresponding node-map.
+// void hide(const Node& n) const { node_filter_map->set(n, false); }
+
+// /// This function hides \c e in the graph, i.e. the iteration
+// /// jumps over it. This is done by simply setting the value of \c e
+// /// to be false in the corresponding edge-map.
+// void hide(const Edge& e) const { edge_filter_map->set(e, false); }
+
+// /// The value of \c n is set to be true in the node-map which stores
+// /// hide information. If \c n was hidden previuosly, then it is shown
+// /// again
+// void unHide(const Node& n) const { node_filter_map->set(n, true); }
+
+// /// The value of \c e is set to be true in the edge-map which stores
+// /// hide information. If \c e was hidden previuosly, then it is shown
+// /// again
+// void unHide(const Edge& e) const { edge_filter_map->set(e, true); }
+
+// /// Returns true if \c n is hidden.
+// bool hidden(const Node& n) const { return !(*node_filter_map)[n]; }
+
+// /// Returns true if \c n is hidden.
+// bool hidden(const Edge& e) const { return !(*edge_filter_map)[e]; }
+
+// /// \warning This is a linear time operation and works only if
+// /// \c Graph::NodeIt is defined.
+// int nodeNum() const {
+// int i=0;
+// for (NodeIt n(*this); n!=INVALID; ++n) ++i;
+// return i;
+// }
- /// \warning This is a linear time operation and works only if
- /// \c Graph::EdgeIt is defined.
- int edgeNum() const {
- int i=0;
- for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
- return i;
- }
+// /// \warning This is a linear time operation and works only if
+// /// \c Graph::EdgeIt is defined.
+// int edgeNum() const {
+// int i=0;
+// for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
+// return i;
+// }
- // KEEP_MAPS(Parent, SubGraphWrapper);
- };
+// // KEEP_MAPS(Parent, SubGraphWrapper);
+// };
/*! \brief A wrapper for hiding nodes from a graph.
@@ -799,55 +931,19 @@
// KEEP_MAPS(Parent, UndirGraph);
};
-
-
- ///\brief A wrapper for composing a subgraph of a
- /// bidirected graph made from a directed one.
- ///
- /// A wrapper for composing a subgraph of a
- /// bidirected graph made from a directed one.
- ///
- ///\warning Graph wrappers are in even more experimental state than the other
- ///parts of the lib. Use them at you own risk.
- ///
- /// Let \f$G=(V, A)\f$ be a directed graph and for each directed edge
- /// \f$e\in A\f$, let \f$\bar e\f$ denote the edge obtained by
- /// reversing its orientation. We are given moreover two bool valued
- /// maps on the edge-set,
- /// \f$forward\_filter\f$, and \f$backward\_filter\f$.
- /// SubBidirGraphWrapper implements the graph structure with node-set
- /// \f$V\f$ and edge-set
- /// \f$\{e : e\in A \mbox{ and } forward\_filter(e) \mbox{ is true}\}+\{\bar e : e\in A \mbox{ and } backward\_filter(e) \mbox{ is true}\}\f$.
- /// The purpose of writing + instead of union is because parallel
- /// edges can arise. (Similarly, antiparallel edges also can arise).
- /// In other words, a subgraph of the bidirected graph obtained, which
- /// is given by orienting the edges of the original graph in both directions.
- /// As the oppositely directed edges are logically different,
- /// the maps are able to attach different values for them.
- ///
- /// An example for such a construction is \c RevGraphWrapper where the
- /// forward_filter is everywhere false and the backward_filter is
- /// everywhere true. We note that for sake of efficiency,
- /// \c RevGraphWrapper is implemented in a different way.
- /// But BidirGraphWrapper is obtained from
- /// SubBidirGraphWrapper by considering everywhere true
- /// valued maps both for forward_filter and backward_filter.
- /// Finally, one of the most important applications of SubBidirGraphWrapper
- /// is ResGraphWrapper, which stands for the residual graph in directed
- /// flow and circulation problems.
- /// As wrappers usually, the SubBidirGraphWrapper implements the
- /// above mentioned graph structure without its physical storage,
- /// that is the whole stuff is stored in constant memory.
- template<typename Graph,
- typename ForwardFilterMap, typename BackwardFilterMap>
- class SubBidirGraphWrapper : public GraphWrapper<Graph> {
+
+ template <typename _Graph,
+ typename ForwardFilterMap, typename BackwardFilterMap>
+ class SubBidirGraphWrapperBase : public GraphWrapperBase<_Graph> {
public:
- typedef GraphWrapper<Graph> Parent;
+ typedef _Graph Graph;
+ typedef GraphWrapperBase<_Graph> Parent;
protected:
ForwardFilterMap* forward_filter;
BackwardFilterMap* backward_filter;
+ SubBidirGraphWrapperBase() : Parent(),
+ forward_filter(0), backward_filter(0) { }
- SubBidirGraphWrapper() : GraphWrapper<Graph>() { }
void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
forward_filter=&_forward_filter;
}
@@ -856,34 +952,23 @@
}
public:
-
- SubBidirGraphWrapper(Graph& _graph, ForwardFilterMap& _forward_filter,
- BackwardFilterMap& _backward_filter) :
- GraphWrapper<Graph>(_graph),
- forward_filter(&_forward_filter), backward_filter(&_backward_filter) { }
- SubBidirGraphWrapper(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& gw) :
- Parent(gw),
- forward_filter(gw.forward_filter),
- backward_filter(gw.backward_filter) { }
-
- class Edge;
- class OutEdgeIt;
- friend class Edge;
- friend class OutEdgeIt;
-
- template<typename T> class EdgeMap;
-
- typedef typename GraphWrapper<Graph>::Node Node;
-
- typedef typename Graph::Edge GraphEdge;
- /// SubBidirGraphWrapper<..., ..., ...>::Edge is inherited from
- /// Graph::Edge. It contains an extra bool flag which is true
+// SubGraphWrapperBase(Graph& _graph,
+// NodeFilterMap& _node_filter_map,
+// EdgeFilterMap& _edge_filter_map) :
+// Parent(&_graph),
+// node_filter_map(&node_filter_map),
+// edge_filter_map(&edge_filter_map) { }
+
+ typedef typename Parent::Node Node;
+ typedef typename _Graph::Edge GraphEdge;
+ template <typename T> class EdgeMap;
+ /// SubBidirGraphWrapperBase<..., ..., ...>::Edge is inherited from
+ /// _Graph::Edge. It contains an extra bool flag which is true
/// if and only if the
/// edge is the backward version of the original edge.
- class Edge : public Graph::Edge {
- friend class SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>;
+ class Edge : public _Graph::Edge {
+ friend class SubBidirGraphWrapperBase<
+ Graph, ForwardFilterMap, BackwardFilterMap>;
template<typename T> friend class EdgeMap;
protected:
bool backward; //true, iff backward
@@ -892,202 +977,123 @@
/// \todo =false is needed, or causes problems?
/// If \c _backward is false, then we get an edge corresponding to the
/// original one, otherwise its oppositely directed pair is obtained.
- Edge(const typename Graph::Edge& e, bool _backward/*=false*/) :
- Graph::Edge(e), backward(_backward) { }
- Edge(Invalid i) : Graph::Edge(i), backward(true) { }
+ Edge(const typename _Graph::Edge& e, bool _backward/*=false*/) :
+ _Graph::Edge(e), backward(_backward) { }
+ Edge(Invalid i) : _Graph::Edge(i), backward(true) { }
bool operator==(const Edge& v) const {
return (this->backward==v.backward &&
- static_cast<typename Graph::Edge>(*this)==
- static_cast<typename Graph::Edge>(v));
+ static_cast<typename _Graph::Edge>(*this)==
+ static_cast<typename _Graph::Edge>(v));
}
bool operator!=(const Edge& v) const {
return (this->backward!=v.backward ||
- static_cast<typename Graph::Edge>(*this)!=
- static_cast<typename Graph::Edge>(v));
+ static_cast<typename _Graph::Edge>(*this)!=
+ static_cast<typename _Graph::Edge>(v));
}
};
- class OutEdgeIt : public Edge {
- friend class SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>;
- protected:
- const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>* gw;
- public:
- OutEdgeIt() { }
- OutEdgeIt(Invalid i) : Edge(i) { }
- OutEdgeIt(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) :
- Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), false), gw(&_gw) {
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->forward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- if (*static_cast<GraphEdge*>(this)==INVALID) {
- *static_cast<Edge*>(this)=
- Edge(typename Graph::InEdgeIt(*(_gw.graph), n), true);
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- }
+ void first(Node& i) const {
+ Parent::first(i);
+ }
+
+ void first(Edge& i) const {
+ Parent::first(i);
+ i.backward=false;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*forward_filter)[i]) Parent::next(i);
+ if (*static_cast<GraphEdge*>(&i)==INVALID) {
+ Parent::first(i);
+ i.backward=true;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::next(i);
}
- OutEdgeIt(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) :
- Edge(e), gw(&_gw) { }
- OutEdgeIt& operator++() {
- if (!this->backward) {
- Node n=gw->source(*this);
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->forward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- if (*static_cast<GraphEdge*>(this)==INVALID) {
- *static_cast<Edge*>(this)=
- Edge(typename Graph::InEdgeIt(*(gw->graph), n), true);
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- }
- } else {
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- }
- return *this;
+ }
+
+ void firstIn(Edge& i, const Node& n) const {
+ Parent::firstIn(i, n);
+ i.backward=false;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*forward_filter)[i]) Parent::nextOut(i);
+ if (*static_cast<GraphEdge*>(&i)==INVALID) {
+ Parent::firstOut(i, n);
+ i.backward=true;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::nextOut(i);
}
- };
+ }
- class InEdgeIt : public Edge {
- friend class SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>;
- protected:
- const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>* gw;
- public:
- InEdgeIt() { }
- InEdgeIt(Invalid i) : Edge(i) { }
- InEdgeIt(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) :
- Edge(typename Graph::InEdgeIt(*(_gw.graph), n), false), gw(&_gw) {
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->forward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- if (*static_cast<GraphEdge*>(this)==INVALID) {
- *static_cast<Edge*>(this)=
- Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), true);
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- }
+ void firstOut(Edge& i, const Node& n) const {
+ Parent::firstOut(i, n);
+ i.backward=false;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*forward_filter)[i]) Parent::nextOut(i);
+ if (*static_cast<GraphEdge*>(&i)==INVALID) {
+ Parent::firstIn(i, n);
+ i.backward=true;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::nextIn(i);
}
- InEdgeIt(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) :
- Edge(e), gw(&_gw) { }
- InEdgeIt& operator++() {
- if (!this->backward) {
- Node n=gw->source(*this);
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->forward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::InEdgeIt(*(gw->graph), *this));
- if (*static_cast<GraphEdge*>(this)==INVALID) {
- *static_cast<Edge*>(this)=
- Edge(typename Graph::OutEdgeIt(*(gw->graph), n), true);
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- }
- } else {
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+ }
+
+ void next(Node& i) const {
+ Parent::next(i);
+ }
+
+ void next(Edge& i) const {
+ if (!(i.backward)) {
+ Parent::next(i);
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*forward_filter)[i]) Parent::next(i);
+ if (*static_cast<GraphEdge*>(&i)==INVALID) {
+ Parent::first(i);
+ i.backward=true;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::next(i);
}
- return *this;
+ } else {
+ Parent::next(i);
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::next(i);
}
- };
+ }
- class EdgeIt : public Edge {
- friend class SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>;
- protected:
- const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>* gw;
- public:
- EdgeIt() { }
- EdgeIt(Invalid i) : Edge(i) { }
- EdgeIt(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& _gw) :
- Edge(typename Graph::EdgeIt(*(_gw.graph)), false), gw(&_gw) {
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->forward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- if (*static_cast<GraphEdge*>(this)==INVALID) {
- *static_cast<Edge*>(this)=
- Edge(typename Graph::EdgeIt(*(_gw.graph)), true);
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
+ void nextIn(Edge& i) const {
+ if (!(i.backward)) {
+ Node n=Parent::target(i);
+ Parent::nextIn(i);
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*forward_filter)[i]) Parent::nextIn(i);
+ if (*static_cast<GraphEdge*>(&i)==INVALID) {
+ Parent::firstOut(i, n);
+ i.backward=true;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::nextOut(i);
}
+ } else {
+ Parent::nextOut(i);
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::nextOut(i);
}
- EdgeIt(const SubBidirGraphWrapper<Graph,
- ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) :
- Edge(e), gw(&_gw) { }
- EdgeIt& operator++() {
- if (!this->backward) {
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->forward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- if (*static_cast<GraphEdge*>(this)==INVALID) {
- *static_cast<Edge*>(this)=
- Edge(typename Graph::EdgeIt(*(gw->graph)), true);
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- }
- } else {
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
- while (*static_cast<GraphEdge*>(this)!=INVALID &&
- !(*(gw->backward_filter))[*this])
- *(static_cast<GraphEdge*>(this))=
- ++(typename Graph::EdgeIt(*(gw->graph), *this));
+ }
+
+ void nextOut(Edge& i) const {
+ if (!(i.backward)) {
+ Node n=Parent::source(i);
+ Parent::nextOut(i);
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*forward_filter)[i]) Parent::nextOut(i);
+ if (*static_cast<GraphEdge*>(&i)==INVALID) {
+ Parent::firstIn(i, n);
+ i.backward=true;
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::nextIn(i);
}
- return *this;
+ } else {
+ Parent::nextIn(i);
+ while (*static_cast<GraphEdge*>(&i)!=INVALID &&
+ !(*backward_filter)[i]) Parent::nextIn(i);
}
- };
-
-// using GraphWrapper<Graph>::first;
-// OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
-// i=OutEdgeIt(*this, p); return i;
-// }
-// InEdgeIt& first(InEdgeIt& i, const Node& p) const {
-// i=InEdgeIt(*this, p); return i;
-// }
-// EdgeIt& first(EdgeIt& i) const {
-// i=EdgeIt(*this); return i;
-// }
-
+ }
Node source(Edge e) const {
return ((!e.backward) ? this->graph->source(e) : this->graph->target(e)); }
@@ -1103,45 +1109,46 @@
/// \warning This is a linear time operation and works only if
/// \c Graph::EdgeIt is defined.
+ /// \todo hmm
int edgeNum() const {
int i=0;
- for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
+ Edge e;
+ for (first(e); e!=INVALID; next(e)) ++i;
return i;
}
bool forward(const Edge& e) const { return !e.backward; }
bool backward(const Edge& e) const { return e.backward; }
-
template <typename T>
- /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two
- /// Graph::EdgeMap one for the forward edges and
+ /// \c SubBidirGraphWrapperBase<..., ..., ...>::EdgeMap contains two
+ /// _Graph::EdgeMap one for the forward edges and
/// one for the backward edges.
class EdgeMap {
template <typename TT> friend class EdgeMap;
- typename Graph::template EdgeMap<T> forward_map, backward_map;
+ typename _Graph::template EdgeMap<T> forward_map, backward_map;
public:
typedef T Value;
typedef Edge Key;
- EdgeMap(const SubBidirGraphWrapper<Graph,
+ EdgeMap(const SubBidirGraphWrapperBase<_Graph,
ForwardFilterMap, BackwardFilterMap>& g) :
forward_map(*(g.graph)), backward_map(*(g.graph)) { }
- EdgeMap(const SubBidirGraphWrapper<Graph,
+ EdgeMap(const SubBidirGraphWrapperBase<_Graph,
ForwardFilterMap, BackwardFilterMap>& g, T a) :
forward_map(*(g.graph), a), backward_map(*(g.graph), a) { }
- template <typename TT>
- EdgeMap(const EdgeMap<TT>& copy)
- : forward_map(copy.forward_map), backward_map(copy.backward_map) {}
-
- template <typename TT>
- EdgeMap& operator=(const EdgeMap<TT>& copy) {
- forward_map = copy.forward_map;
- backward_map = copy.backward_map;
- return *this;
- }
+// template <typename TT>
+// EdgeMap(const EdgeMap<TT>& copy)
+// : forward_map(copy.forward_map), backward_map(copy.backward_map) {}
+
+// template <typename TT>
+// EdgeMap& operator=(const EdgeMap<TT>& copy) {
+// forward_map = copy.forward_map;
+// backward_map = copy.backward_map;
+// return *this;
+// }
void set(Edge e, T a) {
if (!e.backward)
@@ -1150,16 +1157,16 @@
backward_map.set(e, a);
}
- typename Graph::template EdgeMap<T>::ConstReference
- operator[](Edge e) const {
- if (!e.backward)
- return forward_map[e];
- else
- return backward_map[e];
- }
+// typename _Graph::template EdgeMap<T>::ConstReference
+// operator[](Edge e) const {
+// if (!e.backward)
+// return forward_map[e];
+// else
+// return backward_map[e];
+// }
- typename Graph::template EdgeMap<T>::Reference
- operator[](Edge e) {
+// typename _Graph::template EdgeMap<T>::Reference
+ T operator[](Edge e) {
if (!e.backward)
return forward_map[e];
else
@@ -1172,11 +1179,406 @@
}
};
+ };
- // KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);
+ ///\brief A wrapper for composing a subgraph of a
+ /// bidirected graph made from a directed one.
+ ///
+ /// A wrapper for composing a subgraph of a
+ /// bidirected graph made from a directed one.
+ ///
+ ///\warning Graph wrappers are in even more experimental state than the other
+ ///parts of the lib. Use them at you own risk.
+ ///
+ /// Let \f$G=(V, A)\f$ be a directed graph and for each directed edge
+ /// \f$e\in A\f$, let \f$\bar e\f$ denote the edge obtained by
+ /// reversing its orientation. We are given moreover two bool valued
+ /// maps on the edge-set,
+ /// \f$forward\_filter\f$, and \f$backward\_filter\f$.
+ /// SubBidirGraphWrapper implements the graph structure with node-set
+ /// \f$V\f$ and edge-set
+ /// \f$\{e : e\in A \mbox{ and } forward\_filter(e) \mbox{ is true}\}+\{\bar e : e\in A \mbox{ and } backward\_filter(e) \mbox{ is true}\}\f$.
+ /// The purpose of writing + instead of union is because parallel
+ /// edges can arise. (Similarly, antiparallel edges also can arise).
+ /// In other words, a subgraph of the bidirected graph obtained, which
+ /// is given by orienting the edges of the original graph in both directions.
+ /// As the oppositely directed edges are logically different,
+ /// the maps are able to attach different values for them.
+ ///
+ /// An example for such a construction is \c RevGraphWrapper where the
+ /// forward_filter is everywhere false and the backward_filter is
+ /// everywhere true. We note that for sake of efficiency,
+ /// \c RevGraphWrapper is implemented in a different way.
+ /// But BidirGraphWrapper is obtained from
+ /// SubBidirGraphWrapper by considering everywhere true
+ /// valued maps both for forward_filter and backward_filter.
+ /// Finally, one of the most important applications of SubBidirGraphWrapper
+ /// is ResGraphWrapper, which stands for the residual graph in directed
+ /// flow and circulation problems.
+ /// As wrappers usually, the SubBidirGraphWrapper implements the
+ /// above mentioned graph structure without its physical storage,
+ /// that is the whole stuff is stored in constant memory.
+ template<typename _Graph,
+ typename ForwardFilterMap, typename BackwardFilterMap>
+ class SubBidirGraphWrapper :
+ public IterableGraphExtender<
+ SubBidirGraphWrapperBase<_Graph, ForwardFilterMap, BackwardFilterMap> > {
+ public:
+ typedef _Graph Graph;
+ typedef IterableGraphExtender<
+ SubBidirGraphWrapperBase<
+ _Graph, ForwardFilterMap, BackwardFilterMap> > Parent;
+ protected:
+ SubBidirGraphWrapper() { }
+ public:
+ SubBidirGraphWrapper(_Graph& _graph, ForwardFilterMap& _forward_filter,
+ BackwardFilterMap& _backward_filter) {
+ setGraph(_graph);
+ setForwardFilterMap(_forward_filter);
+ setBackwardFilterMap(_backward_filter);
+ }
};
+// template<typename Graph,
+// typename ForwardFilterMap, typename BackwardFilterMap>
+// class SubBidirGraphWrapper : public GraphWrapper<Graph> {
+// public:
+// typedef GraphWrapper<Graph> Parent;
+// protected:
+// ForwardFilterMap* forward_filter;
+// BackwardFilterMap* backward_filter;
+
+// SubBidirGraphWrapper() : GraphWrapper<Graph>() { }
+// void setForwardFilterMap(ForwardFilterMap& _forward_filter) {
+// forward_filter=&_forward_filter;
+// }
+// void setBackwardFilterMap(BackwardFilterMap& _backward_filter) {
+// backward_filter=&_backward_filter;
+// }
+
+// public:
+
+// SubBidirGraphWrapper(Graph& _graph, ForwardFilterMap& _forward_filter,
+// BackwardFilterMap& _backward_filter) :
+// GraphWrapper<Graph>(_graph),
+// forward_filter(&_forward_filter), backward_filter(&_backward_filter) { }
+// SubBidirGraphWrapper(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& gw) :
+// Parent(gw),
+// forward_filter(gw.forward_filter),
+// backward_filter(gw.backward_filter) { }
+
+// class Edge;
+// class OutEdgeIt;
+// friend class Edge;
+// friend class OutEdgeIt;
+
+// template<typename T> class EdgeMap;
+
+// typedef typename GraphWrapper<Graph>::Node Node;
+
+// typedef typename Graph::Edge GraphEdge;
+// /// SubBidirGraphWrapper<..., ..., ...>::Edge is inherited from
+// /// Graph::Edge. It contains an extra bool flag which is true
+// /// if and only if the
+// /// edge is the backward version of the original edge.
+// class Edge : public Graph::Edge {
+// friend class SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>;
+// template<typename T> friend class EdgeMap;
+// protected:
+// bool backward; //true, iff backward
+// public:
+// Edge() { }
+// /// \todo =false is needed, or causes problems?
+// /// If \c _backward is false, then we get an edge corresponding to the
+// /// original one, otherwise its oppositely directed pair is obtained.
+// Edge(const typename Graph::Edge& e, bool _backward/*=false*/) :
+// Graph::Edge(e), backward(_backward) { }
+// Edge(Invalid i) : Graph::Edge(i), backward(true) { }
+// bool operator==(const Edge& v) const {
+// return (this->backward==v.backward &&
+// static_cast<typename Graph::Edge>(*this)==
+// static_cast<typename Graph::Edge>(v));
+// }
+// bool operator!=(const Edge& v) const {
+// return (this->backward!=v.backward ||
+// static_cast<typename Graph::Edge>(*this)!=
+// static_cast<typename Graph::Edge>(v));
+// }
+// };
+
+// class OutEdgeIt : public Edge {
+// friend class SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>;
+// protected:
+// const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>* gw;
+// public:
+// OutEdgeIt() { }
+// OutEdgeIt(Invalid i) : Edge(i) { }
+// OutEdgeIt(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) :
+// Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), false), gw(&_gw) {
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->forward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// if (*static_cast<GraphEdge*>(this)==INVALID) {
+// *static_cast<Edge*>(this)=
+// Edge(typename Graph::InEdgeIt(*(_gw.graph), n), true);
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// }
+// }
+// OutEdgeIt(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) :
+// Edge(e), gw(&_gw) { }
+// OutEdgeIt& operator++() {
+// if (!this->backward) {
+// Node n=gw->source(*this);
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->forward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// if (*static_cast<GraphEdge*>(this)==INVALID) {
+// *static_cast<Edge*>(this)=
+// Edge(typename Graph::InEdgeIt(*(gw->graph), n), true);
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// }
+// } else {
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// }
+// return *this;
+// }
+// };
+
+// class InEdgeIt : public Edge {
+// friend class SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>;
+// protected:
+// const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>* gw;
+// public:
+// InEdgeIt() { }
+// InEdgeIt(Invalid i) : Edge(i) { }
+// InEdgeIt(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& _gw, const Node& n) :
+// Edge(typename Graph::InEdgeIt(*(_gw.graph), n), false), gw(&_gw) {
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->forward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// if (*static_cast<GraphEdge*>(this)==INVALID) {
+// *static_cast<Edge*>(this)=
+// Edge(typename Graph::OutEdgeIt(*(_gw.graph), n), true);
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// }
+// }
+// InEdgeIt(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) :
+// Edge(e), gw(&_gw) { }
+// InEdgeIt& operator++() {
+// if (!this->backward) {
+// Node n=gw->source(*this);
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->forward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::InEdgeIt(*(gw->graph), *this));
+// if (*static_cast<GraphEdge*>(this)==INVALID) {
+// *static_cast<Edge*>(this)=
+// Edge(typename Graph::OutEdgeIt(*(gw->graph), n), true);
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// }
+// } else {
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::OutEdgeIt(*(gw->graph), *this));
+// }
+// return *this;
+// }
+// };
+
+// class EdgeIt : public Edge {
+// friend class SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>;
+// protected:
+// const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>* gw;
+// public:
+// EdgeIt() { }
+// EdgeIt(Invalid i) : Edge(i) { }
+// EdgeIt(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& _gw) :
+// Edge(typename Graph::EdgeIt(*(_gw.graph)), false), gw(&_gw) {
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->forward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// if (*static_cast<GraphEdge*>(this)==INVALID) {
+// *static_cast<Edge*>(this)=
+// Edge(typename Graph::EdgeIt(*(_gw.graph)), true);
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// }
+// }
+// EdgeIt(const SubBidirGraphWrapper<Graph,
+// ForwardFilterMap, BackwardFilterMap>& _gw, const Edge& e) :
+// Edge(e), gw(&_gw) { }
+// EdgeIt& operator++() {
+// if (!this->backward) {
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->forward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// if (*static_cast<GraphEdge*>(this)==INVALID) {
+// *static_cast<Edge*>(this)=
+// Edge(typename Graph::EdgeIt(*(gw->graph)), true);
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// }
+// } else {
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// while (*static_cast<GraphEdge*>(this)!=INVALID &&
+// !(*(gw->backward_filter))[*this])
+// *(static_cast<GraphEdge*>(this))=
+// ++(typename Graph::EdgeIt(*(gw->graph), *this));
+// }
+// return *this;
+// }
+// };
+
+// // using GraphWrapper<Graph>::first;
+// // OutEdgeIt& first(OutEdgeIt& i, const Node& p) const {
+// // i=OutEdgeIt(*this, p); return i;
+// // }
+// // InEdgeIt& first(InEdgeIt& i, const Node& p) const {
+// // i=InEdgeIt(*this, p); return i;
+// // }
+// // EdgeIt& first(EdgeIt& i) const {
+// // i=EdgeIt(*this); return i;
+// // }
+
+
+// Node source(Edge e) const {
+// return ((!e.backward) ? this->graph->source(e) : this->graph->target(e)); }
+// Node target(Edge e) const {
+// return ((!e.backward) ? this->graph->target(e) : this->graph->source(e)); }
+
+// /// Gives back the opposite edge.
+// Edge opposite(const Edge& e) const {
+// Edge f=e;
+// f.backward=!f.backward;
+// return f;
+// }
+
+// /// \warning This is a linear time operation and works only if
+// /// \c Graph::EdgeIt is defined.
+// int edgeNum() const {
+// int i=0;
+// for (EdgeIt e(*this); e!=INVALID; ++e) ++i;
+// return i;
+// }
+
+// bool forward(const Edge& e) const { return !e.backward; }
+// bool backward(const Edge& e) const { return e.backward; }
+
+
+// template <typename T>
+// /// \c SubBidirGraphWrapper<..., ..., ...>::EdgeMap contains two
+// /// Graph::EdgeMap one for the forward edges and
+// /// one for the backward edges.
+// class EdgeMap {
+// template <typename TT> friend class EdgeMap;
+// typename Graph::template EdgeMap<T> forward_map, backward_map;
+// public:
+// typedef T Value;
+// typedef Edge Key;
+
+// 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) { }
+
+// template <typename TT>
+// EdgeMap(const EdgeMap<TT>& copy)
+// : forward_map(copy.forward_map), backward_map(copy.backward_map) {}
+
+// template <typename TT>
+// EdgeMap& operator=(const EdgeMap<TT>& copy) {
+// forward_map = copy.forward_map;
+// backward_map = copy.backward_map;
+// return *this;
+// }
+
+// void set(Edge e, T a) {
+// if (!e.backward)
+// forward_map.set(e, a);
+// else
+// backward_map.set(e, a);
+// }
+
+// typename Graph::template EdgeMap<T>::ConstReference
+// operator[](Edge e) const {
+// if (!e.backward)
+// return forward_map[e];
+// else
+// return backward_map[e];
+// }
+
+// typename Graph::template EdgeMap<T>::Reference
+// operator[](Edge e) {
+// if (!e.backward)
+// return forward_map[e];
+// else
+// return backward_map[e];
+// }
+
+// void update() {
+// forward_map.update();
+// backward_map.update();
+// }
+// };
+
+
+// // KEEP_NODE_MAP(Parent, SubBidirGraphWrapper);
+
+// };
+
///\brief A wrapper for composing bidirected graph from a directed one.
///
Modified: hugo/trunk/src/test/graph_wrapper_test.cc
==============================================================================
--- hugo/trunk/src/test/graph_wrapper_test.cc (original)
+++ hugo/trunk/src/test/graph_wrapper_test.cc Mon Nov 15 13:25:39 2004
@@ -46,15 +46,20 @@
// function_requires<StaticGraphConcept<RevGraphWrapper<Graph> > >();
-// function_requires<StaticGraphConcept<SubGraphWrapper<Graph, Graph::NodeMap<bool> , Graph::EdgeMap<bool> > > >();
-// function_requires<StaticGraphConcept<NodeSubGraphWrapper<Graph, Graph::NodeMap<bool> > > >();
-// function_requires<StaticGraphConcept<EdgeSubGraphWrapper<Graph, Graph::EdgeMap<bool> > > >();
+ checkConcept<StaticGraph, SubGraphWrapper<StaticGraph,
+ StaticGraph::NodeMap<bool> , StaticGraph::EdgeMap<bool> > >();
+ checkConcept<StaticGraph, NodeSubGraphWrapper<StaticGraph,
+ StaticGraph::NodeMap<bool> > >();
+ checkConcept<StaticGraph, EdgeSubGraphWrapper<StaticGraph,
+ StaticGraph::EdgeMap<bool> > >();
+
+ checkConcept<StaticGraph, SubBidirGraphWrapper<StaticGraph,
+ StaticGraph::EdgeMap<bool>, StaticGraph::EdgeMap<bool> > >();
-// function_requires<StaticGraphConcept<SubBidirGraphWrapper<Graph, Graph::EdgeMap<bool>, Graph::EdgeMap<bool> > > > ();
+ checkConcept<StaticGraph, BidirGraph<StaticGraph> >();
-// function_requires<StaticGraphConcept<BidirGraph<Graph> > >();
-
-// function_requires<StaticGraphConcept<ResGraphWrapper<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> > > >();
+ checkConcept<StaticGraph, ResGraphWrapper<StaticGraph, int,
+ StaticGraph::EdgeMap<int>, StaticGraph::EdgeMap<int> > >();
// function_requires<StaticGraphConcept<ErasingFirstGraphWrapper<Graph, Graph::NodeMap<Graph::Edge> > > >();
}
More information about the Lemon-commits
mailing list