test/suurballe_test.cc
author alpar
Mon, 04 Sep 2006 19:12:44 +0000
changeset 2194 eaf16c8f6fef
parent 1875 98698b69a902
child 2391 14a343be7a5a
permissions -rw-r--r--
'make doc' is now working also in case of external build.
alpar@906
     1
/* -*- C++ -*-
alpar@906
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906
     8
 *
alpar@906
     9
 * Permission to use, modify and distribute this software is granted
alpar@906
    10
 * provided that this copyright notice appears in all copies. For
alpar@906
    11
 * precise terms see the accompanying LICENSE file.
alpar@906
    12
 *
alpar@906
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    14
 * express or implied, and with no claim as to its suitability for any
alpar@906
    15
 * purpose.
alpar@906
    16
 *
alpar@906
    17
 */
alpar@906
    18
alpar@899
    19
#include <iostream>
alpar@921
    20
#include <lemon/list_graph.h>
alpar@921
    21
#include <lemon/suurballe.h>
alpar@899
    22
//#include <path.h>
alpar@899
    23
#include "test_tools.h"
alpar@899
    24
alpar@921
    25
using namespace lemon;
alpar@899
    26
alpar@899
    27
alpar@899
    28
bool passed = true;
alpar@899
    29
alpar@899
    30
alpar@899
    31
int main()
alpar@899
    32
{
marci@941
    33
  typedef ListGraph Graph;
marci@941
    34
  typedef Graph::Node Node;
marci@941
    35
  typedef Graph::Edge Edge;
alpar@899
    36
marci@941
    37
  Graph graph;
alpar@899
    38
alpar@899
    39
  //Ahuja könyv példája
alpar@899
    40
alpar@899
    41
  Node s=graph.addNode();
alpar@899
    42
  Node v1=graph.addNode();  
alpar@899
    43
  Node v2=graph.addNode();
alpar@899
    44
  Node v3=graph.addNode();
alpar@899
    45
  Node v4=graph.addNode();
alpar@899
    46
  Node v5=graph.addNode();
alpar@899
    47
  Node t=graph.addNode();
alpar@899
    48
alpar@899
    49
  Edge s_v1=graph.addEdge(s, v1);
alpar@899
    50
  Edge v1_v2=graph.addEdge(v1, v2);
alpar@899
    51
  Edge s_v3=graph.addEdge(s, v3);
alpar@899
    52
  Edge v2_v4=graph.addEdge(v2, v4);
alpar@899
    53
  Edge v2_v5=graph.addEdge(v2, v5);
alpar@899
    54
  Edge v3_v5=graph.addEdge(v3, v5);
alpar@899
    55
  Edge v4_t=graph.addEdge(v4, t);
alpar@899
    56
  Edge v5_t=graph.addEdge(v5, t);
alpar@899
    57
  
alpar@899
    58
marci@941
    59
  Graph::EdgeMap<int> length(graph);
alpar@899
    60
alpar@899
    61
  length.set(s_v1, 6);
alpar@899
    62
  length.set(v1_v2, 4);
alpar@899
    63
  length.set(s_v3, 10);
alpar@899
    64
  length.set(v2_v4, 5);
alpar@899
    65
  length.set(v2_v5, 1);
alpar@899
    66
  length.set(v3_v5, 5);
alpar@899
    67
  length.set(v4_t, 8);
alpar@899
    68
  length.set(v5_t, 8);
alpar@899
    69
alpar@899
    70
  std::cout << "Minlengthpaths algorithm test..." << std::endl;
alpar@899
    71
alpar@899
    72
  
alpar@899
    73
  int k=3;
marci@941
    74
  Suurballe< Graph, Graph::EdgeMap<int> >
marci@941
    75
    surb_test(graph, length, s, t);
alpar@899
    76
marci@941
    77
  check(  surb_test.run(k) == 2 && surb_test.totalLength() == 46,
alpar@899
    78
	  "Two paths, total length should be 46");
alpar@899
    79
alpar@899
    80
  check(  surb_test.checkComplementarySlackness(),
alpar@899
    81
	  "Complementary slackness conditions are not met.");
alpar@899
    82
marci@941
    83
  //  typedef DirPath<Graph> DPath;
alpar@899
    84
  //  DPath P(graph);
alpar@899
    85
alpar@899
    86
  /*
alpar@899
    87
  surb_test.getPath(P,0);
alpar@899
    88
  check(P.length() == 4, "First path should contain 4 edges.");  
marci@941
    89
  std::cout<<P.length()<<std::endl;
alpar@899
    90
  surb_test.getPath(P,1);
alpar@899
    91
  check(P.length() == 3, "Second path: 3 edges.");
marci@941
    92
  std::cout<<P.length()<<std::endl;
alpar@899
    93
  */  
alpar@899
    94
alpar@899
    95
  k=1;
marci@941
    96
  check(  surb_test.run(k) == 1 && surb_test.totalLength() == 19,
alpar@899
    97
	  "One path, total length should be 19");
alpar@899
    98
alpar@899
    99
  check(  surb_test.checkComplementarySlackness(),
alpar@899
   100
	  "Complementary slackness conditions are not met.");
alpar@899
   101
 
alpar@899
   102
  //  surb_test.getPath(P,0);
alpar@899
   103
  //  check(P.length() == 4, "First path should contain 4 edges.");  
alpar@899
   104
marci@941
   105
  std::cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
marci@941
   106
	    << std::endl;
alpar@899
   107
alpar@899
   108
  return passed ? 0 : 1;
alpar@899
   109
alpar@899
   110
}