gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 3 0
merge default
2 files changed with 10 insertions and 10 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -1267,97 +1267,97 @@
1267 1267
    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1268 1268
    typedef typename Digraph::template NodeMap<bool> ReachedMap;
1269 1269

	
1270 1270
    /// \brief Instantiates a \ref ReachedMap.
1271 1271
    ///
1272 1272
    /// This function instantiates a \ref ReachedMap.
1273 1273
    /// \param digraph is the digraph, to which
1274 1274
    /// we would like to define the \ref ReachedMap.
1275 1275
    static ReachedMap *createReachedMap(const Digraph &digraph) {
1276 1276
      return new ReachedMap(digraph);
1277 1277
    }
1278 1278

	
1279 1279
  };
1280 1280

	
1281 1281
  /// \ingroup search
1282 1282
  ///
1283 1283
  /// \brief %BFS algorithm class with visitor interface.
1284 1284
  ///
1285 1285
  /// This class provides an efficient implementation of the %BFS algorithm
1286 1286
  /// with visitor interface.
1287 1287
  ///
1288 1288
  /// The %BfsVisit class provides an alternative interface to the Bfs
1289 1289
  /// class. It works with callback mechanism, the BfsVisit object calls
1290 1290
  /// the member functions of the \c Visitor class on every BFS event.
1291 1291
  ///
1292 1292
  /// This interface of the BFS algorithm should be used in special cases
1293 1293
  /// when extra actions have to be performed in connection with certain
1294 1294
  /// events of the BFS algorithm. Otherwise consider to use Bfs or bfs()
1295 1295
  /// instead.
1296 1296
  ///
1297 1297
  /// \tparam _Digraph The type of the digraph the algorithm runs on.
1298 1298
  /// The default value is
1299 1299
  /// \ref ListDigraph. The value of _Digraph is not used directly by
1300 1300
  /// \ref BfsVisit, it is only passed to \ref BfsVisitDefaultTraits.
1301 1301
  /// \tparam _Visitor The Visitor type that is used by the algorithm.
1302 1302
  /// \ref BfsVisitor "BfsVisitor<_Digraph>" is an empty visitor, which
1303 1303
  /// does not observe the BFS events. If you want to observe the BFS
1304 1304
  /// events, you should implement your own visitor class.
1305 1305
  /// \tparam _Traits Traits class to set various data types used by the
1306 1306
  /// algorithm. The default traits class is
1307 1307
  /// \ref BfsVisitDefaultTraits "BfsVisitDefaultTraits<_Digraph>".
1308 1308
  /// See \ref BfsVisitDefaultTraits for the documentation of
1309 1309
  /// a BFS visit traits class.
1310 1310
#ifdef DOXYGEN
1311 1311
  template <typename _Digraph, typename _Visitor, typename _Traits>
1312 1312
#else
1313 1313
  template <typename _Digraph = ListDigraph,
1314 1314
            typename _Visitor = BfsVisitor<_Digraph>,
1315
            typename _Traits = BfsDefaultTraits<_Digraph> >
1315
            typename _Traits = BfsVisitDefaultTraits<_Digraph> >
