src/lemon/tight_edge_filter_map.h
author alpar
Wed, 29 Sep 2004 15:30:04 +0000
changeset 921 818510fa3d99
permissions -rw-r--r--
hugo -> lemon
alpar@921
     1
/* -*- C++ -*-
alpar@921
     2
 * src/hugo/tight_edge_filter_map.h - Part of HUGOlib, a generic C++ optimization library
alpar@921
     3
 *
alpar@921
     4
 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@921
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
alpar@921
     6
 *
alpar@921
     7
 * Permission to use, modify and distribute this software is granted
alpar@921
     8
 * provided that this copyright notice appears in all copies. For
alpar@921
     9
 * precise terms see the accompanying LICENSE file.
alpar@921
    10
 *
alpar@921
    11
 * This software is provided "AS IS" with no warranty of any kind,
alpar@921
    12
 * express or implied, and with no claim as to its suitability for any
alpar@921
    13
 * purpose.
alpar@921
    14
 *
alpar@921
    15
 */
alpar@921
    16
alpar@921
    17
#ifndef HUGO_TIGHT_EDGE_FILTER_MAP_H
alpar@921
    18
#define HUGO_TIGHT_EDGE_FILTER_MAP_H
alpar@921
    19
alpar@921
    20
#include <hugo/maps.h>
alpar@921
    21
alpar@921
    22
// /// \file
alpar@921
    23
// /// \brief Maximum flow algorithms.
alpar@921
    24
// /// \ingroup galgs
alpar@921
    25
alpar@921
    26
namespace hugo {
alpar@921
    27
alpar@921
    28
  /// \brief A map for filtering the edge-set to those edges 
alpar@921
    29
  /// which are tight w.r.t. some node_potential map and 
alpar@921
    30
  /// edge_distance map.
alpar@921
    31
  ///
alpar@921
    32
  /// A node-map node_potential is said to be a potential w.r.t. 
alpar@921
    33
  /// an edge-map edge_distance 
alpar@921
    34
  /// if and only if for each edge e, node_potential[g.head(e)] 
alpar@921
    35
  /// <= edge_distance[e]+node_potential[g.tail(e)] 
alpar@921
    36
  /// (or the reverse inequality holds for each edge).
alpar@921
    37
  /// An edge is said to be tight if this inequality holds with equality, 
alpar@921
    38
  /// and the map returns true exactly for those edges.
alpar@921
    39
  /// To avoid rounding errors, it is recommended to use this class with exact 
alpar@921
    40
  /// types, e.g. with int.
alpar@921
    41
  template<typename Graph, 
alpar@921
    42
	   typename NodePotentialMap, typename EdgeDistanceMap>
alpar@921
    43
  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
alpar@921
    44
  protected:
alpar@921
    45
    const Graph* g;
alpar@921
    46
    NodePotentialMap* node_potential;
alpar@921
    47
    EdgeDistanceMap* edge_distance;
alpar@921
    48
  public:
alpar@921
    49
    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
alpar@921
    50
		       EdgeDistanceMap& _edge_distance) : 
alpar@921
    51
      g(&_g), node_potential(&_node_potential), 
alpar@921
    52
      edge_distance(&_edge_distance) { }
alpar@921
    53
    bool operator[](const typename Graph::Edge& e) const {
alpar@921
    54
      return ((*node_potential)[g->head(e)] == 
alpar@921
    55
	      (*edge_distance)[e]+(*node_potential)[g->tail(e)]);
alpar@921
    56
    }
alpar@921
    57
  };
alpar@921
    58
alpar@921
    59
} //namespace hugo
alpar@921
    60
alpar@921
    61
#endif //HUGO_TIGHT_EDGE_FILTER_MAP_H
alpar@921
    62
alpar@921
    63