test/adaptors_test.cc
author Balazs Dezso <deba@inf.elte.hu>
Sat, 18 Apr 2009 21:01:12 +0200
changeset 644 2ca0cdb5f366
parent 487 acfb0f24d178
child 550 c35afa9e89e7
child 1156 939d747055cd
child 1157 761fe0846f49
permissions -rw-r--r--
Fix in HaoOrlin (#264)
deba@432
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@430
     2
 *
deba@432
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@430
     4
 *
alpar@463
     5
 * Copyright (C) 2003-2009
deba@430
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@430
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@430
     8
 *
deba@430
     9
 * Permission to use, modify and distribute this software is granted
deba@430
    10
 * provided that this copyright notice appears in all copies. For
deba@430
    11
 * precise terms see the accompanying LICENSE file.
deba@430
    12
 *
deba@430
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@430
    14
 * express or implied, and with no claim as to its suitability for any
deba@430
    15
 * purpose.
deba@430
    16
 *
deba@430
    17
 */
deba@430
    18
kpeter@486
    19
#include <iostream>
kpeter@486
    20
#include <limits>
deba@430
    21
kpeter@486
    22
#include <lemon/list_graph.h>
kpeter@486
    23
#include <lemon/grid_graph.h>
deba@430
    24
#include <lemon/bfs.h>
deba@430
    25
#include <lemon/path.h>
deba@430
    26
kpeter@486
    27
#include <lemon/concepts/digraph.h>
kpeter@486
    28
#include <lemon/concepts/graph.h>
kpeter@486
    29
#include <lemon/concepts/graph_components.h>
kpeter@486
    30
#include <lemon/concepts/maps.h>
kpeter@486
    31
#include <lemon/concept_check.h>
kpeter@486
    32
kpeter@486
    33
#include <lemon/adaptors.h>
kpeter@486
    34
kpeter@486
    35
#include "test/test_tools.h"
kpeter@486
    36
#include "test/graph_test.h"
deba@430
    37
deba@430
    38
using namespace lemon;
deba@430
    39
deba@432
    40
void checkReverseDigraph() {
kpeter@486
    41
  // Check concepts
deba@432
    42
  checkConcept<concepts::Digraph, ReverseDigraph<concepts::Digraph> >();
kpeter@486
    43
  checkConcept<concepts::Digraph, ReverseDigraph<ListDigraph> >();
kpeter@486
    44
  checkConcept<concepts::AlterableDigraphComponent<>,
kpeter@486
    45
               ReverseDigraph<ListDigraph> >();
kpeter@486
    46
  checkConcept<concepts::ExtendableDigraphComponent<>,
kpeter@486
    47
               ReverseDigraph<ListDigraph> >();
kpeter@486
    48
  checkConcept<concepts::ErasableDigraphComponent<>,
kpeter@486
    49
               ReverseDigraph<ListDigraph> >();
kpeter@486
    50
  checkConcept<concepts::ClearableDigraphComponent<>,
kpeter@486
    51
               ReverseDigraph<ListDigraph> >();
deba@430
    52
kpeter@486
    53
  // Create a digraph and an adaptor
deba@430
    54
  typedef ListDigraph Digraph;
deba@432
    55
  typedef ReverseDigraph<Digraph> Adaptor;
deba@430
    56
deba@430
    57
  Digraph digraph;
deba@430
    58
  Adaptor adaptor(digraph);
deba@430
    59
kpeter@486
    60
  // Add nodes and arcs to the original digraph
deba@430
    61
  Digraph::Node n1 = digraph.addNode();
deba@430
    62
  Digraph::Node n2 = digraph.addNode();
deba@430
    63
  Digraph::Node n3 = digraph.addNode();
deba@430
    64
deba@430
    65
  Digraph::Arc a1 = digraph.addArc(n1, n2);
deba@430
    66
  Digraph::Arc a2 = digraph.addArc(n1, n3);
deba@430
    67
  Digraph::Arc a3 = digraph.addArc(n2, n3);
deba@432
    68
kpeter@486
    69
  // Check the adaptor
deba@430
    70
  checkGraphNodeList(adaptor, 3);
deba@430
    71
  checkGraphArcList(adaptor, 3);
deba@430
    72
  checkGraphConArcList(adaptor, 3);
deba@430
    73
deba@430
    74
  checkGraphOutArcList(adaptor, n1, 0);
deba@430
    75
  checkGraphOutArcList(adaptor, n2, 1);
deba@430
    76
  checkGraphOutArcList(adaptor, n3, 2);
deba@430
    77
deba@430
    78
  checkGraphInArcList(adaptor, n1, 2);
deba@430
    79
  checkGraphInArcList(adaptor, n2, 1);
deba@430
    80
  checkGraphInArcList(adaptor, n3, 0);
deba@430
    81
deba@430
    82
  checkNodeIds(adaptor);
deba@430
    83
  checkArcIds(adaptor);
deba@430
    84
deba@430
    85
  checkGraphNodeMap(adaptor);
deba@430
    86
  checkGraphArcMap(adaptor);
deba@430
    87
kpeter@486
    88
  // Check the orientation of the arcs
deba@430
    89
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
deba@430
    90
    check(adaptor.source(a) == digraph.target(a), "Wrong reverse");
deba@430
    91
    check(adaptor.target(a) == digraph.source(a), "Wrong reverse");
deba@430
    92
  }
kpeter@486
    93
kpeter@486
    94
  // Add and erase nodes and arcs in the digraph through the adaptor
kpeter@486
    95
  Adaptor::Node n4 = adaptor.addNode();
kpeter@486
    96
kpeter@486
    97
  Adaptor::Arc a4 = adaptor.addArc(n4, n3);
kpeter@486
    98
  Adaptor::Arc a5 = adaptor.addArc(n2, n4);
kpeter@486
    99
  Adaptor::Arc a6 = adaptor.addArc(n2, n4);
kpeter@486
   100
  Adaptor::Arc a7 = adaptor.addArc(n1, n4);
kpeter@486
   101
  Adaptor::Arc a8 = adaptor.addArc(n1, n2);
kpeter@486
   102
kpeter@486
   103
  adaptor.erase(a1);
kpeter@486
   104
  adaptor.erase(n3);
kpeter@486
   105
kpeter@486
   106
  // Check the adaptor
kpeter@486
   107
  checkGraphNodeList(adaptor, 3);
kpeter@486
   108
  checkGraphArcList(adaptor, 4);
kpeter@486
   109
  checkGraphConArcList(adaptor, 4);
kpeter@486
   110
kpeter@486
   111
  checkGraphOutArcList(adaptor, n1, 2);
kpeter@486
   112
  checkGraphOutArcList(adaptor, n2, 2);
kpeter@486
   113
  checkGraphOutArcList(adaptor, n4, 0);
kpeter@486
   114
kpeter@486
   115
  checkGraphInArcList(adaptor, n1, 0);
kpeter@486
   116
  checkGraphInArcList(adaptor, n2, 1);
kpeter@486
   117
  checkGraphInArcList(adaptor, n4, 3);
kpeter@486
   118
kpeter@486
   119
  checkNodeIds(adaptor);
kpeter@486
   120
  checkArcIds(adaptor);
kpeter@486
   121
kpeter@486
   122
  checkGraphNodeMap(adaptor);
kpeter@486
   123
  checkGraphArcMap(adaptor);
kpeter@486
   124
kpeter@486
   125
  // Check the digraph
kpeter@486
   126
  checkGraphNodeList(digraph, 3);
kpeter@486
   127
  checkGraphArcList(digraph, 4);
kpeter@486
   128
  checkGraphConArcList(digraph, 4);
kpeter@486
   129
kpeter@486
   130
  checkGraphOutArcList(digraph, n1, 0);
kpeter@486
   131
  checkGraphOutArcList(digraph, n2, 1);
kpeter@486
   132
  checkGraphOutArcList(digraph, n4, 3);
kpeter@486
   133
kpeter@486
   134
  checkGraphInArcList(digraph, n1, 2);
kpeter@486
   135
  checkGraphInArcList(digraph, n2, 2);
kpeter@486
   136
  checkGraphInArcList(digraph, n4, 0);
kpeter@486
   137
kpeter@486
   138
  checkNodeIds(digraph);
kpeter@486
   139
  checkArcIds(digraph);
kpeter@486
   140
kpeter@486
   141
  checkGraphNodeMap(digraph);
kpeter@486
   142
  checkGraphArcMap(digraph);
kpeter@486
   143
kpeter@486
   144
  // Check the conversion of nodes and arcs
kpeter@486
   145
  Digraph::Node nd = n4;
kpeter@486
   146
  nd = n4;
kpeter@486
   147
  Adaptor::Node na = n1;
kpeter@486
   148
  na = n2;
kpeter@486
   149
  Digraph::Arc ad = a4;
kpeter@486
   150
  ad = a5;
kpeter@486
   151
  Adaptor::Arc aa = a1;
kpeter@486
   152
  aa = a2;
deba@430
   153
}
deba@430
   154
deba@432
   155
