3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
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_PRED_MAP_PATH_H
20 #define LEMON_BITS_PRED_MAP_PATH_H
24 template <typename _Graph, typename _PredMap>
27 typedef True RevPathTag;
30 typedef typename Graph::Edge Edge;
31 typedef _PredMap PredMap;
33 PredMapPath(const Graph& _graph, const PredMap& _predMap,
34 typename Graph::Node _target)
35 : graph(_graph), predMap(_predMap), target(_target) {}
39 typename Graph::Node node = target;
40 typename Graph::Edge edge;
41 while ((edge = predMap[node]) != INVALID) {
42 node = graph.source(edge);
49 return predMap[target] != INVALID;
55 RevEdgeIt(Invalid) : path(0), current(INVALID) {}
56 RevEdgeIt(const PredMapPath& _path)
57 : path(&_path), current(_path.target) {
58 if (path->predMap[current] == INVALID) current = INVALID;
61 operator const typename Graph::Edge() const {
62 return path->predMap[current];
65 RevEdgeIt& operator++() {
66 current = path->graph.source(path->predMap[current]);
67 if (path->predMap[current] == INVALID) current = INVALID;
71 bool operator==(const RevEdgeIt& e) const {
72 return current == e.current;
75 bool operator!=(const RevEdgeIt& e) const {
76 return current != e.current;
79 bool operator<(const RevEdgeIt& e) const {
80 return current < e.current;
84 const PredMapPath* path;
85 typename Graph::Node current;
90 const PredMap& predMap;
91 typename Graph::Node target;
95 template <typename _Graph, typename _PredMatrixMap>
96 class PredMatrixMapPath {
98 typedef True RevPathTag;
100 typedef _Graph Graph;
101 typedef typename Graph::Edge Edge;
102 typedef _PredMatrixMap PredMatrixMap;
104 PredMatrixMapPath(const Graph& _graph,
105 const PredMatrixMap& _predMatrixMap,
106 typename Graph::Node _source,
107 typename Graph::Node _target)
108 : graph(_graph), predMatrixMap(_predMatrixMap),
109 source(_source), target(_target) {}
113 typename Graph::Node node = target;
114 typename Graph::Edge edge;
115 while ((edge = predMatrixMap(source, node)) != INVALID) {
116 node = graph.source(edge);
123 return source != target;
129 RevEdgeIt(Invalid) : path(0), current(INVALID) {}
130 RevEdgeIt(const PredMatrixMapPath& _path)
131 : path(&_path), current(_path.target) {
132 if (path->predMatrixMap(path->source, current) == INVALID)
136 operator const typename Graph::Edge() const {
137 return path->predMatrixMap(path->source, current);
140 RevEdgeIt& operator++() {
142 path->graph.source(path->predMatrixMap(path->source, current));
143 if (path->predMatrixMap(path->source, current) == INVALID)
148 bool operator==(const RevEdgeIt& e) const {
149 return current == e.current;
152 bool operator!=(const RevEdgeIt& e) const {
153 return current != e.current;
156 bool operator<(const RevEdgeIt& e) const {
157 return current < e.current;
161 const PredMatrixMapPath* path;
162 typename Graph::Node current;
167 const PredMatrixMap& predMatrixMap;
168 typename Graph::Node source;
169 typename Graph::Node target;