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