test/digraph_test.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Sun, 09 Jan 2011 00:56:52 +0100
changeset 1034 ef200e268af2
parent 780 580af8cf2f6a
child 998 7fdaa05a69a1
permissions -rw-r--r--
Unifications and improvements in TSP algorithms (#386)
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@57
     2
 *
alpar@209
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@57
     4
 *
alpar@877
     5
 * Copyright (C) 2003-2010
deba@57
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@57
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@57
     8
 *
deba@57
     9
 * Permission to use, modify and distribute this software is granted
deba@57
    10
 * provided that this copyright notice appears in all copies. For
deba@57
    11
 * precise terms see the accompanying LICENSE file.
deba@57
    12
 *
deba@57
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@57
    14
 * express or implied, and with no claim as to its suitability for any
deba@57
    15
 * purpose.
deba@57
    16
 *
deba@57
    17
 */
deba@57
    18
deba@57
    19
#include <lemon/concepts/digraph.h>
deba@57
    20
#include <lemon/list_graph.h>
kpeter@171
    21
#include <lemon/smart_graph.h>
kpeter@774
    22
#include <lemon/static_graph.h>
deba@353
    23
#include <lemon/full_graph.h>
deba@57
    24
deba@57
    25
#include "test_tools.h"
kpeter@171
    26
#include "graph_test.h"
deba@57
    27
deba@57
    28
using namespace lemon;
deba@57
    29
using namespace lemon::concepts;
deba@57
    30
deba@228
    31
template <class Digraph>
kpeter@374
    32
void checkDigraphBuild() {
deba@228
    33
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
deba@228
    34
  Digraph G;
deba@228
    35
deba@228
    36
  checkGraphNodeList(G, 0);
deba@228
    37
  checkGraphArcList(G, 0);
deba@228
    38
kpeter@736
    39
  G.reserveNode(3);
kpeter@736
    40
  G.reserveArc(4);
kpeter@736
    41
deba@228
    42
  Node
deba@228
    43
    n1 = G.addNode(),
deba@228
    44
    n2 = G.addNode(),
deba@228
    45
    n3 = G.addNode();
deba@228
    46
  checkGraphNodeList(G, 3);
deba@228
    47
  checkGraphArcList(G, 0);
deba@228
    48
deba@228
    49
  Arc a1 = G.addArc(n1, n2);
deba@228
    50
  check(G.source(a1) == n1 && G.target(a1) == n2, "Wrong arc");
deba@228
    51
  checkGraphNodeList(G, 3);
deba@228
    52
  checkGraphArcList(G, 1);
deba@228
    53
deba@228
    54
  checkGraphOutArcList(G, n1, 1);
deba@228
    55
  checkGraphOutArcList(G, n2, 0);
deba@228
    56
  checkGraphOutArcList(G, n3, 0);
deba@228
    57
deba@228
    58
  checkGraphInArcList(G, n1, 0);
deba@228
    59
  checkGraphInArcList(G, n2, 1);
deba@228
    60
  checkGraphInArcList(G, n3, 0);
deba@228
    61
deba@228
    62
  checkGraphConArcList(G, 1);
deba@228
    63
kpeter@374
    64
  Arc a2 = G.addArc(n2, n1),
kpeter@374
    65
      a3 = G.addArc(n2, n3),
kpeter@374
    66
      a4 = G.addArc(n2, n3);
kpeter@374
    67
kpeter@374
    68
  checkGraphNodeList(G, 3);
kpeter@374
    69
  checkGraphArcList(G, 4);
kpeter@374
    70
kpeter@374
    71
  checkGraphOutArcList(G, n1, 1);
kpeter@374
    72
  checkGraphOutArcList(G, n2, 3);
kpeter@374
    73
  checkGraphOutArcList(G, n3, 0);
kpeter@374
    74
kpeter@374
    75
  checkGraphInArcList(G, n1, 1);
kpeter@374
    76
  checkGraphInArcList(G, n2, 1);
kpeter@374
    77
  checkGraphInArcList(G, n3, 2);
kpeter@374
    78
kpeter@374
    79
  checkGraphConArcList(G, 4);
kpeter@374
    80
kpeter@374
    81
  checkNodeIds(G);
kpeter@374
    82
  checkArcIds(G);
kpeter@374
    83
  checkGraphNodeMap(G);
kpeter@374
    84
  checkGraphArcMap(G);
kpeter@374
    85
}
kpeter@374
    86
kpeter@374
    87
template <class Digraph>
kpeter@374
    88
void checkDigraphSplit() {
kpeter@374
    89
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
    90
kpeter@374
    91
  Digraph G;
kpeter@374
    92
  Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
kpeter@374
    93
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
kpeter@374
    94
      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
kpeter@374
    95
kpeter@374
    96
  Node n4 = G.split(n2);
kpeter@374
    97
kpeter@374
    98
  check(G.target(OutArcIt(G, n2)) == n4 &&
kpeter@374
    99
        G.source(InArcIt(G, n4)) == n2,
kpeter@374
   100
        "Wrong split.");
kpeter@374
   101
kpeter@374
   102
  checkGraphNodeList(G, 4);
kpeter@374
   103
  checkGraphArcList(G, 5);
kpeter@374
   104
kpeter@374
   105
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   106
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   107
  checkGraphOutArcList(G, n3, 0);
kpeter@374
   108
  checkGraphOutArcList(G, n4, 3);
kpeter@374
   109
kpeter@374
   110
  checkGraphInArcList(G, n1, 1);
kpeter@374
   111
  checkGraphInArcList(G, n2, 1);
kpeter@374
   112
  checkGraphInArcList(G, n3, 2);
kpeter@374
   113
  checkGraphInArcList(G, n4, 1);
kpeter@374
   114
kpeter@374
   115
  checkGraphConArcList(G, 5);
kpeter@374
   116
}
kpeter@374
   117
kpeter@374
   118
template <class Digraph>
kpeter@374
   119
void checkDigraphAlter() {
kpeter@374
   120
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
   121
kpeter@374
   122
  Digraph G;
kpeter@374
   123
  Node n1 = G.addNode(), n2 = G.addNode(),
kpeter@374
   124
       n3 = G.addNode(), n4 = G.addNode();
kpeter@374
   125
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
kpeter@374
   126
      a3 = G.addArc(n4, n3), a4 = G.addArc(n4, n3),
kpeter@374
   127
      a5 = G.addArc(n2, n4);
kpeter@374
   128
kpeter@374
   129
  checkGraphNodeList(G, 4);
kpeter@374
   130
  checkGraphArcList(G, 5);
kpeter@374
   131
kpeter@374
   132
  // Check changeSource() and changeTarget()
kpeter@374
   133
  G.changeTarget(a4, n1);
kpeter@374
   134
kpeter@374
   135
  checkGraphNodeList(G, 4);
kpeter@374
   136
  checkGraphArcList(G, 5);
kpeter@374
   137
kpeter@374
   138
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   139
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   140
  checkGraphOutArcList(G, n3, 0);
kpeter@374
   141
  checkGraphOutArcList(G, n4, 3);
kpeter@374
   142
kpeter@374
   143
  checkGraphInArcList(G, n1, 2);
kpeter@374
   144
  checkGraphInArcList(G, n2, 1);
kpeter@374
   145
  checkGraphInArcList(G, n3, 1);
kpeter@374
   146
  checkGraphInArcList(G, n4, 1);
kpeter@374
   147
kpeter@374
   148
  checkGraphConArcList(G, 5);
kpeter@374
   149
kpeter@374
   150
  G.changeSource(a4, n3);
kpeter@374
   151
kpeter@374
   152
  checkGraphNodeList(G, 4);
kpeter@374
   153
  checkGraphArcList(G, 5);
kpeter@374
   154
kpeter@374
   155
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   156
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   157
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   158
  checkGraphOutArcList(G, n4, 2);
kpeter@374
   159
kpeter@374
   160
  checkGraphInArcList(G, n1, 2);
kpeter@374
   161
  checkGraphInArcList(G, n2, 1);
kpeter@374
   162
  checkGraphInArcList(G, n3, 1);
kpeter@374
   163
  checkGraphInArcList(G, n4, 1);
kpeter@374
   164
kpeter@374
   165
  checkGraphConArcList(G, 5);
kpeter@374
   166
kpeter@374
   167
  // Check contract()
kpeter@374
   168
  G.contract(n2, n4, false);
kpeter@374
   169
kpeter@374
   170
  checkGraphNodeList(G, 3);
kpeter@374
   171
  checkGraphArcList(G, 5);
kpeter@374
   172
kpeter@374
   173
  checkGraphOutArcList(G, n1, 1);
kpeter@374
   174
  checkGraphOutArcList(G, n2, 3);
kpeter@374
   175
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   176
kpeter@374
   177
  checkGraphInArcList(G, n1, 2);
kpeter@374
   178
  checkGraphInArcList(G, n2, 2);
kpeter@374
   179
  checkGraphInArcList(G, n3, 1);
kpeter@374
   180
kpeter@374
   181
  checkGraphConArcList(G, 5);
kpeter@374
   182
kpeter@374
   183
  G.contract(n2, n1);
kpeter@374
   184
kpeter@374
   185
  checkGraphNodeList(G, 2);
kpeter@374
   186
  checkGraphArcList(G, 3);
kpeter@374
   187
kpeter@374
   188
  checkGraphOutArcList(G, n2, 2);
kpeter@374
   189
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   190
kpeter@374
   191
  checkGraphInArcList(G, n2, 2);
kpeter@374
   192
  checkGraphInArcList(G, n3, 1);
kpeter@374
   193
kpeter@374
   194
  checkGraphConArcList(G, 3);
kpeter@374
   195
}
kpeter@374
   196
kpeter@374
   197
template <class Digraph>
kpeter@374
   198
void checkDigraphErase() {
kpeter@374
   199
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
   200
kpeter@374
   201
  Digraph G;
kpeter@374
   202
  Node n1 = G.addNode(), n2 = G.addNode(),
kpeter@374
   203
       n3 = G.addNode(), n4 = G.addNode();
kpeter@374
   204
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n4, n1),
kpeter@374
   205
      a3 = G.addArc(n4, n3), a4 = G.addArc(n3, n1),
kpeter@374
   206
      a5 = G.addArc(n2, n4);
kpeter@374
   207
kpeter@374
   208
  // Check arc deletion
kpeter@374
   209
  G.erase(a1);
kpeter@374
   210
kpeter@374
   211
  checkGraphNodeList(G, 4);
kpeter@374
   212
  checkGraphArcList(G, 4);
kpeter@374
   213
kpeter@374
   214
  checkGraphOutArcList(G, n1, 0);
kpeter@374
   215
  checkGraphOutArcList(G, n2, 1);
kpeter@374
   216
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   217
  checkGraphOutArcList(G, n4, 2);
kpeter@374
   218
kpeter@374
   219
  checkGraphInArcList(G, n1, 2);
kpeter@374
   220
  checkGraphInArcList(G, n2, 0);
kpeter@374
   221
  checkGraphInArcList(G, n3, 1);
kpeter@374
   222
  checkGraphInArcList(G, n4, 1);
kpeter@374
   223
kpeter@374
   224
  checkGraphConArcList(G, 4);
kpeter@374
   225
kpeter@374
   226
  // Check node deletion
kpeter@374
   227
  G.erase(n4);
kpeter@374
   228
kpeter@374
   229
  checkGraphNodeList(G, 3);
kpeter@374
   230
  checkGraphArcList(G, 1);
kpeter@374
   231
kpeter@374
   232
  checkGraphOutArcList(G, n1, 0);
kpeter@374
   233
  checkGraphOutArcList(G, n2, 0);
kpeter@374
   234
  checkGraphOutArcList(G, n3, 1);
kpeter@374
   235
  checkGraphOutArcList(G, n4, 0);
kpeter@374
   236
kpeter@374
   237
  checkGraphInArcList(G, n1, 1);
kpeter@374
   238
  checkGraphInArcList(G, n2, 0);
kpeter@374
   239
  checkGraphInArcList(G, n3, 0);
kpeter@374
   240
  checkGraphInArcList(G, n4, 0);
kpeter@374
   241
kpeter@374
   242
  checkGraphConArcList(G, 1);
kpeter@374
   243
}
kpeter@374
   244
