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