test/arc_look_up_test.cc
author Peter Kovacs <kpeter@inf.elte.hu>
Sat, 16 Mar 2013 16:50:39 +0100
changeset 802 0e30f63d45d0
permissions -rw-r--r--
Bugfix in assert.h (#461)
alpar@789
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@789
     2
 *
alpar@789
     3
 * This file is a part of LEMON, a generic C++ optimization library.
alpar@789
     4
 *
alpar@789
     5
 * Copyright (C) 2003-2009
alpar@789
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@789
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@789
     8
 *
alpar@789
     9
 * Permission to use, modify and distribute this software is granted
alpar@789
    10
 * provided that this copyright notice appears in all copies. For
alpar@789
    11
 * precise terms see the accompanying LICENSE file.
alpar@789
    12
 *
alpar@789
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@789
    14
 * express or implied, and with no claim as to its suitability for any
alpar@789
    15
 * purpose.
alpar@789
    16
 *
alpar@789
    17
 */
alpar@789
    18
alpar@789
    19
#include <iostream>
alpar@789
    20
#include "lemon/list_graph.h"
alpar@789
    21
#include "lemon/lgf_reader.h"
alpar@789
    22
alpar@789
    23
#include "test_tools.h"
alpar@789
    24
alpar@789
    25
using namespace lemon;
alpar@789
    26
alpar@789
    27
const int lgfn = 4;
alpar@789
    28
const std::string lgf =
alpar@789
    29
  "@nodes\n"
alpar@789
    30
"label\n"
alpar@789
    31
"0\n"
alpar@789
    32
"1\n"
alpar@789
    33
"2\n"
alpar@789
    34
"3\n"
alpar@789
    35
"4\n"
alpar@789
    36
"5\n"
alpar@789
    37
"6\n"
alpar@789
    38
"@arcs\n"
alpar@789
    39
"label\n"
alpar@789
    40
"5 6 0\n"
alpar@789
    41
"5 4 1\n"
alpar@789
    42
"4 6 2\n"
alpar@789
    43
"3 4 3\n"
alpar@789
    44
"3 4 4\n"
alpar@789
    45
"3 2 5\n"
alpar@789
    46
"3 5 6\n"
alpar@789
    47
"3 5 7\n"
alpar@789
    48
"3 5 8\n"
alpar@789
    49
"3 5 9\n"
alpar@789
    50
"2 4 10\n"
alpar@789
    51
"2 4 11\n"
alpar@789
    52
"2 4 12\n"
alpar@789
    53
"2 4 13\n"
alpar@789
    54
"1 2 14\n"
alpar@789
    55
"1 2 15\n"
alpar@789
    56
"1 0 16\n"
alpar@789
    57
"1 3 17\n"
alpar@789
    58
"1 3 18\n"
alpar@789
    59
"1 3 19\n"
alpar@789
    60
"1 3 20\n"
alpar@789
    61
"0 2 21\n"
alpar@789
    62
"0 2 22\n"
alpar@789
    63
"0 2 23\n"
alpar@789
    64
"0 2 24\n";
alpar@789
    65
alpar@789
    66
alpar@789
    67
int main() {
alpar@789
    68
  ListDigraph graph;
alpar@789
    69
  std::istringstream lgfs(lgf);
alpar@789
    70
  DigraphReader<ListDigraph>(graph, lgfs).run();
alpar@789
    71
  
alpar@789
    72
  AllArcLookUp<ListDigraph> lookup(graph);
alpar@789
    73
	
alpar@789
    74
  int numArcs = countArcs(graph);
alpar@789
    75
	
alpar@789
    76
  int arcCnt = 0;
alpar@789
    77
  for(ListDigraph::NodeIt n1(graph); n1 != INVALID; ++n1)
alpar@789
    78
    for(ListDigraph::NodeIt n2(graph); n2 != INVALID; ++n2)
alpar@789
    79
      for(ListDigraph::Arc a = lookup(n1, n2); a != INVALID;
alpar@789
    80
	  a = lookup(n1, n2, a))
alpar@789
    81
	++arcCnt;
alpar@789
    82
  check(arcCnt==numArcs, "Wrong total number of arcs");
alpar@789
    83
alpar@789
    84
  return 0;
alpar@789
    85
}