gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge bugfix #392 to branch 1.0
0 2 0
merge 1.0
1 file changed with 14 insertions and 3 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -545,33 +545,33 @@
545 545

	
546 546
    ///Executes the algorithm until the given target node is reached.
547 547

	
548 548
    ///Executes the algorithm until the given target node is reached.
549 549
    ///
550 550
    ///This method runs the %DFS algorithm from the root node
551 551
    ///in order to compute the DFS path to \c t.
552 552
    ///
553 553
    ///The algorithm computes
554 554
    ///- the %DFS path to \c t,
555 555
    ///- the distance of \c t from the root in the %DFS tree.
556 556
    ///
557 557
    ///\pre init() must be called and a root node should be
558 558
    ///added with addSource() before using this function.
559 559
    void start(Node t)
560 560
    {
561
      while ( !emptyQueue() && G->target(_stack[_stack_head])!=t )
561
      while ( !emptyQueue() && !(*_reached)[t] )
562 562
        processNextArc();
563 563
    }
564 564

	
565 565
    ///Executes the algorithm until a condition is met.
566 566

	
567 567
    ///Executes the algorithm until a condition is met.
568 568
    ///
569 569
    ///This method runs the %DFS algorithm from the root node
570 570
    ///until an arc \c a with <tt>am[a]</tt> true is found.
571 571
    ///
572 572
    ///\param am A \c bool (or convertible) arc map. The algorithm
573 573
    ///will stop when it reaches an arc \c a with <tt>am[a]</tt> true.
574 574
    ///
575 575
    ///\return The reached arc \c a with <tt>am[a]</tt> true or
576 576
    ///\c INVALID if no such arc was found.
577 577
    ///
... ...
@@ -1499,33 +1499,33 @@
1499 1499
    }
1500 1500

	
1501 1501
    /// \brief Executes the algorithm until the given target node is reached.
1502 1502
    ///
1503 1503
    /// Executes the algorithm until the given target node is reached.
1504 1504
    ///
1505 1505
    /// This method runs the %DFS algorithm from the root node
1506 1506
    /// in order to compute the DFS path to \c t.
1507 1507
    ///
1508 1508
    /// The algorithm computes
1509 1509
    /// - the %DFS path to \c t,
1510 1510
    /// - the distance of \c t from the root in the %DFS tree.
1511 1511
    ///
1512 1512
    /// \pre init() must be called and a root node should be added
1513 1513
    /// with addSource() before using this function.
1514 1514
    void start(Node t) {
1515
      while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != t )
1515
      while ( !emptyQueue() && !(*_reached)[t] )
1516 1516
        processNextArc();
1517 1517
    }
1518 1518

	
1519 1519
    /// \brief Executes the algorithm until a condition is met.
1520 1520
    ///
1521 1521
    /// Executes the algorithm until a condition is met.
1522 1522
    ///
1523 1523
    /// This method runs the %DFS algorithm from the root node
1524 1524
    /// until an arc \c a with <tt>am[a]</tt> true is found.
1525 1525
    ///
1526 1526
    /// \param am A \c bool (or convertible) arc map. The algorithm
1527 1527
    /// will stop when it reaches an arc \c a with <tt>am[a]</tt> true.
1528 1528
    ///
1529 1529
    /// \return The reached arc \c a with <tt>am[a]</tt> true or
1530 1530
    /// \c INVALID if no such arc was found.
1531 1531
    ///
Ignore white space 32 line context
... ...
@@ -37,33 +37,36 @@
37 37
  "3\n"
38 38
  "4\n"
39 39
  "5\n"
40 40
  "6\n"
41 41
  "@arcs\n"
42 42
  "     label\n"
43 43
  "0 1  0\n"
44 44
  "1 2  1\n"
45 45
  "2 3  2\n"
46 46
  "1 4  3\n"
47 47
  "4 2  4\n"
48 48
  "4 5  5\n"
49 49
  "5 0  6\n"
50 50
  "6 3  7\n"
51 51
  "@attributes\n"
52 52
  "source 0\n"
53
  "target 5\n";
53
  "target 5\n"
54
  "source1 6\n"
55
  "target1 3\n";
56

	
54 57

	
55 58
void checkDfsCompile()
56 59
{
57 60
  typedef concepts::Digraph Digraph;
58 61
  typedef Dfs<Digraph> DType;
59 62
  typedef Digraph::Node Node;
60 63
  typedef Digraph::Arc Arc;
61 64

	
62 65
  Digraph G;
63 66
  Node s, t;
64 67
  Arc e;
65 68
  int l;
66 69
  bool b;
67 70
  DType::DistMap d(G);
68 71
  DType::PredMap p(G);
69 72
  Path<Digraph> pp;
... ...
@@ -131,58 +134,66 @@
131 134
    .dist(VType())
132 135
    .run(Node(),Node());
133 136
  dfs(g)
134 137
    .predMap(concepts::ReadWriteMap<Node,Arc>())
135 138
    .distMap(concepts::ReadWriteMap<Node,VType>())
136 139
    .reachedMap(concepts::ReadWriteMap<Node,bool>())
137 140
    .processedMap(concepts::WriteMap<Node,bool>())
138 141
    .run();
139 142
}
140 143

	
141 144
template <class Digraph>
142 145
void checkDfs() {
143 146
  TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
144 147

	
145 148
  Digraph G;
146 149
  Node s, t;
150
  Node s1, t1;
147 151

	
148 152
  std::istringstream input(test_lgf);
149 153
  digraphReader(G, input).
150 154
    node("source", s).
151 155
    node("target", t).
156
    node("source1", s1).
157
    node("target1", t1).
152 158
    run();
153 159

	
154 160
  Dfs<Digraph> dfs_test(G);
155 161
  dfs_test.run(s);
156 162

	
157 163
  Path<Digraph> p = dfs_test.path(t);
158 164
  check(p.length() == dfs_test.dist(t),"path() found a wrong path.");
159 165
  check(checkPath(G, p),"path() found a wrong path.");
160 166
  check(pathSource(G, p) == s,"path() found a wrong path.");
161 167
  check(pathTarget(G, p) == t,"path() found a wrong path.");
162 168

	
163 169
  for(NodeIt v(G); v!=INVALID; ++v) {
164 170
    if (dfs_test.reached(v)) {
165 171
      check(v==s || dfs_test.predArc(v)!=INVALID, "Wrong tree.");
166 172
      if (dfs_test.predArc(v)!=INVALID ) {
167 173
        Arc e=dfs_test.predArc(v);
168 174
        Node u=G.source(e);
169 175
        check(u==dfs_test.predNode(v),"Wrong tree.");
170 176
        check(dfs_test.dist(v) - dfs_test.dist(u) == 1,
171 177
              "Wrong distance. (" << dfs_test.dist(u) << "->"
172 178
              << dfs_test.dist(v) << ")");
173 179
      }
174 180
    }
175 181
  }
176 182

	
177 183
  {
184
  Dfs<Digraph> dfs(G);
185
  check(dfs.run(s1,t1) && dfs.reached(t1),"Node 3 is reachable from Node 6.");
186
  }
187
  
188
  {
178 189
    NullMap<Node,Arc> myPredMap;
179 190
    dfs(G).predMap(myPredMap).run(s);
180 191
  }
181 192
}
182 193

	
183 194
int main()
184 195
{
185 196
  checkDfs<ListDigraph>();
186 197
  checkDfs<SmartDigraph>();
187 198
  return 0;
188 199
}
0 comments (0 inline)