1316 1316
#endif
1317 1317
  class BfsVisit {
1318 1318
  public:
1319 1319

	
1320 1320
    ///The traits class.
1321 1321
    typedef _Traits Traits;
1322 1322

	
1323 1323
    ///The type of the digraph the algorithm runs on.
1324 1324
    typedef typename Traits::Digraph Digraph;
1325 1325

	
1326 1326
    ///The visitor type used by the algorithm.
1327 1327
    typedef _Visitor Visitor;
1328 1328

	
1329 1329
    ///The type of the map that indicates which nodes are reached.
1330 1330
    typedef typename Traits::ReachedMap ReachedMap;
1331 1331

	
1332 1332
  private:
1333 1333

	
1334 1334
    typedef typename Digraph::Node Node;
1335 1335
    typedef typename Digraph::NodeIt NodeIt;
1336 1336
    typedef typename Digraph::Arc Arc;
1337 1337
    typedef typename Digraph::OutArcIt OutArcIt;
1338 1338

	
1339 1339
    //Pointer to the underlying digraph.
1340 1340
    const Digraph *_digraph;
1341 1341
    //Pointer to the visitor object.
1342 1342
    Visitor *_visitor;
1343 1343
    //Pointer to the map of reached status of the nodes.
1344 1344
    ReachedMap *_reached;
1345 1345
    //Indicates if _reached is locally allocated (true) or not.
1346 1346
    bool local_reached;
1347 1347

	
1348 1348
    std::vector<typename Digraph::Node> _list;
1349 1349
    int _list_front, _list_back;
1350 1350

	
1351 1351
    //Creates the maps if necessary.
1352 1352
    void create_maps() {
1353 1353
      if(!_reached) {
1354 1354
        local_reached = true;
1355 1355
        _reached = Traits::createReachedMap(*_digraph);
1356 1356
      }
1357 1357
    }
1358 1358

	
1359 1359
  protected:
1360 1360

	
1361 1361
    BfsVisit() {}
1362 1362

	
1363 1363
  public:
Ignore white space 96 line context
... ...
@@ -253,134 +253,134 @@
253 253
        if (arc != INVALID) return direct(arc, false);
254 254
      }
255 255
      return INVALID;
256 256
    }
257 257

	
258 258
    Edge findEdge(Node s, Node t, Edge p = INVALID) const {
259 259
      if (s != t) {
260 260
        if (p == INVALID) {
261 261
          Edge arc = Parent::findArc(s, t);
262 262
          if (arc != INVALID) return arc;
263 263
          arc = Parent::findArc(t, s);
264 264
          if (arc != INVALID) return arc;
265 265
        } else if (Parent::s(p) == s) {
266 266
          Edge arc = Parent::findArc(s, t, p);
267 267
          if (arc != INVALID) return arc;
268 268
          arc = Parent::findArc(t, s);
269 269
          if (arc != INVALID) return arc;
270 270
        } else {
271 271
          Edge arc = Parent::findArc(t, s, p);
272 272
          if (arc != INVALID) return arc;
273 273
        }
274 274
      } else {
275 275
        return Parent::findArc(s, t, p);
276 276
      }
277 277
      return INVALID;
278 278
    }
279 279
  };
280 280

	
281 281
  template <typename Base>