kpeter@374
   245
kpeter@374
   246
template <class Digraph>
kpeter@374
   247
void checkDigraphSnapshot() {
kpeter@374
   248
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@374
   249
kpeter@374
   250
  Digraph G;
kpeter@374
   251
  Node n1 = G.addNode(), n2 = G.addNode(), n3 = G.addNode();
kpeter@374
   252
  Arc a1 = G.addArc(n1, n2), a2 = G.addArc(n2, n1),
kpeter@374
   253
      a3 = G.addArc(n2, n3), a4 = G.addArc(n2, n3);
kpeter@374
   254
kpeter@374
   255
  typename Digraph::Snapshot snapshot(G);
kpeter@374
   256
kpeter@374
   257
  Node n = G.addNode();
kpeter@374
   258
  G.addArc(n3, n);
kpeter@374
   259
  G.addArc(n, n3);
kpeter@374
   260
kpeter@374
   261
  checkGraphNodeList(G, 4);
kpeter@374
   262
  checkGraphArcList(G, 6);
kpeter@374
   263
kpeter@374
   264
  snapshot.restore();
kpeter@374
   265
deba@228
   266
  checkGraphNodeList(G, 3);
deba@228
   267
  checkGraphArcList(G, 4);
deba@228
   268
deba@228
   269
  checkGraphOutArcList(G, n1, 1);
deba@228
   270
  checkGraphOutArcList(G, n2, 3);
deba@228
   271
  checkGraphOutArcList(G, n3, 0);
deba@228
   272
deba@228
   273
  checkGraphInArcList(G, n1, 1);
deba@228
   274
  checkGraphInArcList(G, n2, 1);
deba@228
   275
  checkGraphInArcList(G, n3, 2);
deba@228
   276
deba@228
   277
  checkGraphConArcList(G, 4);
deba@228
   278
deba@228
   279
  checkNodeIds(G);
deba@228
   280
  checkArcIds(G);
deba@228
   281
  checkGraphNodeMap(G);
deba@228
   282
  checkGraphArcMap(G);
deba@228
   283
kpeter@374
   284
  G.addNode();
kpeter@374
   285
  snapshot.save(G);
kpeter@374
   286
kpeter@374
   287
  G.addArc(G.addNode(), G.addNode());
kpeter@374
   288
kpeter@374
   289
  snapshot.restore();
kpeter@740
   290
  snapshot.save(G);
kpeter@740
   291
kpeter@740
   292
  checkGraphNodeList(G, 4);
kpeter@740
   293
  checkGraphArcList(G, 4);
kpeter@740
   294
kpeter@740
   295
  G.addArc(G.addNode(), G.addNode());
kpeter@740
   296
kpeter@740
   297
  snapshot.restore();
kpeter@374
   298
kpeter@374
   299
  checkGraphNodeList(G, 4);
kpeter@374
   300
  checkGraphArcList(G, 4);
deba@228
   301
}
deba@228
   302
