test/matching_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Thu, 21 Jan 2021 08:36:53 +0100
changeset 1204 736a341e604b
parent 1092 dceba191c00d
permissions -rw-r--r--
Update CMakeLists.txt to match current CMAKE versions (#641)
deba@326
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
deba@326
     2
 *
deba@326
     3
 * This file is a part of LEMON, a generic C++ optimization library.
deba@326
     4
 *
alpar@1092
     5
 * Copyright (C) 2003-2013
deba@326
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@326
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@326
     8
 *
deba@326
     9
 * Permission to use, modify and distribute this software is granted
deba@326
    10
 * provided that this copyright notice appears in all copies. For
deba@326
    11
 * precise terms see the accompanying LICENSE file.
deba@326
    12
 *
deba@326
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@326
    14
 * express or implied, and with no claim as to its suitability for any
deba@326
    15
 * purpose.
deba@326
    16
 *
deba@326
    17
 */
deba@326
    18
deba@326
    19
#include <iostream>
deba@327
    20
#include <sstream>
deba@326
    21
#include <vector>
deba@326
    22
#include <queue>
deba@326
    23
#include <cstdlib>
deba@326
    24
kpeter@594
    25
#include <lemon/matching.h>
deba@327
    26
#include <lemon/smart_graph.h>
kpeter@590
    27
#include <lemon/concepts/graph.h>
kpeter@590
    28
#include <lemon/concepts/maps.h>
deba@327
    29
#include <lemon/lgf_reader.h>
kpeter@590
    30
#include <lemon/math.h>
deba@327
    31
deba@326
    32
#include "test_tools.h"
deba@326
    33
deba@326
    34
using namespace std;
deba@326
    35
using namespace lemon;
deba@326
    36
deba@327
    37
GRAPH_TYPEDEFS(SmartGraph);
deba@327
    38
deba@327
    39
deba@327
    40
const int lgfn = 3;
deba@327
    41
const std::string lgf[lgfn] = {
deba@327
    42
  "@nodes\n"
deba@327
    43
  "label\n"
deba@327
    44
  "0\n"
deba@327
    45
  "1\n"
deba@327
    46
  "2\n"
deba@327
    47
  "3\n"
deba@327
    48
  "4\n"
deba@327
    49
  "5\n"
deba@327
    50
  "6\n"
deba@327
    51
  "7\n"
deba@327
    52
  "@edges\n"
deba@327
    53
  "     label  weight\n"
deba@327
    54
  "7 4  0      984\n"
deba@327
    55
  "0 7  1      73\n"
deba@327
    56
  "7 1  2      204\n"
deba@327
    57
  "2 3  3      583\n"
deba@327
    58
  "2 7  4      565\n"
deba@327
    59
  "2 1  5      582\n"
deba@327
    60
  "0 4  6      551\n"
deba@327
    61
  "2 5  7      385\n"
deba@327
    62
  "1 5  8      561\n"
deba@327
    63
  "5 3  9      484\n"
deba@327
    64
  "7 5  10     904\n"
deba@327
    65
  "3 6  11     47\n"
deba@327
    66
  "7 6  12     888\n"
deba@327
    67
  "3 0  13     747\n"
deba@327
    68
  "6 1  14     310\n",
deba@327
    69
deba@327
    70
  "@nodes\n"
deba@327
    71
  "label\n"
deba@327
    72
  "0\n"
deba@327
    73
  "1\n"
deba@327
    74
  "2\n"
deba@327
    75
  "3\n"
deba@327
    76
  "4\n"
deba@327
    77
  "5\n"
deba@327
    78
  "6\n"
deba@327
    79
  "7\n"
deba@327
    80
  "@edges\n"
deba@327
    81
  "     label  weight\n"
deba@327
    82
  "2 5  0      710\n"
deba@327
    83
  "0 5  1      241\n"
deba@327
    84
  "2 4  2      856\n"
deba@327
    85
  "2 6  3      762\n"
deba@327
    86
  "4 1  4      747\n"
deba@327
    87
  "6 1  5      962\n"
deba@327
    88
  "4 7  6      723\n"
deba@327
    89
  "1 7  7      661\n"
deba@327
    90
  "2 3  8      376\n"
deba@327
    91
  "1 0  9      416\n"
deba@327
    92
  "6 7  10     391\n",
deba@327
    93
deba@327
    94
  "@nodes\n"
deba@327
    95
  "label\n"
deba@327
    96
  "0\n"
deba@327
    97
  "1\n"
deba@327
    98
  "2\n"
deba@327
    99
  "3\n"
deba@327
   100
  "4\n"
deba@327
   101
  "5\n"
deba@327
   102
  "6\n"
deba@327
   103
  "7\n"
deba@327
   104
  "@edges\n"
deba@327
   105
  "     label  weight\n"
deba@327
   106
  "6 2  0      553\n"
deba@327
   107
  "0 7  1      653\n"
deba@327
   108
  "6 3  2      22\n"
deba@327
   109
  "4 7  3      846\n"
deba@327
   110
  "7 2  4      981\n"
deba@327
   111
  "7 6  5      250\n"
deba@327
   112
  "5 2  6      539\n",
deba@327
   113
};
deba@327
   114
kpeter@590
   115
void checkMaxMatchingCompile()
kpeter@590
   116
{
kpeter@590
   117
  typedef concepts::Graph Graph;
kpeter@590
   118
  typedef Graph::Node Node;
kpeter@590
   119
  typedef Graph::Edge Edge;
kpeter@590
   120
  typedef Graph::EdgeMap<bool> MatMap;
kpeter@590
   121
kpeter@590
   122
  Graph g;
kpeter@590
   123
  Node n;
kpeter@590
   124
  Edge e;
kpeter@590
   125
  MatMap mat(g);
kpeter@590
   126
kpeter@590
   127
  MaxMatching<Graph> mat_test(g);
kpeter@590
   128
  const MaxMatching<Graph>&
kpeter@590
   129
    const_mat_test = mat_test;
kpeter@590
   130
kpeter@590
   131
  mat_test.init();
kpeter@590
   132
  mat_test.greedyInit();
kpeter@590
   133
  mat_test.matchingInit(mat);
kpeter@590
   134
  mat_test.startSparse();
kpeter@590
   135
  mat_test.startDense();
kpeter@590
   136
  mat_test.run();
deba@1203
   137
  mat_test.startSparse(false);
deba@1203
   138
  mat_test.startDense(false);
deba@1203
   139
  mat_test.run(false);
alpar@877
   140
kpeter@590
   141
  const_mat_test.matchingSize();
kpeter@590
   142
  const_mat_test.matching(e);
kpeter@590
   143
  const_mat_test.matching(n);
kpeter@593
   144
  const MaxMatching<Graph>::MatchingMap& mmap =
kpeter@593
   145
    const_mat_test.matchingMap();
kpeter@593
   146
  e = mmap[n];
kpeter@590
   147
  const_mat_test.mate(n);
kpeter@590
   148
alpar@877
   149
  MaxMatching<Graph>::Status stat =
kpeter@593
   150
    const_mat_test.status(n);
alpar@1083
   151
  ::lemon::ignore_unused_variable_warning(stat);
kpeter@593
   152
  const MaxMatching<Graph>::StatusMap& smap =
kpeter@593
   153
    const_mat_test.statusMap();
kpeter@593
   154
  stat = smap[n];
kpeter@590
   155
  const_mat_test.barrier(n);
kpeter@590
   156
}
kpeter@590
   157
kpeter@590
   158
void checkMaxWeightedMatchingCompile()
kpeter@590
   159
{
kpeter@590
   160
  typedef concepts::Graph Graph;
kpeter@590
   161
  typedef Graph::Node Node;
kpeter@590
   162
  typedef Graph::Edge Edge;
kpeter@590
   163
  typedef Graph::EdgeMap<int> WeightMap;
kpeter@590
   164
kpeter@590
   165
  Graph g;
kpeter@590
   166
  Node n;
kpeter@590
   167
  Edge e;
kpeter@590
   168
  WeightMap w(g);
kpeter@590
   169
kpeter@590
   170
  MaxWeightedMatching<Graph> mat_test(g, w);
kpeter@590
   171
  const MaxWeightedMatching<Graph>&
kpeter@590
   172
    const_mat_test = mat_test;
kpeter@590
   173
kpeter@590
   174
  mat_test.init();
kpeter@590
   175
  mat_test.start();
kpeter@590
   176
  mat_test.run();
alpar@877
   177
kpeter@593
   178
  const_mat_test.matchingWeight();
kpeter@590
   179
  const_mat_test.matchingSize();
kpeter@590
   180
  const_mat_test.matching(e);
kpeter@590
   181
  const_mat_test.matching(n);
kpeter@593
   182
  const MaxWeightedMatching<Graph>::MatchingMap& mmap =
kpeter@593
   183
    const_mat_test.matchingMap();
kpeter@593
   184
  e = mmap[n];
kpeter@590
   185
  const_mat_test.mate(n);
alpar@877
   186
kpeter@590
   187
  int k = 0;
kpeter@590
   188
  const_mat_test.dualValue();
kpeter@590
   189
  const_mat_test.nodeValue(n);
kpeter@590
   190
  const_mat_test.blossomNum();
kpeter@590
   191
  const_mat_test.blossomSize(k);
kpeter@590
   192
  const_mat_test.blossomValue(k);
kpeter@590
   193
}
kpeter@590
   194
kpeter@590
   195
void checkMaxWeightedPerfectMatchingCompile()
kpeter@590
   196
{
kpeter@590
   197
  typedef concepts::Graph Graph;
kpeter@590
   198
  typedef Graph::Node Node;
kpeter@590
   199
  typedef Graph::Edge Edge;
kpeter@590
   200
  typedef Graph::EdgeMap<int> WeightMap;
kpeter@590
   201
kpeter@590
   202
  Graph g;
kpeter@590
   203
  Node n;
kpeter@590
   204
  Edge e;
kpeter@590
   205
  WeightMap w(g);
kpeter@590
   206
kpeter@590
   207
  MaxWeightedPerfectMatching<Graph> mat_test(g, w);
kpeter@590
   208
  const MaxWeightedPerfectMatching<Graph>&
kpeter@590
   209
    const_mat_test = mat_test;
kpeter@590
   210
kpeter@590
   211
  mat_test.init();
kpeter@590
   212
  mat_test.start();
kpeter@590
   213
  mat_test.run();
alpar@877
   214
kpeter@593
   215
  const_mat_test.matchingWeight();
kpeter@590
   216
  const_mat_test.matching(e);
kpeter@590
   217
  const_mat_test.matching(n);
kpeter@593
   218
  const MaxWeightedPerfectMatching<Graph>::MatchingMap& mmap =
kpeter@593
   219
    const_mat_test.matchingMap();
kpeter@593
   220
  e = mmap[n];
kpeter@590
   221
  const_mat_test.mate(n);
alpar@877
   222
kpeter@590
   223
  int k = 0;
kpeter@590
   224
  const_mat_test.dualValue();
kpeter@590
   225
  const_mat_test.nodeValue(n);
kpeter@590
   226
  const_mat_test.blossomNum();
kpeter@590
   227
  const_mat_test.blossomSize(k);
kpeter@590
   228
  const_mat_test.blossomValue(k);
kpeter@590
   229
}
kpeter@590
   230
deba@327
   231
void checkMatching(const SmartGraph& graph,
deba@327
   232
                   const MaxMatching<SmartGraph>& mm) {
deba@327
   233
  int num = 0;
deba@327
   234
deba@327
   235
  IntNodeMap comp_index(graph);
deba@327
   236
  UnionFind<IntNodeMap> comp(comp_index);
deba@327
   237
deba@327
   238
  int barrier_num = 0;
deba@327
   239
deba@327
   240
  for (NodeIt n(graph); n != INVALID; ++n) {
kpeter@593
   241
    check(mm.status(n) == MaxMatching<SmartGraph>::EVEN ||
deba@327
   242
          mm.matching(n) != INVALID, "Wrong Gallai-Edmonds decomposition");
kpeter@593
   243
    if (mm.status(n) == MaxMatching<SmartGraph>::ODD) {
deba@327
   244
      ++barrier_num;
deba@327
   245
    } else {
deba@327
   246
      comp.insert(n);
deba@327
   247
    }
deba@327
   248
  }
deba@327
   249
deba@327
   250
  for (EdgeIt e(graph); e != INVALID; ++e) {
deba@327
   251
    if (mm.matching(e)) {
deba@327
   252
      check(e == mm.matching(graph.u(e)), "Wrong matching");
deba@327
   253
      check(e == mm.matching(graph.v(e)), "Wrong matching");
deba@327
   254
      ++num;
deba@327
   255
    }
kpeter@593
   256
    check(mm.status(graph.u(e)) != MaxMatching<SmartGraph>::EVEN ||
kpeter@593
   257
          mm.status(graph.v(e)) != MaxMatching<SmartGraph>::MATCHED,
deba@327
   258
          "Wrong Gallai-Edmonds decomposition");
deba@327
   259
kpeter@593
   260
    check(mm.status(graph.v(e)) != MaxMatching<SmartGraph>::EVEN ||
kpeter@593
   261
          mm.status(graph.u(e)) != MaxMatching<SmartGraph>::MATCHED,
deba@327
   262
          "Wrong Gallai-Edmonds decomposition");
deba@327
   263
kpeter@593
   264
    if (mm.status(graph.u(e)) != MaxMatching<SmartGraph>::ODD &&
kpeter@593
   265
        mm.status(graph.v(e)) != MaxMatching<SmartGraph>::ODD) {
deba@327
   266
      comp.join(graph.u(e), graph.v(e));
deba@327
   267
    }
deba@327
   268
  }
deba@327
   269
deba@327
   270
  std::set<int> comp_root;
deba@327
   271
  int odd_comp_num = 0;
deba@327
   272
  for (NodeIt n(graph); n != INVALID; ++n) {
kpeter@593
   273
    if (mm.status(n) != MaxMatching<SmartGraph>::ODD) {
deba@327
   274
      int root = comp.find(n);
deba@327
   275
      if (comp_root.find(root) == comp_root.end()) {
deba@327
   276
        comp_root.insert(root);
deba@327
   277
        if (comp.size(n) % 2 == 1) {
deba@327
   278
          ++odd_comp_num;
deba@327
   279
        }
deba@327
   280
      }
deba@327
   281
    }
deba@327
   282
  }
deba@327
   283
deba@327
   284
  check(mm.matchingSize() == num, "Wrong matching");
deba@327
   285
  check(2 * num == countNodes(graph) - (odd_comp_num - barrier_num),
deba@327
   286
         "Wrong matching");
deba@327
   287
  return;
deba@327
   288
}
deba@327
   289
deba@327
   290
void checkWeightedMatching(const SmartGraph& graph,
deba@327
   291
                   const SmartGraph::EdgeMap<int>& weight,
deba@327
   292
                   const MaxWeightedMatching<SmartGraph>& mwm) {
deba@327
   293
  for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) {
deba@327
   294
    if (graph.u(e) == graph.v(e)) continue;
deba@327
   295
    int rw = mwm.nodeValue(graph.u(e)) + mwm.nodeValue(graph.v(e));
deba@327
   296
deba@327
   297
    for (int i = 0; i < mwm.blossomNum(); ++i) {
deba@327
   298
      bool s = false, t = false;
deba@327
   299
      for (MaxWeightedMatching<SmartGraph>::BlossomIt n(mwm, i);
deba@327
   300
           n != INVALID; ++n) {
deba@327
   301
        if (graph.u(e) == n) s = true;
deba@327
   302
        if (graph.v(e) == n) t = true;
deba@327
   303
      }
deba@327
   304
      if (s == true && t == true) {
deba@327
   305
        rw += mwm.blossomValue(i);
deba@327
   306
      }
deba@327
   307
    }
deba@327
   308
    rw -= weight[e] * mwm.dualScale;
deba@327
   309
deba@327
   310
    check(rw >= 0, "Negative reduced weight");
deba@327
   311
    check(rw == 0 || !mwm.matching(e),
deba@327
   312
          "Non-zero reduced weight on matching edge");
deba@327
   313
  }
deba@327
   314
deba@327
   315
  int pv = 0;
deba@327
   316
  for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) {
deba@327
   317
    if (mwm.matching(n) != INVALID) {
deba@327
   318
      check(mwm.nodeValue(n) >= 0, "Invalid node value");
deba@327
   319
      pv += weight[mwm.matching(n)];
deba@327
   320
      SmartGraph::Node o = graph.target(mwm.matching(n));
deba@327
   321
      check(mwm.mate(n) == o, "Invalid matching");
deba@327
   322
      check(mwm.matching(n) == graph.oppositeArc(mwm.matching(o)),
deba@327
   323
            "Invalid matching");
deba@327
   324
    } else {
deba@327
   325
      check(mwm.mate(n) == INVALID, "Invalid matching");
deba@327
   326
      check(mwm.nodeValue(n) == 0, "Invalid matching");
deba@327
   327
    }
deba@327
   328
  }