void checkSubDigraph() {
kpeter@486
   156
  // Check concepts
kpeter@486
   157
  checkConcept<concepts::Digraph, SubDigraph<concepts::Digraph> >();
kpeter@486
   158
  checkConcept<concepts::Digraph, SubDigraph<ListDigraph> >();
kpeter@486
   159
  checkConcept<concepts::AlterableDigraphComponent<>,
kpeter@486
   160
               SubDigraph<ListDigraph> >();
kpeter@486
   161
  checkConcept<concepts::ExtendableDigraphComponent<>,
kpeter@486
   162
               SubDigraph<ListDigraph> >();
kpeter@486
   163
  checkConcept<concepts::ErasableDigraphComponent<>,
kpeter@486
   164
               SubDigraph<ListDigraph> >();
kpeter@486
   165
  checkConcept<concepts::ClearableDigraphComponent<>,
kpeter@486
   166
               SubDigraph<ListDigraph> >();
deba@430
   167
kpeter@486
   168
  // Create a digraph and an adaptor
deba@430
   169
  typedef ListDigraph Digraph;
deba@430
   170
  typedef Digraph::NodeMap<bool> NodeFilter;
deba@430
   171
  typedef Digraph::ArcMap<bool> ArcFilter;
deba@432
   172
  typedef SubDigraph<Digraph, NodeFilter, ArcFilter> Adaptor;
deba@430
   173
deba@430
   174
  Digraph digraph;
deba@430
   175
  NodeFilter node_filter(digraph);
deba@430
   176
  ArcFilter arc_filter(digraph);
deba@430
   177
  Adaptor adaptor(digraph, node_filter, arc_filter);
deba@430
   178
kpeter@486
   179
  // Add nodes and arcs to the original digraph and the adaptor
deba@430
   180
  Digraph::Node n1 = digraph.addNode();
deba@430
   181
  Digraph::Node n2 = digraph.addNode();
kpeter@486
   182
  Adaptor::Node n3 = adaptor.addNode();
kpeter@486
   183
kpeter@486
   184
  node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
deba@430
   185
deba@430
   186
  Digraph::Arc a1 = digraph.addArc(n1, n2);
deba@430
   187
  Digraph::Arc a2 = digraph.addArc(n1, n3);
kpeter@486
   188
  Adaptor::Arc a3 = adaptor.addArc(n2, n3);
deba@430
   189
deba@430
   190
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
alpar@463
   191
deba@430
   192
  checkGraphNodeList(adaptor, 3);
deba@430
   193
  checkGraphArcList(adaptor, 3);
deba@430
   194
  checkGraphConArcList(adaptor, 3);
deba@430
   195
deba@430
   196
  checkGraphOutArcList(adaptor, n1, 2);
deba@430
   197
  checkGraphOutArcList(adaptor, n2, 1);
deba@430
   198
  checkGraphOutArcList(adaptor, n3, 0);
deba@430
   199
deba@430
   200
  checkGraphInArcList(adaptor, n1, 0);
deba@430
   201
  checkGraphInArcList(adaptor, n2, 1);
deba@430
   202
  checkGraphInArcList(adaptor, n3, 2);
deba@430
   203
deba@430
   204
  checkNodeIds(adaptor);
deba@430
   205
  checkArcIds(adaptor);
deba@430
   206
deba@430
   207
  checkGraphNodeMap(adaptor);
deba@430
   208
  checkGraphArcMap(adaptor);
deba@430
   209
kpeter@486
   210
  // Hide an arc
kpeter@486
   211
  adaptor.status(a2, false);
kpeter@486
   212
  adaptor.disable(a3);
kpeter@486
   213
  if (!adaptor.status(a3)) adaptor.enable(a3);
deba@430
   214
deba@430
   215
  checkGraphNodeList(adaptor, 3);
deba@430
   216
  checkGraphArcList(adaptor, 2);
deba@430
   217
  checkGraphConArcList(adaptor, 2);
deba@430
   218
deba@430
   219
  checkGraphOutArcList(adaptor, n1, 1);
deba@430
   220
  checkGraphOutArcList(adaptor, n2, 1);
deba@430
   221
  checkGraphOutArcList(adaptor, n3, 0);
deba@430
   222
deba@430
   223
  checkGraphInArcList(adaptor, n1, 0);
deba@430
   224
  checkGraphInArcList(adaptor, n2, 1);
deba@430
   225
  checkGraphInArcList(adaptor, n3, 1);
deba@430
   226
deba@430
   227
  checkNodeIds(adaptor);
deba@430
   228
  checkArcIds(adaptor);
deba@430
   229
deba@430
   230
  checkGraphNodeMap(adaptor);
deba@430
   231
  checkGraphArcMap(adaptor);
deba@430
   232
kpeter@486
   233
  // Hide a node
kpeter@486
   234
  adaptor.status(n1, false);
kpeter@486
   235
  adaptor.disable(n3);
kpeter@486
   236
  if (!adaptor.status(n3)) adaptor.enable(n3);
kpeter@486
   237
kpeter@486
   238
  checkGraphNodeList(adaptor, 2);
kpeter@486
   239
  checkGraphArcList(adaptor, 1);
kpeter@486
   240
  checkGraphConArcList(adaptor, 1);
kpeter@486
   241
kpeter@486
   242
  checkGraphOutArcList(adaptor, n2, 1);
kpeter@486
   243
  checkGraphOutArcList(adaptor, n3, 0);
kpeter@486
   244
kpeter@486
   245
  checkGraphInArcList(adaptor, n2, 0);
kpeter@486
   246
  checkGraphInArcList(adaptor, n3, 1);
kpeter@486
   247
kpeter@486
   248
  checkNodeIds(adaptor);
kpeter@486
   249
  checkArcIds(adaptor);
kpeter@486
   250
kpeter@486
   251
  checkGraphNodeMap(adaptor);
kpeter@486
   252
  checkGraphArcMap(adaptor);
kpeter@486
   253
kpeter@486
   254
  // Hide all nodes and arcs
kpeter@486
   255
  node_filter[n1] = node_filter[n2] = node_filter[n3] = false;
kpeter@486
   256
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false;
kpeter@486
   257
kpeter@486
   258
  checkGraphNodeList(adaptor, 0);
kpeter@486
   259
  checkGraphArcList(adaptor, 0);
kpeter@486
   260
  checkGraphConArcList(adaptor, 0);
kpeter@486
   261
kpeter@486
   262
  checkNodeIds(adaptor);
kpeter@486
   263
  checkArcIds(adaptor);
kpeter@486
   264
kpeter@486
   265
  checkGraphNodeMap(adaptor);
kpeter@486
   266
  checkGraphArcMap(adaptor);
kpeter@486
   267
kpeter@486
   268
  // Check the conversion of nodes and arcs
kpeter@486
   269
  Digraph::Node nd = n3;
kpeter@486
   270
  nd = n3;
kpeter@486
   271
  Adaptor::Node na = n1;
kpeter@486
   272
  na = n2;
kpeter@486
   273
  Digraph::Arc ad = a3;
kpeter@486
   274
  ad = a3;
kpeter@486
   275
  Adaptor::Arc aa = a1;
kpeter@486
   276
  aa = a2;
kpeter@486
   277
}
kpeter@486
   278
kpeter@486
   279
void checkFilterNodes1() {
kpeter@486
   280
  // Check concepts
kpeter@486
   281
  checkConcept<concepts::Digraph, FilterNodes<concepts::Digraph> >();
kpeter@486
   282
  checkConcept<concepts::Digraph, FilterNodes<ListDigraph> >();
kpeter@486
   283
  checkConcept<concepts::AlterableDigraphComponent<>,
kpeter@486
   284
               FilterNodes<ListDigraph> >();
kpeter@486
   285
  checkConcept<concepts::ExtendableDigraphComponent<>,
kpeter@486
   286
               FilterNodes<ListDigraph> >();
kpeter@486
   287
  checkConcept<concepts::ErasableDigraphComponent<>,
kpeter@486
   288
               FilterNodes<ListDigraph> >();
kpeter@486
   289
  checkConcept<concepts::ClearableDigraphComponent<>,
kpeter@486
   290
               FilterNodes<ListDigraph> >();
kpeter@486
   291
kpeter@486
   292
  // Create a digraph and an adaptor
kpeter@486
   293
  typedef ListDigraph Digraph;
kpeter@486
   294
  typedef Digraph::NodeMap<bool> NodeFilter;
kpeter@486
   295
  typedef FilterNodes<Digraph, NodeFilter> Adaptor;
kpeter@486
   296
kpeter@486
   297
  Digraph digraph;
kpeter@486
   298
  NodeFilter node_filter(digraph);
kpeter@486
   299
  Adaptor adaptor(digraph, node_filter);
kpeter@486
   300
kpeter@486
   301
  // Add nodes and arcs to the original digraph and the adaptor
kpeter@486
   302
  Digraph::Node n1 = digraph.addNode();
kpeter@486
   303
  Digraph::Node n2 = digraph.addNode();
kpeter@486
   304
  Adaptor::Node n3 = adaptor.addNode();
kpeter@486
   305
kpeter@486
   306
  node_filter[n1] = node_filter[n2] = node_filter[n3] = true;
kpeter@486
   307
kpeter@486
   308
  Digraph::Arc a1 = digraph.addArc(n1, n2);
kpeter@486
   309
  Digraph::Arc a2 = digraph.addArc(n1, n3);
kpeter@486
   310
  Adaptor::Arc a3 = adaptor.addArc(n2, n3);
kpeter@486
   311
kpeter@486
   312
  checkGraphNodeList(adaptor, 3);
kpeter@486
   313
  checkGraphArcList(adaptor, 3);
kpeter@486
   314
  checkGraphConArcList(adaptor, 3);
kpeter@486
   315
kpeter@486
   316
  checkGraphOutArcList(adaptor, n1, 2);
kpeter@486
   317
  checkGraphOutArcList(adaptor, n2, 1);
kpeter@486
   318
  checkGraphOutArcList(adaptor, n3, 0);
kpeter@486
   319
kpeter@486
   320
  checkGraphInArcList(adaptor, n1, 0);
kpeter@486
   321
  checkGraphInArcList(adaptor, n2, 1);
kpeter@486
   322
  checkGraphInArcList(adaptor, n3, 2);
kpeter@486
   323
kpeter@486
   324
  checkNodeIds(adaptor);
kpeter@486
   325
  checkArcIds(adaptor);
kpeter@486
   326
kpeter@486
   327
  checkGraphNodeMap(adaptor);
kpeter@486
   328
  checkGraphArcMap(adaptor);
kpeter@486
   329
kpeter@486
   330
  // Hide a node
kpeter@486
   331
  adaptor.status(n1, false);
kpeter@486
   332
  adaptor.disable(n3);
kpeter@486
   333
  if (!adaptor.status(n3)) adaptor.enable(n3);
kpeter@486
   334
kpeter@486
   335
  checkGraphNodeList(adaptor, 2);
kpeter@486
   336
  checkGraphArcList(adaptor, 1);
kpeter@486
   337
  checkGraphConArcList(adaptor, 1);
kpeter@486
   338
kpeter@486
   339
  checkGraphOutArcList(adaptor, n2, 1);
kpeter@486
   340
  checkGraphOutArcList(adaptor, n3, 0);
kpeter@486
   341
kpeter@486
   342
  checkGraphInArcList(adaptor, n2, 0);
kpeter@486
   343
  checkGraphInArcList(adaptor, n3, 1);
kpeter@486
   344
kpeter@486
   345
  checkNodeIds(adaptor);
kpeter@486
   346
  checkArcIds(adaptor);
kpeter@486
   347
kpeter@486
   348
  checkGraphNodeMap(adaptor);
kpeter@486
   349
  checkGraphArcMap(adaptor);
kpeter@486
   350
kpeter@486
   351
  // Hide all nodes
kpeter@486
   352
  node_filter[n1] = node_filter[n2] = node_filter[n3] = false;
kpeter@486
   353
kpeter@486
   354
  checkGraphNodeList(adaptor, 0);
kpeter@486
   355
  checkGraphArcList(adaptor, 0);
kpeter@486
   356
  checkGraphConArcList(adaptor, 0);
kpeter@486
   357
kpeter@486
   358
  checkNodeIds(adaptor);
kpeter@486
   359
  checkArcIds(adaptor);
kpeter@486
   360
kpeter@486
   361
  checkGraphNodeMap(adaptor);
kpeter@486
   362
  checkGraphArcMap(adaptor);
kpeter@486
   363
kpeter@486
   364
  // Check the conversion of nodes and arcs
kpeter@486
   365
  Digraph::Node nd = n3;
kpeter@486
   366
  nd = n3;
kpeter@486
   367
  Adaptor::Node na = n1;
kpeter@486
   368
  na = n2;
kpeter@486
   369
  Digraph::Arc ad = a3;
kpeter@486
   370
  ad = a3;
kpeter@486
   371
  Adaptor::Arc aa = a1;
kpeter@486
   372
  aa = a2;
kpeter@486
   373
}
kpeter@486
   374
kpeter@486
   375
