COIN-OR::LEMON - Graph Library

source: lemon-1.2/test/dfs_test.cc @ 162:33247f6fff16

Last change on this file since 162:33247f6fff16 was 100:4f754b4cf82b, checked in by Alpar Juttner <alpar@…>, 17 years ago

Bfs/Dfs/Dijkstra? and their deps ported from svn trung -r 3441.

File size: 3.1 KB
RevLine 
[100]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
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
19#include "test_tools.h"
20// #include <lemon/smart_graph.h>
21#include <lemon/list_graph.h>
22#include <lemon/dfs.h>
23#include <lemon/path.h>
24#include <lemon/concepts/digraph.h>
25
26using namespace lemon;
27
28const int PET_SIZE =5;
29
30
31void check_Dfs_SmartDigraph_Compile()
32{
33  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 Dfs<Digraph> DType;
41 
42  Digraph G;
43  Node n;
44  Arc e;
45  int l;
46  bool b;
47  DType::DistMap d(G);
48  DType::PredMap p(G);
49  //  DType::PredNodeMap pn(G);
50 
51  DType dfs_test(G);
52 
53  dfs_test.run(n);
54 
55  l  = dfs_test.dist(n);
56  e  = dfs_test.predArc(n);
57  n  = dfs_test.predNode(n);
58  d  = dfs_test.distMap();
59  p  = dfs_test.predMap();
60  //  pn = dfs_test.predNodeMap();
61  b  = dfs_test.reached(n);
62
63  Path<Digraph> pp = dfs_test.path(n);
64}
65
66
67void check_Dfs_Function_Compile()
68{
69  typedef int VType;
70  typedef concepts::Digraph Digraph;
71
72  typedef Digraph::Arc Arc;
73  typedef Digraph::Node Node;
74  typedef Digraph::ArcIt ArcIt;
75  typedef Digraph::NodeIt NodeIt;
76  typedef concepts::ReadMap<Arc,VType> LengthMap;
77   
78  Digraph g;
79  dfs(g,Node()).run();
80  dfs(g).source(Node()).run();
81  dfs(g)
82    .predMap(concepts::WriteMap<Node,Arc>())
83    .distMap(concepts::WriteMap<Node,VType>())
84    .reachedMap(concepts::ReadWriteMap<Node,bool>())
85    .processedMap(concepts::WriteMap<Node,bool>())
86    .run(Node());
87 
88}
89
90int main()
91{
92   
93  // typedef SmartDigraph Digraph;
94  typedef ListDigraph Digraph;
95
96  typedef Digraph::Arc Arc;
97  typedef Digraph::Node Node;
98  typedef Digraph::ArcIt ArcIt;
99  typedef Digraph::NodeIt NodeIt;
100  typedef Digraph::ArcMap<int> LengthMap;
101
102  Digraph G;
103  Node s, t;
104  PetStruct<Digraph> ps = addPetersen(G,PET_SIZE);
105   
106  s=ps.outer[2];
107  t=ps.inner[0];
108 
109  Dfs<Digraph> dfs_test(G);
110  dfs_test.run(s); 
111 
112  Path<Digraph> p = dfs_test.path(t);
113  check(p.length()==dfs_test.dist(t),"path() found a wrong path.");
114  check(checkPath(G, p),"path() found a wrong path.");
115  check(pathSource(G, p) == s,"path() found a wrong path.");
116  check(pathTarget(G, p) == t,"path() found a wrong path.");
117 
118  for(NodeIt v(G); v!=INVALID; ++v) {
119    check(dfs_test.reached(v),"Each node should be reached.");
120    if ( dfs_test.predArc(v)!=INVALID ) {
121      Arc e=dfs_test.predArc(v);
122      Node u=G.source(e);
123      check(u==dfs_test.predNode(v),"Wrong tree.");
124      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
125            "Wrong distance. (" << dfs_test.dist(u) << "->"
126            <<dfs_test.dist(v) << ')');
127    }
128  }
129}
130
Note: See TracBrowser for help on using the repository browser.