deba@327
   329
deba@327
   330
  int dv = 0;
deba@327
   331
  for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) {
deba@327
   332
    dv += mwm.nodeValue(n);
deba@327
   333
  }
deba@327
   334
deba@327
   335
  for (int i = 0; i < mwm.blossomNum(); ++i) {
deba@327
   336
    check(mwm.blossomValue(i) >= 0, "Invalid blossom value");
deba@327
   337
    check(mwm.blossomSize(i) % 2 == 1, "Even blossom size");
deba@327
   338
    dv += mwm.blossomValue(i) * ((mwm.blossomSize(i) - 1) / 2);
deba@327
   339
  }
deba@327
   340
deba@327
   341
  check(pv * mwm.dualScale == dv * 2, "Wrong duality");
deba@327
   342
deba@327
   343
  return;
deba@327
   344
}
deba@327
   345
deba@327
   346
void checkWeightedPerfectMatching(const SmartGraph& graph,
deba@327
   347
                          const SmartGraph::EdgeMap<int>& weight,
deba@327
   348
                          const MaxWeightedPerfectMatching<SmartGraph>& mwpm) {
deba@327
   349
  for (SmartGraph::EdgeIt e(graph); e != INVALID; ++e) {
deba@327
   350
    if (graph.u(e) == graph.v(e)) continue;
deba@327
   351
    int rw = mwpm.nodeValue(graph.u(e)) + mwpm.nodeValue(graph.v(e));
deba@327
   352
deba@327
   353
    for (int i = 0; i < mwpm.blossomNum(); ++i) {
deba@327
   354
      bool s = false, t = false;
deba@327
   355
      for (MaxWeightedPerfectMatching<SmartGraph>::BlossomIt n(mwpm, i);
deba@327
   356
           n != INVALID; ++n) {
deba@327
   357
        if (graph.u(e) == n) s = true;
deba@327
   358
        if (graph.v(e) == n) t = true;
deba@327
   359
      }
deba@327
   360
      if (s == true && t == true) {
deba@327
   361
        rw += mwpm.blossomValue(i);
deba@327
   362
      }
deba@327
   363
    }
deba@327
   364
    rw -= weight[e] * mwpm.dualScale;
deba@327
   365
deba@327
   366
    check(rw >= 0, "Negative reduced weight");
deba@327
   367
    check(rw == 0 || !mwpm.matching(e),
deba@327
   368
          "Non-zero reduced weight on matching edge");
deba@327
   369
  }
deba@327
   370
deba@327
   371
  int pv = 0;
deba@327
   372
  for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) {
deba@327
   373
    check(mwpm.matching(n) != INVALID, "Non perfect");
deba@327
   374
    pv += weight[mwpm.matching(n)];
deba@327
   375
    SmartGraph::Node o = graph.target(mwpm.matching(n));
deba@327
   376
    check(mwpm.mate(n) == o, "Invalid matching");
deba@327
   377
    check(mwpm.matching(n) == graph.oppositeArc(mwpm.matching(o)),
deba@327
   378
          "Invalid matching");
deba@327
   379
  }
