diff -r d769d2eb4d50 -r 080d51024ac5 lemon/bpugraph_adaptor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/bpugraph_adaptor.h Mon Apr 03 09:45:23 2006 +0000 @@ -0,0 +1,412 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2006 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_BPUGRAPH_ADAPTOR_H +#define LEMON_BPUGRAPH_ADAPTOR_H + +#include +#include + +#include + +#include + +#include + +///\ingroup graph_adaptors +///\file +///\brief Several graph adaptors. +/// +///This file contains several useful bpugraph adaptor functions. +/// +///\author Balazs Dezso + +namespace lemon { + + /// \ingroup graph_adaptors + /// + /// \brief Base type for the Bipartite Undirected Graph Adaptors + /// + /// This is the base type for most of LEMON bpugraph adaptors. + /// This class implements a trivial graph adaptor i.e. it only wraps the + /// functions and types of the graph. The purpose of this class is to + /// make easier implementing graph adaptors. E.g. if an adaptor is + /// considered which differs from the wrapped graph only in some of its + /// functions or types, then it can be derived from BpUGraphAdaptor, and + /// only the differences should be implemented. + /// + /// \author Balazs Dezso + template + class BpUGraphAdaptorBase { + public: + typedef _BpUGraph Graph; + typedef Graph ParentGraph; + + protected: + Graph* graph; + + BpUGraphAdaptorBase() : graph(0) {} + + void setGraph(Graph& _graph) { graph = &_graph; } + + Graph& getGraph() { return *graph; } + const Graph& getGraph() const { return *graph; } + + public: + + BpUGraphAdaptorBase(Graph& _graph) : graph(&_graph) {} + + typedef typename Graph::Node Node; + typedef typename Graph::ANode ANode; + typedef typename Graph::BNode BNode; + typedef typename Graph::Edge Edge; + typedef typename Graph::UEdge UEdge; + + void first(Node& i) const { graph->first(i); } + void firstANode(Node& i) const { graph->firstANode(i); } + void firstBNode(Node& i) const { graph->firstBNode(i); } + void first(Edge& i) const { graph->first(i); } + void first(UEdge& i) const { graph->first(i); } + void firstIn(Edge& i, const Node& n) const { graph->firstIn(i, n); } + void firstOut(Edge& i, const Node& n ) const { graph->firstOut(i, n); } + void firstInc(UEdge &i, bool &d, const Node &n) const { + graph->firstInc(i, d, n); + } + + void next(Node& i) const { graph->next(i); } + void nextANode(Node& i) const { graph->nextANode(i); } + void nextBNode(Node& i) const { graph->nextBNode(i); } + void next(Edge& i) const { graph->next(i); } + void next(UEdge& i) const { graph->next(i); } + void nextIn(Edge& i) const { graph->nextIn(i); } + void nextOut(Edge& i) const { graph->nextOut(i); } + void nextInc(UEdge &i, bool &d) const { graph->nextInc(i, d); } + + Node source(const UEdge& e) const { return graph->source(e); } + Node target(const UEdge& e) const { return graph->target(e); } + + Node source(const Edge& e) const { return graph->source(e); } + Node target(const Edge& e) const { return graph->target(e); } + + typedef NodeNumTagIndicator NodeNumTag; + int nodeNum() const { return graph->nodeNum(); } + int aNodeNum() const { return graph->aNodeNum(); } + int bNodeNum() const { return graph->bNodeNum(); } + + typedef EdgeNumTagIndicator EdgeNumTag; + int edgeNum() const { return graph->edgeNum(); } + int uEdgeNum() const { return graph->uEdgeNum(); } + + typedef FindEdgeTagIndicator FindEdgeTag; + Edge findEdge(const Node& source, const Node& target, + const Edge& prev = INVALID) { + return graph->findEdge(source, target, prev); + } + UEdge findUEdge(const Node& source, const Node& target, + const UEdge& prev = INVALID) { + return graph->findUEdge(source, target, prev); + } + + Node addNode() const { return graph->addNode(); } + UEdge addEdge(const Node& source, const Node& target) const { + return graph->addEdge(source, target); + } + + void erase(const Node& i) const { graph->erase(i); } + void erase(const UEdge& i) const { graph->erase(i); } + + void clear() const { graph->clear(); } + + bool direction(const Edge& e) const { return graph->direction(e); } + Edge direct(const UEdge& e, bool d) const { return graph->direct(e, d); } + + int id(const Node& v) const { return graph->id(v); } + int id(const ANode& v) const { return graph->id(v); } + int id(const BNode& v) const { return graph->id(v); } + int id(const Edge& e) const { return graph->id(e); } + int id(const UEdge& e) const { return graph->id(e); } + + Node fromNodeId(int id) const { return graph->fromNodeId(id); } + ANode fromANodeId(int id) const { return graph->fromANodeId(id); } + BNode fromBNodeId(int id) const { return graph->fromBNodeId(id); } + Edge fromEdgeId(int id) const { return graph->fromEdgeId(id); } + UEdge fromUEdgeId(int id) const { return graph->fromUEdgeId(id); } + + int maxNodeId() const { return graph->maxNodeId(); } + int maxANodeId() const { return graph->maxANodeId(); } + int maxBNodeId() const { return graph->maxBNodeId(); } + int maxEdgeId() const { return graph->maxEdgeId(); } + int maxUEdgeId() const { return graph->maxEdgeId(); } + + typedef typename ItemSetTraits::ItemNotifier NodeNotifier; + NodeNotifier& getNotifier(Node) const { + return graph->getNotifier(Node()); + } + + typedef typename ItemSetTraits::ItemNotifier ANodeNotifier; + ANodeNotifier& getNotifier(ANode) const { + return graph->getNotifier(ANode()); + } + + typedef typename ItemSetTraits::ItemNotifier BNodeNotifier; + BNodeNotifier& getNotifier(BNode) const { + return graph->getNotifier(BNode()); + } + + typedef typename ItemSetTraits::ItemNotifier EdgeNotifier; + EdgeNotifier& getNotifier(Edge) const { + return graph->getNotifier(Edge()); + } + + typedef typename ItemSetTraits::ItemNotifier UEdgeNotifier; + UEdgeNotifier& getNotifier(UEdge) const { + return graph->getNotifier(UEdge()); + } + + template + class NodeMap : public Graph::template NodeMap<_Value> { + public: + typedef typename Graph::template NodeMap<_Value> Parent; + explicit NodeMap(const BpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + NodeMap(const BpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + NodeMap& operator=(const NodeMap& cmap) { + return operator=(cmap); + } + + template + NodeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + template + class ANodeMap : public Graph::template ANodeMap<_Value> { + public: + typedef typename Graph::template ANodeMap<_Value> Parent; + explicit ANodeMap(const BpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + ANodeMap(const BpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + ANodeMap& operator=(const ANodeMap& cmap) { + return operator=(cmap); + } + + template + ANodeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + template + class BNodeMap : public Graph::template BNodeMap<_Value> { + public: + typedef typename Graph::template BNodeMap<_Value> Parent; + explicit BNodeMap(const BpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + BNodeMap(const BpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + BNodeMap& operator=(const BNodeMap& cmap) { + return operator=(cmap); + } + + template + BNodeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + template + class EdgeMap : public Graph::template EdgeMap<_Value> { + public: + typedef typename Graph::template EdgeMap<_Value> Parent; + explicit EdgeMap(const BpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + EdgeMap(const BpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + EdgeMap& operator=(const EdgeMap& cmap) { + return operator=(cmap); + } + + template + EdgeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + template + class UEdgeMap : public Graph::template UEdgeMap<_Value> { + public: + typedef typename Graph::template UEdgeMap<_Value> Parent; + explicit UEdgeMap(const BpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + UEdgeMap(const BpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + UEdgeMap& operator=(const UEdgeMap& cmap) { + return operator=(cmap); + } + + template + UEdgeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + }; + + /// \ingroup graph_adaptors + template + class BpUGraphAdaptor + : public BpUGraphAdaptorExtender< BpUGraphAdaptorBase<_BpUGraph> > { + public: + typedef _BpUGraph Graph; + typedef BpUGraphAdaptorExtender > Parent; + protected: + BpUGraphAdaptor() : Parent() {} + + public: + explicit BpUGraphAdaptor(Graph& _graph) { setGraph(_graph); } + }; + + template + class SwapBpUGraphAdaptorBase : public BpUGraphAdaptorBase<_BpUGraph> { + public: + + typedef _BpUGraph Graph; + typedef BpUGraphAdaptorBase<_BpUGraph> Parent; + + protected: + + SwapBpUGraphAdaptorBase() {} + + public: + + typedef typename Parent::Node Node; + typedef typename Parent::BNode ANode; + typedef typename Parent::ANode BNode; + + void firstANode(Node& i) const { Parent::firstBNode(i); } + void firstBNode(Node& i) const { Parent::firstANode(i); } + + void nextANode(Node& i) const { Parent::nextBNode(i); } + void nextBNode(Node& i) const { Parent::nextANode(i); } + + int id(const ANode& v) const { return Parent::id(v); } + int id(const BNode& v) const { return Parent::id(v); } + + ANode fromANodeId(int id) const { return Parent::fromBNodeId(id); } + BNode fromBNodeId(int id) const { return Parent::fromANodeId(id); } + + int maxANodeId() const { return Parent::maxBNodeId(); } + int maxBNodeId() const { return Parent::maxANodeId(); } + + int aNodeNum() const { return Parent::bNodeNum(); } + int bNodeNum() const { return Parent::aNodeNum(); } + + typedef typename Parent::BNodeNotifier ANodeNotifier; + ANodeNotifier& getNotifier(ANode) const { + return Parent::getNotifier(typename Parent::BNode()); + } + + typedef typename Parent::ANodeNotifier BNodeNotifier; + BNodeNotifier& getNotifier(BNode) const { + return Parent::getNotifier(typename Parent::ANode()); + } + + template + class ANodeMap : public Graph::template BNodeMap<_Value> { + public: + typedef typename Graph::template BNodeMap<_Value> Parent; + explicit ANodeMap(const SwapBpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + ANodeMap(const SwapBpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + ANodeMap& operator=(const ANodeMap& cmap) { + return operator=(cmap); + } + + template + ANodeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + template + class BNodeMap : public Graph::template ANodeMap<_Value> { + public: + typedef typename Graph::template ANodeMap<_Value> Parent; + explicit BNodeMap(const SwapBpUGraphAdaptorBase& ga) + : Parent(*ga.graph) {} + BNodeMap(const SwapBpUGraphAdaptorBase& ga, const _Value& value) + : Parent(*ga.graph, value) {} + + BNodeMap& operator=(const BNodeMap& cmap) { + return operator=(cmap); + } + + template + BNodeMap& operator=(const CMap& cmap) { + Parent::operator=(cmap); + return *this; + } + }; + + }; + + /// \ingroup graph_adaptors + /// + /// \brief Bipartite graph adaptor which swaps the two nodeset. + /// + /// Bipartite graph adaptor which swaps the two nodeset. The adaptor's + /// a-nodeset will be the original graph's b-nodeset and the adaptor's + /// b-nodeset will be the original graph's a-nodeset. + template + class SwapBpUGraphAdaptor + : public BpUGraphAdaptorExtender > { + public: + + typedef _BpUGraph Graph; + typedef BpUGraphAdaptorExtender > + Parent; + + protected: + SwapBpUGraphAdaptor() : Parent() {} + + public: + + explicit SwapBpUGraphAdaptor(Graph& _graph) { setGraph(_graph); } + + }; + + +} + +#endif