demo/tight_edge_filter_map.h
author hegyi
Mon, 21 Nov 2005 18:03:20 +0000
changeset 1823 cb082cdf3667
parent 1359 1581f961cfaa
child 1875 98698b69a902
permissions -rw-r--r--
NewMapWin has become Dialog instead of Window. Therefore it is created dynamically, when there is need for it, instead of keeping one instance in memory. This solution is slower, but more correct than before.
alpar@906
     1
/* -*- C++ -*-
ladanyi@1435
     2
 * demo/tight_edge_filter_map.h - Part of LEMON, a generic C++ optimization
ladanyi@1435
     3
 * library
alpar@906
     4
 *
alpar@1164
     5
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@1359
     6
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@906
     7
 *
alpar@906
     8
 * Permission to use, modify and distribute this software is granted
alpar@906
     9
 * provided that this copyright notice appears in all copies. For
alpar@906
    10
 * precise terms see the accompanying LICENSE file.
alpar@906
    11
 *
alpar@906
    12
 * This software is provided "AS IS" with no warranty of any kind,
alpar@906
    13
 * express or implied, and with no claim as to its suitability for any
alpar@906
    14
 * purpose.
alpar@906
    15
 *
alpar@906
    16
 */
alpar@906
    17
alpar@921
    18
#ifndef LEMON_TIGHT_EDGE_FILTER_MAP_H
alpar@921
    19
#define LEMON_TIGHT_EDGE_FILTER_MAP_H
marci@888
    20
alpar@921
    21
#include <lemon/maps.h>
marci@910
    22
marci@888
    23
// /// \file
marci@888
    24
// /// \brief Maximum flow algorithms.
marci@888
    25
// /// \ingroup galgs
marci@888
    26
alpar@921
    27
namespace lemon {
marci@888
    28
marci@1276
    29
  /*! 
marci@1276
    30
    \brief A map for filtering the edge-set to those edges 
marci@1276
    31
    which are tight w.r.t. a node-potential and 
marci@1276
    32
    edge-distance.
marci@1276
    33
    
marci@1276
    34
    Let \f$G=(V,A)\f$ be a directed graph (graph for short) and 
marci@1276
    35
    let \f$\mathbb{F}\f$ be a number type. 
marci@1276
    36
    Given a distance function 
marci@1276
    37
    \f$d:E\to\mathbb{F}\f$, 
marci@1276
    38
    \f$\pi:V\to\mathbb{F}\f$ is said to be a potetial 
marci@1276
    39
    w.r.t. \f$d\f$ 
marci@1276
    40
    if and only if 
marci@1276
    41
    \f$\pi(v)\le d(uv)+\pi(u)\f$ holds for each edge \f$uv\in E\f$ 
marci@1276
    42
    (or the reverse inequality holds for each edge). 
marci@1276
    43
    An edge is said to be tight if this inequality holds with equality, 
marci@1276
    44
    and the map returns \c true exactly for those edges. 
marci@1276
    45
    To avoid rounding errors, it is recommended to use this class with exact 
marci@1276
    46
    number types, e.g. with \c int.
marci@1276
    47
  */
marci@888
    48
  template<typename Graph, 
marci@888
    49
	   typename NodePotentialMap, typename EdgeDistanceMap>
marci@910
    50
  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
marci@888
    51
  protected:
marci@888
    52
    const Graph* g;
marci@888
    53
    NodePotentialMap* node_potential;
marci@888
    54
    EdgeDistanceMap* edge_distance;
marci@888
    55
  public:
marci@888
    56
    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
marci@888
    57
		       EdgeDistanceMap& _edge_distance) : 
marci@888
    58
      g(&_g), node_potential(&_node_potential), 
marci@888
    59
      edge_distance(&_edge_distance) { }
marci@888
    60
    bool operator[](const typename Graph::Edge& e) const {
alpar@986
    61
      return ((*node_potential)[g->target(e)] == 
alpar@986
    62
	      (*edge_distance)[e]+(*node_potential)[g->source(e)]);
marci@888
    63
    }
marci@888
    64
  };
marci@888
    65
alpar@921
    66
} //namespace lemon
marci@888
    67
alpar@921
    68
#endif //LEMON_TIGHT_EDGE_FILTER_MAP_H