[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 | |
---|
[780] | 19 | #include "test_tools.h" |
---|
[921] | 20 | #include <lemon/smart_graph.h> |
---|
| 21 | #include <lemon/dfs.h> |
---|
[1283] | 22 | #include <lemon/path.h> |
---|
[959] | 23 | #include <lemon/concept/graph.h> |
---|
[780] | 24 | |
---|
[921] | 25 | using namespace lemon; |
---|
[780] | 26 | |
---|
| 27 | const int PET_SIZE =5; |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | void check_Dfs_SmartGraph_Compile() |
---|
| 31 | { |
---|
[2111] | 32 | typedef concept::Graph Graph; |
---|
[780] | 33 | |
---|
| 34 | typedef Graph::Edge Edge; |
---|
| 35 | typedef Graph::Node Node; |
---|
| 36 | typedef Graph::EdgeIt EdgeIt; |
---|
| 37 | typedef Graph::NodeIt NodeIt; |
---|
| 38 | |
---|
[793] | 39 | typedef Dfs<Graph> DType; |
---|
[780] | 40 | |
---|
| 41 | Graph G; |
---|
| 42 | Node n; |
---|
| 43 | Edge e; |
---|
[793] | 44 | int l; |
---|
[780] | 45 | bool b; |
---|
[793] | 46 | DType::DistMap d(G); |
---|
| 47 | DType::PredMap p(G); |
---|
[1218] | 48 | // DType::PredNodeMap pn(G); |
---|
[780] | 49 | |
---|
[793] | 50 | DType dfs_test(G); |
---|
[780] | 51 | |
---|
| 52 | dfs_test.run(n); |
---|
| 53 | |
---|
| 54 | l = dfs_test.dist(n); |
---|
[1763] | 55 | e = dfs_test.predEdge(n); |
---|
[780] | 56 | n = dfs_test.predNode(n); |
---|
| 57 | d = dfs_test.distMap(); |
---|
| 58 | p = dfs_test.predMap(); |
---|
[1218] | 59 | // pn = dfs_test.predNodeMap(); |
---|
[780] | 60 | b = dfs_test.reached(n); |
---|
| 61 | |
---|
[2247] | 62 | Path<Graph> pp(G); |
---|
[1283] | 63 | dfs_test.getPath(pp,n); |
---|
[780] | 64 | } |
---|
| 65 | |
---|
[1220] | 66 | |
---|
| 67 | void check_Dfs_Function_Compile() |
---|
| 68 | { |
---|
| 69 | typedef int VType; |
---|
[2111] | 70 | typedef concept::Graph Graph; |
---|
[1220] | 71 | |
---|
| 72 | typedef Graph::Edge Edge; |
---|
| 73 | typedef Graph::Node Node; |
---|
| 74 | typedef Graph::EdgeIt EdgeIt; |
---|
| 75 | typedef Graph::NodeIt NodeIt; |
---|
| 76 | typedef concept::ReadMap<Edge,VType> LengthMap; |
---|
| 77 | |
---|
[2135] | 78 | Graph g; |
---|
| 79 | dfs(g,Node()).run(); |
---|
| 80 | dfs(g).source(Node()).run(); |
---|
| 81 | dfs(g) |
---|
[1220] | 82 | .predMap(concept::WriteMap<Node,Edge>()) |
---|
| 83 | .distMap(concept::WriteMap<Node,VType>()) |
---|
| 84 | .reachedMap(concept::ReadWriteMap<Node,bool>()) |
---|
| 85 | .processedMap(concept::WriteMap<Node,bool>()) |
---|
| 86 | .run(Node()); |
---|
| 87 | |
---|
| 88 | } |
---|
| 89 | |
---|
[780] | 90 | int main() |
---|
| 91 | { |
---|
| 92 | |
---|
| 93 | typedef SmartGraph Graph; |
---|
| 94 | |
---|
| 95 | typedef Graph::Edge Edge; |
---|
| 96 | typedef Graph::Node Node; |
---|
| 97 | typedef Graph::EdgeIt EdgeIt; |
---|
| 98 | typedef Graph::NodeIt NodeIt; |
---|
| 99 | typedef Graph::EdgeMap<int> LengthMap; |
---|
| 100 | |
---|
| 101 | Graph G; |
---|
| 102 | Node s, t; |
---|
| 103 | PetStruct<Graph> ps = addPetersen(G,PET_SIZE); |
---|
| 104 | |
---|
| 105 | s=ps.outer[2]; |
---|
| 106 | t=ps.inner[0]; |
---|
| 107 | |
---|
| 108 | Dfs<Graph> dfs_test(G); |
---|
| 109 | dfs_test.run(s); |
---|
| 110 | |
---|
[2247] | 111 | Path<Graph> p(G); |
---|
[1283] | 112 | check(dfs_test.getPath(p,t),"getPath() failed to set the path."); |
---|
| 113 | check(p.length()==dfs_test.dist(t),"getPath() found a wrong path."); |
---|
| 114 | |
---|
[780] | 115 | for(NodeIt v(G); v!=INVALID; ++v) { |
---|
| 116 | check(dfs_test.reached(v),"Each node should be reached."); |
---|
[1763] | 117 | if ( dfs_test.predEdge(v)!=INVALID ) { |
---|
| 118 | Edge e=dfs_test.predEdge(v); |
---|
[986] | 119 | Node u=G.source(e); |
---|
[780] | 120 | check(u==dfs_test.predNode(v),"Wrong tree."); |
---|
| 121 | check(dfs_test.dist(v) - dfs_test.dist(u) == 1, |
---|
[1233] | 122 | "Wrong distance. (" << dfs_test.dist(u) << "->" |
---|
| 123 | <<dfs_test.dist(v) << ')'); |
---|
[780] | 124 | } |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|