demo/tight_edge_filter_map.h
author deba
Wed, 22 Feb 2006 18:26:56 +0000
changeset 1979 c2992fd74dad
parent 1875 98698b69a902
child 2042 bdc953f2a449
permissions -rw-r--r--
Mergeing extendermerge branch
Changes:
the extender system
resize for static size graph
UGraphExtender => UndirectGraphExtender
UGraphExtenders with changed meaning
Some UGraphExtender /SubUGraphExtenders, DirectUGraphExtender/
GridGraph => GridUGraph
radix sort to ansi compatible
alpar@906
     1
/* -*- C++ -*-
alpar@906
     2
 *
alpar@1956
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@1956
     4
 *
alpar@1956
     5
 * Copyright (C) 2003-2006
alpar@1956
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906
     8
 *
alpar@906
     9
 * Permission to use, modify and distribute this software is granted
alpar@906
    10
 * provided that this copyright notice appears in all copies. For
alpar@906
    11
 * precise terms see the accompanying LICENSE file.
alpar@906
    12
 *
alpar@906
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    14
 * express or implied, and with no claim as to its suitability for any
alpar@906
    15
 * purpose.
alpar@906
    16
 *
alpar@906
    17
 */
alpar@906
    18
alpar@921
    19
#ifndef LEMON_TIGHT_EDGE_FILTER_MAP_H
alpar@921
    20
#define LEMON_TIGHT_EDGE_FILTER_MAP_H
marci@888
    21
alpar@921
    22
#include <lemon/maps.h>
marci@910
    23
marci@888
    24
// /// \file
marci@888
    25
// /// \brief Maximum flow algorithms.
marci@888
    26
// /// \ingroup galgs
marci@888
    27
alpar@921
    28
namespace lemon {
marci@888
    29
marci@1276
    30
  /*! 
marci@1276
    31
    \brief A map for filtering the edge-set to those edges 
marci@1276
    32
    which are tight w.r.t. a node-potential and 
marci@1276
    33
    edge-distance.
marci@1276
    34
    
marci@1276
    35
    Let \f$G=(V,A)\f$ be a directed graph (graph for short) and 
marci@1276
    36
    let \f$\mathbb{F}\f$ be a number type. 
marci@1276
    37
    Given a distance function 
marci@1276
    38
    \f$d:E\to\mathbb{F}\f$, 
marci@1276
    39
    \f$\pi:V\to\mathbb{F}\f$ is said to be a potetial 
marci@1276
    40
    w.r.t. \f$d\f$ 
marci@1276
    41
    if and only if 
marci@1276
    42
    \f$\pi(v)\le d(uv)+\pi(u)\f$ holds for each edge \f$uv\in E\f$ 
marci@1276
    43
    (or the reverse inequality holds for each edge). 
marci@1276
    44
    An edge is said to be tight if this inequality holds with equality, 
marci@1276
    45
    and the map returns \c true exactly for those edges. 
marci@1276
    46
    To avoid rounding errors, it is recommended to use this class with exact 
marci@1276
    47
    number types, e.g. with \c int.
marci@1276
    48
  */
marci@888
    49
  template<typename Graph, 
marci@888
    50
	   typename NodePotentialMap, typename EdgeDistanceMap>
marci@910
    51
  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
marci@888
    52
  protected:
marci@888
    53
    const Graph* g;
marci@888
    54
    NodePotentialMap* node_potential;
marci@888
    55
    EdgeDistanceMap* edge_distance;
marci@888
    56
  public:
marci@888
    57
    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
marci@888
    58
		       EdgeDistanceMap& _edge_distance) : 
marci@888
    59
      g(&_g), node_potential(&_node_potential), 
marci@888
    60
      edge_distance(&_edge_distance) { }
marci@888
    61
    bool operator[](const typename Graph::Edge& e) const {
alpar@986
    62
      return ((*node_potential)[g->target(e)] == 
alpar@986
    63
	      (*edge_distance)[e]+(*node_potential)[g->source(e)]);
marci@888
    64
    }
marci@888
    65
  };
marci@888
    66
alpar@921
    67
} //namespace lemon
marci@888
    68
alpar@921
    69
#endif //LEMON_TIGHT_EDGE_FILTER_MAP_H