deba@228
   303
void checkConcepts() {
kpeter@171
   304
  { // Checking digraph components
deba@57
   305
    checkConcept<BaseDigraphComponent, BaseDigraphComponent >();
deba@57
   306
alpar@209
   307
    checkConcept<IDableDigraphComponent<>,
deba@57
   308
      IDableDigraphComponent<> >();
deba@57
   309
alpar@209
   310
    checkConcept<IterableDigraphComponent<>,
deba@57
   311
      IterableDigraphComponent<> >();
deba@57
   312
alpar@209
   313
    checkConcept<MappableDigraphComponent<>,
deba@57
   314
      MappableDigraphComponent<> >();
deba@57
   315
  }
kpeter@171
   316
  { // Checking skeleton digraph
deba@57
   317
    checkConcept<Digraph, Digraph>();
deba@57
   318
  }
kpeter@171
   319
  { // Checking ListDigraph
kpeter@171
   320
    checkConcept<Digraph, ListDigraph>();
deba@57
   321
    checkConcept<AlterableDigraphComponent<>, ListDigraph>();
deba@57
   322
    checkConcept<ExtendableDigraphComponent<>, ListDigraph>();
deba@57
   323
    checkConcept<ClearableDigraphComponent<>, ListDigraph>();
deba@57
   324
    checkConcept<ErasableDigraphComponent<>, ListDigraph>();
kpeter@171
   325
  }
kpeter@171
   326
  { // Checking SmartDigraph
kpeter@171
   327
    checkConcept<Digraph, SmartDigraph>();
kpeter@171
   328
    checkConcept<AlterableDigraphComponent<>, SmartDigraph>();
kpeter@171
   329
    checkConcept<ExtendableDigraphComponent<>, SmartDigraph>();
kpeter@171
   330
    checkConcept<ClearableDigraphComponent<>, SmartDigraph>();
kpeter@171
   331
  }
kpeter@774
   332
  { // Checking StaticDigraph
kpeter@774
   333
    checkConcept<Digraph, StaticDigraph>();
kpeter@774
   334
    checkConcept<ClearableDigraphComponent<>, StaticDigraph>();
kpeter@774
   335
  }
kpeter@354
   336
  { // Checking FullDigraph
kpeter@354
   337
    checkConcept<Digraph, FullDigraph>();
kpeter@354
   338
  }
kpeter@171
   339
}
deba@57
   340