deba@327
   380
deba@327
   381
  int dv = 0;
deba@327
   382
  for (SmartGraph::NodeIt n(graph); n != INVALID; ++n) {
deba@327
   383
    dv += mwpm.nodeValue(n);
deba@327
   384
  }
deba@327
   385
deba@327
   386
  for (int i = 0; i < mwpm.blossomNum(); ++i) {
deba@327
   387
    check(mwpm.blossomValue(i) >= 0, "Invalid blossom value");
deba@327
   388
    check(mwpm.blossomSize(i) % 2 == 1, "Even blossom size");
deba@327
   389
    dv += mwpm.blossomValue(i) * ((mwpm.blossomSize(i) - 1) / 2);
deba@327
   390
  }
deba@327
   391
deba@327
   392
  check(pv * mwpm.dualScale == dv * 2, "Wrong duality");
deba@327
   393
deba@327
   394
  return;
deba@327
   395
}
deba@327
   396
deba@327
   397
deba@326
   398
int main() {
deba@326
   399
deba@327
   400
  for (int i = 0; i < lgfn; ++i) {
deba@327
   401
    SmartGraph graph;
deba@327
   402
    SmartGraph::EdgeMap<int> weight(graph);
deba@326
   403
deba@327
   404
    istringstream lgfs(lgf[i]);
deba@327
   405
    graphReader(graph, lgfs).
deba@327
   406
      edgeMap("weight", weight).run();
deba@326
   407
deba@1203
   408
    int size;
deba@870
   409
    bool perfect;
deba@870
   410
    {
deba@870
   411
      MaxMatching<SmartGraph> mm(graph);
deba@870
   412
      mm.run();
deba@870
   413
      checkMatching(graph, mm);
deba@1203
   414
      size = mm.matchingSize();
deba@870
   415
      perfect = 2 * mm.matchingSize() == countNodes(graph);
deba@870
   416
    }
deba@326
   417
deba@870
   418
    {
deba@1203
   419
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   420
      mm.init();
deba@1203
   421
      mm.startSparse();
deba@1203
   422
      checkMatching(graph, mm);
deba@1203
   423
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   424
    }
deba@1203
   425
deba@1203
   426
    {
deba@1203
   427
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   428
      mm.init();
deba@1203
   429
      mm.startDense();
deba@1203
   430
      checkMatching(graph, mm);
deba@1203
   431
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   432
    }
deba@1203
   433
deba@1203
   434
    {
deba@1203
   435
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   436
      mm.greedyInit();
deba@1203
   437
      mm.startSparse();
deba@1203
   438
      checkMatching(graph, mm);
deba@1203
   439
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   440
    }
deba@1203
   441
deba@1203
   442
    {
deba@1203
   443
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   444
      mm.greedyInit();
deba@1203
   445
      mm.startDense();
deba@1203
   446
      checkMatching(graph, mm);
deba@1203
   447
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   448
    }
deba@1203
   449
deba@1203
   450
    {
deba@1203
   451
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   452
      mm.run(false);
deba@1203
   453
      check(size == mm.matchingSize(), "Inconsistent max cardinality matching");
deba@1203
   454
    }
deba@1203
   455
deba@1203
   456
    {
deba@1203
   457
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   458
      mm.init();
deba@1203
   459
      mm.startSparse(false);
deba@1203
   460
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   461
    }
deba@1203
   462
deba@1203
   463
    {
deba@1203
   464
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   465
      mm.init();
deba@1203
   466
      mm.startDense(false);
deba@1203
   467
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   468
    }
deba@1203
   469
deba@1203
   470
    {
deba@1203
   471
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   472
      mm.greedyInit();
deba@1203
   473
      mm.startSparse(false);
deba@1203
   474
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   475
    }
deba@1203
   476
deba@1203
   477
    {
deba@1203
   478
      MaxMatching<SmartGraph> mm(graph);
deba@1203
   479
      mm.greedyInit();
deba@1203
   480
      mm.startDense(false);
deba@1203
   481
      check(size == mm.matchingSize(), "Inconsistent matching size");
deba@1203
   482
    }
deba@1203
   483
deba@1203
   484
    {
deba@870
   485
      MaxWeightedMatching<SmartGraph> mwm(graph, weight);
deba@870
   486
      mwm.run();
deba@870
   487
      checkWeightedMatching(graph, weight, mwm);
deba@870
   488
    }
deba@326
   489
deba@870
   490
    {
deba@870
   491
      MaxWeightedMatching<SmartGraph> mwm(graph, weight);
deba@870
   492
      mwm.init();
deba@870
   493
      mwm.start();
deba@870
   494
      checkWeightedMatching(graph, weight, mwm);
deba@870
   495
    }
deba@326
   496
deba@870
   497
    {
deba@870
   498
      MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight);
deba@870
   499
      bool result = mwpm.run();
deba@326
   500
deba@870
   501
      check(result == perfect, "Perfect matching found");
deba@870
   502
      if (perfect) {
deba@870
   503
        checkWeightedPerfectMatching(graph, weight, mwpm);
deba@870
   504
      }
deba@870
   505
    }
kpeter@594
   506
deba@870
   507
    {
deba@870
   508
      MaxWeightedPerfectMatching<SmartGraph> mwpm(graph, weight);
deba@870
   509
      mwpm.init();
deba@870
   510
      bool result = mwpm.start();
alpar@877
   511
deba@870
   512
      check(result == perfect, "Perfect matching found");
deba@870
   513
      if (perfect) {
deba@870
   514
        checkWeightedPerfectMatching(graph, weight, mwpm);
deba@870
   515
      }
deba@326
   516
    }
deba@326
   517
  }
deba@326
   518
deba@326
   519
  return 0;
deba@326
   520
}