void checkFilterArcs() {
kpeter@486
   376
  // Check concepts
kpeter@486
   377
  checkConcept<concepts::Digraph, FilterArcs<concepts::Digraph> >();
kpeter@486
   378
  checkConcept<concepts::Digraph, FilterArcs<ListDigraph> >();
kpeter@486
   379
  checkConcept<concepts::AlterableDigraphComponent<>,
kpeter@486
   380
               FilterArcs<ListDigraph> >();
kpeter@486
   381
  checkConcept<concepts::ExtendableDigraphComponent<>,
kpeter@486
   382
               FilterArcs<ListDigraph> >();
kpeter@486
   383
  checkConcept<concepts::ErasableDigraphComponent<>,
kpeter@486
   384
               FilterArcs<ListDigraph> >();
kpeter@486
   385
  checkConcept<concepts::ClearableDigraphComponent<>,
kpeter@486
   386
               FilterArcs<ListDigraph> >();
kpeter@486
   387
kpeter@486
   388
  // Create a digraph and an adaptor
kpeter@486
   389
  typedef ListDigraph Digraph;
kpeter@486
   390
  typedef Digraph::ArcMap<bool> ArcFilter;
kpeter@486
   391
  typedef FilterArcs<Digraph, ArcFilter> Adaptor;
kpeter@486
   392
kpeter@486
   393
  Digraph digraph;
kpeter@486
   394
  ArcFilter arc_filter(digraph);
kpeter@486
   395
  Adaptor adaptor(digraph, arc_filter);
kpeter@486
   396
kpeter@486
   397
  // Add nodes and arcs to the original digraph and the adaptor
kpeter@486
   398
  Digraph::Node n1 = digraph.addNode();
kpeter@486
   399
  Digraph::Node n2 = digraph.addNode();
kpeter@486
   400
  Adaptor::Node n3 = adaptor.addNode();
kpeter@486
   401
kpeter@486
   402
  Digraph::Arc a1 = digraph.addArc(n1, n2);
kpeter@486
   403
  Digraph::Arc a2 = digraph.addArc(n1, n3);
kpeter@486
   404
  Adaptor::Arc a3 = adaptor.addArc(n2, n3);
kpeter@486
   405
kpeter@486
   406
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = true;
kpeter@486
   407
kpeter@486
   408
  checkGraphNodeList(adaptor, 3);
kpeter@486
   409
  checkGraphArcList(adaptor, 3);
kpeter@486
   410
  checkGraphConArcList(adaptor, 3);
kpeter@486
   411
kpeter@486
   412
  checkGraphOutArcList(adaptor, n1, 2);
kpeter@486
   413
  checkGraphOutArcList(adaptor, n2, 1);
kpeter@486
   414
  checkGraphOutArcList(adaptor, n3, 0);
kpeter@486
   415
kpeter@486
   416
  checkGraphInArcList(adaptor, n1, 0);
kpeter@486
   417
  checkGraphInArcList(adaptor, n2, 1);
kpeter@486
   418
  checkGraphInArcList(adaptor, n3, 2);
kpeter@486
   419
kpeter@486
   420
  checkNodeIds(adaptor);
kpeter@486
   421
  checkArcIds(adaptor);
kpeter@486
   422
kpeter@486
   423
  checkGraphNodeMap(adaptor);
kpeter@486
   424
  checkGraphArcMap(adaptor);
kpeter@486
   425
kpeter@486
   426
  // Hide an arc
kpeter@486
   427
  adaptor.status(a2, false);
kpeter@486
   428
  adaptor.disable(a3);
kpeter@486
   429
  if (!adaptor.status(a3)) adaptor.enable(a3);
kpeter@486
   430
kpeter@486
   431
  checkGraphNodeList(adaptor, 3);
kpeter@486
   432
  checkGraphArcList(adaptor, 2);
kpeter@486
   433
  checkGraphConArcList(adaptor, 2);
kpeter@486
   434
kpeter@486
   435
  checkGraphOutArcList(adaptor, n1, 1);
kpeter@486
   436
  checkGraphOutArcList(adaptor, n2, 1);
kpeter@486
   437
  checkGraphOutArcList(adaptor, n3, 0);
kpeter@486
   438
kpeter@486
   439
  checkGraphInArcList(adaptor, n1, 0);
kpeter@486
   440
  checkGraphInArcList(adaptor, n2, 1);
kpeter@486
   441
  checkGraphInArcList(adaptor, n3, 1);
kpeter@486
   442
kpeter@486
   443
  checkNodeIds(adaptor);
kpeter@486
   444
  checkArcIds(adaptor);
kpeter@486
   445
kpeter@486
   446
  checkGraphNodeMap(adaptor);
kpeter@486
   447
  checkGraphArcMap(adaptor);
kpeter@486
   448
kpeter@486
   449
  // Hide all arcs
deba@430
   450
  arc_filter[a1] = arc_filter[a2] = arc_filter[a3] = false;
deba@430
   451
deba@430
   452
  checkGraphNodeList(adaptor, 3);
deba@430
   453
  checkGraphArcList(adaptor, 0);
deba@430
   454
  checkGraphConArcList(adaptor, 0);
deba@430
   455
deba@430
   456
  checkNodeIds(adaptor);
deba@430
   457
  checkArcIds(adaptor);
deba@430
   458
deba@430
   459
  checkGraphNodeMap(adaptor);
deba@430
   460
  checkGraphArcMap(adaptor);
kpeter@486
   461
kpeter@486
   462
  // Check the conversion of nodes and arcs
kpeter@486
   463
  Digraph::Node nd = n3;
kpeter@486
   464
  nd = n3;
kpeter@486
   465
  Adaptor::Node na = n1;
kpeter@486
   466
  na = n2;
kpeter@486
   467
  Digraph::Arc ad = a3;
kpeter@486
   468
  ad = a3;
kpeter@486
   469
  Adaptor::Arc aa = a1;
kpeter@486
   470
  aa = a2;
deba@430
   471
}
deba@430
   472
deba@432
   473
void checkUndirector() {
kpeter@486
   474
  // Check concepts
deba@432
   475
  checkConcept<concepts::Graph, Undirector<concepts::Digraph> >();
kpeter@486
   476
  checkConcept<concepts::Graph, Undirector<ListDigraph> >();
kpeter@486
   477
  checkConcept<concepts::AlterableGraphComponent<>,
kpeter@486
   478
               Undirector<ListDigraph> >();
kpeter@486
   479
  checkConcept<concepts::ExtendableGraphComponent<>,
kpeter@486
   480
               Undirector<ListDigraph> >();
kpeter@486
   481
  checkConcept<concepts::ErasableGraphComponent<>,
kpeter@486
   482
               Undirector<ListDigraph> >();
kpeter@486
   483
  checkConcept<concepts::ClearableGraphComponent<>,
kpeter@486
   484
               Undirector<ListDigraph> >();
deba@430
   485
kpeter@486
   486
kpeter@486
   487
  // Create a digraph and an adaptor
deba@430
   488
  typedef ListDigraph Digraph;
deba@432
   489
  typedef Undirector<Digraph> Adaptor;
deba@430
   490
deba@430
   491
  Digraph digraph;
deba@430
   492
  Adaptor adaptor(digraph);
deba@430
   493
kpeter@486
   494
  // Add nodes and arcs/edges to the original digraph and the adaptor
deba@430
   495
  Digraph::Node n1 = digraph.addNode();
deba@430
   496
  Digraph::Node n2 = digraph.addNode();
kpeter@486
   497
  Adaptor::Node n3 = adaptor.addNode();
deba@430
   498
deba@430
   499
  Digraph::Arc a1 = digraph.addArc(n1, n2);
deba@430
   500
  Digraph::Arc a2 = digraph.addArc(n1, n3);
kpeter@486
   501
  Adaptor::Edge e3 = adaptor.addEdge(n2, n3);
deba@432
   502
kpeter@486
   503
  // Check the original digraph
kpeter@486
   504
  checkGraphNodeList(digraph, 3);
kpeter@486
   505
  checkGraphArcList(digraph, 3);
kpeter@486
   506
  checkGraphConArcList(digraph, 3);
kpeter@486
   507
kpeter@486
   508
  checkGraphOutArcList(digraph, n1, 2);
kpeter@486
   509
  checkGraphOutArcList(digraph, n2, 1);
kpeter@486
   510
  checkGraphOutArcList(digraph, n3, 0);
kpeter@486
   511
kpeter@486
   512
  checkGraphInArcList(digraph, n1, 0);
kpeter@486
   513
  checkGraphInArcList(digraph, n2, 1);
kpeter@486
   514
  checkGraphInArcList(digraph, n3, 2);
kpeter@486
   515
kpeter@486
   516
  checkNodeIds(digraph);
kpeter@486
   517
  checkArcIds(digraph);
kpeter@486
   518
kpeter@486
   519
  checkGraphNodeMap(digraph);
kpeter@486
   520
  checkGraphArcMap(digraph);
kpeter@486
   521
kpeter@486
   522
  // Check the adaptor
deba@430
   523
  checkGraphNodeList(adaptor, 3);
deba@430
   524
  checkGraphArcList(adaptor, 6);
deba@430
   525
  checkGraphEdgeList(adaptor, 3);
deba@430
   526
  checkGraphConArcList(adaptor, 6);
deba@430
   527
  checkGraphConEdgeList(adaptor, 3);
deba@430
   528
kpeter@486
   529
  checkGraphIncEdgeArcLists(adaptor, n1, 2);
kpeter@486
   530
  checkGraphIncEdgeArcLists(adaptor, n2, 2);
kpeter@486
   531
  checkGraphIncEdgeArcLists(adaptor, n3, 2);
deba@430
   532
deba@430
   533
  checkNodeIds(adaptor);
deba@430
   534
  checkArcIds(adaptor);
deba@430
   535
  checkEdgeIds(adaptor);
deba@430
   536
deba@430
   537
  checkGraphNodeMap(adaptor);
deba@430
   538
  checkGraphArcMap(adaptor);
deba@430
   539
  checkGraphEdgeMap(adaptor);
deba@430
   540
kpeter@486
   541
  // Check the edges of the adaptor
deba@430
   542
  for (Adaptor::EdgeIt e(adaptor); e != INVALID; ++e) {
deba@430
   543
    check(adaptor.u(e) == digraph.source(e), "Wrong undir");
deba@430
   544
    check(adaptor.v(e) == digraph.target(e), "Wrong undir");
deba@430
   545
  }
deba@430
   546
kpeter@486
   547
  // Check CombinedArcMap
kpeter@486
   548
  typedef Adaptor::CombinedArcMap
kpeter@486
   549
    <Digraph::ArcMap<int>, Digraph::ArcMap<int> > IntCombinedMap;
kpeter@486
   550
  typedef Adaptor::CombinedArcMap
kpeter@486
   551
    <Digraph::ArcMap<bool>, Digraph::ArcMap<bool> > BoolCombinedMap;
kpeter@486
   552
  checkConcept<concepts::ReferenceMap<Adaptor::Arc, int, int&, const int&>,
kpeter@486
   553
    IntCombinedMap>();
kpeter@486
   554
  checkConcept<concepts::ReferenceMap<Adaptor::Arc, bool, bool&, const bool&>,
kpeter@486
   555
    BoolCombinedMap>();
kpeter@486
   556
kpeter@486
   557
  Digraph::ArcMap<int> fw_map(digraph), bk_map(digraph);
kpeter@486
   558
  for (Digraph::ArcIt a(digraph); a != INVALID; ++a) {
kpeter@486
   559
    fw_map[a] = digraph.id(a);
kpeter@486
   560
    bk_map[a] = -digraph.id(a);
kpeter@486
   561
  }
kpeter@486
   562
kpeter@486
   563
  Adaptor::CombinedArcMap<Digraph::ArcMap<int>, Digraph::ArcMap<int> >
kpeter@486
   564
    comb_map(fw_map, bk_map);
kpeter@486
   565
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
kpeter@486
   566
    if (adaptor.source(a) == digraph.source(a)) {
kpeter@486
   567
      check(comb_map[a] == fw_map[a], "Wrong combined map");
kpeter@486
   568
    } else {
kpeter@486
   569
      check(comb_map[a] == bk_map[a], "Wrong combined map");
kpeter@486
   570
    }
kpeter@486
   571
  }