kpeter@171
   341
template <typename Digraph>
deba@228
   342
void checkDigraphValidity() {
kpeter@171
   343
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
   344
  Digraph g;
kpeter@171
   345
kpeter@171
   346
  Node
kpeter@171
   347
    n1 = g.addNode(),
kpeter@171
   348
    n2 = g.addNode(),
kpeter@171
   349
    n3 = g.addNode();
kpeter@171
   350
kpeter@171
   351
  Arc
kpeter@171
   352
    e1 = g.addArc(n1, n2),
kpeter@171
   353
    e2 = g.addArc(n2, n3);
kpeter@171
   354
kpeter@171
   355
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   356
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   357
kpeter@171
   358
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   359
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   360
}
kpeter@171
   361
kpeter@171
   362
template <typename Digraph>
deba@228
   363
void checkDigraphValidityErase() {
kpeter@171
   364
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
kpeter@171
   365
  Digraph g;
kpeter@171
   366
kpeter@171
   367
  Node
kpeter@171
   368
    n1 = g.addNode(),
kpeter@171
   369
    n2 = g.addNode(),
kpeter@171
   370
    n3 = g.addNode();
kpeter@171
   371
kpeter@171
   372
  Arc
kpeter@171
   373
    e1 = g.addArc(n1, n2),
kpeter@171
   374
    e2 = g.addArc(n2, n3);
kpeter@171
   375
kpeter@171
   376
  check(g.valid(n1), "Wrong validity check");
kpeter@171
   377
  check(g.valid(e1), "Wrong validity check");
kpeter@171
   378
kpeter@171
   379
  g.erase(n1);
kpeter@171
   380
kpeter@171
   381
  check(!g.valid(n1), "Wrong validity check");
kpeter@171
   382
  check(g.valid(n2), "Wrong validity check");
kpeter@171
   383
  check(g.valid(n3), "Wrong validity check");
kpeter@171
   384
  check(!g.valid(e1), "Wrong validity check");
kpeter@171
   385
  check(g.valid(e2), "Wrong validity check");
kpeter@171
   386
kpeter@171
   387
  check(!g.valid(g.nodeFromId(-1)), "Wrong validity check");
kpeter@171
   388
  check(!g.valid(g.arcFromId(-1)), "Wrong validity check");
kpeter@171
   389
}
kpeter@171
   390
