tests/circulation.cc
author Alpar Juttner <alpar@cs.elte.hu>
Sun, 11 Dec 2011 16:08:52 +0100
changeset 12 4eab99ff2666
parent 11 cf6519daa7fa
permissions -rw-r--r--
Add Copyright headers
alpar@12
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@12
     2
 *
alpar@12
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@12
     4
 *
alpar@12
     5
 * Copyright (C) 2003-2011
alpar@12
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@12
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@12
     8
 *
alpar@12
     9
 * Permission to use, modify and distribute this software is granted
alpar@12
    10
 * provided that this copyright notice appears in all copies. For
alpar@12
    11
 * precise terms see the accompanying LICENSE file.
alpar@12
    12
 *
alpar@12
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@12
    14
 * express or implied, and with no claim as to its suitability for any
alpar@12
    15
 * purpose.
alpar@12
    16
 *
alpar@12
    17
 */
alpar@12
    18
alpar@10
    19
#include <benchmark_tools.h>
alpar@9
    20
#include <lemon/circulation.h>
alpar@9
    21
#include <lemon/smart_graph.h>
alpar@9
    22
#include <lemon/lgf_reader.h>
alpar@9
    23
#include <lemon/dimacs.h>
alpar@9
    24
#include <lemon/error.h>
alpar@11
    25
#include <istream>
alpar@9
    26
alpar@11
    27
std::string test_name = "circulation";
alpar@9
    28
alpar@9
    29
using namespace lemon;
alpar@9
    30
alpar@11
    31
int testMain(std::istream &input)
alpar@9
    32
{
alpar@9
    33
  typedef int Value;
alpar@9
    34
  
alpar@9
    35
  SmartDigraph g;
alpar@9
    36
  
alpar@9
    37
  SmartDigraph::ArcMap<Value> lo_cap(g);
alpar@9
    38
  SmartDigraph::ArcMap<Value> up_cap(g);
alpar@9
    39
  SmartDigraph::ArcMap<Value> cost(g);
alpar@9
    40
  SmartDigraph::NodeMap<Value> sup(g);
alpar@9
    41
  
alpar@9
    42
  Timer ti;
alpar@9
    43
  try {
alpar@9
    44
    readDimacsMin(input, g, lo_cap, up_cap, cost, sup);
alpar@9
    45
  } catch (FormatError& error) {
alpar@9
    46
    std::cerr << error.what() << std::endl;
alpar@9
    47
    return 1;
alpar@9
    48
  }
alpar@11
    49
  logTime("fread",ti);
alpar@10
    50
alpar@10
    51
  Timer tf;
alpar@9
    52
  ti.restart();
alpar@9
    53
  Circulation<SmartDigraph,
alpar@9
    54
    SmartDigraph::ArcMap<Value>,SmartDigraph::ArcMap<Value>,
alpar@9
    55
    SmartDigraph::NodeMap<Value> > circ(g,lo_cap,up_cap,sup);
alpar@10
    56
  logTime("setup",ti);
alpar@9
    57
  ti.restart();
alpar@9
    58
  bool res = circ.run();
alpar@10
    59
  logTime("alg",ti);
alpar@10
    60
  logTime("full",tf);
alpar@9
    61
  if(res)
alpar@9
    62
    {
alpar@10
    63
      std::cerr << "A feasible circulation is found\n";
alpar@10
    64
      std::cerr << "Checking...\n";
alpar@9
    65
      ti.restart();
alpar@9
    66
      bool res2 = circ.checkFlow();
alpar@10
    67
      logTime("check",ti);
alpar@9
    68
      if(res2)
alpar@10
    69
        std::cerr << "Success!\n";
alpar@9
    70
      else
alpar@10
    71
        std::cerr << "Oops!!!!\n";
alpar@9
    72
    }
alpar@9
    73
  else
alpar@9
    74
    {
alpar@10
    75
      std::cerr << "A dual solution is found\n";
alpar@10
    76
      std::cerr << "Checking...\n";
alpar@9
    77
      ti.restart();
alpar@9
    78
      bool res2 = circ.checkBarrier();
alpar@10
    79
      logTime("check",ti);
alpar@9
    80
      if(res2)
alpar@10
    81
        std::cerr << "Success!\n";
alpar@9
    82
      else
alpar@10
    83
        std::cerr << "Dual-Oops!!!!\n";
alpar@9
    84
alpar@9
    85
    }
alpar@9
    86
}
alpar@9
    87