kpeter@486
   572
kpeter@486
   573
  // Check the conversion of nodes and arcs/edges
kpeter@486
   574
  Digraph::Node nd = n3;
kpeter@486
   575
  nd = n3;
kpeter@486
   576
  Adaptor::Node na = n1;
kpeter@486
   577
  na = n2;
kpeter@486
   578
  Digraph::Arc ad = e3;
kpeter@486
   579
  ad = e3;
kpeter@486
   580
  Adaptor::Edge ea = a1;
kpeter@486
   581
  ea = a2;
deba@430
   582
}
deba@430
   583
kpeter@487
   584
void checkResidualDigraph() {
kpeter@486
   585
  // Check concepts
kpeter@487
   586
  checkConcept<concepts::Digraph, ResidualDigraph<concepts::Digraph> >();
kpeter@487
   587
  checkConcept<concepts::Digraph, ResidualDigraph<ListDigraph> >();
deba@430
   588
kpeter@486
   589
  // Create a digraph and an adaptor
deba@430
   590
  typedef ListDigraph Digraph;
deba@430
   591
  typedef Digraph::ArcMap<int> IntArcMap;
kpeter@487
   592
  typedef ResidualDigraph<Digraph, IntArcMap> Adaptor;
deba@430
   593
deba@430
   594
  Digraph digraph;
deba@430
   595
  IntArcMap capacity(digraph), flow(digraph);
deba@430
   596
  Adaptor adaptor(digraph, capacity, flow);
deba@430
   597
deba@430
   598
  Digraph::Node n1 = digraph.addNode();
deba@430
   599
  Digraph::Node n2 = digraph.addNode();
deba@430
   600
  Digraph::Node n3 = digraph.addNode();
deba@430
   601
  Digraph::Node n4 = digraph.addNode();
deba@430
   602
deba@430
   603
  Digraph::Arc a1 = digraph.addArc(n1, n2);
deba@430
   604
  Digraph::Arc a2 = digraph.addArc(n1, n3);
deba@430
   605
  Digraph::Arc a3 = digraph.addArc(n1, n4);
deba@430
   606
  Digraph::Arc a4 = digraph.addArc(n2, n3);
deba@430
   607
  Digraph::Arc a5 = digraph.addArc(n2, n4);
deba@430
   608
  Digraph::Arc a6 = digraph.addArc(n3, n4);
deba@430
   609
deba@430
   610
  capacity[a1] = 8;
deba@430
   611
  capacity[a2] = 6;
deba@430
   612
  capacity[a3] = 4;
deba@430
   613
  capacity[a4] = 4;
deba@430
   614
  capacity[a5] = 6;
deba@430
   615
  capacity[a6] = 10;
deba@430
   616
kpeter@486
   617
  // Check the adaptor with various flow values
kpeter@486
   618
  for (Digraph::ArcIt a(digraph); a != INVALID; ++a) {
deba@430
   619
    flow[a] = 0;
deba@430
   620
  }
deba@432
   621
deba@430
   622
  checkGraphNodeList(adaptor, 4);
deba@430
   623
  checkGraphArcList(adaptor, 6);
deba@430
   624
  checkGraphConArcList(adaptor, 6);
deba@430
   625
deba@430
   626
  checkGraphOutArcList(adaptor, n1, 3);
deba@430
   627
  checkGraphOutArcList(adaptor, n2, 2);
deba@430
   628
  checkGraphOutArcList(adaptor, n3, 1);
deba@430
   629
  checkGraphOutArcList(adaptor, n4, 0);
deba@430
   630
deba@430
   631
  checkGraphInArcList(adaptor, n1, 0);
deba@430
   632
  checkGraphInArcList(adaptor, n2, 1);
deba@430
   633
  checkGraphInArcList(adaptor, n3, 2);
deba@430
   634
  checkGraphInArcList(adaptor, n4, 3);
deba@430
   635
kpeter@486
   636
  for (Digraph::ArcIt a(digraph); a != INVALID; ++a) {
deba@430
   637
    flow[a] = capacity[a] / 2;
deba@430
   638
  }
deba@432
   639
deba@430
   640
  checkGraphNodeList(adaptor, 4);
deba@430
   641
  checkGraphArcList(adaptor, 12);
deba@430
   642
  checkGraphConArcList(adaptor, 12);
deba@430
   643
deba@430
   644
  checkGraphOutArcList(adaptor, n1, 3);
deba@430
   645
  checkGraphOutArcList(adaptor, n2, 3);
deba@430
   646
  checkGraphOutArcList(adaptor, n3, 3);
deba@430
   647
  checkGraphOutArcList(adaptor, n4, 3);
deba@430
   648
deba@430
   649
  checkGraphInArcList(adaptor, n1, 3);
deba@430
   650
  checkGraphInArcList(adaptor, n2, 3);
deba@430
   651
  checkGraphInArcList(adaptor, n3, 3);
deba@430
   652
  checkGraphInArcList(adaptor, n4, 3);
deba@430
   653
deba@430
   654
  checkNodeIds(adaptor);
deba@430
   655
  checkArcIds(adaptor);
deba@430
   656
deba@430
   657
  checkGraphNodeMap(adaptor);
deba@430
   658
  checkGraphArcMap(adaptor);
deba@430
   659
kpeter@486
   660
  for (Digraph::ArcIt a(digraph); a != INVALID; ++a) {
deba@430
   661
    flow[a] = capacity[a];
deba@430
   662
  }
deba@432
   663
deba@430
   664
  checkGraphNodeList(adaptor, 4);
deba@430
   665
  checkGraphArcList(adaptor, 6);
deba@430
   666
  checkGraphConArcList(adaptor, 6);
deba@430
   667
deba@430
   668
  checkGraphOutArcList(adaptor, n1, 0);
deba@430
   669
  checkGraphOutArcList(adaptor, n2, 1);
deba@430
   670
  checkGraphOutArcList(adaptor, n3, 2);
deba@430
   671
  checkGraphOutArcList(adaptor, n4, 3);
deba@430
   672
deba@430
   673
  checkGraphInArcList(adaptor, n1, 3);
deba@430
   674
  checkGraphInArcList(adaptor, n2, 2);
deba@430
   675
  checkGraphInArcList(adaptor, n3, 1);
deba@430
   676
  checkGraphInArcList(adaptor, n4, 0);
deba@430
   677
kpeter@486
   678
  // Saturate all backward arcs
kpeter@486
   679
  // (set the flow to zero on all forward arcs)
deba@430
   680
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
kpeter@486
   681
    if (adaptor.backward(a))
kpeter@486
   682
      adaptor.augment(a, adaptor.residualCapacity(a));
deba@430
   683
  }
deba@430
   684
kpeter@486
   685
  checkGraphNodeList(adaptor, 4);
kpeter@486
   686
  checkGraphArcList(adaptor, 6);
kpeter@486
   687
  checkGraphConArcList(adaptor, 6);
kpeter@486
   688
kpeter@486
   689
  checkGraphOutArcList(adaptor, n1, 3);
kpeter@486
   690
  checkGraphOutArcList(adaptor, n2, 2);
kpeter@486
   691
  checkGraphOutArcList(adaptor, n3, 1);
kpeter@486
   692
  checkGraphOutArcList(adaptor, n4, 0);
kpeter@486
   693
kpeter@486
   694
  checkGraphInArcList(adaptor, n1, 0);
kpeter@486
   695
  checkGraphInArcList(adaptor, n2, 1);
kpeter@486
   696
  checkGraphInArcList(adaptor, n3, 2);
kpeter@486
   697
  checkGraphInArcList(adaptor, n4, 3);
kpeter@486
   698
kpeter@486
   699
  // Find maximum flow by augmenting along shortest paths
deba@430
   700
  int flow_value = 0;
kpeter@486
   701
  Adaptor::ResidualCapacity res_cap(adaptor);
deba@430
   702
  while (true) {
deba@432
   703
deba@430
   704
    Bfs<Adaptor> bfs(adaptor);
deba@430
   705
    bfs.run(n1, n4);
deba@432
   706
deba@430
   707
    if (!bfs.reached(n4)) break;
deba@430
   708
deba@430
   709
    Path<Adaptor> p = bfs.path(n4);
deba@432
   710
deba@430
   711
    int min = std::numeric_limits<int>::max();
deba@430
   712
    for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
kpeter@486
   713
      if (res_cap[a] < min) min = res_cap[a];
deba@430
   714
    }
deba@430
   715
deba@430
   716
    for (Path<Adaptor>::ArcIt a(p); a != INVALID; ++a) {
deba@430
   717
      adaptor.augment(a, min);
deba@430
   718
    }
deba@430
   719
    flow_value += min;
deba@430
   720
  }
deba@430
   721
deba@430
   722
  check(flow_value == 18, "Wrong flow with res graph adaptor");
deba@430
   723
kpeter@486
   724
  // Check forward() and backward()
kpeter@486
   725
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
kpeter@486
   726
    check(adaptor.forward(a) != adaptor.backward(a),
kpeter@486
   727
          "Wrong forward() or backward()");
kpeter@486
   728
    check((adaptor.forward(a) && adaptor.forward(Digraph::Arc(a)) == a) ||
kpeter@486
   729
          (adaptor.backward(a) && adaptor.backward(Digraph::Arc(a)) == a),
kpeter@486
   730
          "Wrong forward() or backward()");
kpeter@486
   731
  }
kpeter@486
   732
kpeter@486
   733
  // Check the conversion of nodes and arcs
kpeter@486
   734
  Digraph::Node nd = Adaptor::NodeIt(adaptor);
kpeter@486
   735
  nd = ++Adaptor::NodeIt(adaptor);
kpeter@486
   736
  Adaptor::Node na = n1;
kpeter@486
   737
  na = n2;
kpeter@486
   738
  Digraph::Arc ad = Adaptor::ArcIt(adaptor);
kpeter@486
   739
  ad = ++Adaptor::ArcIt(adaptor);
deba@430
   740
}
deba@430
   741
deba@432
   742
