COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/dfs_test.cc @ 1265:47c60ae9c26a

Last change on this file since 1265:47c60ae9c26a was 1233:f3d856bf1ebf, checked in by Alpar Juttner, 20 years ago

Several serious bugs fixed

File size: 2.6 KB
RevLine 
[906]1/* -*- C++ -*-
[921]2 * src/test/dfs_test.cc - Part of LEMON, a generic C++ optimization library
[906]3 *
[1164]4 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[906]5 * (Egervary Combinatorial Optimization Research Group, EGRES).
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>
[959]20#include <lemon/concept/graph.h>
[780]21
[921]22using namespace lemon;
[780]23
24const int PET_SIZE =5;
25
26
27void check_Dfs_SmartGraph_Compile()
28{
[959]29  typedef concept::StaticGraph Graph;
[780]30
31  typedef Graph::Edge Edge;
32  typedef Graph::Node Node;
33  typedef Graph::EdgeIt EdgeIt;
34  typedef Graph::NodeIt NodeIt;
35 
[793]36  typedef Dfs<Graph> DType;
[780]37 
38  Graph G;
39  Node n;
40  Edge e;
[793]41  int l;
[780]42  bool b;
[793]43  DType::DistMap d(G);
44  DType::PredMap p(G);
[1218]45  //  DType::PredNodeMap pn(G);
[780]46 
[793]47  DType dfs_test(G);
[780]48 
49  dfs_test.run(n);
50 
51  l  = dfs_test.dist(n);
52  e  = dfs_test.pred(n);
53  n  = dfs_test.predNode(n);
54  d  = dfs_test.distMap();
55  p  = dfs_test.predMap();
[1218]56  //  pn = dfs_test.predNodeMap();
[780]57  b  = dfs_test.reached(n);
58
59}
60
[1220]61
62void check_Dfs_Function_Compile()
63{
64  typedef int VType;
65  typedef concept::StaticGraph Graph;
66
67  typedef Graph::Edge Edge;
68  typedef Graph::Node Node;
69  typedef Graph::EdgeIt EdgeIt;
70  typedef Graph::NodeIt NodeIt;
71  typedef concept::ReadMap<Edge,VType> LengthMap;
72   
73  dfs(Graph(),Node()).run();
74  dfs(Graph()).source(Node()).run();
75  dfs(Graph())
76    .predMap(concept::WriteMap<Node,Edge>())
77    .distMap(concept::WriteMap<Node,VType>())
78    .reachedMap(concept::ReadWriteMap<Node,bool>())
79    .processedMap(concept::WriteMap<Node,bool>())
80    .run(Node());
81 
82}
83
[780]84int main()
85{
86   
87  typedef SmartGraph Graph;
88
89  typedef Graph::Edge Edge;
90  typedef Graph::Node Node;
91  typedef Graph::EdgeIt EdgeIt;
92  typedef Graph::NodeIt NodeIt;
93  typedef Graph::EdgeMap<int> LengthMap;
94
95  Graph G;
96  Node s, t;
97  PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
98   
99  s=ps.outer[2];
100  t=ps.inner[0];
101 
102  Dfs<Graph> dfs_test(G);
103  dfs_test.run(s); 
104 
105  for(NodeIt v(G); v!=INVALID; ++v) {
106    check(dfs_test.reached(v),"Each node should be reached.");
107    if ( dfs_test.pred(v)!=INVALID ) {
108      Edge e=dfs_test.pred(v);
[986]109      Node u=G.source(e);
[780]110      check(u==dfs_test.predNode(v),"Wrong tree.");
111      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
[1233]112            "Wrong distance. (" << dfs_test.dist(u) << "->"
113            <<dfs_test.dist(v) << ')');
[780]114    }
115  }
116}
117
Note: See TracBrowser for help on using the repository browser.