2 * demo/tight_edge_filter_map.h - Part of LEMON, a generic C++ optimization
5 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
6 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 * Permission to use, modify and distribute this software is granted
9 * provided that this copyright notice appears in all copies. For
10 * precise terms see the accompanying LICENSE file.
12 * This software is provided "AS IS" with no warranty of any kind,
13 * express or implied, and with no claim as to its suitability for any
18 #ifndef LEMON_TIGHT_EDGE_FILTER_MAP_H
19 #define LEMON_TIGHT_EDGE_FILTER_MAP_H
21 #include <lemon/maps.h>
24 // /// \brief Maximum flow algorithms.
30 \brief A map for filtering the edge-set to those edges
31 which are tight w.r.t. a node-potential and
34 Let \f$G=(V,A)\f$ be a directed graph (graph for short) and
35 let \f$\mathbb{F}\f$ be a number type.
36 Given a distance function
37 \f$d:E\to\mathbb{F}\f$,
38 \f$\pi:V\to\mathbb{F}\f$ is said to be a potetial
41 \f$\pi(v)\le d(uv)+\pi(u)\f$ holds for each edge \f$uv\in E\f$
42 (or the reverse inequality holds for each edge).
43 An edge is said to be tight if this inequality holds with equality,
44 and the map returns \c true exactly for those edges.
45 To avoid rounding errors, it is recommended to use this class with exact
46 number types, e.g. with \c int.
48 template<typename Graph,
49 typename NodePotentialMap, typename EdgeDistanceMap>
50 class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
53 NodePotentialMap* node_potential;
54 EdgeDistanceMap* edge_distance;
56 TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential,
57 EdgeDistanceMap& _edge_distance) :
58 g(&_g), node_potential(&_node_potential),
59 edge_distance(&_edge_distance) { }
60 bool operator[](const typename Graph::Edge& e) const {
61 return ((*node_potential)[g->target(e)] ==
62 (*edge_distance)[e]+(*node_potential)[g->source(e)]);
68 #endif //LEMON_TIGHT_EDGE_FILTER_MAP_H