src/test/dfs_test.cc
author deba
Tue, 19 Apr 2005 13:33:44 +0000
changeset 1374 bcfa3980b432
parent 1283 fc20371677b9
permissions -rw-r--r--
Call the default constructor of the ObserverBase.
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/test/dfs_test.cc - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@1164
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906
     6
 *
alpar@906
     7
 * Permission to use, modify and distribute this software is granted
alpar@906
     8
 * provided that this copyright notice appears in all copies. For
alpar@906
     9
 * precise terms see the accompanying LICENSE file.
alpar@906
    10
 *
alpar@906
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    12
 * express or implied, and with no claim as to its suitability for any
alpar@906
    13
 * purpose.
alpar@906
    14
 *
alpar@906
    15
 */
alpar@906
    16
alpar@780
    17
#include "test_tools.h"
alpar@921
    18
#include <lemon/smart_graph.h>
alpar@921
    19
#include <lemon/dfs.h>
alpar@1283
    20
#include <lemon/path.h>
klao@959
    21
#include <lemon/concept/graph.h>
alpar@780
    22
alpar@921
    23
using namespace lemon;
alpar@780
    24
alpar@780
    25
const int PET_SIZE =5;
alpar@780
    26
alpar@780
    27
alpar@780
    28
void check_Dfs_SmartGraph_Compile() 
alpar@780
    29
{
klao@959
    30
  typedef concept::StaticGraph Graph;
alpar@780
    31
alpar@780
    32
  typedef Graph::Edge Edge;
alpar@780
    33
  typedef Graph::Node Node;
alpar@780
    34
  typedef Graph::EdgeIt EdgeIt;
alpar@780
    35
  typedef Graph::NodeIt NodeIt;
alpar@780
    36
 
alpar@793
    37
  typedef Dfs<Graph> DType;
alpar@780
    38
  
alpar@780
    39
  Graph G;
alpar@780
    40
  Node n;
alpar@780
    41
  Edge e;
alpar@793
    42
  int l;
alpar@780
    43
  bool b;
alpar@793
    44
  DType::DistMap d(G);
alpar@793
    45
  DType::PredMap p(G);
alpar@1218
    46
  //  DType::PredNodeMap pn(G);
alpar@780
    47
  
alpar@793
    48
  DType dfs_test(G);
alpar@780
    49
  
alpar@780
    50
  dfs_test.run(n);
alpar@780
    51
  
alpar@780
    52
  l  = dfs_test.dist(n);
alpar@780
    53
  e  = dfs_test.pred(n);
alpar@780
    54
  n  = dfs_test.predNode(n);
alpar@780
    55
  d  = dfs_test.distMap();
alpar@780
    56
  p  = dfs_test.predMap();
alpar@1218
    57
  //  pn = dfs_test.predNodeMap();
alpar@780
    58
  b  = dfs_test.reached(n);
alpar@780
    59
alpar@1283
    60
  DirPath<Graph> pp(G);
alpar@1283
    61
  dfs_test.getPath(pp,n);
alpar@780
    62
}
alpar@780
    63
alpar@1220
    64
alpar@1220
    65
void check_Dfs_Function_Compile() 
alpar@1220
    66
{
alpar@1220
    67
  typedef int VType;
alpar@1220
    68
  typedef concept::StaticGraph Graph;
alpar@1220
    69
alpar@1220
    70
  typedef Graph::Edge Edge;
alpar@1220
    71
  typedef Graph::Node Node;
alpar@1220
    72
  typedef Graph::EdgeIt EdgeIt;
alpar@1220
    73
  typedef Graph::NodeIt NodeIt;
alpar@1220
    74
  typedef concept::ReadMap<Edge,VType> LengthMap;
alpar@1220
    75
   
alpar@1220
    76
  dfs(Graph(),Node()).run();
alpar@1220
    77
  dfs(Graph()).source(Node()).run();
alpar@1220
    78
  dfs(Graph())
alpar@1220
    79
    .predMap(concept::WriteMap<Node,Edge>())
alpar@1220
    80
    .distMap(concept::WriteMap<Node,VType>())
alpar@1220
    81
    .reachedMap(concept::ReadWriteMap<Node,bool>())
alpar@1220
    82
    .processedMap(concept::WriteMap<Node,bool>())
alpar@1220
    83
    .run(Node());
alpar@1220
    84
  
alpar@1220
    85
}
alpar@1220
    86
alpar@780
    87
int main()
alpar@780
    88
{
alpar@780
    89
    
alpar@780
    90
  typedef SmartGraph Graph;
alpar@780
    91
alpar@780
    92
  typedef Graph::Edge Edge;
alpar@780
    93
  typedef Graph::Node Node;
alpar@780
    94
  typedef Graph::EdgeIt EdgeIt;
alpar@780
    95
  typedef Graph::NodeIt NodeIt;
alpar@780
    96
  typedef Graph::EdgeMap<int> LengthMap;
alpar@780
    97
alpar@780
    98
  Graph G;
alpar@780
    99
  Node s, t;
alpar@780
   100
  PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
alpar@780
   101
   
alpar@780
   102
  s=ps.outer[2];
alpar@780
   103
  t=ps.inner[0];
alpar@780
   104
  
alpar@780
   105
  Dfs<Graph> dfs_test(G);
alpar@780
   106
  dfs_test.run(s);  
alpar@780
   107
  
alpar@1283
   108
  DirPath<Graph> p(G);
alpar@1283
   109
  check(dfs_test.getPath(p,t),"getPath() failed to set the path.");
alpar@1283
   110
  check(p.length()==dfs_test.dist(t),"getPath() found a wrong path.");
alpar@1283
   111
  
alpar@780
   112
  for(NodeIt v(G); v!=INVALID; ++v) {
alpar@780
   113
    check(dfs_test.reached(v),"Each node should be reached.");
alpar@780
   114
    if ( dfs_test.pred(v)!=INVALID ) {
alpar@780
   115
      Edge e=dfs_test.pred(v);
alpar@986
   116
      Node u=G.source(e);
alpar@780
   117
      check(u==dfs_test.predNode(v),"Wrong tree.");
alpar@780
   118
      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
alpar@1233
   119
	    "Wrong distance. (" << dfs_test.dist(u) << "->" 
alpar@1233
   120
	    <<dfs_test.dist(v) << ')');
alpar@780
   121
    }
alpar@780
   122
  }
alpar@780
   123
}
alpar@780
   124