lemon/full_graph.h
author Balazs Dezso <deba@inf.elte.hu>
Sun, 14 Nov 2010 22:48:32 +0100
changeset 1188 5ef0ab7b61cd
parent 956 141f9c0db4a3
child 1192 b84e68af8248
permissions -rw-r--r--
FullBpGraph implementation (#69)
deba@365
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@365
     2
 *
deba@365
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@365
     4
 *
alpar@956
     5
 * Copyright (C) 2003-2010
deba@365
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@365
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@365
     8
 *
deba@365
     9
 * Permission to use, modify and distribute this software is granted
deba@365
    10
 * provided that this copyright notice appears in all copies. For
deba@365
    11
 * precise terms see the accompanying LICENSE file.
deba@365
    12
 *
deba@365
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@365
    14
 * express or implied, and with no claim as to its suitability for any
deba@365
    15
 * purpose.
deba@365
    16
 *
deba@365
    17
 */
deba@365
    18
deba@365
    19
#ifndef LEMON_FULL_GRAPH_H
deba@365
    20
#define LEMON_FULL_GRAPH_H
deba@365
    21
deba@365
    22
#include <lemon/core.h>
deba@365
    23
#include <lemon/bits/graph_extender.h>
deba@365
    24
deba@365
    25
///\ingroup graphs
deba@365
    26
///\file
kpeter@782
    27
///\brief FullDigraph and FullGraph classes.
kpeter@366
    28
deba@365
    29
namespace lemon {
deba@365
    30
deba@365
    31
  class FullDigraphBase {
deba@365
    32
  public:
deba@365
    33
kpeter@664
    34
    typedef FullDigraphBase Digraph;
deba@365
    35
deba@365
    36
    class Node;
deba@365
    37
    class Arc;
deba@365
    38
deba@365
    39
  protected:
deba@365
    40
deba@365
    41
    int _node_num;
deba@365
    42
    int _arc_num;
deba@365
    43
deba@365
    44
    FullDigraphBase() {}
deba@365
    45
deba@365
    46
    void construct(int n) { _node_num = n; _arc_num = n * n; }
deba@365
    47
deba@365
    48
  public:
deba@365
    49
deba@365
    50
    typedef True NodeNumTag;
deba@365
    51
    typedef True ArcNumTag;
deba@365
    52
deba@365
    53
    Node operator()(int ix) const { return Node(ix); }
kpeter@825
    54
    static int index(const Node& node) { return node._id; }
deba@365
    55
deba@365
    56
    Arc arc(const Node& s, const Node& t) const {
deba@365
    57
      return Arc(s._id * _node_num + t._id);
deba@365
    58
    }
deba@365
    59
deba@365
    60
    int nodeNum() const { return _node_num; }
deba@365
    61
    int arcNum() const { return _arc_num; }
deba@365
    62
deba@365
    63
    int maxNodeId() const { return _node_num - 1; }
deba@365
    64
    int maxArcId() const { return _arc_num - 1; }
deba@365
    65
deba@365
    66
    Node source(Arc arc) const { return arc._id / _node_num; }
deba@365
    67
    Node target(Arc arc) const { return arc._id % _node_num; }
deba@365
    68
deba@365
    69
    static int id(Node node) { return node._id; }
deba@365
    70
    static int id(Arc arc) { return arc._id; }
deba@365
    71
deba@365
    72
    static Node nodeFromId(int id) { return Node(id);}
deba@365
    73
    static Arc arcFromId(int id) { return Arc(id);}
deba@365
    74
deba@365
    75
    typedef True FindArcTag;
deba@365
    76
deba@365
    77
    Arc findArc(Node s, Node t, Arc prev = INVALID) const {
kpeter@367
    78
      return prev == INVALID ? arc(s, t) : INVALID;
deba@365
    79
    }
deba@365
    80
deba@365
    81
    class Node {
deba@365
    82
      friend class FullDigraphBase;
deba@365
    83
deba@365
    84
    protected:
deba@365
    85
      int _id;
deba@365
    86
      Node(int id) : _id(id) {}
deba@365
    87
    public:
deba@365
    88
      Node() {}
deba@365
    89
      Node (Invalid) : _id(-1) {}
deba@365
    90
      bool operator==(const Node node) const {return _id == node._id;}
deba@365
    91
      bool operator!=(const Node node) const {return _id != node._id;}
deba@365
    92
      bool operator<(const Node node) const {return _id < node._id;}
deba@365
    93
    };
deba@365
    94
deba@365
    95
    class Arc {
deba@365
    96
      friend class FullDigraphBase;
deba@365
    97
deba@365
    98
    protected:
deba@365
    99
      int _id;  // _node_num * source + target;
deba@365
   100
deba@365
   101
      Arc(int id) : _id(id) {}
deba@365
   102
deba@365
   103
    public:
deba@365
   104
      Arc() { }
deba@365
   105
      Arc (Invalid) { _id = -1; }
deba@365
   106
      bool operator==(const Arc arc) const {return _id == arc._id;}
deba@365
   107
      bool operator!=(const Arc arc) const {return _id != arc._id;}
deba@365
   108
      bool operator<(const Arc arc) const {return _id < arc._id;}
deba@365
   109
    };
deba@365
   110
deba@365
   111
    void first(Node& node) const {
deba@365
   112
      node._id = _node_num - 1;
deba@365
   113
    }
deba@365
   114
deba@365
   115
    static void next(Node& node) {
deba@365
   116
      --node._id;
deba@365
   117
    }
deba@365
   118
deba@365
   119
    void first(Arc& arc) const {
deba@365
   120
      arc._id = _arc_num - 1;
deba@365
   121
    }
deba@365
   122
deba@365
   123
    static void next(Arc& arc) {
deba@365
   124
      --arc._id;
deba@365
   125
    }
deba@365
   126
deba@365
   127
    void firstOut(Arc& arc, const Node& node) const {
deba@365
   128
      arc._id = (node._id + 1) * _node_num - 1;
deba@365
   129
    }
deba@365
   130
deba@365
   131
    void nextOut(Arc& arc) const {
deba@365
   132
      if (arc._id % _node_num == 0) arc._id = 0;
deba@365
   133
      --arc._id;
deba@365
   134
    }
deba@365
   135
deba@365
   136
    void firstIn(Arc& arc, const Node& node) const {
deba@365
   137
      arc._id = _arc_num + node._id - _node_num;
deba@365
   138
    }
deba@365
   139
deba@365
   140
    void nextIn(Arc& arc) const {
deba@365
   141
      arc._id -= _node_num;
deba@365
   142
      if (arc._id < 0) arc._id = -1;
deba@365
   143
    }
deba@365
   144
deba@365
   145
  };
deba@365
   146
deba@365
   147
  typedef DigraphExtender<FullDigraphBase> ExtendedFullDigraphBase;
deba@365
   148
deba@365
   149
  /// \ingroup graphs
deba@365
   150
  ///
kpeter@782
   151
  /// \brief A directed full graph class.
deba@365
   152
  ///
kpeter@782
   153
  /// FullDigraph is a simple and fast implmenetation of directed full
kpeter@782
   154
  /// (complete) graphs. It contains an arc from each node to each node
kpeter@782
   155
  /// (including a loop for each node), therefore the number of arcs
kpeter@782
   156
  /// is the square of the number of nodes.
kpeter@782
   157
  /// This class is completely static and it needs constant memory space.
kpeter@782
   158
  /// Thus you can neither add nor delete nodes or arcs, however
kpeter@782
   159
  /// the structure can be resized using resize().
deba@365
   160
  ///
kpeter@782
   161
  /// This type fully conforms to the \ref concepts::Digraph "Digraph concept".
kpeter@782
   162
  /// Most of its member functions and nested classes are documented
kpeter@782
   163
  /// only in the concept class.
kpeter@366
   164
  ///
kpeter@834
   165
  /// This class provides constant time counting for nodes and arcs.
kpeter@834
   166
  ///
kpeter@782
   167
  /// \note FullDigraph and FullGraph classes are very similar,
kpeter@366
   168
  /// but there are two differences. While this class conforms only
kpeter@782
   169
  /// to the \ref concepts::Digraph "Digraph" concept, FullGraph
kpeter@782
   170
  /// conforms to the \ref concepts::Graph "Graph" concept,
kpeter@782
   171
  /// moreover FullGraph does not contain a loop for each
kpeter@782
   172
  /// node as this class does.
deba@365
   173
  ///
deba@365
   174
  /// \sa FullGraph
deba@365
   175
  class FullDigraph : public ExtendedFullDigraphBase {
kpeter@664
   176
    typedef ExtendedFullDigraphBase Parent;
kpeter@664
   177
deba@365
   178
  public:
deba@365
   179
kpeter@782
   180
    /// \brief Default constructor.
kpeter@782
   181
    ///
kpeter@782
   182
    /// Default constructor. The number of nodes and arcs will be zero.
deba@365
   183
    FullDigraph() { construct(0); }
deba@365
   184
deba@365
   185
    /// \brief Constructor
deba@365
   186
    ///
kpeter@366
   187
    /// Constructor.
deba@365
   188
    /// \param n The number of the nodes.
deba@365
   189
    FullDigraph(int n) { construct(n); }
deba@365
   190
kpeter@366
   191
    /// \brief Resizes the digraph
deba@365
   192
    ///
kpeter@782
   193
    /// This function resizes the digraph. It fully destroys and
kpeter@782
   194
    /// rebuilds the structure, therefore the maps of the digraph will be
kpeter@366
   195
    /// reallocated automatically and the previous values will be lost.
deba@365
   196
    void resize(int n) {
deba@365
   197
      Parent::notifier(Arc()).clear();
deba@365
   198
      Parent::notifier(Node()).clear();
deba@365
   199
      construct(n);
deba@365
   200
      Parent::notifier(Node()).build();
deba@365
   201
      Parent::notifier(Arc()).build();
deba@365
   202
    }
deba@365
   203
deba@365
   204
    /// \brief Returns the node with the given index.
deba@365
   205
    ///
alpar@956
   206
    /// Returns the node with the given index. Since this structure is
kpeter@782
   207
    /// completely static, the nodes can be indexed with integers from
kpeter@782
   208
    /// the range <tt>[0..nodeNum()-1]</tt>.
kpeter@834
   209
    /// The index of a node is the same as its ID.
kpeter@366
   210
    /// \sa index()
deba@365
   211
    Node operator()(int ix) const { return Parent::operator()(ix); }
deba@365
   212
kpeter@366
   213
    /// \brief Returns the index of the given node.
deba@365
   214
    ///
alpar@956
   215
    /// Returns the index of the given node. Since this structure is
kpeter@782
   216
    /// completely static, the nodes can be indexed with integers from
kpeter@782
   217
    /// the range <tt>[0..nodeNum()-1]</tt>.
kpeter@834
   218
    /// The index of a node is the same as its ID.
kpeter@782
   219
    /// \sa operator()()
kpeter@825
   220
    static int index(const Node& node) { return Parent::index(node); }
deba@365
   221
kpeter@366
   222
    /// \brief Returns the arc connecting the given nodes.
deba@365
   223
    ///
kpeter@366
   224
    /// Returns the arc connecting the given nodes.
kpeter@782
   225
    Arc arc(Node u, Node v) const {
deba@365
   226
      return Parent::arc(u, v);
deba@365
   227
    }
deba@365
   228
deba@365
   229
    /// \brief Number of nodes.
deba@365
   230
    int nodeNum() const { return Parent::nodeNum(); }
deba@365
   231
    /// \brief Number of arcs.
deba@365
   232
    int arcNum() const { return Parent::arcNum(); }
deba@365
   233
  };
deba@365
   234
deba@365
   235
deba@365
   236
  class FullGraphBase {
deba@365
   237
  public:
deba@365
   238
deba@365
   239
    typedef FullGraphBase Graph;
deba@365
   240
deba@365
   241
    class Node;
deba@365
   242
    class Arc;
deba@365
   243
    class Edge;
deba@365
   244
deba@365
   245
  protected:
deba@365
   246
kpeter@664
   247
    int _node_num;
kpeter@664
   248
    int _edge_num;
kpeter@664
   249
deba@365
   250
    FullGraphBase() {}
deba@365
   251
deba@365
   252
    void construct(int n) { _node_num = n; _edge_num = n * (n - 1) / 2; }
deba@365
   253
deba@365
   254
    int _uid(int e) const {
deba@365
   255
      int u = e / _node_num;
deba@365
   256
      int v = e % _node_num;
deba@365
   257
      return u < v ? u : _node_num - 2 - u;
deba@365
   258
    }
deba@365
   259
deba@365
   260
    int _vid(int e) const {
deba@365
   261
      int u = e / _node_num;
deba@365
   262
      int v = e % _node_num;
deba@365
   263
      return u < v ? v : _node_num - 1 - v;
deba@365
   264
    }
deba@365
   265
deba@365
   266
    void _uvid(int e, int& u, int& v) const {
deba@365
   267
      u = e / _node_num;
deba@365
   268
      v = e % _node_num;
deba@365
   269
      if  (u >= v) {
deba@365
   270
        u = _node_num - 2 - u;
deba@365
   271
        v = _node_num - 1 - v;
deba@365
   272
      }
deba@365
   273
    }
deba@365
   274
deba@365
   275
    void _stid(int a, int& s, int& t) const {
deba@365
   276
      if ((a & 1) == 1) {
deba@365
   277
        _uvid(a >> 1, s, t);
deba@365
   278
      } else {
deba@365
   279
        _uvid(a >> 1, t, s);
deba@365
   280
      }
deba@365
   281
    }
deba@365
   282
deba@365
   283
    int _eid(int u, int v) const {
deba@365
   284
      if (u < (_node_num - 1) / 2) {
deba@365
   285
        return u * _node_num + v;
deba@365
   286
      } else {
deba@365
   287
        return (_node_num - 1 - u) * _node_num - v - 1;
deba@365
   288
      }
deba@365
   289
    }
deba@365
   290
deba@365
   291
  public:
deba@365
   292
deba@365
   293
    Node operator()(int ix) const { return Node(ix); }
kpeter@825
   294
    static int index(const Node& node) { return node._id; }
deba@365
   295
deba@365
   296
    Edge edge(const Node& u, const Node& v) const {
deba@365
   297
      if (u._id < v._id) {
deba@365
   298
        return Edge(_eid(u._id, v._id));
deba@365
   299
      } else if (u._id != v._id) {
deba@365
   300
        return Edge(_eid(v._id, u._id));
deba@365
   301
      } else {
deba@365
   302
        return INVALID;
deba@365
   303
      }
deba@365
   304
    }
deba@365
   305
deba@365
   306
    Arc arc(const Node& s, const Node& t) const {
deba@365
   307
      if (s._id < t._id) {
deba@365
   308
        return Arc((_eid(s._id, t._id) << 1) | 1);
deba@365
   309
      } else if (s._id != t._id) {
deba@365
   310
        return Arc(_eid(t._id, s._id) << 1);
deba@365
   311
      } else {
deba@365
   312
        return INVALID;
deba@365
   313
      }
deba@365
   314
    }
deba@365
   315
deba@365
   316
    typedef True NodeNumTag;
kpeter@372
   317
    typedef True ArcNumTag;
deba@365
   318
    typedef True EdgeNumTag;
deba@365
   319
deba@365
   320
    int nodeNum() const { return _node_num; }
deba@365
   321
    int arcNum() const { return 2 * _edge_num; }
deba@365
   322
    int edgeNum() const { return _edge_num; }
deba@365
   323
deba@365
   324
    static int id(Node node) { return node._id; }
deba@365
   325
    static int id(Arc arc) { return arc._id; }
deba@365
   326
    static int id(Edge edge) { return edge._id; }
deba@365
   327
deba@365
   328
    int maxNodeId() const { return _node_num-1; }
deba@365
   329
    int maxArcId() const { return 2 * _edge_num-1; }
deba@365
   330
    int maxEdgeId() const { return _edge_num-1; }
deba@365
   331
deba@365
   332
    static Node nodeFromId(int id) { return Node(id);}
deba@365
   333
    static Arc arcFromId(int id) { return Arc(id);}
deba@365
   334
    static Edge edgeFromId(int id) { return Edge(id);}
deba@365
   335
deba@365
   336
    Node u(Edge edge) const {
deba@365
   337
      return Node(_uid(edge._id));
deba@365
   338
    }
deba@365
   339
deba@365
   340
    Node v(Edge edge) const {
deba@365
   341
      return Node(_vid(edge._id));
deba@365
   342
    }
deba@365
   343
deba@365
   344
    Node source(Arc arc) const {
deba@365
   345
      return Node((arc._id & 1) == 1 ?
deba@365
   346
                  _uid(arc._id >> 1) : _vid(arc._id >> 1));
deba@365
   347
    }
deba@365
   348
deba@365
   349
    Node target(Arc arc) const {
deba@365
   350
      return Node((arc._id & 1) == 1 ?
deba@365
   351
                  _vid(arc._id >> 1) : _uid(arc._id >> 1));
deba@365
   352
    }
deba@365
   353
deba@365
   354
    typedef True FindEdgeTag;
kpeter@372
   355
    typedef True FindArcTag;
deba@365
   356
deba@365
   357
    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
deba@365
   358
      return prev != INVALID ? INVALID : edge(u, v);
deba@365
   359
    }
deba@365
   360
deba@365
   361
    Arc findArc(Node s, Node t, Arc prev = INVALID) const {
deba@365
   362
      return prev != INVALID ? INVALID : arc(s, t);
deba@365
   363
    }
deba@365
   364
deba@365
   365
    class Node {
deba@365
   366
      friend class FullGraphBase;
deba@365
   367
deba@365
   368
    protected:
deba@365
   369
      int _id;
deba@365
   370
      Node(int id) : _id(id) {}
deba@365
   371
    public:
deba@365
   372
      Node() {}
deba@365
   373
      Node (Invalid) { _id = -1; }
deba@365
   374
      bool operator==(const Node node) const {return _id == node._id;}
deba@365
   375
      bool operator!=(const Node node) const {return _id != node._id;}
deba@365
   376
      bool operator<(const Node node) const {return _id < node._id;}
deba@365
   377
    };
deba@365
   378
deba@365
   379
    class Edge {
deba@365
   380
      friend class FullGraphBase;
kpeter@366
   381
      friend class Arc;
deba@365
   382
deba@365
   383
    protected:
deba@365
   384
      int _id;
deba@365
   385
deba@365
   386
      Edge(int id) : _id(id) {}
deba@365
   387
deba@365
   388
    public:
deba@365
   389
      Edge() { }
deba@365
   390
      Edge (Invalid) { _id = -1; }
deba@365
   391
deba@365
   392
      bool operator==(const Edge edge) const {return _id == edge._id;}
deba@365
   393
      bool operator!=(const Edge edge) const {return _id != edge._id;}
deba@365
   394
      bool operator<(const Edge edge) const {return _id < edge._id;}
deba@365
   395
    };
deba@365
   396
deba@365
   397
    class Arc {
deba@365
   398
      friend class FullGraphBase;
deba@365
   399
deba@365
   400
    protected:
deba@365
   401
      int _id;
deba@365
   402
deba@365
   403
      Arc(int id) : _id(id) {}
deba@365
   404
deba@365
   405
    public:
deba@365
   406
      Arc() { }
deba@365
   407
      Arc (Invalid) { _id = -1; }
deba@365
   408
deba@365
   409
      operator Edge() const { return Edge(_id != -1 ? (_id >> 1) : -1); }
deba@365
   410
deba@365
   411
      bool operator==(const Arc arc) const {return _id == arc._id;}
deba@365
   412
      bool operator!=(const Arc arc) const {return _id != arc._id;}
deba@365
   413
      bool operator<(const Arc arc) const {return _id < arc._id;}
deba@365
   414
    };
deba@365
   415
deba@365
   416
    static bool direction(Arc arc) {
deba@365
   417
      return (arc._id & 1) == 1;
deba@365
   418
    }
deba@365
   419
deba@365
   420
    static Arc direct(Edge edge, bool dir) {
deba@365
   421
      return Arc((edge._id << 1) | (dir ? 1 : 0));
deba@365
   422
    }
deba@365
   423
deba@365
   424
    void first(Node& node) const {
deba@365
   425
      node._id = _node_num - 1;
deba@365
   426
    }
deba@365
   427
deba@365
   428
    static void next(Node& node) {
deba@365
   429
      --node._id;
deba@365
   430
    }
deba@365
   431
deba@365
   432
    void first(Arc& arc) const {
deba@365
   433
      arc._id = (_edge_num << 1) - 1;
deba@365
   434
    }
deba@365
   435
deba@365
   436
    static void next(Arc& arc) {
deba@365
   437
      --arc._id;
deba@365
   438
    }
deba@365
   439
deba@365
   440
    void first(Edge& edge) const {
deba@365
   441
      edge._id = _edge_num - 1;
deba@365
   442
    }
deba@365
   443
deba@365
   444
    static void next(Edge& edge) {
deba@365
   445
      --edge._id;
deba@365
   446
    }
deba@365
   447
deba@365
   448
    void firstOut(Arc& arc, const Node& node) const {
deba@365
   449
      int s = node._id, t = _node_num - 1;
deba@365
   450
      if (s < t) {
deba@365
   451
        arc._id = (_eid(s, t) << 1) | 1;
deba@365
   452
      } else {
deba@365
   453
        --t;
deba@365
   454
        arc._id = (t != -1 ? (_eid(t, s) << 1) : -1);
deba@365
   455
      }
deba@365
   456
    }
deba@365
   457
deba@365
   458
    void nextOut(Arc& arc) const {
deba@365
   459
      int s, t;
deba@365
   460
      _stid(arc._id, s, t);
deba@365
   461
      --t;
deba@365
   462
      if (s < t) {
deba@365
   463
        arc._id = (_eid(s, t) << 1) | 1;
deba@365
   464
      } else {
deba@365
   465
        if (s == t) --t;
deba@365
   466
        arc._id = (t != -1 ? (_eid(t, s) << 1) : -1);
deba@365
   467
      }
deba@365
   468
    }
deba@365
   469
deba@365
   470
    void firstIn(Arc& arc, const Node& node) const {
deba@365
   471
      int s = _node_num - 1, t = node._id;
deba@365
   472
      if (s > t) {
deba@365
   473
        arc._id = (_eid(t, s) << 1);
deba@365
   474
      } else {
deba@365
   475
        --s;
deba@365
   476
        arc._id = (s != -1 ? (_eid(s, t) << 1) | 1 : -1);
deba@365
   477
      }
deba@365
   478
    }
deba@365
   479
deba@365
   480
    void nextIn(Arc& arc) const {
deba@365
   481
      int s, t;
deba@365
   482
      _stid(arc._id, s, t);
deba@365
   483
      --s;
deba@365
   484
      if (s > t) {
deba@365
   485
        arc._id = (_eid(t, s) << 1);
deba@365
   486
      } else {
deba@365
   487
        if (s == t) --s;
deba@365
   488
        arc._id = (s != -1 ? (_eid(s, t) << 1) | 1 : -1);
deba@365
   489
      }
deba@365
   490
    }
deba@365
   491
deba@365
   492
    void firstInc(Edge& edge, bool& dir, const Node& node) const {
deba@365
   493
      int u = node._id, v = _node_num - 1;
deba@365
   494
      if (u < v) {
deba@365
   495
        edge._id = _eid(u, v);
deba@365
   496
        dir = true;
deba@365
   497
      } else {
deba@365
   498
        --v;
deba@365
   499
        edge._id = (v != -1 ? _eid(v, u) : -1);
deba@365
   500
        dir = false;
deba@365
   501
      }
deba@365
   502
    }
deba@365
   503
deba@365
   504
    void nextInc(Edge& edge, bool& dir) const {
deba@365
   505
      int u, v;
deba@365
   506
      if (dir) {
deba@365
   507
        _uvid(edge._id, u, v);
deba@365
   508
        --v;
deba@365
   509
        if (u < v) {
deba@365
   510
          edge._id = _eid(u, v);
deba@365
   511
        } else {
deba@365
   512
          --v;
deba@365
   513
          edge._id = (v != -1 ? _eid(v, u) : -1);
deba@365
   514
          dir = false;
deba@365
   515
        }
deba@365
   516
      } else {
deba@365
   517
        _uvid(edge._id, v, u);
deba@365
   518
        --v;
deba@365
   519
        edge._id = (v != -1 ? _eid(v, u) : -1);
deba@365
   520
      }
deba@365
   521
    }
deba@365
   522
deba@365
   523
  };
deba@365
   524
deba@365
   525
  typedef GraphExtender<FullGraphBase> ExtendedFullGraphBase;
deba@365
   526
deba@365
   527
  /// \ingroup graphs
deba@365
   528
  ///
deba@365
   529
  /// \brief An undirected full graph class.
deba@365
   530
  ///
kpeter@782
   531
  /// FullGraph is a simple and fast implmenetation of undirected full
kpeter@782
   532
  /// (complete) graphs. It contains an edge between every distinct pair
kpeter@782
   533
  /// of nodes, therefore the number of edges is <tt>n(n-1)/2</tt>.
kpeter@782
   534
  /// This class is completely static and it needs constant memory space.
kpeter@782
   535
  /// Thus you can neither add nor delete nodes or edges, however
kpeter@782
   536
  /// the structure can be resized using resize().
deba@365
   537
  ///
kpeter@782
   538
  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
kpeter@782
   539
  /// Most of its member functions and nested classes are documented
kpeter@782
   540
  /// only in the concept class.
deba@365
   541
  ///
kpeter@834
   542
  /// This class provides constant time counting for nodes, edges and arcs.
kpeter@834
   543
  ///
kpeter@782
   544
  /// \note FullDigraph and FullGraph classes are very similar,
kpeter@782
   545
  /// but there are two differences. While FullDigraph
kpeter@366
   546
  /// conforms only to the \ref concepts::Digraph "Digraph" concept,
kpeter@366
   547
  /// this class conforms to the \ref concepts::Graph "Graph" concept,
kpeter@782
   548
  /// moreover this class does not contain a loop for each
kpeter@782
   549
  /// node as FullDigraph does.
deba@365
   550
  ///
deba@365
   551
  /// \sa FullDigraph
deba@365
   552
  class FullGraph : public ExtendedFullGraphBase {
kpeter@664
   553
    typedef ExtendedFullGraphBase Parent;
kpeter@664
   554
deba@365
   555
  public:
deba@365
   556
kpeter@782
   557
    /// \brief Default constructor.
kpeter@782
   558
    ///
kpeter@782
   559
    /// Default constructor. The number of nodes and edges will be zero.
deba@365
   560
    FullGraph() { construct(0); }
deba@365
   561
deba@365
   562
    /// \brief Constructor
deba@365
   563
    ///
kpeter@366
   564
    /// Constructor.
deba@365
   565
    /// \param n The number of the nodes.
deba@365
   566
    FullGraph(int n) { construct(n); }
deba@365
   567
kpeter@366
   568
    /// \brief Resizes the graph
deba@365
   569
    ///
kpeter@782
   570
    /// This function resizes the graph. It fully destroys and
kpeter@782
   571
    /// rebuilds the structure, therefore the maps of the graph will be
kpeter@366
   572
    /// reallocated automatically and the previous values will be lost.
deba@365
   573
    void resize(int n) {
deba@365
   574
      Parent::notifier(Arc()).clear();
deba@365
   575
      Parent::notifier(Edge()).clear();
deba@365
   576
      Parent::notifier(Node()).clear();
deba@365
   577
      construct(n);
deba@365
   578
      Parent::notifier(Node()).build();
deba@365
   579
      Parent::notifier(Edge()).build();
deba@365
   580
      Parent::notifier(Arc()).build();
deba@365
   581
    }
deba@365
   582
deba@365
   583
    /// \brief Returns the node with the given index.
deba@365
   584
    ///
alpar@956
   585
    /// Returns the node with the given index. Since this structure is
kpeter@782
   586
    /// completely static, the nodes can be indexed with integers from
kpeter@782
   587
    /// the range <tt>[0..nodeNum()-1]</tt>.
kpeter@834
   588
    /// The index of a node is the same as its ID.
kpeter@366
   589
    /// \sa index()
deba@365
   590
    Node operator()(int ix) const { return Parent::operator()(ix); }
deba@365
   591
kpeter@366
   592
    /// \brief Returns the index of the given node.
deba@365
   593
    ///
alpar@956
   594
    /// Returns the index of the given node. Since this structure is
kpeter@782
   595
    /// completely static, the nodes can be indexed with integers from
kpeter@782
   596
    /// the range <tt>[0..nodeNum()-1]</tt>.
kpeter@834
   597
    /// The index of a node is the same as its ID.
kpeter@782
   598
    /// \sa operator()()
kpeter@825
   599
    static int index(const Node& node) { return Parent::index(node); }
deba@365
   600
kpeter@366
   601
    /// \brief Returns the arc connecting the given nodes.
deba@365
   602
    ///
kpeter@366
   603
    /// Returns the arc connecting the given nodes.
kpeter@782
   604
    Arc arc(Node s, Node t) const {
deba@365
   605
      return Parent::arc(s, t);
deba@365
   606
    }
deba@365
   607
kpeter@782
   608
    /// \brief Returns the edge connecting the given nodes.
deba@365
   609
    ///
kpeter@782
   610
    /// Returns the edge connecting the given nodes.
kpeter@782
   611
    Edge edge(Node u, Node v) const {
deba@365
   612
      return Parent::edge(u, v);
deba@365
   613
    }
kpeter@366
   614
kpeter@366
   615
    /// \brief Number of nodes.
kpeter@366
   616
    int nodeNum() const { return Parent::nodeNum(); }
kpeter@366
   617
    /// \brief Number of arcs.
kpeter@366
   618
    int arcNum() const { return Parent::arcNum(); }
kpeter@366
   619
    /// \brief Number of edges.
kpeter@366
   620
    int edgeNum() const { return Parent::edgeNum(); }
kpeter@366
   621
deba@365
   622
  };
deba@365
   623
deba@1188
   624
  class FullBpGraphBase {
deba@1188
   625
deba@1188
   626
  protected:
deba@1188
   627
deba@1188
   628
    int _red_num, _blue_num;
deba@1188
   629
    int _node_num, _edge_num;
deba@1188
   630
deba@1188
   631
  public:
deba@1188
   632
deba@1188
   633
    typedef FullBpGraphBase Graph;
deba@1188
   634
deba@1188
   635
    class Node;
deba@1188
   636
    class Arc;
deba@1188
   637
    class Edge;
deba@1188
   638
deba@1188
   639
    class Node {
deba@1188
   640
      friend class FullBpGraphBase;
deba@1188
   641
    protected:
deba@1188
   642
deba@1188
   643
      int _id;
deba@1188
   644
      explicit Node(int id) { _id = id;}
deba@1188
   645
deba@1188
   646
    public:
deba@1188
   647
      Node() {}
deba@1188
   648
      Node (Invalid) { _id = -1; }
deba@1188
   649
      bool operator==(const Node& node) const {return _id == node._id;}
deba@1188
   650
      bool operator!=(const Node& node) const {return _id != node._id;}
deba@1188
   651
      bool operator<(const Node& node) const {return _id < node._id;}
deba@1188
   652
    };
deba@1188
   653
deba@1188
   654
    class Edge {
deba@1188
   655
      friend class FullBpGraphBase;
deba@1188
   656
    protected:
deba@1188
   657
deba@1188
   658
      int _id;
deba@1188
   659
      explicit Edge(int id) { _id = id;}
deba@1188
   660
deba@1188
   661
    public:
deba@1188
   662
      Edge() {}
deba@1188
   663
      Edge (Invalid) { _id = -1; }
deba@1188
   664
      bool operator==(const Edge& arc) const {return _id == arc._id;}
deba@1188
   665
      bool operator!=(const Edge& arc) const {return _id != arc._id;}
deba@1188
   666
      bool operator<(const Edge& arc) const {return _id < arc._id;}
deba@1188
   667
    };
deba@1188
   668
deba@1188
   669
    class Arc {
deba@1188
   670
      friend class FullBpGraphBase;
deba@1188
   671
    protected:
deba@1188
   672
deba@1188
   673
      int _id;
deba@1188
   674
      explicit Arc(int id) { _id = id;}
deba@1188
   675
deba@1188
   676
    public:
deba@1188
   677
      operator Edge() const {
deba@1188
   678
        return _id != -1 ? edgeFromId(_id / 2) : INVALID;
deba@1188
   679
      }
deba@1188
   680
deba@1188
   681
      Arc() {}
deba@1188
   682
      Arc (Invalid) { _id = -1; }
deba@1188
   683
      bool operator==(const Arc& arc) const {return _id == arc._id;}
deba@1188
   684
      bool operator!=(const Arc& arc) const {return _id != arc._id;}
deba@1188
   685
      bool operator<(const Arc& arc) const {return _id < arc._id;}
deba@1188
   686
    };
deba@1188
   687
deba@1188
   688
deba@1188
   689
  protected:
deba@1188
   690
deba@1188
   691
    FullBpGraphBase()
deba@1188
   692
      : _red_num(0), _blue_num(0), _node_num(0), _edge_num(0) {}
deba@1188
   693
deba@1188
   694
    void construct(int redNum, int blueNum) {
deba@1188
   695
      _red_num = redNum; _blue_num = blueNum;
deba@1188
   696
      _node_num = redNum + blueNum; _edge_num = redNum * blueNum;
deba@1188
   697
    }
deba@1188
   698
deba@1188
   699
  public:
deba@1188
   700
deba@1188
   701
    typedef True NodeNumTag;
deba@1188
   702
    typedef True EdgeNumTag;
deba@1188
   703
    typedef True ArcNumTag;
deba@1188
   704
deba@1188
   705
    int nodeNum() const { return _node_num; }
deba@1188
   706
    int redNum() const { return _red_num; }
deba@1188
   707
    int blueNum() const { return _blue_num; }
deba@1188
   708
    int edgeNum() const { return _edge_num; }
deba@1188
   709
    int arcNum() const { return 2 * _edge_num; }
deba@1188
   710
deba@1188
   711
    int maxNodeId() const { return _node_num - 1; }
deba@1188
   712
    int maxRedId() const { return _red_num - 1; }
deba@1188
   713
    int maxBlueId() const { return _blue_num - 1; }
deba@1188
   714
    int maxEdgeId() const { return _edge_num - 1; }
deba@1188
   715
    int maxArcId() const { return 2 * _edge_num - 1; }
deba@1188
   716
deba@1188
   717
    bool red(Node n) const { return n._id < _red_num; }
deba@1188
   718
    bool blue(Node n) const { return n._id >= _red_num; }
deba@1188
   719
deba@1188
   720
    Node source(Arc a) const {
deba@1188
   721
      if (a._id & 1) {
deba@1188
   722
        return Node((a._id >> 1) % _red_num);
deba@1188
   723
      } else {
deba@1188
   724
        return Node((a._id >> 1) / _red_num + _red_num);
deba@1188
   725
      }
deba@1188
   726
    }
deba@1188
   727
    Node target(Arc a) const {
deba@1188
   728
      if (a._id & 1) {
deba@1188
   729
        return Node((a._id >> 1) / _red_num + _red_num);
deba@1188
   730
      } else {
deba@1188
   731
        return Node((a._id >> 1) % _red_num);
deba@1188
   732
      }
deba@1188
   733
    }
deba@1188
   734
deba@1188
   735
    Node redNode(Edge e) const {
deba@1188
   736
      return Node(e._id % _red_num);
deba@1188
   737
    }
deba@1188
   738
    Node blueNode(Edge e) const {
deba@1188
   739
      return Node(e._id / _red_num + _red_num);
deba@1188
   740
    }
deba@1188
   741
deba@1188
   742
    static bool direction(Arc a) {
deba@1188
   743
      return (a._id & 1) == 1;
deba@1188
   744
    }
deba@1188
   745
deba@1188
   746
    static Arc direct(Edge e, bool d) {
deba@1188
   747
      return Arc(e._id * 2 + (d ? 1 : 0));
deba@1188
   748
    }
deba@1188
   749
deba@1188
   750
    void first(Node& node) const {
deba@1188
   751
      node._id = _node_num - 1;
deba@1188
   752
    }
deba@1188
   753
deba@1188
   754
    static void next(Node& node) {
deba@1188
   755
      --node._id;
deba@1188
   756
    }
deba@1188
   757
deba@1188
   758
    void firstRed(Node& node) const {
deba@1188
   759
      node._id = _red_num - 1;
deba@1188
   760
    }
deba@1188
   761
deba@1188
   762
    static void nextRed(Node& node) {
deba@1188
   763
      --node._id;
deba@1188
   764
    }
deba@1188
   765
deba@1188
   766
    void firstBlue(Node& node) const {
deba@1188
   767
      if (_red_num == _node_num) node._id = -1;
deba@1188
   768
      else node._id = _node_num - 1;
deba@1188
   769
    }
deba@1188
   770
deba@1188
   771
    void nextBlue(Node& node) const {
deba@1188
   772
      if (node._id == _red_num) node._id = -1;
deba@1188
   773
      else --node._id;
deba@1188
   774
    }
deba@1188
   775
deba@1188
   776
    void first(Arc& arc) const {
deba@1188
   777
      arc._id = 2 * _edge_num - 1;
deba@1188
   778
    }
deba@1188
   779
deba@1188
   780
    static void next(Arc& arc) {
deba@1188
   781
      --arc._id;
deba@1188
   782
    }
deba@1188
   783
deba@1188
   784
    void first(Edge& arc) const {
deba@1188
   785
      arc._id = _edge_num - 1;
deba@1188
   786
    }
deba@1188
   787
deba@1188
   788
    static void next(Edge& arc) {
deba@1188
   789
      --arc._id;
deba@1188
   790
    }
deba@1188
   791
deba@1188
   792
    void firstOut(Arc &a, const Node& v) const {
deba@1188
   793
      if (v._id < _red_num) {
deba@1188
   794
        a._id = 2 * (v._id + _red_num * (_blue_num - 1)) + 1;
deba@1188
   795
      } else {
deba@1188
   796
        a._id = 2 * (_red_num - 1 + _red_num * (v._id - _red_num));
deba@1188
   797
      }
deba@1188
   798
    }
deba@1188
   799
    void nextOut(Arc &a) const {
deba@1188
   800
      if (a._id & 1) {
deba@1188
   801
        a._id -= 2 * _red_num;
deba@1188
   802
        if (a._id < 0) a._id = -1;
deba@1188
   803
      } else {
deba@1188
   804
        if (a._id % (2 * _red_num) == 0) a._id = -1;
deba@1188
   805
        else a._id -= 2;
deba@1188
   806
      }
deba@1188
   807
    }
deba@1188
   808
deba@1188
   809
    void firstIn(Arc &a, const Node& v) const {
deba@1188
   810
      if (v._id < _red_num) {
deba@1188
   811
        a._id = 2 * (v._id + _red_num * (_blue_num - 1));
deba@1188
   812
      } else {
deba@1188
   813
        a._id = 2 * (_red_num - 1 + _red_num * (v._id - _red_num)) + 1;
deba@1188
   814
      }
deba@1188
   815
    }
deba@1188
   816
    void nextIn(Arc &a) const {
deba@1188
   817
      if (a._id & 1) {
deba@1188
   818
        if (a._id % (2 * _red_num) == 1) a._id = -1;
deba@1188
   819
        else a._id -= 2;
deba@1188
   820
      } else {
deba@1188
   821
        a._id -= 2 * _red_num;
deba@1188
   822
        if (a._id < 0) a._id = -1;
deba@1188
   823
      }
deba@1188
   824
    }
deba@1188
   825
deba@1188
   826
    void firstInc(Edge &e, bool& d, const Node& v) const {
deba@1188
   827
      if (v._id < _red_num) {
deba@1188
   828
        d = true;
deba@1188
   829
        e._id = v._id + _red_num * (_blue_num - 1);
deba@1188
   830
      } else {
deba@1188
   831
        d = false;
deba@1188
   832
        e._id = _red_num - 1 + _red_num * (v._id - _red_num);
deba@1188
   833
      }
deba@1188
   834
    }
deba@1188
   835
    void nextInc(Edge &e, bool& d) const {
deba@1188
   836
      if (d) {
deba@1188
   837
        e._id -= _red_num;
deba@1188
   838
        if (e._id < 0) e._id = -1;
deba@1188
   839
      } else {
deba@1188
   840
        if (e._id % _red_num == 0) e._id = -1;
deba@1188
   841
        else --e._id;
deba@1188
   842
      }
deba@1188
   843
    }
deba@1188
   844
deba@1188
   845
    static int id(Node v) { return v._id; }
deba@1188
   846
    int redId(Node v) const {
deba@1188
   847
      LEMON_DEBUG(v._id < _red_num, "Node has to be red");
deba@1188
   848
      return v._id;
deba@1188
   849
    }
deba@1188
   850
    int blueId(Node v) const {
deba@1188
   851
      LEMON_DEBUG(v._id >= _red_num, "Node has to be blue");
deba@1188
   852
      return v._id - _red_num;
deba@1188
   853
    }
deba@1188
   854
    static int id(Arc e) { return e._id; }
deba@1188
   855
    static int id(Edge e) { return e._id; }
deba@1188
   856
    
deba@1188
   857
    static Node nodeFromId(int id) { return Node(id);}
deba@1188
   858
    static Arc arcFromId(int id) { return Arc(id);}
deba@1188
   859
    static Edge edgeFromId(int id) { return Edge(id);}
deba@1188
   860
deba@1188
   861
    bool valid(Node n) const {
deba@1188
   862
      return n._id >= 0 && n._id < _node_num;
deba@1188
   863
    }
deba@1188
   864
    bool valid(Arc a) const {
deba@1188
   865
      return a._id >= 0 && a._id < 2 * _edge_num;
deba@1188
   866
    }
deba@1188
   867
    bool valid(Edge e) const {
deba@1188
   868
      return e._id >= 0 && e._id < _edge_num;
deba@1188
   869
    }
deba@1188
   870
deba@1188
   871
    Node redNode(int index) const {
deba@1188
   872
      return Node(index);
deba@1188
   873
    }
deba@1188
   874
deba@1188
   875
    int redIndex(Node n) const {
deba@1188
   876
      return n._id;
deba@1188
   877
    }
deba@1188
   878
deba@1188
   879
    Node blueNode(int index) const {
deba@1188
   880
      return Node(index + _red_num);
deba@1188
   881
    }
deba@1188
   882
deba@1188
   883
    int blueIndex(Node n) const {
deba@1188
   884
      return n._id - _red_num;
deba@1188
   885
    }
deba@1188
   886
        
deba@1188
   887
    void clear() {
deba@1188
   888
      _red_num = 0; _blue_num = 0;
deba@1188
   889
      _node_num = 0; _edge_num = 0;
deba@1188
   890
    }
deba@1188
   891
deba@1188
   892
    Edge edge(const Node& u, const Node& v) const { 
deba@1188
   893
      if (u._id < _red_num) {
deba@1188
   894
        if (v._id < _red_num) {
deba@1188
   895
          return Edge(-1);
deba@1188
   896
        } else {
deba@1188
   897
          return Edge(u._id + _red_num * (v._id - _red_num));
deba@1188
   898
        }
deba@1188
   899
      } else {
deba@1188
   900
        if (v._id < _red_num) {
deba@1188
   901
          return Edge(v._id + _red_num * (u._id - _red_num));
deba@1188
   902
        } else {
deba@1188
   903
          return Edge(-1);
deba@1188
   904
        }
deba@1188
   905
      }
deba@1188
   906
    }
deba@1188
   907
deba@1188
   908
    Arc arc(const Node& u, const Node& v) const { 
deba@1188
   909
      if (u._id < _red_num) {
deba@1188
   910
        if (v._id < _red_num) {
deba@1188
   911
          return Arc(-1);
deba@1188
   912
        } else {
deba@1188
   913
          return Arc(2 * (u._id + _red_num * (v._id - _red_num)) + 1);
deba@1188
   914
        }
deba@1188
   915
      } else {
deba@1188
   916
        if (v._id < _red_num) {
deba@1188
   917
          return Arc(2 * (v._id + _red_num * (u._id - _red_num)));
deba@1188
   918
        } else {
deba@1188
   919
          return Arc(-1);
deba@1188
   920
        }
deba@1188
   921
      }
deba@1188
   922
    }
deba@1188
   923
deba@1188
   924
    typedef True FindEdgeTag;
deba@1188
   925
    typedef True FindArcTag;
deba@1188
   926
deba@1188
   927
    Edge findEdge(Node u, Node v, Edge prev = INVALID) const {
deba@1188
   928
      return prev != INVALID ? INVALID : edge(u, v);
deba@1188
   929
    }
deba@1188
   930
deba@1188
   931
    Arc findArc(Node s, Node t, Arc prev = INVALID) const {
deba@1188
   932
      return prev != INVALID ? INVALID : arc(s, t);
deba@1188
   933
    }
deba@1188
   934
deba@1188
   935
  };
deba@1188
   936
deba@1188
   937
  typedef BpGraphExtender<FullBpGraphBase> ExtendedFullBpGraphBase;
deba@1188
   938
deba@1188
   939
  /// \ingroup graphs
deba@1188
   940
  ///
deba@1188
   941
  /// \brief An undirected full bipartite graph class.
deba@1188
   942
  ///
deba@1188
   943
  /// FullBpGraph is a simple and fast implmenetation of undirected
deba@1188
   944
  /// full bipartite graphs. It contains an edge between every
deba@1188
   945
  /// red-blue pairs of nodes, therefore the number of edges is
deba@1188
   946
  /// <tt>nr*nb</tt>.  This class is completely static and it needs
deba@1188
   947
  /// constant memory space.  Thus you can neither add nor delete
deba@1188
   948
  /// nodes or edges, however the structure can be resized using
deba@1188
   949
  /// resize().
deba@1188
   950
  ///
deba@1188
   951
  /// This type fully conforms to the \ref concepts::BpGraph "BpGraph concept".
deba@1188
   952
  /// Most of its member functions and nested classes are documented
deba@1188
   953
  /// only in the concept class.
deba@1188
   954
  ///
deba@1188
   955
  /// This class provides constant time counting for nodes, edges and arcs.
deba@1188
   956
  ///
deba@1188
   957
  /// \sa FullGraph
deba@1188
   958
  class FullBpGraph : public ExtendedFullBpGraphBase {
deba@1188
   959
  public:
deba@1188
   960
deba@1188
   961
    typedef ExtendedFullBpGraphBase Parent;
deba@1188
   962
deba@1188
   963
    /// \brief Default constructor.
deba@1188
   964
    ///
deba@1188
   965
    /// Default constructor. The number of nodes and edges will be zero.
deba@1188
   966
    FullBpGraph() { construct(0, 0); }
deba@1188
   967
deba@1188
   968
    /// \brief Constructor
deba@1188
   969
    ///
deba@1188
   970
    /// Constructor.
deba@1188
   971
    /// \param redNum The number of the red nodes.
deba@1188
   972
    /// \param blueNum The number of the blue nodes.
deba@1188
   973
    FullBpGraph(int redNum, int blueNum) { construct(redNum, blueNum); }
deba@1188
   974
deba@1188
   975
    /// \brief Resizes the graph
deba@1188
   976
    ///
deba@1188
   977
    /// This function resizes the graph. It fully destroys and
deba@1188
   978
    /// rebuilds the structure, therefore the maps of the graph will be
deba@1188
   979
    /// reallocated automatically and the previous values will be lost.
deba@1188
   980
    void resize(int redNum, int blueNum) {
deba@1188
   981
      Parent::notifier(Arc()).clear();
deba@1188
   982
      Parent::notifier(Edge()).clear();
deba@1188
   983
      Parent::notifier(Node()).clear();
deba@1188
   984
      Parent::notifier(BlueNode()).clear();
deba@1188
   985
      Parent::notifier(RedNode()).clear();
deba@1188
   986
      construct(redNum, blueNum);
deba@1188
   987
      Parent::notifier(RedNode()).build();
deba@1188
   988
      Parent::notifier(BlueNode()).build();
deba@1188
   989
      Parent::notifier(Node()).build();
deba@1188
   990
      Parent::notifier(Edge()).build();
deba@1188
   991
      Parent::notifier(Arc()).build();
deba@1188
   992
    }
deba@1188
   993
deba@1188
   994
    /// \brief Returns the red node with the given index.
deba@1188
   995
    ///
deba@1188
   996
    /// Returns the red node with the given index. Since this
deba@1188
   997
    /// structure is completely static, the red nodes can be indexed
deba@1188
   998
    /// with integers from the range <tt>[0..redNum()-1]</tt>.
deba@1188
   999
    /// \sa redIndex()
deba@1188
  1000
    Node redNode(int index) const { return Parent::redNode(index); }
deba@1188
  1001
deba@1188
  1002
    /// \brief Returns the index of the given red node.
deba@1188
  1003
    ///
deba@1188
  1004
    /// Returns the index of the given red node. Since this structure
deba@1188
  1005
    /// is completely static, the red nodes can be indexed with
deba@1188
  1006
    /// integers from the range <tt>[0..redNum()-1]</tt>.
deba@1188
  1007
    ///
deba@1188
  1008
    /// \sa operator()()
deba@1188
  1009
    int redIndex(Node node) const { return Parent::redIndex(node); }
deba@1188
  1010
deba@1188
  1011
    /// \brief Returns the blue node with the given index.
deba@1188
  1012
    ///
deba@1188
  1013
    /// Returns the blue node with the given index. Since this
deba@1188
  1014
    /// structure is completely static, the blue nodes can be indexed
deba@1188
  1015
    /// with integers from the range <tt>[0..blueNum()-1]</tt>.
deba@1188
  1016
    /// \sa blueIndex()
deba@1188
  1017
    Node blueNode(int index) const { return Parent::blueNode(index); }
deba@1188
  1018
deba@1188
  1019
    /// \brief Returns the index of the given blue node.
deba@1188
  1020
    ///
deba@1188
  1021
    /// Returns the index of the given blue node. Since this structure
deba@1188
  1022
    /// is completely static, the blue nodes can be indexed with
deba@1188
  1023
    /// integers from the range <tt>[0..blueNum()-1]</tt>.
deba@1188
  1024
    ///
deba@1188
  1025
    /// \sa operator()()
deba@1188
  1026
    int blueIndex(Node node) const { return Parent::blueIndex(node); }
deba@1188
  1027
deba@1188
  1028
    /// \brief Returns the edge which connects the given nodes.
deba@1188
  1029
    ///
deba@1188
  1030
    /// Returns the edge which connects the given nodes.
deba@1188
  1031
    Edge edge(const Node& u, const Node& v) const {
deba@1188
  1032
      return Parent::edge(u, v);
deba@1188
  1033
    }
deba@1188
  1034
deba@1188
  1035
    /// \brief Returns the arc which connects the given nodes.
deba@1188
  1036
    ///
deba@1188
  1037
    /// Returns the arc which connects the given nodes.
deba@1188
  1038
    Arc arc(const Node& u, const Node& v) const {
deba@1188
  1039
      return Parent::arc(u, v);
deba@1188
  1040
    }
deba@1188
  1041
deba@1188
  1042
    /// \brief Number of nodes.
deba@1188
  1043
    int nodeNum() const { return Parent::nodeNum(); }
deba@1188
  1044
    /// \brief Number of red nodes.
deba@1188
  1045
    int redNum() const { return Parent::redNum(); }
deba@1188
  1046
    /// \brief Number of blue nodes.
deba@1188
  1047
    int blueNum() const { return Parent::blueNum(); }
deba@1188
  1048
    /// \brief Number of arcs.
deba@1188
  1049
    int arcNum() const { return Parent::arcNum(); }
deba@1188
  1050
    /// \brief Number of edges.
deba@1188
  1051
    int edgeNum() const { return Parent::edgeNum(); }
deba@1188
  1052
  };
deba@1188
  1053
deba@365
  1054
deba@365
  1055
} //namespace lemon
deba@365
  1056
deba@365
  1057
deba@365
  1058
#endif //LEMON_FULL_GRAPH_H