kpeter@774
   391
void checkStaticDigraph() {
kpeter@774
   392
  SmartDigraph g;
kpeter@774
   393
  SmartDigraph::NodeMap<StaticDigraph::Node> nref(g);
kpeter@774
   394
  SmartDigraph::ArcMap<StaticDigraph::Arc> aref(g);
alpar@877
   395
kpeter@774
   396
  StaticDigraph G;
alpar@877
   397
kpeter@774
   398
  checkGraphNodeList(G, 0);
kpeter@774
   399
  checkGraphArcList(G, 0);
kpeter@774
   400
kpeter@774
   401
  G.build(g, nref, aref);
kpeter@774
   402
kpeter@774
   403
  checkGraphNodeList(G, 0);
kpeter@774
   404
  checkGraphArcList(G, 0);
kpeter@774
   405
kpeter@774
   406
  SmartDigraph::Node
kpeter@774
   407
    n1 = g.addNode(),
kpeter@774
   408
    n2 = g.addNode(),
kpeter@774
   409
    n3 = g.addNode();
kpeter@774
   410
kpeter@774
   411
  G.build(g, nref, aref);
kpeter@774
   412
kpeter@774
   413
  checkGraphNodeList(G, 3);
kpeter@774
   414
  checkGraphArcList(G, 0);
kpeter@774
   415
kpeter@774
   416
  SmartDigraph::Arc a1 = g.addArc(n1, n2);
kpeter@774
   417
kpeter@774
   418
  G.build(g, nref, aref);
kpeter@774
   419
kpeter@774
   420
  check(G.source(aref[a1]) == nref[n1] && G.target(aref[a1]) == nref[n2],
kpeter@774
   421
        "Wrong arc or wrong references");
kpeter@774
   422
  checkGraphNodeList(G, 3);
kpeter@774
   423
  checkGraphArcList(G, 1);
kpeter@774
   424
kpeter@774
   425
  checkGraphOutArcList(G, nref[n1], 1);
kpeter@774
   426
  checkGraphOutArcList(G, nref[n2], 0);
kpeter@774
   427
  checkGraphOutArcList(G, nref[n3], 0);
kpeter@774
   428
kpeter@774
   429
  checkGraphInArcList(G, nref[n1], 0);
kpeter@774
   430
  checkGraphInArcList(G, nref[n2], 1);
kpeter@774
   431
  checkGraphInArcList(G, nref[n3], 0);
kpeter@774
   432
kpeter@774
   433
  checkGraphConArcList(G, 1);
kpeter@774
   434
kpeter@774
   435
  SmartDigraph::Arc
kpeter@774
   436
    a2 = g.addArc(n2, n1),
kpeter@774
   437
    a3 = g.addArc(n2, n3),
kpeter@774
   438
    a4 = g.addArc(n2, n3);
kpeter@774
   439
kpeter@774
   440
  digraphCopy(g, G).nodeRef(nref).run();
kpeter@774
   441
kpeter@774
   442
  checkGraphNodeList(G, 3);
kpeter@774
   443
  checkGraphArcList(G, 4);
kpeter@774
   444
kpeter@774
   445
  checkGraphOutArcList(G, nref[n1], 1);
kpeter@774
   446
  checkGraphOutArcList(G, nref[n2], 3);
kpeter@774
   447
  checkGraphOutArcList(G, nref[n3], 0);
kpeter@774
   448
kpeter@774
   449
  checkGraphInArcList(G, nref[n1], 1);
kpeter@774
   450
  checkGraphInArcList(G, nref[n2], 1);
kpeter@774
   451
  checkGraphInArcList(G, nref[n3], 2);
kpeter@774
   452
kpeter@774
   453
  checkGraphConArcList(G, 4);
kpeter@774
   454
kpeter@777
   455
  std::vector<std::pair<int,int> > arcs;
kpeter@777
   456
  arcs.push_back(std::make_pair(0,1));
kpeter@777
   457
  arcs.push_back(std::make_pair(0,2));
kpeter@777
   458
  arcs.push_back(std::make_pair(1,3));
kpeter@777
   459
  arcs.push_back(std::make_pair(1,2));
kpeter@777
   460
  arcs.push_back(std::make_pair(3,0));
kpeter@777
   461
  arcs.push_back(std::make_pair(3,3));
kpeter@777
   462
  arcs.push_back(std::make_pair(4,2));
kpeter@777
   463
  arcs.push_back(std::make_pair(4,3));
kpeter@777
   464
  arcs.push_back(std::make_pair(4,1));
kpeter@777
   465
kpeter@777
   466
  G.build(6, arcs.begin(), arcs.end());
alpar@877
   467
kpeter@777
   468
  checkGraphNodeList(G, 6);
kpeter@777
   469
  checkGraphArcList(G, 9);
kpeter@777
   470
kpeter@777
   471
  checkGraphOutArcList(G, G.node(0), 2);
kpeter@777
   472
  checkGraphOutArcList(G, G.node(1), 2);
kpeter@777
   473
  checkGraphOutArcList(G, G.node(2), 0);
kpeter@777
   474
  checkGraphOutArcList(G, G.node(3), 2);
kpeter@777
   475
  checkGraphOutArcList(G, G.node(4), 3);
kpeter@777
   476
  checkGraphOutArcList(G, G.node(5), 0);
kpeter@777
   477
kpeter@777
   478
  checkGraphInArcList(G, G.node(0), 1);
kpeter@777
   479
  checkGraphInArcList(G, G.node(1), 2);
kpeter@777
   480
  checkGraphInArcList(G, G.node(2), 3);
kpeter@777
   481
  checkGraphInArcList(G, G.node(3), 3);
kpeter@777
   482
  checkGraphInArcList(G, G.node(4), 0);
kpeter@777
   483
  checkGraphInArcList(G, G.node(5), 0);
kpeter@777
   484
kpeter@777
   485
  checkGraphConArcList(G, 9);
kpeter@777
   486
kpeter@774
   487
  checkNodeIds(G);
kpeter@774
   488
  checkArcIds(G);
kpeter@774
   489
  checkGraphNodeMap(G);
kpeter@774
   490
  checkGraphArcMap(G);
alpar@877
   491
kpeter@776
   492
  int n = G.nodeNum();
kpeter@776
   493
  int m = G.arcNum();
kpeter@776
   494
  check(G.index(G.node(n-1)) == n-1, "Wrong index.");
kpeter@776
   495
  check(G.index(G.arc(m-1)) == m-1, "Wrong index.");
kpeter@774
   496
}
kpeter@774
   497