void checkSplitNodes() {
kpeter@486
   743
  // Check concepts
deba@432
   744
  checkConcept<concepts::Digraph, SplitNodes<concepts::Digraph> >();
kpeter@486
   745
  checkConcept<concepts::Digraph, SplitNodes<ListDigraph> >();
deba@430
   746
kpeter@486
   747
  // Create a digraph and an adaptor
deba@430
   748
  typedef ListDigraph Digraph;
deba@432
   749
  typedef SplitNodes<Digraph> Adaptor;
deba@430
   750
deba@430
   751
  Digraph digraph;
deba@430
   752
  Adaptor adaptor(digraph);
deba@430
   753
deba@430
   754
  Digraph::Node n1 = digraph.addNode();
deba@430
   755
  Digraph::Node n2 = digraph.addNode();
deba@430
   756
  Digraph::Node n3 = digraph.addNode();
deba@430
   757
deba@430
   758
  Digraph::Arc a1 = digraph.addArc(n1, n2);
deba@430
   759
  Digraph::Arc a2 = digraph.addArc(n1, n3);
deba@430
   760
  Digraph::Arc a3 = digraph.addArc(n2, n3);
deba@432
   761
deba@430
   762
  checkGraphNodeList(adaptor, 6);
deba@430
   763
  checkGraphArcList(adaptor, 6);
deba@430
   764
  checkGraphConArcList(adaptor, 6);
deba@430
   765
deba@430
   766
  checkGraphOutArcList(adaptor, adaptor.inNode(n1), 1);
deba@430
   767
  checkGraphOutArcList(adaptor, adaptor.outNode(n1), 2);
deba@430
   768
  checkGraphOutArcList(adaptor, adaptor.inNode(n2), 1);
deba@430
   769
  checkGraphOutArcList(adaptor, adaptor.outNode(n2), 1);
deba@430
   770
  checkGraphOutArcList(adaptor, adaptor.inNode(n3), 1);
deba@430
   771
  checkGraphOutArcList(adaptor, adaptor.outNode(n3), 0);
deba@430
   772
deba@430
   773
  checkGraphInArcList(adaptor, adaptor.inNode(n1), 0);
deba@430
   774
  checkGraphInArcList(adaptor, adaptor.outNode(n1), 1);
deba@430
   775
  checkGraphInArcList(adaptor, adaptor.inNode(n2), 1);
deba@430
   776
  checkGraphInArcList(adaptor, adaptor.outNode(n2), 1);
deba@430
   777
  checkGraphInArcList(adaptor, adaptor.inNode(n3), 2);
deba@430
   778
  checkGraphInArcList(adaptor, adaptor.outNode(n3), 1);
deba@430
   779
deba@430
   780
  checkNodeIds(adaptor);
deba@430
   781
  checkArcIds(adaptor);
deba@432
   782
deba@430
   783
  checkGraphNodeMap(adaptor);
deba@430
   784
  checkGraphArcMap(adaptor);
deba@430
   785
kpeter@486
   786
  // Check split
deba@430
   787
  for (Adaptor::ArcIt a(adaptor); a != INVALID; ++a) {
deba@430
   788
    if (adaptor.origArc(a)) {
deba@430
   789
      Digraph::Arc oa = a;
deba@432
   790
      check(adaptor.source(a) == adaptor.outNode(digraph.source(oa)),
deba@432
   791
            "Wrong split");
deba@432
   792
      check(adaptor.target(a) == adaptor.inNode(digraph.target(oa)),
deba@432
   793
            "Wrong split");
deba@430
   794
    } else {
deba@430
   795
      Digraph::Node on = a;
deba@430
   796
      check(adaptor.source(a) == adaptor.inNode(on), "Wrong split");
deba@430
   797
      check(adaptor.target(a) == adaptor.outNode(on), "Wrong split");
deba@430
   798
    }
deba@430
   799
  }
kpeter@486
   800
kpeter@486
   801
  // Check combined node map
kpeter@486
   802
  typedef Adaptor::CombinedNodeMap
kpeter@486
   803
    <Digraph::NodeMap<int>, Digraph::NodeMap<int> > IntCombinedNodeMap;
kpeter@486
   804
  typedef Adaptor::CombinedNodeMap
kpeter@486
   805
    <Digraph::NodeMap<bool>, Digraph::NodeMap<bool> > BoolCombinedNodeMap;
kpeter@486
   806
  checkConcept<concepts::ReferenceMap<Adaptor::Node, int, int&, const int&>,
kpeter@486
   807
    IntCombinedNodeMap>();
kpeter@486
   808
//checkConcept<concepts::ReferenceMap<Adaptor::Node, bool, bool&, const bool&>,
kpeter@486
   809
//  BoolCombinedNodeMap>();
kpeter@486
   810
  checkConcept<concepts::ReadWriteMap<Adaptor::Node, bool>,
kpeter@486
   811
    BoolCombinedNodeMap>();
kpeter@486
   812
kpeter@486
   813
  Digraph::NodeMap<int> in_map(digraph), out_map(digraph);
kpeter@486
   814
  for (Digraph::NodeIt n(digraph); n != INVALID; ++n) {
kpeter@486
   815
    in_map[n] = digraph.id(n);
kpeter@486
   816
    out_map[n] = -digraph.id(n);
kpeter@486
   817
  }
kpeter@486
   818
kpeter@486
   819
  Adaptor::CombinedNodeMap<Digraph::NodeMap<int>, Digraph::NodeMap<int> >
kpeter@486
   820
    node_map(in_map, out_map);
kpeter@486
   821
  for (Adaptor::NodeIt n(adaptor); n != INVALID; ++n) {
kpeter@486
   822
    if (adaptor.inNode(n)) {
kpeter@486
   823
      check(node_map[n] == in_map[n], "Wrong combined node map");
kpeter@486
   824
    } else {
kpeter@486
   825
      check(node_map[n] == out_map[n], "Wrong combined node map");
kpeter@486
   826
    }
kpeter@486
   827
  }
kpeter@486
   828
kpeter@486
   829
  // Check combined arc map
kpeter@486
   830
  typedef Adaptor::CombinedArcMap
kpeter@486
   831
    <Digraph::ArcMap<int>, Digraph::NodeMap<int> > IntCombinedArcMap;
kpeter@486
   832
  typedef Adaptor::CombinedArcMap
kpeter@486
   833
    <Digraph::ArcMap<bool>, Digraph::NodeMap<bool> > BoolCombinedArcMap;
kpeter@486
   834
  checkConcept<concepts::ReferenceMap<Adaptor::Arc, int, int&, const int&>,
kpeter@486
   835
    IntCombinedArcMap>();
kpeter@486
   836
//checkConcept<concepts::ReferenceMap<Adaptor::Arc, bool, bool&, const bool&>,
kpeter@486
   837
//  BoolCombinedArcMap>();
kpeter@486
   838
  checkConcept<concepts::ReadWriteMap<Adaptor::Arc, bool>,
kpeter@486
   839
    BoolCombinedArcMap>();
kpeter@486
   840
kpeter@486
   841
  Digraph::ArcMap<int> a_map(digraph);
kpeter@486
   842
  for (Digraph::ArcIt a(digraph); a != INVALID; ++a) {
kpeter@486
   843
    a_map[a] = digraph.id(a);
kpeter@486
   844
  }
kpeter@486
   845
kpeter@486
   846
  Adaptor::CombinedArcMap<Digraph::ArcMap<int>, Digraph::NodeMap<int> >
kpeter@486
   847
    arc_map(a_map, out_map);
kpeter@486
   848
  for (Digraph::ArcIt a(digraph); a != INVALID; ++a) {
kpeter@486
   849
    check(arc_map[adaptor.arc(a)] == a_map[a],  "Wrong combined arc map");
kpeter@486
   850
  }
kpeter@486
   851
  for (Digraph::NodeIt n(digraph); n != INVALID; ++n) {
kpeter@486
   852
    check(arc_map[adaptor.arc(n)] == out_map[n],  "Wrong combined arc map");
kpeter@486
   853
  }
kpeter@486
   854
kpeter@486
   855
  // Check the conversion of nodes
kpeter@486
   856
  Digraph::Node nd = adaptor.inNode(n1);
kpeter@486
   857
  check (nd == n1, "Wrong node conversion");
kpeter@486
   858
  nd = adaptor.outNode(n2);
kpeter@486
   859
  check (nd == n2, "Wrong node conversion");
deba@430
   860
}
deba@430
   861
deba@432
   862
void checkSubGraph() {
kpeter@486
   863
  // Check concepts
kpeter@486
   864
  checkConcept<concepts::Graph, SubGraph<concepts::Graph> >();
kpeter@486
   865
  checkConcept<concepts::Graph, SubGraph<ListGraph> >();
kpeter@486
   866
  checkConcept<concepts::AlterableGraphComponent<>,
kpeter@486
   867
               SubGraph<ListGraph> >();
kpeter@486
   868
  checkConcept<concepts::ExtendableGraphComponent<>,
kpeter@486
   869
               SubGraph<ListGraph> >();
kpeter@486
   870
  checkConcept<concepts::ErasableGraphComponent<>,
kpeter@486
   871
               SubGraph<ListGraph> >();
kpeter@486
   872
  checkConcept<concepts::ClearableGraphComponent<>,
kpeter@486
   873
               SubGraph<ListGraph> >();
deba@430
   874
kpeter@486
   875
  // Create a graph and an adaptor
deba@430
   876
  typedef ListGraph Graph;
deba@430
   877
  typedef Graph::NodeMap<bool> NodeFilter;
deba@430
   878
  typedef Graph::EdgeMap<bool> EdgeFilter;
deba@432
   879
  typedef SubGraph<Graph, NodeFilter, EdgeFilter> Adaptor;
deba@430
   880
deba@430
   881
  Graph graph;
deba@430
   882
  NodeFilter node_filter(graph);
deba@430
   883
  EdgeFilter edge_filter(graph);
deba@430
   884
  Adaptor adaptor(graph, node_filter, edge_filter);
deba@430
   885
kpeter@486
   886
  // Add nodes and edges to the original graph and the adaptor
deba@430
   887
  Graph::Node n1 = graph.addNode();
deba@430
   888
  Graph::Node n2 = graph.addNode();
kpeter@486
   889
  Adaptor::Node n3 = adaptor.addNode();
kpeter@486
   890
  Adaptor::Node n4 = adaptor.addNode();
kpeter@486
   891
kpeter@486
   892
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
deba@430
   893
deba@430
   894
  Graph::Edge e1 = graph.addEdge(n1, n2);
deba@430
   895
  Graph::Edge e2 = graph.addEdge(n1, n3);
kpeter@486
   896
  Adaptor::Edge e3 = adaptor.addEdge(n2, n3);
kpeter@486
   897
  Adaptor::Edge e4 = adaptor.addEdge(n3, n4);
deba@430
   898
deba@430
   899
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
alpar@463
   900
deba@430
   901
  checkGraphNodeList(adaptor, 4);
deba@430
   902
  checkGraphArcList(adaptor, 8);
deba@430
   903
  checkGraphEdgeList(adaptor, 4);
deba@430
   904
  checkGraphConArcList(adaptor, 8);
deba@430
   905
  checkGraphConEdgeList(adaptor, 4);
deba@430
   906
kpeter@486
   907
  checkGraphIncEdgeArcLists(adaptor, n1, 2);
kpeter@486
   908
  checkGraphIncEdgeArcLists(adaptor, n2, 2);
kpeter@486
   909
  checkGraphIncEdgeArcLists(adaptor, n3, 3);
kpeter@486
   910
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
   911
deba@430
   912
  checkNodeIds(adaptor);
deba@430
   913
  checkArcIds(adaptor);
deba@430
   914
  checkEdgeIds(adaptor);
deba@430
   915
deba@430
   916
  checkGraphNodeMap(adaptor);
deba@430
   917
  checkGraphArcMap(adaptor);
deba@430
   918
  checkGraphEdgeMap(adaptor);
deba@430
   919
kpeter@486
   920
  // Hide an edge
kpeter@486
   921
  adaptor.status(e2, false);
kpeter@486
   922
  adaptor.disable(e3);
kpeter@486
   923
  if (!adaptor.status(e3)) adaptor.enable(e3);
deba@430
   924
deba@430
   925
  checkGraphNodeList(adaptor, 4);
deba@430
   926
  checkGraphArcList(adaptor, 6);
deba@430
   927
  checkGraphEdgeList(adaptor, 3);
deba@430
   928
  checkGraphConArcList(adaptor, 6);
deba@430
   929
  checkGraphConEdgeList(adaptor, 3);
deba@430
   930
kpeter@486
   931
  checkGraphIncEdgeArcLists(adaptor, n1, 1);
kpeter@486
   932
  checkGraphIncEdgeArcLists(adaptor, n2, 2);
kpeter@486
   933
  checkGraphIncEdgeArcLists(adaptor, n3, 2);
kpeter@486
   934
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
   935
deba@430
   936
  checkNodeIds(adaptor);
deba@430
   937
  checkArcIds(adaptor);
deba@430
   938
  checkEdgeIds(adaptor);
deba@430
   939
deba@430
   940
  checkGraphNodeMap(adaptor);
deba@430
   941
  checkGraphArcMap(adaptor);
deba@430
   942
  checkGraphEdgeMap(adaptor);
deba@430
   943
kpeter@486
   944
  // Hide a node
kpeter@486
   945
  adaptor.status(n1, false);
kpeter@486
   946
  adaptor.disable(n3);
kpeter@486
   947
  if (!adaptor.status(n3)) adaptor.enable(n3);
deba@430
   948
deba@430
   949
  checkGraphNodeList(adaptor, 3);
deba@430
   950
  checkGraphArcList(adaptor, 4);
deba@430
   951
  checkGraphEdgeList(adaptor, 2);
deba@430
   952
  checkGraphConArcList(adaptor, 4);
deba@430
   953
  checkGraphConEdgeList(adaptor, 2);
deba@430
   954
kpeter@486
   955
  checkGraphIncEdgeArcLists(adaptor, n2, 1);
kpeter@486
   956
  checkGraphIncEdgeArcLists(adaptor, n3, 2);
kpeter@486
   957
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
   958
deba@430
   959
  checkNodeIds(adaptor);
deba@430
   960
  checkArcIds(adaptor);
deba@430
   961
  checkEdgeIds(adaptor);
deba@430
   962
deba@430
   963
  checkGraphNodeMap(adaptor);
deba@430
   964
  checkGraphArcMap(adaptor);
deba@430
   965
  checkGraphEdgeMap(adaptor);
deba@430
   966
kpeter@486
   967
  // Hide all nodes and edges
deba@430
   968
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false;
deba@430
   969
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false;
deba@430
   970
deba@430
   971
  checkGraphNodeList(adaptor, 0);
deba@430
   972
  checkGraphArcList(adaptor, 0);
deba@430
   973
  checkGraphEdgeList(adaptor, 0);
deba@430
   974
  checkGraphConArcList(adaptor, 0);
deba@430
   975
  checkGraphConEdgeList(adaptor, 0);
deba@430
   976
deba@430
   977
  checkNodeIds(adaptor);
deba@430
   978
  checkArcIds(adaptor);
deba@430
   979
  checkEdgeIds(adaptor);
deba@430
   980
deba@430
   981
  checkGraphNodeMap(adaptor);
deba@430
   982
  checkGraphArcMap(adaptor);
deba@430
   983
  checkGraphEdgeMap(adaptor);
kpeter@486
   984
kpeter@486
   985
  // Check the conversion of nodes and edges
kpeter@486
   986
  Graph::Node ng = n3;
kpeter@486
   987
  ng = n4;
kpeter@486
   988
  Adaptor::Node na = n1;
kpeter@486
   989
  na = n2;
kpeter@486
   990
  Graph::Edge eg = e3;
kpeter@486
   991
  eg = e4;
kpeter@486
   992
  Adaptor::Edge ea = e1;
kpeter@486
   993
  ea = e2;
deba@430
   994
}
deba@430
   995
