COIN-OR::LEMON - Graph Library

Ignore:
Timestamp:
11/30/08 19:18:32 (15 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Reorganication of graph adaptors and doc improvements (#67)

  • Moving to one file, lemon/adaptors.h
  • Renamings
  • Doc cleanings
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/bits/graph_adaptor_extender.h

    r430 r432  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    2525#include <lemon/bits/default_map.h>
    2626
    27 
    28 ///\ingroup digraphbits
    29 ///\file
    30 ///\brief Extenders for the digraph adaptor types
    3127namespace lemon {
    3228
    33   /// \ingroup digraphbits
    34   ///
    35   /// \brief Extender for the DigraphAdaptors
    3629  template <typename _Digraph>
    3730  class DigraphAdaptorExtender : public _Digraph {
     
    6558    Node oppositeNode(const Node &n, const Arc &e) const {
    6659      if (n == Parent::source(e))
    67         return Parent::target(e);
     60        return Parent::target(e);
    6861      else if(n==Parent::target(e))
    69         return Parent::source(e);
     62        return Parent::source(e);
    7063      else
    71         return INVALID;
    72     }
    73 
    74     class NodeIt : public Node { 
     64        return INVALID;
     65    }
     66
     67    class NodeIt : public Node {
    7568      const Adaptor* _adaptor;
    7669    public:
     
    8174
    8275      explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
    83         _adaptor->first(static_cast<Node&>(*this));
    84       }
    85 
    86       NodeIt(const Adaptor& adaptor, const Node& node) 
    87         : Node(node), _adaptor(&adaptor) {}
    88 
    89       NodeIt& operator++() { 
    90         _adaptor->next(*this);
    91         return *this;
    92       }
    93 
    94     };
    95 
    96 
    97     class ArcIt : public Arc { 
     76        _adaptor->first(static_cast<Node&>(*this));
     77      }
     78
     79      NodeIt(const Adaptor& adaptor, const Node& node)
     80        : Node(node), _adaptor(&adaptor) {}
     81
     82      NodeIt& operator++() {
     83        _adaptor->next(*this);
     84        return *this;
     85      }
     86
     87    };
     88
     89
     90    class ArcIt : public Arc {
    9891      const Adaptor* _adaptor;
    9992    public:
     
    10497
    10598      explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
    106         _adaptor->first(static_cast<Arc&>(*this));
    107       }
    108 
    109       ArcIt(const Adaptor& adaptor, const Arc& e) : 
    110         Arc(e), _adaptor(&adaptor) { }
    111 
    112       ArcIt& operator++() { 
    113         _adaptor->next(*this);
    114         return *this;
    115       }
    116 
    117     };
    118 
    119 
    120     class OutArcIt : public Arc { 
     99        _adaptor->first(static_cast<Arc&>(*this));
     100      }
     101
     102      ArcIt(const Adaptor& adaptor, const Arc& e) :
     103        Arc(e), _adaptor(&adaptor) { }
     104
     105      ArcIt& operator++() {
     106        _adaptor->next(*this);
     107        return *this;
     108      }
     109
     110    };
     111
     112
     113    class OutArcIt : public Arc {
    121114      const Adaptor* _adaptor;
    122115    public:
     
    126119      OutArcIt(Invalid i) : Arc(i) { }
    127120
    128       OutArcIt(const Adaptor& adaptor, const Node& node) 
    129         : _adaptor(&adaptor) {
    130         _adaptor->firstOut(*this, node);
    131       }
    132 
    133       OutArcIt(const Adaptor& adaptor, const Arc& arc) 
    134         : Arc(arc), _adaptor(&adaptor) {}
    135 
    136       OutArcIt& operator++() { 
    137         _adaptor->nextOut(*this);
    138         return *this;
    139       }
    140 
    141     };
    142 
    143 
    144     class InArcIt : public Arc { 
     121      OutArcIt(const Adaptor& adaptor, const Node& node)
     122        : _adaptor(&adaptor) {
     123        _adaptor->firstOut(*this, node);
     124      }
     125
     126      OutArcIt(const Adaptor& adaptor, const Arc& arc)
     127        : Arc(arc), _adaptor(&adaptor) {}
     128
     129      OutArcIt& operator++() {
     130        _adaptor->nextOut(*this);
     131        return *this;
     132      }
     133
     134    };
     135
     136
     137    class InArcIt : public Arc {
    145138      const Adaptor* _adaptor;
    146139    public:
     
    150143      InArcIt(Invalid i) : Arc(i) { }
    151144
    152       InArcIt(const Adaptor& adaptor, const Node& node)
    153         : _adaptor(&adaptor) {
    154         _adaptor->firstIn(*this, node);
    155       }
    156 
    157       InArcIt(const Adaptor& adaptor, const Arc& arc) :
    158         Arc(arc), _adaptor(&adaptor) {}
    159 
    160       InArcIt& operator++() {
    161         _adaptor->nextIn(*this);
    162         return *this;
    163       }
    164 
    165     };
    166 
    167     /// \brief Base node of the iterator
    168     ///
    169     /// Returns the base node (ie. the source in this case) of the iterator
     145      InArcIt(const Adaptor& adaptor, const Node& node)
     146        : _adaptor(&adaptor) {
     147        _adaptor->firstIn(*this, node);
     148      }
     149
     150      InArcIt(const Adaptor& adaptor, const Arc& arc) :
     151        Arc(arc), _adaptor(&adaptor) {}
     152
     153      InArcIt& operator++() {
     154        _adaptor->nextIn(*this);
     155        return *this;
     156      }
     157
     158    };
     159
    170160    Node baseNode(const OutArcIt &e) const {
    171161      return Parent::source(e);
    172162    }
    173     /// \brief Running node of the iterator
    174     ///
    175     /// Returns the running node (ie. the target in this case) of the
    176     /// iterator
    177163    Node runningNode(const OutArcIt &e) const {
    178164      return Parent::target(e);
    179165    }
    180166
    181     /// \brief Base node of the iterator
    182     ///
    183     /// Returns the base node (ie. the target in this case) of the iterator
    184167    Node baseNode(const InArcIt &e) const {
    185168      return Parent::target(e);
    186169    }
    187     /// \brief Running node of the iterator
    188     ///
    189     /// Returns the running node (ie. the source in this case) of the
    190     /// iterator
    191170    Node runningNode(const InArcIt &e) const {
    192171      return Parent::source(e);
     
    199178  ///
    200179  /// \brief Extender for the GraphAdaptors
    201   template <typename _Graph> 
     180  template <typename _Graph>
    202181  class GraphAdaptorExtender : public _Graph {
    203182  public:
    204    
     183
    205184    typedef _Graph Parent;
    206185    typedef _Graph Graph;
     
    211190    typedef typename Parent::Edge Edge;
    212191
    213     // Graph extension   
     192    // Graph extension
    214193
    215194    int maxId(Node) const {
     
    239218    Node oppositeNode(const Node &n, const Edge &e) const {
    240219      if( n == Parent::u(e))
    241         return Parent::v(e);
     220        return Parent::v(e);
    242221      else if( n == Parent::v(e))
    243         return Parent::u(e);
     222        return Parent::u(e);
    244223      else
    245         return INVALID;
     224        return INVALID;
    246225    }
    247226
     
    256235
    257236
    258     class NodeIt : public Node { 
     237    class NodeIt : public Node {
    259238      const Adaptor* _adaptor;
    260239    public:
     
    265244
    266245      explicit NodeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
    267         _adaptor->first(static_cast<Node&>(*this));
    268       }
    269 
    270       NodeIt(const Adaptor& adaptor, const Node& node) 
    271         : Node(node), _adaptor(&adaptor) {}
    272 
    273       NodeIt& operator++() { 
    274         _adaptor->next(*this);
    275         return *this;
    276       }
    277 
    278     };
    279 
    280 
    281     class ArcIt : public Arc { 
     246        _adaptor->first(static_cast<Node&>(*this));
     247      }
     248
     249      NodeIt(const Adaptor& adaptor, const Node& node)
     250        : Node(node), _adaptor(&adaptor) {}
     251
     252      NodeIt& operator++() {
     253        _adaptor->next(*this);
     254        return *this;
     255      }
     256
     257    };
     258
     259
     260    class ArcIt : public Arc {
    282261      const Adaptor* _adaptor;
    283262    public:
     
    288267
    289268      explicit ArcIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
    290         _adaptor->first(static_cast<Arc&>(*this));
    291       }
    292 
    293       ArcIt(const Adaptor& adaptor, const Arc& e) : 
    294         Arc(e), _adaptor(&adaptor) { }
    295 
    296       ArcIt& operator++() { 
    297         _adaptor->next(*this);
    298         return *this;
    299       }
    300 
    301     };
    302 
    303 
    304     class OutArcIt : public Arc { 
     269        _adaptor->first(static_cast<Arc&>(*this));
     270      }
     271
     272      ArcIt(const Adaptor& adaptor, const Arc& e) :
     273        Arc(e), _adaptor(&adaptor) { }
     274
     275      ArcIt& operator++() {
     276        _adaptor->next(*this);
     277        return *this;
     278      }
     279
     280    };
     281
     282
     283    class OutArcIt : public Arc {
    305284      const Adaptor* _adaptor;
    306285    public:
     
    310289      OutArcIt(Invalid i) : Arc(i) { }
    311290
    312       OutArcIt(const Adaptor& adaptor, const Node& node) 
    313         : _adaptor(&adaptor) {
    314         _adaptor->firstOut(*this, node);
    315       }
    316 
    317       OutArcIt(const Adaptor& adaptor, const Arc& arc) 
    318         : Arc(arc), _adaptor(&adaptor) {}
    319 
    320       OutArcIt& operator++() { 
    321         _adaptor->nextOut(*this);
    322         return *this;
    323       }
    324 
    325     };
    326 
    327 
    328     class InArcIt : public Arc { 
     291      OutArcIt(const Adaptor& adaptor, const Node& node)
     292        : _adaptor(&adaptor) {
     293        _adaptor->firstOut(*this, node);
     294      }
     295
     296      OutArcIt(const Adaptor& adaptor, const Arc& arc)
     297        : Arc(arc), _adaptor(&adaptor) {}
     298
     299      OutArcIt& operator++() {
     300        _adaptor->nextOut(*this);
     301        return *this;
     302      }
     303
     304    };
     305
     306
     307    class InArcIt : public Arc {
    329308      const Adaptor* _adaptor;
    330309    public:
     
    334313      InArcIt(Invalid i) : Arc(i) { }
    335314
    336       InArcIt(const Adaptor& adaptor, const Node& node) 
    337         : _adaptor(&adaptor) {
    338         _adaptor->firstIn(*this, node);
    339       }
    340 
    341       InArcIt(const Adaptor& adaptor, const Arc& arc) : 
    342         Arc(arc), _adaptor(&adaptor) {}
    343 
    344       InArcIt& operator++() { 
    345         _adaptor->nextIn(*this);
    346         return *this;
    347       }
    348 
    349     };
    350 
    351     class EdgeIt : public Parent::Edge { 
     315      InArcIt(const Adaptor& adaptor, const Node& node)
     316        : _adaptor(&adaptor) {
     317        _adaptor->firstIn(*this, node);
     318      }
     319
     320      InArcIt(const Adaptor& adaptor, const Arc& arc) :
     321        Arc(arc), _adaptor(&adaptor) {}
     322
     323      InArcIt& operator++() {
     324        _adaptor->nextIn(*this);
     325        return *this;
     326      }
     327
     328    };
     329
     330    class EdgeIt : public Parent::Edge {
    352331      const Adaptor* _adaptor;
    353332    public:
     
    358337
    359338      explicit EdgeIt(const Adaptor& adaptor) : _adaptor(&adaptor) {
    360         _adaptor->first(static_cast<Edge&>(*this));
    361       }
    362 
    363       EdgeIt(const Adaptor& adaptor, const Edge& e) : 
    364         Edge(e), _adaptor(&adaptor) { }
    365 
    366       EdgeIt& operator++() { 
    367         _adaptor->next(*this);
    368         return *this;
    369       }
    370 
    371     };
    372 
    373     class IncEdgeIt : public Edge { 
     339        _adaptor->first(static_cast<Edge&>(*this));
     340      }
     341
     342      EdgeIt(const Adaptor& adaptor, const Edge& e) :
     343        Edge(e), _adaptor(&adaptor) { }
     344
     345      EdgeIt& operator++() {
     346        _adaptor->next(*this);
     347        return *this;
     348      }
     349
     350    };
     351
     352    class IncEdgeIt : public Edge {
    374353      friend class GraphAdaptorExtender;
    375354      const Adaptor* _adaptor;
     
    382361
    383362      IncEdgeIt(const Adaptor& adaptor, const Node &n) : _adaptor(&adaptor) {
    384         _adaptor->firstInc(static_cast<Edge&>(*this), direction, n);
     363        _adaptor->firstInc(static_cast<Edge&>(*this), direction, n);
    385364      }
    386365
    387366      IncEdgeIt(const Adaptor& adaptor, const Edge &e, const Node &n)
    388         : _adaptor(&adaptor), Edge(e) {
    389         direction = (_adaptor->u(e) == n);
     367        : _adaptor(&adaptor), Edge(e) {
     368        direction = (_adaptor->u(e) == n);
    390369      }
    391370
    392371      IncEdgeIt& operator++() {
    393         _adaptor->nextInc(*this, direction);
    394         return *this;
    395       }
    396     };
    397 
    398     /// \brief Base node of the iterator
    399     ///
    400     /// Returns the base node (ie. the source in this case) of the iterator
     372        _adaptor->nextInc(*this, direction);
     373        return *this;
     374      }
     375    };
     376
    401377    Node baseNode(const OutArcIt &a) const {
    402378      return Parent::source(a);
    403379    }
    404     /// \brief Running node of the iterator
    405     ///
    406     /// Returns the running node (ie. the target in this case) of the
    407     /// iterator
    408380    Node runningNode(const OutArcIt &a) const {
    409381      return Parent::target(a);
    410382    }
    411383
    412     /// \brief Base node of the iterator
    413     ///
    414     /// Returns the base node (ie. the target in this case) of the iterator
    415384    Node baseNode(const InArcIt &a) const {
    416385      return Parent::target(a);
    417386    }
    418     /// \brief Running node of the iterator
    419     ///
    420     /// Returns the running node (ie. the source in this case) of the
    421     /// iterator
    422387    Node runningNode(const InArcIt &a) const {
    423388      return Parent::source(a);
    424389    }
    425390
    426     /// Base node of the iterator
    427     ///
    428     /// Returns the base node of the iterator
    429391    Node baseNode(const IncEdgeIt &e) const {
    430392      return e.direction ? Parent::u(e) : Parent::v(e);
    431393    }
    432     /// Running node of the iterator
    433     ///
    434     /// Returns the running node of the iterator
    435394    Node runningNode(const IncEdgeIt &e) const {
    436395      return e.direction ? Parent::v(e) : Parent::u(e);
Note: See TracChangeset for help on using the changeset viewer.