alpar@375
   498
void checkFullDigraph(int num) {
alpar@375
   499
  typedef FullDigraph Digraph;
alpar@375
   500
  DIGRAPH_TYPEDEFS(Digraph);
kpeter@737
   501
alpar@375
   502
  Digraph G(num);
kpeter@737
   503
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
kpeter@737
   504
kpeter@737
   505
  G.resize(num);
kpeter@737
   506
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
alpar@375
   507
alpar@375
   508
  checkGraphNodeList(G, num);
alpar@375
   509
  checkGraphArcList(G, num * num);
alpar@375
   510
alpar@375
   511
  for (NodeIt n(G); n != INVALID; ++n) {
alpar@375
   512
    checkGraphOutArcList(G, n, num);
alpar@375
   513
    checkGraphInArcList(G, n, num);
alpar@375
   514
  }
alpar@375
   515
alpar@375
   516
  checkGraphConArcList(G, num * num);
alpar@375
   517
alpar@375
   518
  checkNodeIds(G);
alpar@375
   519
  checkArcIds(G);
alpar@375
   520
  checkGraphNodeMap(G);
alpar@375
   521
  checkGraphArcMap(G);
alpar@375
   522
alpar@375
   523
  for (int i = 0; i < G.nodeNum(); ++i) {
alpar@375
   524
    check(G.index(G(i)) == i, "Wrong index");
alpar@375
   525
  }
alpar@375
   526
alpar@375
   527
  for (NodeIt s(G); s != INVALID; ++s) {
alpar@375
   528
    for (NodeIt t(G); t != INVALID; ++t) {
alpar@375
   529
      Arc a = G.arc(s, t);
alpar@375
   530
      check(G.source(a) == s && G.target(a) == t, "Wrong arc lookup");
alpar@375
   531
    }
alpar@375
   532
  }
alpar@375
   533
}
alpar@375
   534
