COIN-OR::LEMON - Graph Library

source: lemon-1.1/test/dfs_test.cc @ 210:81cfc04531e8

Last change on this file since 210:81cfc04531e8 was 209:765619b7cbb2, checked in by Alpar Juttner <alpar@…>, 16 years ago

Apply unify-sources.sh to the source tree

File size: 2.8 KB
RevLine 
[209]1/* -*- mode: C++; indent-tabs-mode: nil; -*-
[100]2 *
[209]3 * This file is a part of LEMON, a generic C++ optimization library.
[100]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
[171]19#include <lemon/concepts/digraph.h>
20#include <lemon/smart_graph.h>
[100]21#include <lemon/list_graph.h>
22#include <lemon/dfs.h>
23#include <lemon/path.h>
[171]24
25#include "graph_test.h"
26#include "test_tools.h"
[100]27
28using namespace lemon;
29
[209]30void checkDfsCompile()
[100]31{
32  typedef concepts::Digraph Digraph;
33  typedef Dfs<Digraph> DType;
[209]34
[100]35  Digraph G;
[171]36  Digraph::Node n;
37  Digraph::Arc e;
[100]38  int l;
39  bool b;
40  DType::DistMap d(G);
41  DType::PredMap p(G);
42  //  DType::PredNodeMap pn(G);
[209]43
[100]44  DType dfs_test(G);
[209]45
[100]46  dfs_test.run(n);
[209]47
[100]48  l  = dfs_test.dist(n);
49  e  = dfs_test.predArc(n);
50  n  = dfs_test.predNode(n);
51  d  = dfs_test.distMap();
52  p  = dfs_test.predMap();
53  //  pn = dfs_test.predNodeMap();
54  b  = dfs_test.reached(n);
55
56  Path<Digraph> pp = dfs_test.path(n);
57}
58
[209]59void checkDfsFunctionCompile()
[100]60{
61  typedef int VType;
62  typedef concepts::Digraph Digraph;
63  typedef Digraph::Arc Arc;
64  typedef Digraph::Node Node;
[209]65
[100]66  Digraph g;
67  dfs(g,Node()).run();
68  dfs(g).source(Node()).run();
69  dfs(g)
70    .predMap(concepts::WriteMap<Node,Arc>())
71    .distMap(concepts::WriteMap<Node,VType>())
72    .reachedMap(concepts::ReadWriteMap<Node,bool>())
73    .processedMap(concepts::WriteMap<Node,bool>())
[209]74    .run(Node());
[100]75}
76
[171]77template <class Digraph>
78void checkDfs() {
79  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
[100]80
81  Digraph G;
82  Node s, t;
[171]83  PetStruct<Digraph> ps = addPetersen(G, 5);
[209]84
[100]85  s=ps.outer[2];
86  t=ps.inner[0];
[209]87
[100]88  Dfs<Digraph> dfs_test(G);
[209]89  dfs_test.run(s);
90
[100]91  Path<Digraph> p = dfs_test.path(t);
[171]92  check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
[100]93  check(checkPath(G, p),"path() found a wrong path.");
94  check(pathSource(G, p) == s,"path() found a wrong path.");
95  check(pathTarget(G, p) == t,"path() found a wrong path.");
[209]96
[100]97  for(NodeIt v(G); v!=INVALID; ++v) {
98    check(dfs_test.reached(v),"Each node should be reached.");
99    if ( dfs_test.predArc(v)!=INVALID ) {
100      Arc e=dfs_test.predArc(v);
101      Node u=G.source(e);
102      check(u==dfs_test.predNode(v),"Wrong tree.");
103      check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
[209]104            "Wrong distance. (" << dfs_test.dist(u) << "->"
105            <<dfs_test.dist(v) << ')');
[100]106    }
107  }
108}
109
[171]110int main()
111{
112  checkDfs<ListDigraph>();
113  checkDfs<SmartDigraph>();
114  return 0;
115}
Note: See TracBrowser for help on using the repository browser.