deba@432
   996
void checkFilterNodes2() {
kpeter@486
   997
  // Check concepts
kpeter@486
   998
  checkConcept<concepts::Graph, FilterNodes<concepts::Graph> >();
kpeter@486
   999
  checkConcept<concepts::Graph, FilterNodes<ListGraph> >();
kpeter@486
  1000
  checkConcept<concepts::AlterableGraphComponent<>,
kpeter@486
  1001
               FilterNodes<ListGraph> >();
kpeter@486
  1002
  checkConcept<concepts::ExtendableGraphComponent<>,
kpeter@486
  1003
               FilterNodes<ListGraph> >();
kpeter@486
  1004
  checkConcept<concepts::ErasableGraphComponent<>,
kpeter@486
  1005
               FilterNodes<ListGraph> >();
kpeter@486
  1006
  checkConcept<concepts::ClearableGraphComponent<>,
kpeter@486
  1007
               FilterNodes<ListGraph> >();
deba@430
  1008
kpeter@486
  1009
  // Create a graph and an adaptor
deba@430
  1010
  typedef ListGraph Graph;
deba@430
  1011
  typedef Graph::NodeMap<bool> NodeFilter;
deba@432
  1012
  typedef FilterNodes<Graph, NodeFilter> Adaptor;
deba@430
  1013
kpeter@486
  1014
  // Add nodes and edges to the original graph and the adaptor
deba@430
  1015
  Graph graph;
deba@430
  1016
  NodeFilter node_filter(graph);
deba@430
  1017
  Adaptor adaptor(graph, node_filter);
deba@430
  1018
deba@430
  1019
  Graph::Node n1 = graph.addNode();
deba@430
  1020
  Graph::Node n2 = graph.addNode();
kpeter@486
  1021
  Adaptor::Node n3 = adaptor.addNode();
kpeter@486
  1022
  Adaptor::Node n4 = adaptor.addNode();
kpeter@486
  1023
kpeter@486
  1024
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = true;
deba@430
  1025
deba@430
  1026
  Graph::Edge e1 = graph.addEdge(n1, n2);
deba@430
  1027
  Graph::Edge e2 = graph.addEdge(n1, n3);
kpeter@486
  1028
  Adaptor::Edge e3 = adaptor.addEdge(n2, n3);
kpeter@486
  1029
  Adaptor::Edge e4 = adaptor.addEdge(n3, n4);
alpar@463
  1030
deba@430
  1031
  checkGraphNodeList(adaptor, 4);
deba@430
  1032
  checkGraphArcList(adaptor, 8);
deba@430
  1033
  checkGraphEdgeList(adaptor, 4);
deba@430
  1034
  checkGraphConArcList(adaptor, 8);
deba@430
  1035
  checkGraphConEdgeList(adaptor, 4);
deba@430
  1036
kpeter@486
  1037
  checkGraphIncEdgeArcLists(adaptor, n1, 2);
kpeter@486
  1038
  checkGraphIncEdgeArcLists(adaptor, n2, 2);
kpeter@486
  1039
  checkGraphIncEdgeArcLists(adaptor, n3, 3);
kpeter@486
  1040
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
  1041
deba@430
  1042
  checkNodeIds(adaptor);
deba@430
  1043
  checkArcIds(adaptor);
deba@430
  1044
  checkEdgeIds(adaptor);
deba@430
  1045
deba@430
  1046
  checkGraphNodeMap(adaptor);
deba@430
  1047
  checkGraphArcMap(adaptor);
deba@430
  1048
  checkGraphEdgeMap(adaptor);
deba@430
  1049
kpeter@486
  1050
  // Hide a node
kpeter@486
  1051
  adaptor.status(n1, false);
kpeter@486
  1052
  adaptor.disable(n3);
kpeter@486
  1053
  if (!adaptor.status(n3)) adaptor.enable(n3);
deba@430
  1054
deba@430
  1055
  checkGraphNodeList(adaptor, 3);
deba@430
  1056
  checkGraphArcList(adaptor, 4);
deba@430
  1057
  checkGraphEdgeList(adaptor, 2);
deba@430
  1058
  checkGraphConArcList(adaptor, 4);
deba@430
  1059
  checkGraphConEdgeList(adaptor, 2);
deba@430
  1060
kpeter@486
  1061
  checkGraphIncEdgeArcLists(adaptor, n2, 1);
kpeter@486
  1062
  checkGraphIncEdgeArcLists(adaptor, n3, 2);
kpeter@486
  1063
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
  1064
deba@430
  1065
  checkNodeIds(adaptor);
deba@430
  1066
  checkArcIds(adaptor);
deba@430
  1067
  checkEdgeIds(adaptor);
deba@430
  1068
deba@430
  1069
  checkGraphNodeMap(adaptor);
deba@430
  1070
  checkGraphArcMap(adaptor);
deba@430
  1071
  checkGraphEdgeMap(adaptor);
deba@430
  1072
kpeter@486
  1073
  // Hide all nodes
deba@430
  1074
  node_filter[n1] = node_filter[n2] = node_filter[n3] = node_filter[n4] = false;
deba@430
  1075
deba@430
  1076
  checkGraphNodeList(adaptor, 0);
deba@430
  1077
  checkGraphArcList(adaptor, 0);
deba@430
  1078
  checkGraphEdgeList(adaptor, 0);
deba@430
  1079
  checkGraphConArcList(adaptor, 0);
deba@430
  1080
  checkGraphConEdgeList(adaptor, 0);
deba@430
  1081
deba@430
  1082
  checkNodeIds(adaptor);
deba@430
  1083
  checkArcIds(adaptor);
deba@430
  1084
  checkEdgeIds(adaptor);
deba@430
  1085
deba@430
  1086
  checkGraphNodeMap(adaptor);
deba@430
  1087
  checkGraphArcMap(adaptor);
deba@430
  1088
  checkGraphEdgeMap(adaptor);
kpeter@486
  1089
kpeter@486
  1090
  // Check the conversion of nodes and edges
kpeter@486
  1091
  Graph::Node ng = n3;
kpeter@486
  1092
  ng = n4;
kpeter@486
  1093
  Adaptor::Node na = n1;
kpeter@486
  1094
  na = n2;
kpeter@486
  1095
  Graph::Edge eg = e3;
kpeter@486
  1096
  eg = e4;
kpeter@486
  1097
  Adaptor::Edge ea = e1;
kpeter@486
  1098
  ea = e2;
deba@430
  1099
}
deba@430
  1100
deba@432
  1101