deba@228
   535
void checkDigraphs() {
kpeter@171
   536
  { // Checking ListDigraph
kpeter@374
   537
    checkDigraphBuild<ListDigraph>();
kpeter@374
   538
    checkDigraphSplit<ListDigraph>();
kpeter@374
   539
    checkDigraphAlter<ListDigraph>();
kpeter@374
   540
    checkDigraphErase<ListDigraph>();
kpeter@374
   541
    checkDigraphSnapshot<ListDigraph>();
deba@228
   542
    checkDigraphValidityErase<ListDigraph>();
deba@57
   543
  }
kpeter@171
   544
  { // Checking SmartDigraph
kpeter@374
   545
    checkDigraphBuild<SmartDigraph>();
kpeter@374
   546
    checkDigraphSplit<SmartDigraph>();
kpeter@374
   547
    checkDigraphSnapshot<SmartDigraph>();
deba@228
   548
    checkDigraphValidity<SmartDigraph>();
kpeter@171
   549
  }
kpeter@774
   550
  { // Checking StaticDigraph
kpeter@774
   551
    checkStaticDigraph();
kpeter@774
   552
  }
deba@353
   553
  { // Checking FullDigraph
deba@353
   554
    checkFullDigraph(8);
deba@353
   555
  }
kpeter@171
   556
}
deba@57
   557
kpeter@171
   558
int main() {
deba@228
   559
  checkDigraphs();
deba@228
   560
  checkConcepts();
deba@57
   561
  return 0;
deba@57
   562
}