1 /* -*- mode: C++; indent-tabs-mode: nil; -*-
3 * This file is a part of LEMON, a generic C++ optimization library.
5 * Copyright (C) 2003-2009
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
19 #ifndef LEMON_BITS_PATH_DUMP_H
20 #define LEMON_BITS_PATH_DUMP_H
22 #include <lemon/core.h>
23 #include <lemon/concept_check.h>
27 template <typename _Digraph, typename _PredMap>
30 typedef True RevPathTag;
32 typedef _Digraph Digraph;
33 typedef typename Digraph::Arc Arc;
34 typedef _PredMap PredMap;
36 PredMapPath(const Digraph& _digraph, const PredMap& _predMap,
37 typename Digraph::Node _target)
38 : digraph(_digraph), predMap(_predMap), target(_target) {}
42 typename Digraph::Node node = target;
43 typename Digraph::Arc arc;
44 while ((arc = predMap[node]) != INVALID) {
45 node = digraph.source(arc);
52 return predMap[target] != INVALID;
58 RevArcIt(Invalid) : path(0), current(INVALID) {}
59 RevArcIt(const PredMapPath& _path)
60 : path(&_path), current(_path.target) {
61 if (path->predMap[current] == INVALID) current = INVALID;
64 operator const typename Digraph::Arc() const {
65 return path->predMap[current];
68 RevArcIt& operator++() {
69 current = path->digraph.source(path->predMap[current]);
70 if (path->predMap[current] == INVALID) current = INVALID;
74 bool operator==(const RevArcIt& e) const {
75 return current == e.current;
78 bool operator!=(const RevArcIt& e) const {
79 return current != e.current;
82 bool operator<(const RevArcIt& e) const {
83 return current < e.current;
87 const PredMapPath* path;
88 typename Digraph::Node current;
92 const Digraph& digraph;
93 const PredMap& predMap;
94 typename Digraph::Node target;
98 template <typename _Digraph, typename _PredMatrixMap>
99 class PredMatrixMapPath {
101 typedef True RevPathTag;
103 typedef _Digraph Digraph;
104 typedef typename Digraph::Arc Arc;
105 typedef _PredMatrixMap PredMatrixMap;
107 PredMatrixMapPath(const Digraph& _digraph,
108 const PredMatrixMap& _predMatrixMap,
109 typename Digraph::Node _source,
110 typename Digraph::Node _target)
111 : digraph(_digraph), predMatrixMap(_predMatrixMap),
112 source(_source), target(_target) {}
116 typename Digraph::Node node = target;
117 typename Digraph::Arc arc;
118 while ((arc = predMatrixMap(source, node)) != INVALID) {
119 node = digraph.source(arc);
126 return source != target;
132 RevArcIt(Invalid) : path(0), current(INVALID) {}
133 RevArcIt(const PredMatrixMapPath& _path)
134 : path(&_path), current(_path.target) {
135 if (path->predMatrixMap(path->source, current) == INVALID)
139 operator const typename Digraph::Arc() const {
140 return path->predMatrixMap(path->source, current);
143 RevArcIt& operator++() {
145 path->digraph.source(path->predMatrixMap(path->source, current));
146 if (path->predMatrixMap(path->source, current) == INVALID)
151 bool operator==(const RevArcIt& e) const {
152 return current == e.current;
155 bool operator!=(const RevArcIt& e) const {
156 return current != e.current;
159 bool operator<(const RevArcIt& e) const {
160 return current < e.current;
164 const PredMatrixMapPath* path;
165 typename Digraph::Node current;
169 const Digraph& digraph;
170 const PredMatrixMap& predMatrixMap;
171 typename Digraph::Node source;
172 typename Digraph::Node target;