gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Fix typos (ticket #192)
0 3 0
default
3 files changed with 4 insertions and 4 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -250,97 +250,97 @@
250 250

	
251 251
    using namespace _connectivity_bits;
252 252

	
253 253
    typedef DfsVisitor<Digraph> Visitor;
254 254
    Visitor visitor;
255 255

	
256 256
    DfsVisit<Digraph, Visitor> dfs(digraph, visitor);
257 257
    dfs.init();
258 258
    dfs.addSource(source);
259 259
    dfs.start();
260 260

	
261 261
    for (NodeIt it(digraph); it != INVALID; ++it) {
262 262
      if (!dfs.reached(it)) {
263 263
        return false;
264 264
      }
265 265
    }
266 266

	
267 267
    typedef ReverseDigraph<const Digraph> RDigraph;
268 268
    typedef typename RDigraph::NodeIt RNodeIt;
269 269
    RDigraph rdigraph(digraph);
270 270

	
271 271
    typedef DfsVisitor<Digraph> RVisitor;
272 272
    RVisitor rvisitor;
273 273

	
274 274
    DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor);
275 275
    rdfs.init();
276 276
    rdfs.addSource(source);
277 277
    rdfs.start();
278 278

	
279 279
    for (RNodeIt it(rdigraph); it != INVALID; ++it) {
280 280
      if (!rdfs.reached(it)) {
281 281
        return false;
282 282
      }
283 283
    }
284 284

	
285 285
    return true;
286 286
  }
287 287

	
288 288
  /// \ingroup connectivity
289 289
  ///
290 290
  /// \brief Count the strongly connected components of a directed graph
291 291
  ///
292 292
  /// Count the strongly connected components of a directed graph.
293 293
  /// The strongly connected components are the classes of an
294 294
  /// equivalence relation on the nodes of the graph. Two nodes are in
295 295
  /// the same class if they are connected with directed paths in both
296 296
  /// direction.
297 297
  ///
298
  /// \param graph The graph.
298
  /// \param digraph The graph.
299 299
  /// \return The number of components
300 300
  /// \note By definition, the empty graph has zero
301 301
  /// strongly connected components.
302 302
  template <typename Digraph>
