gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Adds tests for the new MCF algorithms (#180)
0 1 0
default
1 file changed with 66 insertions and 0 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2009
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#include <iostream>
20 20
#include <fstream>
21 21
#include <limits>
22 22

	
23 23
#include <lemon/list_graph.h>
24 24
#include <lemon/lgf_reader.h>
25 25

	
26 26
#include <lemon/network_simplex.h>
27
#include <lemon/capacity_scaling.h>
28
#include <lemon/cost_scaling.h>
29
#include <lemon/cycle_canceling.h>
27 30

	
28 31
#include <lemon/concepts/digraph.h>
32
#include <lemon/concepts/heap.h>
29 33
#include <lemon/concept_check.h>
30 34

	
31 35
#include "test_tools.h"
32 36

	
33 37
using namespace lemon;
34 38

	
35 39
// Test networks
36 40
char test_lgf[] =
37 41
  "@nodes\n"
38 42
  "label  sup1 sup2 sup3 sup4 sup5 sup6\n"
39 43
  "    1    20   27    0   30   20   30\n"
40 44
  "    2    -4    0    0    0   -8   -3\n"
41 45
  "    3     0    0    0    0    0    0\n"
42 46
  "    4     0    0    0    0    0    0\n"
43 47
  "    5     9    0    0    0    6   11\n"
44 48
  "    6    -6    0    0    0   -5   -6\n"
45 49
  "    7     0    0    0    0    0    0\n"
46 50
  "    8     0    0    0    0    0    3\n"
47 51
  "    9     3    0    0    0    0    0\n"
48 52
  "   10    -2    0    0    0   -7   -2\n"
49 53
  "   11     0    0    0    0  -10    0\n"
50 54
  "   12   -20  -27    0  -30  -30  -20\n"
51 55
  "\n"                
52 56
  "@arcs\n"
53 57
  "       cost  cap low1 low2 low3\n"
54 58
  " 1  2    70   11    0    8    8\n"
55 59
  " 1  3   150    3    0    1    0\n"
56 60
  " 1  4    80   15    0    2    2\n"
57 61
  " 2  8    80   12    0    0    0\n"
58 62
  " 3  5   140    5    0    3    1\n"
59 63
  " 4  6    60   10    0    1    0\n"
60 64
  " 4  7    80    2    0    0    0\n"
61 65
  " 4  8   110    3    0    0    0\n"
62 66
  " 5  7    60   14    0    0    0\n"
63 67
  " 5 11   120   12    0    0    0\n"
64 68
  " 6  3     0    3    0    0    0\n"
65 69
  " 6  9   140    4    0    0    0\n"
66 70
  " 6 10    90    8    0    0    0\n"
67 71
  " 7  1    30    5    0    0   -5\n"
68 72
  " 8 12    60   16    0    4    3\n"
69 73
  " 9 12    50    6    0    0    0\n"
70 74
  "10 12    70   13    0    5    2\n"
71 75
  "10  2   100    7    0    0    0\n"
72 76
  "10  7    60   10    0    0   -3\n"
73 77
  "11 10    20   14    0    6  -20\n"
74 78
  "12 11    30   10    0    0  -10\n"
75 79
  "\n"
76 80
  "@attributes\n"
... ...
@@ -412,65 +416,127 @@
412 416
}
413 417

	
414 418

	
415 419
int main()
416 420
{
417 421
  // Read the test networks
418 422
  std::istringstream input(test_lgf);
419 423
  DigraphReader<Digraph>(gr, input)
420 424
    .arcMap("cost", c)
421 425
    .arcMap("cap", u)
422 426
    .arcMap("low1", l1)
423 427
    .arcMap("low2", l2)
424 428
    .arcMap("low3", l3)
425 429
    .nodeMap("sup1", s1)
426 430
    .nodeMap("sup2", s2)
427 431
    .nodeMap("sup3", s3)
428 432
    .nodeMap("sup4", s4)
429 433
    .nodeMap("sup5", s5)
430 434
    .nodeMap("sup6", s6)
431 435
    .node("source", v)
432 436
    .node("target", w)
433 437
    .run();
434 438
  
435 439
  std::istringstream neg_inp1(test_neg1_lgf);
436 440
  DigraphReader<Digraph>(neg1_gr, neg_inp1)
437 441
    .arcMap("cost", neg1_c)
438 442
    .arcMap("low1", neg1_l1)
439 443
    .arcMap("low2", neg1_l2)
440 444
    .nodeMap("sup", neg1_s)
441 445
    .run();
442 446
  
443 447
  std::istringstream neg_inp2(test_neg2_lgf);
444 448
  DigraphReader<Digraph>(neg2_gr, neg_inp2)
445 449
    .arcMap("cost", neg2_c)
446 450
    .nodeMap("sup", neg2_s)
447 451
    .run();
448 452
  
449 453
  // Check the interface of NetworkSimplex
450 454
  {
451 455
    typedef concepts::Digraph GR;
452 456
    checkConcept< McfClassConcept<GR, int, int>,
453 457
                  NetworkSimplex<GR> >();
454 458
    checkConcept< McfClassConcept<GR, double, double>,
455 459
                  NetworkSimplex<GR, double> >();
456 460
    checkConcept< McfClassConcept<GR, int, double>,
457 461
                  NetworkSimplex<GR, int, double> >();
458 462
  }
459 463

	
464
  // Check the interface of CapacityScaling
465
  {
466
    typedef concepts::Digraph GR;
467
    checkConcept< McfClassConcept<GR, int, int>,
468
                  CapacityScaling<GR> >();
469
    checkConcept< McfClassConcept<GR, double, double>,
470
                  CapacityScaling<GR, double> >();
471
    checkConcept< McfClassConcept<GR, int, double>,
472
                  CapacityScaling<GR, int, double> >();
473
    typedef CapacityScaling<GR>::
474
      SetHeap<concepts::Heap<int, RangeMap<int> > >::Create CAS;
475
    checkConcept< McfClassConcept<GR, int, int>, CAS >();
476
  }
477

	
478
  // Check the interface of CostScaling
479
  {
480
    typedef concepts::Digraph GR;
481
    checkConcept< McfClassConcept<GR, int, int>,
482
                  CostScaling<GR> >();
483
    checkConcept< McfClassConcept<GR, double, double>,
484
                  CostScaling<GR, double> >();
485
    checkConcept< McfClassConcept<GR, int, double>,
486
                  CostScaling<GR, int, double> >();
487
    typedef CostScaling<GR>::
488
      SetLargeCost<double>::Create COS;
489
    checkConcept< McfClassConcept<GR, int, int>, COS >();
490
  }
491

	
492
  // Check the interface of CycleCanceling
493
  {
494
    typedef concepts::Digraph GR;
495
    checkConcept< McfClassConcept<GR, int, int>,
496
                  CycleCanceling<GR> >();
497
    checkConcept< McfClassConcept<GR, double, double>,
498
                  CycleCanceling<GR, double> >();
499
    checkConcept< McfClassConcept<GR, int, double>,
500
                  CycleCanceling<GR, int, double> >();
501
  }
502

	
460 503
  // Test NetworkSimplex
461 504
  { 
462 505
    typedef NetworkSimplex<Digraph> MCF;
463 506
    runMcfGeqTests<MCF>(MCF::FIRST_ELIGIBLE, "NS-FE", true);
464 507
    runMcfLeqTests<MCF>(MCF::FIRST_ELIGIBLE, "NS-FE");
465 508
    runMcfGeqTests<MCF>(MCF::BEST_ELIGIBLE,  "NS-BE", true);
466 509
    runMcfLeqTests<MCF>(MCF::BEST_ELIGIBLE,  "NS-BE");
467 510
    runMcfGeqTests<MCF>(MCF::BLOCK_SEARCH,   "NS-BS", true);
468 511
    runMcfLeqTests<MCF>(MCF::BLOCK_SEARCH,   "NS-BS");
469 512
    runMcfGeqTests<MCF>(MCF::CANDIDATE_LIST, "NS-CL", true);
470 513
    runMcfLeqTests<MCF>(MCF::CANDIDATE_LIST, "NS-CL");
471 514
    runMcfGeqTests<MCF>(MCF::ALTERING_LIST,  "NS-AL", true);
472 515
    runMcfLeqTests<MCF>(MCF::ALTERING_LIST,  "NS-AL");
473 516
  }
517
  
518
  // Test CapacityScaling
519
  {
520
    typedef CapacityScaling<Digraph> MCF;
521
    runMcfGeqTests<MCF>(0, "SSP");
522
    runMcfGeqTests<MCF>(2, "CAS");
523
  }
524

	
525
  // Test CostScaling
526
  {
527
    typedef CostScaling<Digraph> MCF;
528
    runMcfGeqTests<MCF>(MCF::PUSH, "COS-PR");
529
    runMcfGeqTests<MCF>(MCF::AUGMENT, "COS-AR");
530
    runMcfGeqTests<MCF>(MCF::PARTIAL_AUGMENT, "COS-PAR");
531
  }
532

	
533
  // Test CycleCanceling
534
  {
535
    typedef CycleCanceling<Digraph> MCF;
536
    runMcfGeqTests<MCF>(MCF::SIMPLE_CYCLE_CANCELING, "SCC");
537
    runMcfGeqTests<MCF>(MCF::MINIMUM_MEAN_CYCLE_CANCELING, "MMCC");
538
    runMcfGeqTests<MCF>(MCF::CANCEL_AND_TIGHTEN, "CAT");
539
  }
474 540

	
475 541
  return 0;
476 542
}
0 comments (0 inline)