test/bfs_test.cc
changeset 188 70694e6bdcac
parent 100 4f754b4cf82b
child 209 765619b7cbb2
equal deleted inserted replaced
0:c80a3233e455 1:e686b2ff8c1c
    14  * express or implied, and with no claim as to its suitability for any
    14  * express or implied, and with no claim as to its suitability for any
    15  * purpose.
    15  * purpose.
    16  *
    16  *
    17  */
    17  */
    18 
    18 
    19 #include "test_tools.h"
    19 #include <lemon/concepts/digraph.h>
    20 //#include <lemon/smart_graph.h>
    20 #include <lemon/smart_graph.h>
    21 #include <lemon/list_graph.h>
    21 #include <lemon/list_graph.h>
    22 #include <lemon/bfs.h>
    22 #include <lemon/bfs.h>
    23 #include <lemon/path.h>
    23 #include <lemon/path.h>
    24 #include<lemon/concepts/digraph.h>
    24 
       
    25 #include "graph_test.h"
       
    26 #include "test_tools.h"
    25 
    27 
    26 using namespace lemon;
    28 using namespace lemon;
    27 
    29 
    28 const int PET_SIZE =5;
    30 void checkBfsCompile() 
    29 
       
    30 
       
    31 void check_Bfs_Compile() 
       
    32 {
    31 {
    33   typedef concepts::Digraph Digraph;
    32   typedef concepts::Digraph Digraph;
    34 
       
    35   typedef Digraph::Arc Arc;
       
    36   typedef Digraph::Node Node;
       
    37   typedef Digraph::ArcIt ArcIt;
       
    38   typedef Digraph::NodeIt NodeIt;
       
    39  
       
    40   typedef Bfs<Digraph> BType;
    33   typedef Bfs<Digraph> BType;
    41   
    34   
    42   Digraph G;
    35   Digraph G;
    43   Node n;
    36   Digraph::Node n;
    44   Arc e;
    37   Digraph::Arc e;
    45   int l;
    38   int l;
    46   bool b;
    39   bool b;
    47   BType::DistMap d(G);
    40   BType::DistMap d(G);
    48   BType::PredMap p(G);
    41   BType::PredMap p(G);
    49   //  BType::PredNodeMap pn(G);
    42   //  BType::PredNodeMap pn(G);
    61   b  = bfs_test.reached(n);
    54   b  = bfs_test.reached(n);
    62 
    55 
    63   Path<Digraph> pp = bfs_test.path(n);
    56   Path<Digraph> pp = bfs_test.path(n);
    64 }
    57 }
    65 
    58 
    66 void check_Bfs_Function_Compile() 
    59 void checkBfsFunctionCompile() 
    67 {
    60 {
    68   typedef int VType;
    61   typedef int VType;
    69   typedef concepts::Digraph Digraph;
    62   typedef concepts::Digraph Digraph;
    70 
       
    71   typedef Digraph::Arc Arc;
    63   typedef Digraph::Arc Arc;
    72   typedef Digraph::Node Node;
    64   typedef Digraph::Node Node;
    73   typedef Digraph::ArcIt ArcIt;
       
    74   typedef Digraph::NodeIt NodeIt;
       
    75   typedef concepts::ReadMap<Arc,VType> LengthMap;
       
    76    
    65    
    77   Digraph g;
    66   Digraph g;
    78   bfs(g,Node()).run();
    67   bfs(g,Node()).run();
    79   bfs(g).source(Node()).run();
    68   bfs(g).source(Node()).run();
    80   bfs(g)
    69   bfs(g)
    81     .predMap(concepts::WriteMap<Node,Arc>())
    70     .predMap(concepts::WriteMap<Node,Arc>())
    82     .distMap(concepts::WriteMap<Node,VType>())
    71     .distMap(concepts::WriteMap<Node,VType>())
    83     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    72     .reachedMap(concepts::ReadWriteMap<Node,bool>())
    84     .processedMap(concepts::WriteMap<Node,bool>())
    73     .processedMap(concepts::WriteMap<Node,bool>())
    85     .run(Node());
    74     .run(Node());
    86   
       
    87 }
    75 }
    88 
    76 
    89 int main()
    77 template <class Digraph>
    90 {
    78 void checkBfs() {
    91     
    79   TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    92   // typedef SmartDigraph Digraph;
       
    93   typedef ListDigraph Digraph;
       
    94 
       
    95   typedef Digraph::Arc Arc;
       
    96   typedef Digraph::Node Node;
       
    97   typedef Digraph::ArcIt ArcIt;
       
    98   typedef Digraph::NodeIt NodeIt;
       
    99   typedef Digraph::ArcMap<int> LengthMap;
       
   100 
    80 
   101   Digraph G;
    81   Digraph G;
   102   Node s, t;
    82   Node s, t;
   103   PetStruct<Digraph> ps = addPetersen(G,PET_SIZE);
    83   PetStruct<Digraph> ps = addPetersen(G, 5);
   104    
    84    
   105   s=ps.outer[2];
    85   s=ps.outer[2];
   106   t=ps.inner[0];
    86   t=ps.inner[0];
   107   
    87   
   108   Bfs<Digraph> bfs_test(G);
    88   Bfs<Digraph> bfs_test(G);
   109   bfs_test.run(s);
    89   bfs_test.run(s);
   110   
    90   
   111   check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t));
    91   check(bfs_test.dist(t)==3,"Bfs found a wrong path." << bfs_test.dist(t));
   112 
    92 
   113   Path<Digraph> p = bfs_test.path(t);
    93   Path<Digraph> p = bfs_test.path(t);
   114   check(p.length()==3,"getPath() found a wrong path.");
    94   check(p.length()==3,"path() found a wrong path.");
   115   check(checkPath(G, p),"path() found a wrong path.");
    95   check(checkPath(G, p),"path() found a wrong path.");
   116   check(pathSource(G, p) == s,"path() found a wrong path.");
    96   check(pathSource(G, p) == s,"path() found a wrong path.");
   117   check(pathTarget(G, p) == t,"path() found a wrong path.");
    97   check(pathTarget(G, p) == t,"path() found a wrong path.");
   118   
    98   
   119 
    99 
   137 			- 1));
   117 			- 1));
   138     }
   118     }
   139   }
   119   }
   140 }
   120 }
   141 
   121 
       
   122 int main()
       
   123 {
       
   124   checkBfs<ListDigraph>();
       
   125   checkBfs<SmartDigraph>();
       
   126   return 0;
       
   127 }