COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/test/bfs_test.cc @ 933:1b7c88fbb950

Last change on this file since 933:1b7c88fbb950 was 921:818510fa3d99, checked in by Alpar Juttner, 20 years ago

hugo -> lemon

File size: 2.3 KB
Line 
1/* -*- C++ -*-
2 * src/test/bfs_test.cc - Part of LEMON, a generic C++ optimization library
3 *
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
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
17#include "test_tools.h"
18#include <lemon/smart_graph.h>
19#include <lemon/bfs.h>
20#include<lemon/skeletons/graph.h>
21
22using namespace lemon;
23
24const int PET_SIZE =5;
25
26
27void check_Bfs_Compile()
28{
29  typedef skeleton::StaticGraph Graph;
30
31  typedef Graph::Edge Edge;
32  typedef Graph::Node Node;
33  typedef Graph::EdgeIt EdgeIt;
34  typedef Graph::NodeIt NodeIt;
35 
36  typedef Bfs<Graph> BType;
37 
38  Graph G;
39  Node n;
40  Edge e;
41  int l;
42  bool b;
43  BType::DistMap d(G);
44  BType::PredMap p(G);
45  BType::PredNodeMap pn(G);
46 
47  BType bfs_test(G);
48 
49  bfs_test.run(n);
50 
51  l  = bfs_test.dist(n);
52  e  = bfs_test.pred(n);
53  n  = bfs_test.predNode(n);
54  d  = bfs_test.distMap();
55  p  = bfs_test.predMap();
56  pn = bfs_test.predNodeMap();
57  b  = bfs_test.reached(n);
58
59}
60
61int main()
62{
63   
64  typedef SmartGraph Graph;
65
66  typedef Graph::Edge Edge;
67  typedef Graph::Node Node;
68  typedef Graph::EdgeIt EdgeIt;
69  typedef Graph::NodeIt NodeIt;
70  typedef Graph::EdgeMap<int> LengthMap;
71
72  Graph G;
73  Node s, t;
74  PetStruct<Graph> ps = addPetersen(G,PET_SIZE);
75   
76  s=ps.outer[2];
77  t=ps.inner[0];
78 
79  Bfs<Graph> bfs_test(G);
80  bfs_test.run(s);
81 
82  check(bfs_test.dist(t)==3,"Bfs found a wrong path. " << bfs_test.dist(t));
83
84
85  for(EdgeIt e(G); e==INVALID; ++e) {
86    Node u=G.tail(e);
87    Node v=G.head(e);
88    check( !bfs_test.reached(u) ||
89           (bfs_test.dist(v) > bfs_test.dist(u)+1),
90           "Wrong output.");
91  }
92
93  for(NodeIt v(G); v==INVALID; ++v) {
94    check(bfs_test.reached(v),"Each node should be reached.");
95    if ( bfs_test.pred(v)!=INVALID ) {
96      Edge e=bfs_test.pred(v);
97      Node u=G.tail(e);
98      check(u==bfs_test.predNode(v),"Wrong tree.");
99      check(bfs_test.dist(v) - bfs_test.dist(u) == 1,
100            "Wrong distance. Difference: "
101            << std::abs(bfs_test.dist(v) - bfs_test.dist(u)
102                        - 1));
103    }
104  }
105}
106
Note: See TracBrowser for help on using the repository browser.