test/dfs_test.cc
changeset 1435 8e85e6bbefdf
parent 1359 1581f961cfaa
child 1763 49045f2d28d4
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/dfs_test.cc	Mon May 23 04:48:14 2005 +0000
     1.3 @@ -0,0 +1,124 @@
     1.4 +/* -*- C++ -*-
     1.5 + * test/dfs_test.cc - Part of LEMON, a generic C++ optimization library
     1.6 + *
     1.7 + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
     1.8 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
     1.9 + *
    1.10 + * Permission to use, modify and distribute this software is granted
    1.11 + * provided that this copyright notice appears in all copies. For
    1.12 + * precise terms see the accompanying LICENSE file.
    1.13 + *
    1.14 + * This software is provided "AS IS" with no warranty of any kind,
    1.15 + * express or implied, and with no claim as to its suitability for any
    1.16 + * purpose.
    1.17 + *
    1.18 + */
    1.19 +
    1.20 +#include "test_tools.h"
    1.21 +#include <lemon/smart_graph.h>
    1.22 +#include <lemon/dfs.h>
    1.23 +#include <lemon/path.h>
    1.24 +#include <lemon/concept/graph.h>
    1.25 +
    1.26 +using namespace lemon;
    1.27 +
    1.28 +const int PET_SIZE =5;
    1.29 +
    1.30 +
    1.31 +void check_Dfs_SmartGraph_Compile() 
    1.32 +{
    1.33 +  typedef concept::StaticGraph Graph;
    1.34 +
    1.35 +  typedef Graph::Edge Edge;
    1.36 +  typedef Graph::Node Node;
    1.37 +  typedef Graph::EdgeIt EdgeIt;
    1.38 +  typedef Graph::NodeIt NodeIt;
    1.39 + 
    1.40 +  typedef Dfs<Graph> DType;
    1.41 +  
    1.42 +  Graph G;
    1.43 +  Node n;
    1.44 +  Edge e;
    1.45 +  int l;
    1.46 +  bool b;
    1.47 +  DType::DistMap d(G);
    1.48 +  DType::PredMap p(G);
    1.49 +  //  DType::PredNodeMap pn(G);
    1.50 +  
    1.51 +  DType dfs_test(G);
    1.52 +  
    1.53 +  dfs_test.run(n);
    1.54 +  
    1.55 +  l  = dfs_test.dist(n);
    1.56 +  e  = dfs_test.pred(n);
    1.57 +  n  = dfs_test.predNode(n);
    1.58 +  d  = dfs_test.distMap();
    1.59 +  p  = dfs_test.predMap();
    1.60 +  //  pn = dfs_test.predNodeMap();
    1.61 +  b  = dfs_test.reached(n);
    1.62 +
    1.63 +  DirPath<Graph> pp(G);
    1.64 +  dfs_test.getPath(pp,n);
    1.65 +}
    1.66 +
    1.67 +
    1.68 +void check_Dfs_Function_Compile() 
    1.69 +{
    1.70 +  typedef int VType;
    1.71 +  typedef concept::StaticGraph Graph;
    1.72 +
    1.73 +  typedef Graph::Edge Edge;
    1.74 +  typedef Graph::Node Node;
    1.75 +  typedef Graph::EdgeIt EdgeIt;
    1.76 +  typedef Graph::NodeIt NodeIt;
    1.77 +  typedef concept::ReadMap<Edge,VType> LengthMap;
    1.78 +   
    1.79 +  dfs(Graph(),Node()).run();
    1.80 +  dfs(Graph()).source(Node()).run();
    1.81 +  dfs(Graph())
    1.82 +    .predMap(concept::WriteMap<Node,Edge>())
    1.83 +    .distMap(concept::WriteMap<Node,VType>())
    1.84 +    .reachedMap(concept::ReadWriteMap<Node,bool>())
    1.85 +    .processedMap(concept::WriteMap<Node,bool>())
    1.86 +    .run(Node());
    1.87 +  
    1.88 +}
    1.89 +
    1.90 +int main()
    1.91 +{
    1.92 +    
    1.93 +  typedef SmartGraph Graph;
    1.94 +
    1.95 +  typedef Graph::Edge Edge;
    1.96 +  typedef Graph::Node Node;
    1.97 +  typedef Graph::EdgeIt EdgeIt;
    1.98 +  typedef Graph::NodeIt NodeIt;
    1.99 +  typedef Graph::EdgeMap<int> LengthMap;
   1.100 +
   1.101 +  Graph G;
   1.102 +  Node s, t;
   1.103 +  PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
   1.104 +   
   1.105 +  s=ps.outer[2];
   1.106 +  t=ps.inner[0];
   1.107 +  
   1.108 +  Dfs<Graph> dfs_test(G);
   1.109 +  dfs_test.run(s);  
   1.110 +  
   1.111 +  DirPath<Graph> p(G);
   1.112 +  check(dfs_test.getPath(p,t),"getPath() failed to set the path.");
   1.113 +  check(p.length()==dfs_test.dist(t),"getPath() found a wrong path.");
   1.114 +  
   1.115 +  for(NodeIt v(G); v!=INVALID; ++v) {
   1.116 +    check(dfs_test.reached(v),"Each node should be reached.");
   1.117 +    if ( dfs_test.pred(v)!=INVALID ) {
   1.118 +      Edge e=dfs_test.pred(v);
   1.119 +      Node u=G.source(e);
   1.120 +      check(u==dfs_test.predNode(v),"Wrong tree.");
   1.121 +      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
   1.122 +	    "Wrong distance. (" << dfs_test.dist(u) << "->" 
   1.123 +	    <<dfs_test.dist(v) << ')');
   1.124 +    }
   1.125 +  }
   1.126 +}
   1.127 +