src/work/marci/bfs_mm_test.cc
author marci
Sat, 16 Oct 2004 00:20:13 +0000
changeset 944 4f064aff855e
parent 921 src/test/bfs_test.cc@818510fa3d99
child 959 c80ef5912903
permissions -rw-r--r--
It's time to design an iterable generic bfs
alpar@906
     1
/* -*- C++ -*-
alpar@921
     2
 * src/test/bfs_test.cc - Part of LEMON, a generic C++ optimization library
alpar@906
     3
 *
alpar@906
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@906
     5
 * (Egervary Combinatorial Optimization Research Group, 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
marci@944
    17
#include <test/test_tools.h>
alpar@921
    18
#include <lemon/smart_graph.h>
marci@944
    19
#include <bfs_mm.h>
marci@944
    20
#include <lemon/skeletons/graph.h>
alpar@774
    21
alpar@921
    22
using namespace lemon;
alpar@774
    23
alpar@774
    24
const int PET_SIZE =5;
alpar@774
    25
alpar@774
    26
alpar@793
    27
void check_Bfs_Compile() 
alpar@774
    28
{
alpar@880
    29
  typedef skeleton::StaticGraph Graph;
alpar@774
    30
alpar@774
    31
  typedef Graph::Edge Edge;
alpar@774
    32
  typedef Graph::Node Node;
alpar@774
    33
  typedef Graph::EdgeIt EdgeIt;
alpar@774
    34
  typedef Graph::NodeIt NodeIt;
alpar@774
    35
 
marci@944
    36
  typedef marci::Bfs<Graph> BType;
alpar@774
    37
  
alpar@774
    38
  Graph G;
alpar@774
    39
  Node n;
alpar@774
    40
  Edge e;
alpar@793
    41
  int l;
alpar@774
    42
  bool b;
alpar@774
    43
  BType::DistMap d(G);
alpar@774
    44
  BType::PredMap p(G);
alpar@774
    45
  BType::PredNodeMap pn(G);
marci@944
    46
marci@944
    47
   Graph::NodeMap<bool> reached(G);
marci@944
    48
   Graph::NodeMap<Edge> pred(G);
marci@944
    49
   Graph::NodeMap<Node> pred_node(G);
marci@944
    50
   Graph::NodeMap<int> dist(G);  
marci@944
    51
   BType bfs_test(G, reached, pred, pred_node, dist);
alpar@774
    52
  
alpar@774
    53
  bfs_test.run(n);
alpar@774
    54
  
alpar@774
    55
  l  = bfs_test.dist(n);
alpar@774
    56
  e  = bfs_test.pred(n);
alpar@774
    57
  n  = bfs_test.predNode(n);
alpar@774
    58
  d  = bfs_test.distMap();
alpar@774
    59
  p  = bfs_test.predMap();
alpar@774
    60
  pn = bfs_test.predNodeMap();
alpar@774
    61
  b  = bfs_test.reached(n);
alpar@774
    62
alpar@774
    63
}
alpar@774
    64
alpar@774
    65
int main()
alpar@774
    66
{
alpar@774
    67
    
alpar@774
    68
  typedef SmartGraph Graph;
alpar@774
    69
alpar@774
    70
  typedef Graph::Edge Edge;
alpar@774
    71
  typedef Graph::Node Node;
alpar@774
    72
  typedef Graph::EdgeIt EdgeIt;
alpar@774
    73
  typedef Graph::NodeIt NodeIt;
alpar@774
    74
  typedef Graph::EdgeMap<int> LengthMap;
alpar@774
    75
alpar@774
    76
  Graph G;
alpar@774
    77
  Node s, t;
alpar@774
    78
  PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
alpar@774
    79
   
alpar@774
    80
  s=ps.outer[2];
alpar@774
    81
  t=ps.inner[0];
alpar@774
    82
  
marci@944
    83
   Graph::NodeMap<bool> reached(G);
marci@944
    84
   Graph::NodeMap<Edge> pred(G);
marci@944
    85
   Graph::NodeMap<Node> pred_node(G);
marci@944
    86
   Graph::NodeMap<int> dist(G);
marci@944
    87
   marci::Bfs<Graph> bfs_test(G, reached, pred, pred_node, dist);
alpar@774
    88
  bfs_test.run(s);
alpar@774
    89
  
marci@944
    90
//   check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t));
alpar@774
    91
alpar@774
    92
marci@944
    93
//   for(EdgeIt e(G); e==INVALID; ++e) {
marci@944
    94
//     Node u=G.tail(e);
marci@944
    95
//     Node v=G.head(e);
marci@944
    96
//     check( !bfs_test.reached(u) ||
marci@944
    97
// 	   (bfs_test.dist(v) > bfs_test.dist(u)+1),
marci@944
    98
// 	   "Wrong output.");
marci@944
    99
//   }
alpar@774
   100
marci@944
   101
//   for(NodeIt v(G); v==INVALID; ++v) {
marci@944
   102
//     check(bfs_test.reached(v),"Each node should be reached.");
marci@944
   103
//     if ( bfs_test.pred(v)!=INVALID ) {
marci@944
   104
//       Edge e=bfs_test.pred(v);
marci@944
   105
//       Node u=G.tail(e);
marci@944
   106
//       check(u==bfs_test.predNode(v),"Wrong tree.");
marci@944
   107
//       check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
marci@944
   108
// 	    "Wrong distance. Difference: " 
marci@944
   109
// 	    << std::abs(bfs_test.dist(v) - bfs_test.dist(u) 
marci@944
   110
// 			- 1));
marci@944
   111
//     }
marci@944
   112
//   }
alpar@774
   113
}
alpar@780
   114