282 282
  class BidirBpGraphExtender : public Base {
283 283
  public:
284 284
    typedef Base Parent;
285 285
    typedef BidirBpGraphExtender Digraph;
286 286

	
287 287
    typedef typename Parent::Node Node;
288 288
    typedef typename Parent::Edge Edge;
289 289

	
290 290

	
291 291
    using Parent::first;
292 292
    using Parent::next;
293 293

	
294 294
    using Parent::id;
295 295

	
296 296
    class Red : public Node {
297 297
      friend class BidirBpGraphExtender;
298 298
    public:
299 299
      Red() {}
300 300
      Red(const Node& node) : Node(node) {
301
        LEMON_ASSERT(Parent::red(node) || node == INVALID,
302
                     typename Parent::NodeSetError());
301
        LEMON_DEBUG(Parent::red(node) || node == INVALID,
302
                    typename Parent::NodeSetError());
303 303
      }
304 304
      Red& operator=(const Node& node) {
305
        LEMON_ASSERT(Parent::red(node) || node == INVALID,
306
                     typename Parent::NodeSetError());
305
        LEMON_DEBUG(Parent::red(node) || node == INVALID,
306
                    typename Parent::NodeSetError());
307 307
        Node::operator=(node);
308 308
        return *this;
309 309
      }
310 310
      Red(Invalid) : Node(INVALID) {}
311 311
      Red& operator=(Invalid) {
312 312
        Node::operator=(INVALID);
313 313
        return *this;
314 314
      }
315 315
    };
316 316

	
317 317
    void first(Red& node) const {
318 318
      Parent::firstRed(static_cast<Node&>(node));
319 319
    }
320 320
    void next(Red& node) const {
321 321
      Parent::nextRed(static_cast<Node&>(node));
322 322
    }
323 323

	
324 324
    int id(const Red& node) const {
325 325
      return Parent::redId(node);
326 326
    }
327 327

	
328 328
    class Blue : public Node {
329 329
      friend class BidirBpGraphExtender;
330 330
    public:
331 331
      Blue() {}
332 332
      Blue(const Node& node) : Node(node) {
333
        LEMON_ASSERT(Parent::blue(node) || node == INVALID,
334
                     typename Parent::NodeSetError());
333
        LEMON_DEBUG(Parent::blue(node) || node == INVALID,
334
                    typename Parent::NodeSetError());
335 335
      }
336 336
      Blue& operator=(const Node& node) {
337
        LEMON_ASSERT(Parent::blue(node) || node == INVALID,
338
                     typename Parent::NodeSetError());
337
        LEMON_DEBUG(Parent::blue(node) || node == INVALID,
338
                    typename Parent::NodeSetError());
339 339
        Node::operator=(node);
340 340
        return *this;
341 341
      }
342 342
      Blue(Invalid) : Node(INVALID) {}
343 343
      Blue& operator=(Invalid) {
344 344
        Node::operator=(INVALID);
345 345
        return *this;
346 346
      }
347 347
    };
348 348

	
349 349
    void first(Blue& node) const {
350 350
      Parent::firstBlue(static_cast<Node&>(node));
351 351
    }
352 352
    void next(Blue& node) const {
353 353
      Parent::nextBlue(static_cast<Node&>(node));
354 354
    }
355 355

	
356 356
    int id(const Blue& node) const {
357 357
      return Parent::redId(node);
358 358
    }
359 359

	
360 360
    Node source(const Edge& arc) const {
361 361
      return red(arc);
362 362
    }
363 363
    Node target(const Edge& arc) const {
364 364
      return blue(arc);
365 365
    }
366 366

	
367 367
    void firstInc(Edge& arc, bool& dir, const Node& node) const {
368 368
      if (Parent::red(node)) {
369 369
        Parent::firstFromRed(arc, node);
370 370
        dir = true;
371 371
      } else {
372 372
        Parent::firstFromBlue(arc, node);
373 373
        dir = static_cast<Edge&>(arc) == INVALID;
374 374
      }
375 375
    }
376 376
    void nextInc(Edge& arc, bool& dir) const {
377 377
      if (dir) {
378 378
        Parent::nextFromRed(arc);
379 379
      } else {
380 380
        Parent::nextFromBlue(arc);
381 381
        if (arc == INVALID) dir = true;
382 382
      }
383 383
    }
384 384

	
385 385
    class Arc : public Edge {
386 386
      friend class BidirBpGraphExtender;
Ignore white space 96 line context
... ...
@@ -1213,97 +1213,97 @@
1213 1213
    /// It must meet the \ref concepts::ReadWriteMap "ReadWriteMap" concept.
1214 1214
    typedef typename Digraph::template NodeMap<bool> ReachedMap;
1215 1215

	
1216 1216
    /// \brief Instantiates a \ref ReachedMap.
1217 1217
    ///
1218 1218
    /// This function instantiates a \ref ReachedMap.
1219 1219
    /// \param digraph is the digraph, to which
1220 1220
    /// we would like to define the \ref ReachedMap.
1221 1221
    static ReachedMap *createReachedMap(const Digraph &digraph) {
1222 1222
      return new ReachedMap(digraph);
1223 1223
    }
1224 1224

	
1225 1225
  };
1226 1226

	
1227 1227
  /// \ingroup search
1228 1228
  ///
1229 1229
  /// \brief %DFS algorithm class with visitor interface.
1230 1230
  ///
1231 1231
  /// This class provides an efficient implementation of the %DFS algorithm
1232 1232
  /// with visitor interface.
1233 1233
  ///
1234 1234
  /// The %DfsVisit class provides an alternative interface to the Dfs
1235 1235
  /// class. It works with callback mechanism, the DfsVisit object calls
1236 1236
  /// the member functions of the \c Visitor class on every DFS event.
1237 1237
  ///
1238 1238
  /// This interface of the DFS algorithm should be used in special cases
1239 1239
  /// when extra actions have to be performed in connection with certain
1240 1240
  /// events of the DFS algorithm. Otherwise consider to use Dfs or dfs()
1241 1241
  /// instead.
1242 1242
  ///
1243 1243
  /// \tparam _Digraph The type of the digraph the algorithm runs on.
1244 1244
  /// The default value is
1245 1245
  /// \ref ListDigraph. The value of _Digraph is not used directly by
1246 1246
  /// \ref DfsVisit, it is only passed to \ref DfsVisitDefaultTraits.
1247 1247
  /// \tparam _Visitor The Visitor type that is used by the algorithm.
1248 1248
  /// \ref DfsVisitor "DfsVisitor<_Digraph>" is an empty visitor, which
1249 1249
  /// does not observe the DFS events. If you want to observe the DFS
1250 1250
  /// events, you should implement your own visitor class.
1251 1251
  /// \tparam _Traits Traits class to set various data types used by the
1252 1252
  /// algorithm. The default traits class is
1253 1253
  /// \ref DfsVisitDefaultTraits "DfsVisitDefaultTraits<_Digraph>".
1254 1254
  /// See \ref DfsVisitDefaultTraits for the documentation of
1255 1255
  /// a DFS visit traits class.
1256 1256
#ifdef DOXYGEN
1257 1257
  template <typename _Digraph, typename _Visitor, typename _Traits>
1258 1258
#else
1259 1259
  template <typename _Digraph = ListDigraph,
1260 1260
            typename _Visitor = DfsVisitor<_Digraph>,
1261
            typename _Traits = DfsDefaultTraits<_Digraph> >
1261
            typename _Traits = DfsVisitDefaultTraits<_Digraph> >
1262 1262
#endif
1263 1263
  class DfsVisit {
1264 1264
  public:
1265 1265

	
1266 1266
    ///The traits class.
1267 1267
    typedef _Traits Traits;
1268 1268

	
1269 1269
    ///The type of the digraph the algorithm runs on.
1270 1270
    typedef typename Traits::Digraph Digraph;
1271 1271

	
1272 1272
    ///The visitor type used by the algorithm.
1273 1273
    typedef _Visitor Visitor;
1274 1274

	
1275 1275
    ///The type of the map that indicates which nodes are reached.
1276 1276
    typedef typename Traits::ReachedMap ReachedMap;
1277 1277

	
1278 1278
  private:
1279 1279

	
1280 1280
    typedef typename Digraph::Node Node;
1281 1281
    typedef typename Digraph::NodeIt NodeIt;
1282 1282
    typedef typename Digraph::Arc Arc;
1283 1283
    typedef typename Digraph::OutArcIt OutArcIt;
1284 1284

	
1285 1285
    //Pointer to the underlying digraph.
1286 1286
    const Digraph *_digraph;
1287 1287
    //Pointer to the visitor object.
1288 1288
    Visitor *_visitor;
1289 1289
    //Pointer to the map of reached status of the nodes.
1290 1290
    ReachedMap *_reached;
1291 1291
    //Indicates if _reached is locally allocated (true) or not.
1292 1292
    bool local_reached;
1293 1293

	
1294 1294
    std::vector<typename Digraph::Arc> _stack;
1295 1295
    int _stack_head;
1296 1296

	
1297 1297
    //Creates the maps if necessary.
1298 1298
    void create_maps() {
1299 1299
      if(!_reached) {
1300 1300
        local_reached = true;
1301 1301
        _reached = Traits::createReachedMap(*_digraph);
1302 1302
      }
1303 1303
    }
1304 1304

	
1305 1305
  protected:
1306 1306

	
1307 1307
    DfsVisit() {}
1308 1308

	
1309 1309
  public:
0 comments (0 inline)