diff -r 825647d4eca7 -r 0beed7a49063 src/work/marci/graph_wrapper.h --- a/src/work/marci/graph_wrapper.h Wed Apr 21 19:52:09 2004 +0000 +++ b/src/work/marci/graph_wrapper.h Wed Apr 21 20:48:00 2004 +0000 @@ -3,6 +3,7 @@ #define HUGO_GRAPH_WRAPPER_H #include +#include namespace hugo { @@ -865,6 +866,115 @@ } }; + /// A wrapper for composing a bipartite graph. + /// \c _graph have to be a reference to an undirected graph \c Graph + /// and + /// \c _s_false_t_true_map is an \c IterableBoolMap + /// reference containing the elements for the + /// color classes S and T. + /// It results in a directed graph such that the edges are oriented from + /// S to T. + template + class BipartiteGraphWrapper : public GraphWrapper { + typedef IterableBoolMap< typename Graph::NodeMap > SFalseTTrueMap; + SFalseTTrueMap* s_false_t_true_map; + + public: + BipartiteGraphWrapper(Graph& _graph, SFalseTTrueMap& _s_false_t_true_map) + : GraphWrapper(_graph), s_false_t_true_map(&_s_false_t_true_map) { + } + typedef typename GraphWrapper::Node Node; + //using GraphWrapper::NodeIt; + typedef typename GraphWrapper::Edge Edge; + //using GraphWrapper::EdgeIt; + class SNodeIt { + Node n; + public: + SNodeIt() { } + SNodeIt(const Invalid& i) : n(i) { } + SNodeIt(const BipartiteGraphWrapper& _G) { + _G.s_false_t_true_map->first(n, false); + } + operator Node() const { return n; } + }; + class TNodeIt { + Node n; + public: + TNodeIt() { } + TNodeIt(const Invalid& i) : n(i) { } + TNodeIt(const BipartiteGraphWrapper& _G) { + _G.s_false_t_true_map->first(n, true); + } + operator Node() const { return n; } + }; + class OutEdgeIt { + public: + typename Graph::OutEdgeIt e; + public: + OutEdgeIt() { } + OutEdgeIt(const Invalid& i) : e(i) { } + OutEdgeIt(const BipartiteGraphWrapper& _G, const Node& _n) { + if (!(*(_G.s_false_t_true_map))[_n]) + e=OutEdgeIt(*(_G.graph), typename Graph::Node(_n)); + else + e=INVALID; + } + operator Edge() const { return Edge(typename Graph::Edge(e)); } + }; + class InEdgeIt { + public: + typename Graph::InEdgeIt e; + public: + InEdgeIt() { } + InEdgeIt(const Invalid& i) : e(i) { } + InEdgeIt(const BipartiteGraphWrapper& _G, const Node& _n) { + if ((*(_G.s_false_t_true_map))[_n]) + e=InEdgeIt(*(_G.graph), typename Graph::Node(_n)); + else + e=INVALID; + } + operator Edge() const { return Edge(typename Graph::Edge(e)); } + }; + + using GraphWrapper::first; + SNodeIt& first(SNodeIt& n) const { n=SNodeIt(*this); return n; } + TNodeIt& first(TNodeIt& n) const { n=TNodeIt(*this); return n; } + + using GraphWrapper::next; + SNodeIt& next(SNodeIt& n) const { + this->s_false_t_true_map->next(n); return n; + } + TNodeIt& next(TNodeIt& n) const { + this->s_false_t_true_map->next(n); return n; + } + + Node tail(const Edge& e) { + if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) + return Node(this->graph->tail(e)); + else + return Node(this->graph->head(e)); + } + Node head(const Edge& e) { + if (!(*(this->s_false_t_true_map))[this->graph->tail(e)]) + return Node(this->graph->head(e)); + else + return Node(this->graph->tail(e)); + } + + Node aNode(const OutEdgeIt& e) const { + return Node(this->graph->aNode(e.e)); + } + Node aNode(const InEdgeIt& e) const { + return Node(this->graph->aNode(e.e)); + } + Node bNode(const OutEdgeIt& e) const { + return Node(this->graph->bNode(e.e)); + } + Node bNode(const InEdgeIt& e) const { + return Node(this->graph->bNode(e.e)); + } + }; + // /// experimentral, do not try it.