void checkFilterEdges() {
kpeter@486
  1102
  // Check concepts
kpeter@486
  1103
  checkConcept<concepts::Graph, FilterEdges<concepts::Graph> >();
kpeter@486
  1104
  checkConcept<concepts::Graph, FilterEdges<ListGraph> >();
kpeter@486
  1105
  checkConcept<concepts::AlterableGraphComponent<>,
kpeter@486
  1106
               FilterEdges<ListGraph> >();
kpeter@486
  1107
  checkConcept<concepts::ExtendableGraphComponent<>,
kpeter@486
  1108
               FilterEdges<ListGraph> >();
kpeter@486
  1109
  checkConcept<concepts::ErasableGraphComponent<>,
kpeter@486
  1110
               FilterEdges<ListGraph> >();
kpeter@486
  1111
  checkConcept<concepts::ClearableGraphComponent<>,
kpeter@486
  1112
               FilterEdges<ListGraph> >();
deba@430
  1113
kpeter@486
  1114
  // Create a graph and an adaptor
deba@430
  1115
  typedef ListGraph Graph;
deba@430
  1116
  typedef Graph::EdgeMap<bool> EdgeFilter;
deba@432
  1117
  typedef FilterEdges<Graph, EdgeFilter> Adaptor;
deba@430
  1118
deba@430
  1119
  Graph graph;
deba@430
  1120
  EdgeFilter edge_filter(graph);
deba@430
  1121
  Adaptor adaptor(graph, edge_filter);
deba@430
  1122
kpeter@486
  1123
  // Add nodes and edges to the original graph and the adaptor
deba@430
  1124
  Graph::Node n1 = graph.addNode();
deba@430
  1125
  Graph::Node n2 = graph.addNode();
kpeter@486
  1126
  Adaptor::Node n3 = adaptor.addNode();
kpeter@486
  1127
  Adaptor::Node n4 = adaptor.addNode();
deba@430
  1128
deba@430
  1129
  Graph::Edge e1 = graph.addEdge(n1, n2);
deba@430
  1130
  Graph::Edge e2 = graph.addEdge(n1, n3);
kpeter@486
  1131
  Adaptor::Edge e3 = adaptor.addEdge(n2, n3);
kpeter@486
  1132
  Adaptor::Edge e4 = adaptor.addEdge(n3, n4);
deba@430
  1133
deba@430
  1134
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = true;
alpar@463
  1135
deba@430
  1136
  checkGraphNodeList(adaptor, 4);
deba@430
  1137
  checkGraphArcList(adaptor, 8);
deba@430
  1138
  checkGraphEdgeList(adaptor, 4);
deba@430
  1139
  checkGraphConArcList(adaptor, 8);
deba@430
  1140
  checkGraphConEdgeList(adaptor, 4);
deba@430
  1141
kpeter@486
  1142
  checkGraphIncEdgeArcLists(adaptor, n1, 2);
kpeter@486
  1143
  checkGraphIncEdgeArcLists(adaptor, n2, 2);
kpeter@486
  1144
  checkGraphIncEdgeArcLists(adaptor, n3, 3);
kpeter@486
  1145
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
  1146
deba@430
  1147
  checkNodeIds(adaptor);
deba@430
  1148
  checkArcIds(adaptor);
deba@430
  1149
  checkEdgeIds(adaptor);
deba@430
  1150
deba@430
  1151
  checkGraphNodeMap(adaptor);
deba@430
  1152
  checkGraphArcMap(adaptor);
deba@430
  1153
  checkGraphEdgeMap(adaptor);
deba@430
  1154
kpeter@486
  1155
  // Hide an edge
kpeter@486
  1156
  adaptor.status(e2, false);
kpeter@486
  1157
  adaptor.disable(e3);
kpeter@486
  1158
  if (!adaptor.status(e3)) adaptor.enable(e3);
deba@430
  1159
deba@430
  1160
  checkGraphNodeList(adaptor, 4);
deba@430
  1161
  checkGraphArcList(adaptor, 6);
deba@430
  1162
  checkGraphEdgeList(adaptor, 3);
deba@430
  1163
  checkGraphConArcList(adaptor, 6);
deba@430
  1164
  checkGraphConEdgeList(adaptor, 3);
deba@430
  1165
kpeter@486
  1166
  checkGraphIncEdgeArcLists(adaptor, n1, 1);
kpeter@486
  1167
  checkGraphIncEdgeArcLists(adaptor, n2, 2);
kpeter@486
  1168
  checkGraphIncEdgeArcLists(adaptor, n3, 2);
kpeter@486
  1169
  checkGraphIncEdgeArcLists(adaptor, n4, 1);
deba@430
  1170
deba@430
  1171
  checkNodeIds(adaptor);
deba@430
  1172
  checkArcIds(adaptor);
deba@430
  1173
  checkEdgeIds(adaptor);
deba@430
  1174
deba@430
  1175
  checkGraphNodeMap(adaptor);
deba@430
  1176
  checkGraphArcMap(adaptor);
deba@430
  1177
  checkGraphEdgeMap(adaptor);
deba@430
  1178
kpeter@486
  1179
  // Hide all edges
deba@430
  1180
  edge_filter[e1] = edge_filter[e2] = edge_filter[e3] = edge_filter[e4] = false;
deba@430
  1181
deba@430
  1182
  checkGraphNodeList(adaptor, 4);
deba@430
  1183
  checkGraphArcList(adaptor, 0);
deba@430
  1184
  checkGraphEdgeList(adaptor, 0);
deba@430
  1185
  checkGraphConArcList(adaptor, 0);
deba@430
  1186
  checkGraphConEdgeList(adaptor, 0);
deba@430
  1187
deba@430
  1188
  checkNodeIds(adaptor);
deba@430
  1189
  checkArcIds(adaptor);
deba@430
  1190
  checkEdgeIds(adaptor);
deba@430
  1191
deba@430
  1192
  checkGraphNodeMap(adaptor);
deba@430
  1193
  checkGraphArcMap(adaptor);
deba@430
  1194
  checkGraphEdgeMap(adaptor);
kpeter@486
  1195
kpeter@486
  1196
  // Check the conversion of nodes and edges
kpeter@486
  1197
  Graph::Node ng = n3;
kpeter@486
  1198
  ng = n4;
kpeter@486
  1199
  Adaptor::Node na = n1;
kpeter@486
  1200
  na = n2;
kpeter@486
  1201
  Graph::Edge eg = e3;
kpeter@486
  1202
  eg = e4;
kpeter@486
  1203
  Adaptor::Edge ea = e1;
kpeter@486
  1204
  ea = e2;
deba@430
  1205
}
deba@430
  1206
deba@432
  1207
void checkOrienter() {
kpeter@486
  1208
  // Check concepts
kpeter@486
  1209
  checkConcept<concepts::Digraph, Orienter<concepts::Graph> >();
kpeter@486
  1210
  checkConcept<concepts::Digraph, Orienter<ListGraph> >();
kpeter@486
  1211
  checkConcept<concepts::AlterableDigraphComponent<>,
kpeter@486
  1212
               Orienter<ListGraph> >();
kpeter@486
  1213
  checkConcept<concepts::ExtendableDigraphComponent<>,
kpeter@486
  1214
               Orienter<ListGraph> >();
kpeter@486
  1215
  checkConcept<concepts::ErasableDigraphComponent<>,
kpeter@486
  1216
               Orienter<ListGraph> >();
kpeter@486
  1217
  checkConcept<concepts::ClearableDigraphComponent<>,
kpeter@486
  1218
               Orienter<ListGraph> >();
deba@430
  1219
kpeter@486
  1220
  // Create a graph and an adaptor
deba@430
  1221
  typedef ListGraph Graph;
deba@430
  1222
  typedef ListGraph::EdgeMap<bool> DirMap;
deba@432
  1223
  typedef Orienter<Graph> Adaptor;
deba@430
  1224
deba@430
  1225
  Graph graph;
kpeter@486
  1226
  DirMap dir(graph);
deba@430
  1227
  Adaptor adaptor(graph, dir);
deba@430
  1228
kpeter@486
  1229
  // Add nodes and edges to the original graph and the adaptor
deba@430
  1230
  Graph::Node n1 = graph.addNode();
deba@430
  1231
  Graph::Node n2 = graph.addNode();
kpeter@486
  1232
  Adaptor::Node n3 = adaptor.addNode();
deba@430
  1233
deba@430
  1234
  Graph::Edge e1 = graph.addEdge(n1, n2);
deba@430
  1235
  Graph::Edge e2 = graph.addEdge(n1, n3);
kpeter@486
  1236
  Adaptor::Arc e3 = adaptor.addArc(n2, n3);
deba@432
  1237
kpeter@486
  1238
  dir[e1] = dir[e2] = dir[e3] = true;
kpeter@486
  1239
kpeter@486
  1240
  // Check the original graph
kpeter@486
  1241
  checkGraphNodeList(graph, 3);
kpeter@486
  1242
  checkGraphArcList(graph, 6);
kpeter@486
  1243
  checkGraphConArcList(graph, 6);
kpeter@486
  1244
  checkGraphEdgeList(graph, 3);
kpeter@486
  1245
  checkGraphConEdgeList(graph, 3);
kpeter@486
  1246
kpeter@486
  1247
  checkGraphIncEdgeArcLists(graph, n1, 2);
kpeter@486
  1248
  checkGraphIncEdgeArcLists(graph, n2, 2);
kpeter@486
  1249
  checkGraphIncEdgeArcLists(graph, n3, 2);
kpeter@486
  1250
kpeter@486
  1251
  checkNodeIds(graph);
kpeter@486
  1252
  checkArcIds(graph);
kpeter@486
  1253
  checkEdgeIds(graph);
kpeter@486
  1254
kpeter@486
  1255
  checkGraphNodeMap(graph);
kpeter@486
  1256
  checkGraphArcMap(graph);
kpeter@486
  1257
  checkGraphEdgeMap(graph);
kpeter@486
  1258
kpeter@486
  1259
  // Check the adaptor
deba@430
  1260
  checkGraphNodeList(adaptor, 3);
deba@430
  1261
  checkGraphArcList(adaptor, 3);
deba@430
  1262
  checkGraphConArcList(adaptor, 3);
deba@432
  1263
kpeter@486
  1264
  checkGraphOutArcList(adaptor, n1, 2);
kpeter@486
  1265
  checkGraphOutArcList(adaptor, n2, 1);
kpeter@486
  1266
  checkGraphOutArcList(adaptor, n3, 0);
kpeter@486
  1267
kpeter@486
  1268
  checkGraphInArcList(adaptor, n1, 0);
kpeter@486
  1269
  checkGraphInArcList(adaptor, n2, 1);
kpeter@486
  1270
  checkGraphInArcList(adaptor, n3, 2);
kpeter@486
  1271
kpeter@486
  1272
  checkNodeIds(adaptor);
kpeter@486
  1273
  checkArcIds(adaptor);
kpeter@486
  1274
kpeter@486
  1275
  checkGraphNodeMap(adaptor);
kpeter@486
  1276
  checkGraphArcMap(adaptor);
kpeter@486
  1277
kpeter@486
  1278
  // Check direction changing
deba@430
  1279
  {
deba@430
  1280
    dir[e1] = true;
deba@430
  1281
    Adaptor::Node u = adaptor.source(e1);
deba@430
  1282
    Adaptor::Node v = adaptor.target(e1);
deba@432
  1283
deba@430
  1284
    dir[e1] = false;
deba@430
  1285
    check (u == adaptor.target(e1), "Wrong dir");
deba@430
  1286
    check (v == adaptor.source(e1), "Wrong dir");
deba@430
  1287
deba@430
  1288
    check ((u == n1 && v == n2) || (u == n2 && v == n1), "Wrong dir");
deba@430
  1289
    dir[e1] = n1 == u;
deba@430
  1290
  }
deba@430
  1291
deba@430
  1292
  {
deba@430
  1293
    dir[e2] = true;
deba@430
  1294
    Adaptor::Node u = adaptor.source(e2);
deba@430
  1295
    Adaptor::Node v = adaptor.target(e2);
deba@432
  1296
deba@430
  1297
    dir[e2] = false;
deba@430
  1298
    check (u == adaptor.target(e2), "Wrong dir");
deba@430
  1299
    check (v == adaptor.source(e2), "Wrong dir");
deba@430
  1300
deba@430
  1301
    check ((u == n1 && v == n3) || (u == n3 && v == n1), "Wrong dir");
deba@430
  1302
    dir[e2] = n3 == u;
deba@430
  1303
  }
deba@430
  1304
deba@430
  1305
  {
deba@430
  1306
    dir[e3] = true;
deba@430
  1307
    Adaptor::Node u = adaptor.source(e3);
deba@430
  1308
    Adaptor::Node v = adaptor.target(e3);
deba@432
  1309
deba@430
  1310
    dir[e3] = false;
deba@430
  1311
    check (u == adaptor.target(e3), "Wrong dir");
deba@430
  1312
    check (v == adaptor.source(e3), "Wrong dir");
deba@430
  1313
deba@430
  1314
    check ((u == n2 && v == n3) || (u == n3 && v == n2), "Wrong dir");
deba@430
  1315
    dir[e3] = n2 == u;
deba@430
  1316
  }
deba@430
  1317
kpeter@486
  1318
  // Check the adaptor again
kpeter@486
  1319
  checkGraphNodeList(adaptor, 3);
kpeter@486
  1320
  checkGraphArcList(adaptor, 3);
kpeter@486
  1321
  checkGraphConArcList(adaptor, 3);
kpeter@486
  1322
deba@430
  1323
  checkGraphOutArcList(adaptor, n1, 1);
deba@430
  1324
  checkGraphOutArcList(adaptor, n2, 1);
deba@430
  1325
  checkGraphOutArcList(adaptor, n3, 1);
deba@430
  1326
deba@430
  1327
  checkGraphInArcList(adaptor, n1, 1);
deba@430
  1328
  checkGraphInArcList(adaptor, n2, 1);
deba@430
  1329
  checkGraphInArcList(adaptor, n3, 1);
deba@430
  1330
deba@430
  1331
  checkNodeIds(adaptor);
deba@430
  1332
  checkArcIds(adaptor);
deba@430
  1333
deba@430
  1334
  checkGraphNodeMap(adaptor);
deba@430
  1335
  checkGraphArcMap(adaptor);
deba@430
  1336
kpeter@486
  1337
  // Check reverseArc()
kpeter@486
  1338
  adaptor.reverseArc(e2);
kpeter@486
  1339
  adaptor.reverseArc(e3);
kpeter@486
  1340
  adaptor.reverseArc(e2);
kpeter@486
  1341
kpeter@486
  1342
  checkGraphNodeList(adaptor, 3);
kpeter@486
  1343
  checkGraphArcList(adaptor, 3);
kpeter@486
  1344
  checkGraphConArcList(adaptor, 3);
kpeter@486
  1345
kpeter@486
  1346
  checkGraphOutArcList(adaptor, n1, 1);
kpeter@486
  1347
  checkGraphOutArcList(adaptor, n2, 0);
kpeter@486
  1348
  checkGraphOutArcList(adaptor, n3, 2);
kpeter@486
  1349
kpeter@486
  1350
  checkGraphInArcList(adaptor, n1, 1);
kpeter@486
  1351
  checkGraphInArcList(adaptor, n2, 2);
kpeter@486
  1352
  checkGraphInArcList(adaptor, n3, 0);
kpeter@486
  1353
kpeter@486
  1354
  // Check the conversion of nodes and arcs/edges
kpeter@486
  1355
  Graph::Node ng = n3;
kpeter@486
  1356
  ng = n3;
kpeter@486
  1357
  Adaptor::Node na = n1;
kpeter@486
  1358
  na = n2;
kpeter@486
  1359
  Graph::Edge eg = e3;
kpeter@486
  1360
  eg = e3;
kpeter@486
  1361
  Adaptor::Arc aa = e1;
kpeter@486
  1362
  aa = e2;
deba@430
  1363
}
deba@430
  1364
