demo/tight_edge_filter_map.h
author kpeter
Fri, 29 Feb 2008 15:55:13 +0000
changeset 2586 37fb2c384c78
parent 2391 14a343be7a5a
permissions -rw-r--r--
Reimplemented Suurballe class.

- The new version is the specialized version of CapacityScaling.
- It is about 10-20 times faster than the former Suurballe algorithm
and about 20-50 percent faster than CapacityScaling.
- Doc improvements.
- The test file is also replaced.
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@2553
     5
 * Copyright (C) 2003-2008
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
deba@2081
    19
#ifndef DEMO_TIGHT_EDGE_FILTER_MAP_H
deba@2081
    20
#define DEMO_TIGHT_EDGE_FILTER_MAP_H
marci@888
    21
alpar@921
    22
#include <lemon/maps.h>
marci@910
    23
deba@2081
    24
/// \file
deba@2081
    25
/// \brief Tight edge filter map.
deba@2081
    26
///
deba@2081
    27
/// Tight edge filter map is bool map on the edges of the graph
deba@2081
    28
/// which filters the edges which are not tight for a node-potential.
deba@2081
    29
/// It is used in the \ref sub_graph_adaptor_demo.cc file. 
deba@2081
    30
///
deba@2081
    31
/// \include tight_edge_filter_map.h
marci@888
    32
alpar@921
    33
namespace lemon {
marci@888
    34
deba@2081
    35
  /// \brief A map for filtering the edge-set to those edges 
deba@2081
    36
  /// which are tight w.r.t. a node-potential and 
deba@2081
    37
  /// edge-distance.
deba@2081
    38
  /// 
deba@2081
    39
  /// Let \f$ G=(V,A) \f$ be a directed graph (graph for short) and 
deba@2081
    40
  /// let \f$ \mathbb{F} \f$ be a number type. 
deba@2081
    41
  /// Given a distance function 
deba@2081
    42
  /// \f$ d:E\to\mathbb{F} \f$, 
deba@2081
    43
  /// \f$ \pi:V\to\mathbb{F} \f$ is said to be a potetial 
deba@2081
    44
  /// w.r.t. \f$ d \f$ 
deba@2081
    45
  /// if and only if 
deba@2081
    46
  /// \f$ \pi(v)\le d(uv)+\pi(u) \f$ holds for each edge \f$ uv\in E \f$ 
deba@2081
    47
  /// (or the reverse inequality holds for each edge). 
deba@2081
    48
  /// An edge is said to be tight if this inequality holds with equality, 
deba@2081
    49
  /// and the map returns \c true exactly for those edges. 
deba@2081
    50
  /// To avoid rounding errors, it is recommended to use this class with exact 
deba@2081
    51
  /// number types, e.g. with \c int.
marci@888
    52
  template<typename Graph, 
marci@888
    53
	   typename NodePotentialMap, typename EdgeDistanceMap>
marci@910
    54
  class TightEdgeFilterMap : public MapBase<typename Graph::Edge, bool> {
marci@888
    55
  protected:
marci@888
    56
    const Graph* g;
marci@888
    57
    NodePotentialMap* node_potential;
marci@888
    58
    EdgeDistanceMap* edge_distance;
marci@888
    59
  public:
marci@888
    60
    TightEdgeFilterMap(Graph& _g, NodePotentialMap& _node_potential, 
marci@888
    61
		       EdgeDistanceMap& _edge_distance) : 
marci@888
    62
      g(&_g), node_potential(&_node_potential), 
marci@888
    63
      edge_distance(&_edge_distance) { }
marci@888
    64
    bool operator[](const typename Graph::Edge& e) const {
alpar@986
    65
      return ((*node_potential)[g->target(e)] == 
alpar@986
    66
	      (*edge_distance)[e]+(*node_potential)[g->source(e)]);
marci@888
    67
    }
marci@888
    68
  };
marci@888
    69
alpar@921
    70
} //namespace lemon
marci@888
    71
deba@2081
    72
#endif //DEMO_TIGHT_EDGE_FILTER_MAP_H