test/dfs_test.cc
author hegyi
Thu, 05 Jan 2006 12:30:09 +0000
changeset 1878 409a31271efd
parent 1763 49045f2d28d4
child 1956 a055123339d5
permissions -rw-r--r--
Several changes. \n If new map is added to mapstorage it emits signal with the name of the new map. This was important, because from now on not only tha mapwin should be updated. \n Furthermore algobox gets a pointer to mapstorage instead of only the mapnames from it. This is important because without it it would be complicated to pass all of the required maps to algobox.
alpar@906
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * test/dfs_test.cc - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@1875
     4
 * Copyright (C) 2006 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);
deba@1763
    53
  e  = dfs_test.predEdge(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.");
deba@1763
   114
    if ( dfs_test.predEdge(v)!=INVALID ) {
deba@1763
   115
      Edge e=dfs_test.predEdge(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