gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Bug fix in Dfs::start(s,t) (#392)
0 2 0
default
2 files changed with 14 insertions and 3 deletions:
↑ Collapse diff ↑
Show white space 12 line context
... ...
@@ -555,13 +555,13 @@
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.
... ...
@@ -1508,13 +1508,13 @@
1508 1508
    /// - the %DFS path to \c t,
1509 1509
    /// - the distance of \c t from the root in the %DFS tree.
1510 1510
    ///
1511 1511
    /// \pre init() must be called and a root node should be added
1512 1512
    /// with addSource() before using this function.
1513 1513
    void start(Node t) {
1514
      while ( !emptyQueue() && _digraph->target(_stack[_stack_head]) != t )
1514
      while ( !emptyQueue() && !(*_reached)[t] )
1515 1515
        processNextArc();
1516 1516
    }
1517 1517

	
1518 1518
    /// \brief Executes the algorithm until a condition is met.
1519 1519
    ///
1520 1520
    /// Executes the algorithm until a condition is met.
Show white space 12 line context
... ...
@@ -47,13 +47,16 @@
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;
... ...
@@ -141,17 +144,20 @@
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);
... ...
@@ -172,12 +178,17 @@
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()
0 comments (0 inline)