* This file is a part of LEMON, a generic C++ optimization library
* Copyright (C) 2003-2008
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
* (Egervary Research Group on Combinatorial Optimization, EGRES).
* Permission to use, modify and distribute this software is granted
* provided that this copyright notice appears in all copies. For
* precise terms see the accompanying LICENSE file.
* This software is provided "AS IS" with no warranty of any kind,
* express or implied, and with no claim as to its suitability for any
#ifndef LEMON_BITS_PRED_MAP_PATH_H
#define LEMON_BITS_PRED_MAP_PATH_H
template <typename _Digraph, typename _PredMap>
typedef _Digraph Digraph;
typedef typename Digraph::Arc Arc;
typedef _PredMap PredMap;
PredMapPath(const Digraph& _digraph, const PredMap& _predMap,
typename Digraph::Node _target)
: digraph(_digraph), predMap(_predMap), target(_target) {}
typename Digraph::Node node = target;
typename Digraph::Arc arc;
while ((arc = predMap[node]) != INVALID) {
node = digraph.source(arc);
return predMap[target] != INVALID;
RevArcIt(Invalid) : path(0), current(INVALID) {}
RevArcIt(const PredMapPath& _path)
: path(&_path), current(_path.target) {
if (path->predMap[current] == INVALID) current = INVALID;
operator const typename Digraph::Arc() const {
return path->predMap[current];
current = path->digraph.source(path->predMap[current]);
if (path->predMap[current] == INVALID) current = INVALID;
bool operator==(const RevArcIt& e) const {
return current == e.current;
bool operator!=(const RevArcIt& e) const {
return current != e.current;
bool operator<(const RevArcIt& e) const {
return current < e.current;
typename Digraph::Node current;
typename Digraph::Node target;
template <typename _Digraph, typename _PredMatrixMap>
class PredMatrixMapPath {
typedef _Digraph Digraph;
typedef typename Digraph::Arc Arc;
typedef _PredMatrixMap PredMatrixMap;
PredMatrixMapPath(const Digraph& _digraph,
const PredMatrixMap& _predMatrixMap,
typename Digraph::Node _source,
typename Digraph::Node _target)
: digraph(_digraph), predMatrixMap(_predMatrixMap),
source(_source), target(_target) {}
typename Digraph::Node node = target;
typename Digraph::Arc arc;
while ((arc = predMatrixMap(source, node)) != INVALID) {
node = digraph.source(arc);
RevArcIt(Invalid) : path(0), current(INVALID) {}
RevArcIt(const PredMatrixMapPath& _path)
: path(&_path), current(_path.target) {
if (path->predMatrixMap(path->source, current) == INVALID)
operator const typename Digraph::Arc() const {
return path->predMatrixMap(path->source, current);
path->digraph.source(path->predMatrixMap(path->source, current));
if (path->predMatrixMap(path->source, current) == INVALID)
bool operator==(const RevArcIt& e) const {
return current == e.current;
bool operator!=(const RevArcIt& e) const {
return current != e.current;
bool operator<(const RevArcIt& e) const {
return current < e.current;
const PredMatrixMapPath* path;
typename Digraph::Node current;
const PredMatrixMap& predMatrixMap;
typename Digraph::Node source;
typename Digraph::Node target;