303 303
  int countStronglyConnectedComponents(const Digraph& digraph) {
304 304
    checkConcept<concepts::Digraph, Digraph>();
305 305

	
306 306
    using namespace _connectivity_bits;
307 307

	
308 308
    typedef typename Digraph::Node Node;
309 309
    typedef typename Digraph::Arc Arc;
310 310
    typedef typename Digraph::NodeIt NodeIt;
311 311
    typedef typename Digraph::ArcIt ArcIt;
312 312

	
313 313
    typedef std::vector<Node> Container;
314 314
    typedef typename Container::iterator Iterator;
315 315

	
316 316
    Container nodes(countNodes(digraph));
317 317
    typedef LeaveOrderVisitor<Digraph, Iterator> Visitor;
318 318
    Visitor visitor(nodes.begin());
319 319

	
320 320
    DfsVisit<Digraph, Visitor> dfs(digraph, visitor);
321 321
    dfs.init();
322 322
    for (NodeIt it(digraph); it != INVALID; ++it) {
323 323
      if (!dfs.reached(it)) {
324 324
        dfs.addSource(it);
325 325
        dfs.start();
326 326
      }
327 327
    }
328 328

	
329 329
    typedef typename Container::reverse_iterator RIterator;
330 330
    typedef ReverseDigraph<const Digraph> RDigraph;
331 331

	
332 332
    RDigraph rdigraph(digraph);
333 333

	
334 334
    typedef DfsVisitor<Digraph> RVisitor;
335 335
    RVisitor rvisitor;
336 336

	
337 337
    DfsVisit<RDigraph, RVisitor> rdfs(rdigraph, rvisitor);
338 338

	
339 339
    int compNum = 0;
340 340

	
341 341
    rdfs.init();
342 342
    for (RIterator it = nodes.rbegin(); it != nodes.rend(); ++it) {
343 343
      if (!rdfs.reached(*it)) {
344 344
        rdfs.addSource(*it);
345 345
        rdfs.start();
346 346
        ++compNum;
... ...
@@ -1180,97 +1180,97 @@
1180 1180
  }
1181 1181

	
1182 1182
  /// \ingroup connectivity
1183 1183
  ///
1184 1184
  /// \brief Sort the nodes of a DAG into topolgical order.
1185 1185
  ///
1186 1186
  /// Sort the nodes of a DAG into topolgical order.
1187 1187
  ///
1188 1188
  /// \param graph The graph. It must be directed and acyclic.
1189 1189
  /// \retval order A writable node map. The values will be set from 0 to
1190 1190
  /// the number of the nodes in the graph minus one. Each values of the map
1191 1191
  /// will be set exactly once, the values  will be set descending order.
1192 1192
  ///
1193 1193
  /// \see checkedTopologicalSort
1194 1194
  /// \see dag
1195 1195
  template <typename Digraph, typename NodeMap>
1196 1196
  void topologicalSort(const Digraph& graph, NodeMap& order) {
1197 1197
    using namespace _connectivity_bits;
1198 1198

	
1199 1199
    checkConcept<concepts::Digraph, Digraph>();
1200 1200
    checkConcept<concepts::WriteMap<typename Digraph::Node, int>, NodeMap>();
1201 1201

	
1202 1202
    typedef typename Digraph::Node Node;
1203 1203
    typedef typename Digraph::NodeIt NodeIt;
1204 1204
    typedef typename Digraph::Arc Arc;
1205 1205

	
1206 1206
    TopologicalSortVisitor<Digraph, NodeMap>
1207 1207
      visitor(order, countNodes(graph));
1208 1208

	
1209 1209
    DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> >
1210 1210
      dfs(graph, visitor);
1211 1211

	
1212 1212
    dfs.init();
1213 1213
    for (NodeIt it(graph); it != INVALID; ++it) {
1214 1214
      if (!dfs.reached(it)) {
1215 1215
        dfs.addSource(it);
1216 1216
        dfs.start();
1217 1217
      }
1218 1218
    }
1219 1219
  }
1220 1220

	
1221 1221
  /// \ingroup connectivity
1222 1222
  ///
1223 1223
  /// \brief Sort the nodes of a DAG into topolgical order.
1224 1224
  ///
1225 1225
  /// Sort the nodes of a DAG into topolgical order. It also checks
1226 1226
  /// that the given graph is DAG.
1227 1227
  ///
1228
  /// \param graph The graph. It must be directed and acyclic.
1228
  /// \param digraph The graph. It must be directed and acyclic.
1229 1229
  /// \retval order A readable - writable node map. The values will be set
1230 1230
  /// from 0 to the number of the nodes in the graph minus one. Each values
1231 1231
  /// of the map will be set exactly once, the values will be set descending
1232 1232
  /// order.
1233 1233
  /// \return %False when the graph is not DAG.
1234 1234
  ///
1235 1235
  /// \see topologicalSort
1236 1236
  /// \see dag
1237 1237
  template <typename Digraph, typename NodeMap>
1238 1238
  bool checkedTopologicalSort(const Digraph& digraph, NodeMap& order) {
1239 1239
    using namespace _connectivity_bits;
1240 1240

	
1241 1241
    checkConcept<concepts::Digraph, Digraph>();
1242 1242
    checkConcept<concepts::ReadWriteMap<typename Digraph::Node, int>,
1243 1243
      NodeMap>();
1244 1244

	
1245 1245
    typedef typename Digraph::Node Node;
1246 1246
    typedef typename Digraph::NodeIt NodeIt;
1247 1247
    typedef typename Digraph::Arc Arc;
1248 1248

	
1249 1249
    for (NodeIt it(digraph); it != INVALID; ++it) {
1250 1250
      order.set(it, -1);
1251 1251
    }
1252 1252

	
1253 1253
    TopologicalSortVisitor<Digraph, NodeMap>
1254 1254
      visitor(order, countNodes(digraph));
1255 1255

	
1256 1256
    DfsVisit<Digraph, TopologicalSortVisitor<Digraph, NodeMap> >
1257 1257
      dfs(digraph, visitor);
1258 1258

	
1259 1259
    dfs.init();
1260 1260
    for (NodeIt it(digraph); it != INVALID; ++it) {
1261 1261
      if (!dfs.reached(it)) {
1262 1262
        dfs.addSource(it);
1263 1263
        while (!dfs.emptyQueue()) {
1264 1264
           Arc arc = dfs.nextArc();
1265 1265
           Node target = digraph.target(arc);
1266 1266
           if (dfs.reached(target) && order[target] == -1) {
1267 1267
             return false;
1268 1268
           }
1269 1269
           dfs.processNextArc();
1270 1270
         }
1271 1271
      }
1272 1272
    }
1273 1273
    return true;
1274 1274
  }
1275 1275

	
1276 1276
  /// \ingroup connectivity
Ignore white space 6 line context
... ...
@@ -371,97 +371,97 @@
371 371
      while (arc != INVALID) {
372 372
        odd = _graph.target(arc);
373 373
        arc = (*_ear)[odd];
374 374
        even = _graph.target(arc);
375 375
        _matching->set(odd, arc);
376 376
        arc = (*_matching)[even];
377 377
        _matching->set(even, _graph.oppositeArc((*_matching)[odd]));
378 378
      }
379 379

	
380 380
      for (typename TreeSet::ItemIt it(*_tree_set, tree);
381 381
           it != INVALID; ++it) {
382 382
        if ((*_status)[it] == ODD) {
383 383
          _status->set(it, MATCHED);
384 384
        } else {
385 385
          int blossom = _blossom_set->find(it);
386 386
          for (typename BlossomSet::ItemIt jt(*_blossom_set, blossom);
387 387
               jt != INVALID; ++jt) {
388 388
            _status->set(jt, MATCHED);
389 389
          }
390 390
          _blossom_set->eraseClass(blossom);
391 391
        }
392 392
      }
393 393
      _tree_set->eraseClass(tree);
394 394

	
395 395
    }
396 396

	
397 397
  public:
398 398

	
399 399
    /// \brief Constructor
400 400
    ///
401 401
    /// Constructor.
402 402
    MaxMatching(const Graph& graph)
403 403
      : _graph(graph), _matching(0), _status(0), _ear(0),
404 404
        _blossom_set_index(0), _blossom_set(0), _blossom_rep(0),
405 405
        _tree_set_index(0), _tree_set(0) {}
406 406

	
407 407
    ~MaxMatching() {
408 408
      destroyStructures();
409 409
    }
410 410

	
411 411
    /// \name Execution control
412 412
    /// The simplest way to execute the algorithm is to use the
413 413
    /// \c run() member function.
414 414
    /// \n
415 415

	
416 416
    /// If you need better control on the execution, you must call
417 417
    /// \ref init(), \ref greedyInit() or \ref matchingInit()
418 418
    /// functions first, then you can start the algorithm with the \ref
419
    /// startParse() or startDense() functions.
419
    /// startSparse() or startDense() functions.
420 420

	
421 421
    ///@{
422 422

	
423 423
    /// \brief Sets the actual matching to the empty matching.
424 424
    ///
425 425
    /// Sets the actual matching to the empty matching.
426 426
    ///
427 427
    void init() {
428 428
      createStructures();
429 429
      for(NodeIt n(_graph); n != INVALID; ++n) {
430 430
        _matching->set(n, INVALID);
431 431
        _status->set(n, UNMATCHED);
432 432
      }
433 433
    }
434 434

	
435 435
    ///\brief Finds an initial matching in a greedy way
436 436
    ///
437 437
    ///It finds an initial matching in a greedy way.
438 438
    void greedyInit() {
439 439
      createStructures();
440 440
      for (NodeIt n(_graph); n != INVALID; ++n) {
441 441
        _matching->set(n, INVALID);
442 442
        _status->set(n, UNMATCHED);
443 443
      }
444 444
      for (NodeIt n(_graph); n != INVALID; ++n) {
445 445
        if ((*_matching)[n] == INVALID) {
446 446
          for (OutArcIt a(_graph, n); a != INVALID ; ++a) {
447 447
            Node v = _graph.target(a);
448 448
            if ((*_matching)[v] == INVALID && v != n) {
449 449
              _matching->set(n, a);
450 450
              _status->set(n, MATCHED);
451 451
              _matching->set(v, _graph.oppositeArc(a));
452 452
              _status->set(v, MATCHED);
453 453
              break;
454 454
            }
455 455
          }
456 456
        }
457 457
      }
458 458
    }
459 459

	
460 460

	
461 461
    /// \brief Initialize the matching from a map containing.
462 462
    ///
463 463
    /// Initialize the matching from a \c bool valued \c Edge map. This
464 464
    /// map must have the property that there are no two incident edges
465 465
    /// with true value, ie. it contains a matching.
466 466
    /// \return %True if the map contains a matching.
467 467
    template <typename MatchingMap>
Ignore white space 96 line context
... ...
@@ -6,97 +6,97 @@
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_SUURBALLE_H
20 20
#define LEMON_SUURBALLE_H
21 21

	
22 22
///\ingroup shortest_path
23 23
///\file
24 24
///\brief An algorithm for finding arc-disjoint paths between two
25 25
/// nodes having minimum total length.
26 26

	
27 27
#include <vector>
28 28
#include <lemon/bin_heap.h>
29 29
#include <lemon/path.h>
30 30

	
31 31
namespace lemon {
32 32

	
33 33
  /// \addtogroup shortest_path
34 34
  /// @{
35 35

	
36 36
  /// \brief Algorithm for finding arc-disjoint paths between two nodes
37 37
  /// having minimum total length.
38 38
  ///
39 39
  /// \ref lemon::Suurballe "Suurballe" implements an algorithm for
40 40
  /// finding arc-disjoint paths having minimum total length (cost)
41 41
  /// from a given source node to a given target node in a digraph.
42 42
  ///
43 43
  /// In fact, this implementation is the specialization of the
44 44
  /// \ref CapacityScaling "successive shortest path" algorithm.
45 45
  ///
46 46
  /// \tparam Digraph The digraph type the algorithm runs on.
47 47
  /// The default value is \c ListDigraph.
48 48
  /// \tparam LengthMap The type of the length (cost) map.
49 49
  /// The default value is <tt>Digraph::ArcMap<int></tt>.
50 50
  ///
51 51
  /// \warning Length values should be \e non-negative \e integers.
52 52
  ///
53 53
  /// \note For finding node-disjoint paths this algorithm can be used
54
  /// with \ref SplitDigraphAdaptor.
54
  /// with \ref SplitNodes.
55 55
#ifdef DOXYGEN
56 56
  template <typename Digraph, typename LengthMap>
57 57
#else
58 58
  template < typename Digraph = ListDigraph,
59 59
             typename LengthMap = typename Digraph::template ArcMap<int> >
60 60
#endif
61 61
  class Suurballe
62 62
  {
63 63
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
64 64

	
65 65
    typedef typename LengthMap::Value Length;
66 66
    typedef ConstMap<Arc, int> ConstArcMap;
67 67
    typedef typename Digraph::template NodeMap<Arc> PredMap;
68 68

	
69 69
  public:
70 70

	
71 71
    /// The type of the flow map.
72 72
    typedef typename Digraph::template ArcMap<int> FlowMap;
73 73
    /// The type of the potential map.
74 74
    typedef typename Digraph::template NodeMap<Length> PotentialMap;
75 75
    /// The type of the path structures.
76 76
    typedef SimplePath<Digraph> Path;
77 77

	
78 78
  private:
79 79
  
80 80
    /// \brief Special implementation of the Dijkstra algorithm
81 81
    /// for finding shortest paths in the residual network.
82 82
    ///
83 83
    /// \ref ResidualDijkstra is a special implementation of the
84 84
    /// \ref Dijkstra algorithm for finding shortest paths in the
85 85
    /// residual network of the digraph with respect to the reduced arc
86 86
    /// lengths and modifying the node potentials according to the
87 87
    /// distance of the nodes.
88 88
    class ResidualDijkstra
89 89
    {
90 90
      typedef typename Digraph::template NodeMap<int> HeapCrossRef;
91 91
      typedef BinHeap<Length, HeapCrossRef> Heap;
92 92

	
93 93
    private:
94 94

	
95 95
      // The digraph the algorithm runs on
96 96
      const Digraph &_graph;
97 97

	
98 98
      // The main maps
99 99
      const FlowMap &_flow;
100 100
      const LengthMap &_length;
101 101
      PotentialMap &_potential;
102 102

	
0 comments (0 inline)