test/dfs_test.cc
author Balazs Dezso <deba@inf.elte.hu>
Mon, 14 Apr 2008 10:46:41 +0200
changeset 126 e1dd2a70737c
child 171 02f4d5d9bfd7
permissions -rw-r--r--
MinGW compatible time measure + changes in its internals
alpar@100
     1
/* -*- C++ -*-
alpar@100
     2
 *
alpar@100
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@100
     4
 *
alpar@100
     5
 * Copyright (C) 2003-2008
alpar@100
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@100
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@100
     8
 *
alpar@100
     9
 * Permission to use, modify and distribute this software is granted
alpar@100
    10
 * provided that this copyright notice appears in all copies. For
alpar@100
    11
 * precise terms see the accompanying LICENSE file.
alpar@100
    12
 *
alpar@100
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@100
    14
 * express or implied, and with no claim as to its suitability for any
alpar@100
    15
 * purpose.
alpar@100
    16
 *
alpar@100
    17
 */
alpar@100
    18
alpar@100
    19
#include "test_tools.h"
alpar@100
    20
// #include <lemon/smart_graph.h>
alpar@100
    21
#include <lemon/list_graph.h>
alpar@100
    22
#include <lemon/dfs.h>
alpar@100
    23
#include <lemon/path.h>
alpar@100
    24
#include <lemon/concepts/digraph.h>
alpar@100
    25
alpar@100
    26
using namespace lemon;
alpar@100
    27
alpar@100
    28
const int PET_SIZE =5;
alpar@100
    29
alpar@100
    30
alpar@100
    31
void check_Dfs_SmartDigraph_Compile() 
alpar@100
    32
{
alpar@100
    33
  typedef concepts::Digraph Digraph;
alpar@100
    34
alpar@100
    35
  typedef Digraph::Arc Arc;
alpar@100
    36
  typedef Digraph::Node Node;
alpar@100
    37
  typedef Digraph::ArcIt ArcIt;
alpar@100
    38
  typedef Digraph::NodeIt NodeIt;
alpar@100
    39
 
alpar@100
    40
  typedef Dfs<Digraph> DType;
alpar@100
    41
  
alpar@100
    42
  Digraph G;
alpar@100
    43
  Node n;
alpar@100
    44
  Arc e;
alpar@100
    45
  int l;
alpar@100
    46
  bool b;
alpar@100
    47
  DType::DistMap d(G);
alpar@100
    48
  DType::PredMap p(G);
alpar@100
    49
  //  DType::PredNodeMap pn(G);
alpar@100
    50
  
alpar@100
    51
  DType dfs_test(G);
alpar@100
    52
  
alpar@100
    53
  dfs_test.run(n);
alpar@100
    54
  
alpar@100
    55
  l  = dfs_test.dist(n);
alpar@100
    56
  e  = dfs_test.predArc(n);
alpar@100
    57
  n  = dfs_test.predNode(n);
alpar@100
    58
  d  = dfs_test.distMap();
alpar@100
    59
  p  = dfs_test.predMap();
alpar@100
    60
  //  pn = dfs_test.predNodeMap();
alpar@100
    61
  b  = dfs_test.reached(n);
alpar@100
    62
alpar@100
    63
  Path<Digraph> pp = dfs_test.path(n);
alpar@100
    64
}
alpar@100
    65
alpar@100
    66
alpar@100
    67
void check_Dfs_Function_Compile() 
alpar@100
    68
{
alpar@100
    69
  typedef int VType;
alpar@100
    70
  typedef concepts::Digraph Digraph;
alpar@100
    71
alpar@100
    72
  typedef Digraph::Arc Arc;
alpar@100
    73
  typedef Digraph::Node Node;
alpar@100
    74
  typedef Digraph::ArcIt ArcIt;
alpar@100
    75
  typedef Digraph::NodeIt NodeIt;
alpar@100
    76
  typedef concepts::ReadMap<Arc,VType> LengthMap;
alpar@100
    77
   
alpar@100
    78
  Digraph g;
alpar@100
    79
  dfs(g,Node()).run();
alpar@100
    80
  dfs(g).source(Node()).run();
alpar@100
    81
  dfs(g)
alpar@100
    82
    .predMap(concepts::WriteMap<Node,Arc>())
alpar@100
    83
    .distMap(concepts::WriteMap<Node,VType>())
alpar@100
    84
    .reachedMap(concepts::ReadWriteMap<Node,bool>())
alpar@100
    85
    .processedMap(concepts::WriteMap<Node,bool>())
alpar@100
    86
    .run(Node());
alpar@100
    87
  
alpar@100
    88
}
alpar@100
    89
alpar@100
    90
int main()
alpar@100
    91
{
alpar@100
    92
    
alpar@100
    93
  // typedef SmartDigraph Digraph;
alpar@100
    94
  typedef ListDigraph Digraph;
alpar@100
    95
alpar@100
    96
  typedef Digraph::Arc Arc;
alpar@100
    97
  typedef Digraph::Node Node;
alpar@100
    98
  typedef Digraph::ArcIt ArcIt;
alpar@100
    99
  typedef Digraph::NodeIt NodeIt;
alpar@100
   100
  typedef Digraph::ArcMap<int> LengthMap;
alpar@100
   101
alpar@100
   102
  Digraph G;
alpar@100
   103
  Node s, t;
alpar@100
   104
  PetStruct<Digraph> ps = addPetersen(G,PET_SIZE);
alpar@100
   105
   
alpar@100
   106
  s=ps.outer[2];
alpar@100
   107
  t=ps.inner[0];
alpar@100
   108
  
alpar@100
   109
  Dfs<Digraph> dfs_test(G);
alpar@100
   110
  dfs_test.run(s);  
alpar@100
   111
  
alpar@100
   112
  Path<Digraph> p = dfs_test.path(t);
alpar@100
   113
  check(p.length()==dfs_test.dist(t),"path() found a wrong path.");
alpar@100
   114
  check(checkPath(G, p),"path() found a wrong path.");
alpar@100
   115
  check(pathSource(G, p) == s,"path() found a wrong path.");
alpar@100
   116
  check(pathTarget(G, p) == t,"path() found a wrong path.");
alpar@100
   117
  
alpar@100
   118
  for(NodeIt v(G); v!=INVALID; ++v) {
alpar@100
   119
    check(dfs_test.reached(v),"Each node should be reached.");
alpar@100
   120
    if ( dfs_test.predArc(v)!=INVALID ) {
alpar@100
   121
      Arc e=dfs_test.predArc(v);
alpar@100
   122
      Node u=G.source(e);
alpar@100
   123
      check(u==dfs_test.predNode(v),"Wrong tree.");
alpar@100
   124
      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
alpar@100
   125
	    "Wrong distance. (" << dfs_test.dist(u) << "->" 
alpar@100
   126
	    <<dfs_test.dist(v) << ')');
alpar@100
   127
    }
alpar@100
   128
  }
alpar@100
   129
}
alpar@100
   130