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