kpeter@486
  1365
void checkCombiningAdaptors() {
kpeter@486
  1366
  // Create a grid graph
kpeter@486
  1367
  GridGraph graph(2,2);
kpeter@486
  1368
  GridGraph::Node n1 = graph(0,0);
kpeter@486
  1369
  GridGraph::Node n2 = graph(0,1);
kpeter@486
  1370
  GridGraph::Node n3 = graph(1,0);
kpeter@486
  1371
  GridGraph::Node n4 = graph(1,1);
kpeter@486
  1372
kpeter@486
  1373
  GridGraph::EdgeMap<bool> dir_map(graph);
kpeter@486
  1374
  dir_map[graph.right(n1)] = graph.u(graph.right(n1)) == n1;
kpeter@486
  1375
  dir_map[graph.up(n1)] = graph.u(graph.up(n1)) != n1;
kpeter@486
  1376
  dir_map[graph.left(n4)] = graph.u(graph.left(n4)) != n4;
kpeter@486
  1377
  dir_map[graph.down(n4)] = graph.u(graph.down(n4)) != n4;
kpeter@486
  1378
kpeter@486
  1379
  // Apply several adaptors on the grid graph
kpeter@486
  1380
  typedef SplitNodes< ReverseDigraph< const Orienter<
kpeter@486
  1381
            const GridGraph, GridGraph::EdgeMap<bool> > > >
kpeter@486
  1382
    RevSplitGridGraph;
kpeter@486
  1383
  typedef ReverseDigraph<const RevSplitGridGraph> SplitGridGraph;
kpeter@486
  1384
  typedef Undirector<const SplitGridGraph> USplitGridGraph;
kpeter@486
  1385
  typedef Undirector<const USplitGridGraph> UUSplitGridGraph;
kpeter@486
  1386
  checkConcept<concepts::Digraph, RevSplitGridGraph>();
kpeter@486
  1387
  checkConcept<concepts::Digraph, SplitGridGraph>();
kpeter@486
  1388
  checkConcept<concepts::Graph, USplitGridGraph>();
kpeter@486
  1389
  checkConcept<concepts::Graph, UUSplitGridGraph>();
kpeter@486
  1390
kpeter@486
  1391
  RevSplitGridGraph rev_adaptor =
kpeter@486
  1392
    splitNodes(reverseDigraph(orienter(graph, dir_map)));
kpeter@486
  1393
  SplitGridGraph adaptor = reverseDigraph(rev_adaptor);
kpeter@486
  1394
  USplitGridGraph uadaptor = undirector(adaptor);
kpeter@486
  1395
  UUSplitGridGraph uuadaptor = undirector(uadaptor);
kpeter@486
  1396
kpeter@486
  1397
  // Check adaptor
kpeter@486
  1398
  checkGraphNodeList(adaptor, 8);
kpeter@486
  1399
  checkGraphArcList(adaptor, 8);
kpeter@486
  1400
  checkGraphConArcList(adaptor, 8);
kpeter@486
  1401
kpeter@486
  1402
  checkGraphOutArcList(adaptor, rev_adaptor.inNode(n1), 1);
kpeter@486
  1403
  checkGraphOutArcList(adaptor, rev_adaptor.outNode(n1), 1);
kpeter@486
  1404
  checkGraphOutArcList(adaptor, rev_adaptor.inNode(n2), 2);
kpeter@486
  1405
  checkGraphOutArcList(adaptor, rev_adaptor.outNode(n2), 1);
kpeter@486
  1406
  checkGraphOutArcList(adaptor, rev_adaptor.inNode(n3), 1);
kpeter@486
  1407
  checkGraphOutArcList(adaptor, rev_adaptor.outNode(n3), 1);
kpeter@486
  1408
  checkGraphOutArcList(adaptor, rev_adaptor.inNode(n4), 0);
kpeter@486
  1409
  checkGraphOutArcList(adaptor, rev_adaptor.outNode(n4), 1);
kpeter@486
  1410
kpeter@486
  1411
  checkGraphInArcList(adaptor, rev_adaptor.inNode(n1), 1);
kpeter@486
  1412
  checkGraphInArcList(adaptor, rev_adaptor.outNode(n1), 1);
kpeter@486
  1413
  checkGraphInArcList(adaptor, rev_adaptor.inNode(n2), 1);
kpeter@486
  1414
  checkGraphInArcList(adaptor, rev_adaptor.outNode(n2), 0);
kpeter@486
  1415
  checkGraphInArcList(adaptor, rev_adaptor.inNode(n3), 1);
kpeter@486
  1416
  checkGraphInArcList(adaptor, rev_adaptor.outNode(n3), 1);
kpeter@486
  1417
  checkGraphInArcList(adaptor, rev_adaptor.inNode(n4), 1);
kpeter@486
  1418
  checkGraphInArcList(adaptor, rev_adaptor.outNode(n4), 2);
kpeter@486
  1419
kpeter@486
  1420
  checkNodeIds(adaptor);
kpeter@486
  1421
  checkArcIds(adaptor);
kpeter@486
  1422
kpeter@486
  1423
  checkGraphNodeMap(adaptor);
kpeter@486
  1424
  checkGraphArcMap(adaptor);
kpeter@486
  1425
kpeter@486
  1426
  // Check uadaptor
kpeter@486
  1427
  checkGraphNodeList(uadaptor, 8);
kpeter@486
  1428
  checkGraphEdgeList(uadaptor, 8);
kpeter@486
  1429
  checkGraphArcList(uadaptor, 16);
kpeter@486
  1430
  checkGraphConEdgeList(uadaptor, 8);
kpeter@486
  1431
  checkGraphConArcList(uadaptor, 16);
kpeter@486
  1432
kpeter@486
  1433
  checkNodeIds(uadaptor);
kpeter@486
  1434
  checkEdgeIds(uadaptor);
kpeter@486
  1435
  checkArcIds(uadaptor);
kpeter@486
  1436
kpeter@486
  1437
  checkGraphNodeMap(uadaptor);
kpeter@486
  1438
  checkGraphEdgeMap(uadaptor);
kpeter@486
  1439
  checkGraphArcMap(uadaptor);
kpeter@486
  1440
kpeter@486
  1441
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n1), 2);
kpeter@486
  1442
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n1), 2);
kpeter@486
  1443
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n2), 3);
kpeter@486
  1444
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n2), 1);
kpeter@486
  1445
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n3), 2);
kpeter@486
  1446
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n3), 2);
kpeter@486
  1447
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.inNode(n4), 1);
kpeter@486
  1448
  checkGraphIncEdgeArcLists(uadaptor, rev_adaptor.outNode(n4), 3);
kpeter@486
  1449
kpeter@486
  1450
  // Check uuadaptor
kpeter@486
  1451
  checkGraphNodeList(uuadaptor, 8);
kpeter@486
  1452
  checkGraphEdgeList(uuadaptor, 16);
kpeter@486
  1453
  checkGraphArcList(uuadaptor, 32);
kpeter@486
  1454
  checkGraphConEdgeList(uuadaptor, 16);
kpeter@486
  1455
  checkGraphConArcList(uuadaptor, 32);
kpeter@486
  1456
kpeter@486
  1457
  checkNodeIds(uuadaptor);
kpeter@486
  1458
  checkEdgeIds(uuadaptor);
kpeter@486
  1459
  checkArcIds(uuadaptor);
kpeter@486
  1460
kpeter@486
  1461
  checkGraphNodeMap(uuadaptor);
kpeter@486
  1462
  checkGraphEdgeMap(uuadaptor);
kpeter@486
  1463
  checkGraphArcMap(uuadaptor);
kpeter@486
  1464
}
deba@430
  1465
deba@430
  1466
int main(int, const char **) {
kpeter@486
  1467
  // Check the digraph adaptors (using ListDigraph)
deba@432
  1468
  checkReverseDigraph();
deba@432
  1469
  checkSubDigraph();
deba@432
  1470
  checkFilterNodes1();
deba@432
  1471
  checkFilterArcs();
deba@432
  1472
  checkUndirector();
kpeter@487
  1473
  checkResidualDigraph();
deba@432
  1474
  checkSplitNodes();
deba@430
  1475
kpeter@486
  1476
  // Check the graph adaptors (using ListGraph)
deba@432
  1477
  checkSubGraph();
deba@432
  1478
  checkFilterNodes2();
deba@432
  1479
  checkFilterEdges();
deba@432
  1480
  checkOrienter();
deba@430
  1481
kpeter@486
  1482
  // Combine adaptors (using GridGraph)
kpeter@486
  1483
  checkCombiningAdaptors();
kpeter@486
  1484
deba@430
  1485
  return 0;
deba@430
  1486
}