lemon/min_cost_flow.h
author kpeter
Mon, 01 Jun 2009 15:37:51 +0000
changeset 2636 1f99c95ddd2d
parent 2588 4d3bc1d04c1d
permissions -rw-r--r--
Add the Cancel and Tighten min cost flow algorithm
deba@2440
     1
/* -*- C++ -*-
deba@2440
     2
 *
deba@2440
     3
 * This file is a part of LEMON, a generic C++ optimization library
deba@2440
     4
 *
alpar@2553
     5
 * Copyright (C) 2003-2008
deba@2440
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
deba@2440
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
deba@2440
     8
 *
deba@2440
     9
 * Permission to use, modify and distribute this software is granted
deba@2440
    10
 * provided that this copyright notice appears in all copies. For
deba@2440
    11
 * precise terms see the accompanying LICENSE file.
deba@2440
    12
 *
deba@2440
    13
 * This software is provided "AS IS" with no warranty of any kind,
deba@2440
    14
 * express or implied, and with no claim as to its suitability for any
deba@2440
    15
 * purpose.
deba@2440
    16
 *
deba@2440
    17
 */
deba@2440
    18
deba@2440
    19
#ifndef LEMON_MIN_COST_FLOW_H
deba@2440
    20
#define LEMON_MIN_COST_FLOW_H
deba@2440
    21
deba@2440
    22
/// \ingroup min_cost_flow
deba@2440
    23
///
deba@2440
    24
/// \file
deba@2440
    25
/// \brief An efficient algorithm for finding a minimum cost flow.
deba@2440
    26
deba@2440
    27
#include <lemon/network_simplex.h>
deba@2440
    28
deba@2440
    29
namespace lemon {
deba@2440
    30
deba@2440
    31
  /// \addtogroup min_cost_flow
deba@2440
    32
  /// @{
deba@2440
    33
deba@2440
    34
  /// \brief An efficient algorithm for finding a minimum cost flow.
deba@2440
    35
  ///
kpeter@2556
    36
  /// \ref MinCostFlow provides an efficient algorithm for finding
kpeter@2556
    37
  /// a minimum cost flow.
deba@2440
    38
  ///
kpeter@2576
    39
  /// This class is just an alias for \ref NetworkSimplex,
kpeter@2576
    40
  /// which is the most efficient algorithm for the minimum cost
kpeter@2576
    41
  /// flow problem in LEMON according to our benchmark tests.
kpeter@2576
    42
  /// For the detailed documentation of this class see
kpeter@2556
    43
  /// \ref NetworkSimplex.
deba@2440
    44
  ///
kpeter@2576
    45
  /// There are four implementations for the minimum cost flow problem,
kpeter@2581
    46
  /// which can be used exactly the same way.
kpeter@2588
    47
  /// - \ref CapacityScaling
kpeter@2588
    48
  /// - \ref CostScaling
kpeter@2588
    49
  /// - \ref CycleCanceling
kpeter@2588
    50
  /// - \ref NetworkSimplex
kpeter@2576
    51
  ///
kpeter@2576
    52
  /// \tparam Graph The directed graph type the algorithm runs on.
kpeter@2576
    53
  /// \tparam LowerMap The type of the lower bound map.
kpeter@2576
    54
  /// \tparam CapacityMap The type of the capacity (upper bound) map.
kpeter@2576
    55
  /// \tparam CostMap The type of the cost (length) map.
kpeter@2576
    56
  /// \tparam SupplyMap The type of the supply map.
deba@2440
    57
  ///
deba@2440
    58
  /// \warning
kpeter@2576
    59
  /// - Edge capacities and costs should be \e non-negative \e integers.
kpeter@2576
    60
  /// - Supply values should be \e signed \e integers.
kpeter@2581
    61
  /// - The value types of the maps should be convertible to each other.
kpeter@2581
    62
  /// - \c CostMap::Value must be signed type.
deba@2440
    63
  ///
deba@2440
    64
  /// \author Peter Kovacs
kpeter@2533
    65
  template < typename Graph,
kpeter@2533
    66
             typename LowerMap = typename Graph::template EdgeMap<int>,
kpeter@2581
    67
             typename CapacityMap = typename Graph::template EdgeMap<int>,
kpeter@2533
    68
             typename CostMap = typename Graph::template EdgeMap<int>,
kpeter@2581
    69
             typename SupplyMap = typename Graph::template NodeMap<int> >
deba@2440
    70
  class MinCostFlow :
kpeter@2556
    71
    public NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    72
                           CostMap, SupplyMap >
deba@2440
    73
  {
deba@2440
    74
    typedef NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    75
                            CostMap, SupplyMap > MinCostFlowImpl;
deba@2440
    76
    typedef typename Graph::Node Node;
deba@2440
    77
    typedef typename SupplyMap::Value Supply;
deba@2440
    78
deba@2440
    79
  public:
deba@2440
    80
kpeter@2581
    81
    /// General constructor (with lower bounds).
kpeter@2556
    82
    MinCostFlow( const Graph &graph,
kpeter@2556
    83
                 const LowerMap &lower,
kpeter@2556
    84
                 const CapacityMap &capacity,
kpeter@2556
    85
                 const CostMap &cost,
kpeter@2556
    86
                 const SupplyMap &supply ) :
kpeter@2556
    87
      MinCostFlowImpl(graph, lower, capacity, cost, supply) {}
deba@2440
    88
kpeter@2556
    89
    /// General constructor of the class (without lower bounds).
kpeter@2556
    90
    MinCostFlow( const Graph &graph,
kpeter@2556
    91
                 const CapacityMap &capacity,
kpeter@2579
    92
                 const CostMap &cost,
kpeter@2556
    93
                 const SupplyMap &supply ) :
kpeter@2556
    94
      MinCostFlowImpl(graph, capacity, cost, supply) {}
deba@2440
    95
kpeter@2581
    96
    /// Simple constructor (with lower bounds).
kpeter@2556
    97
    MinCostFlow( const Graph &graph,
kpeter@2556
    98
                 const LowerMap &lower,
kpeter@2556
    99
                 const CapacityMap &capacity,
kpeter@2579
   100
                 const CostMap &cost,
kpeter@2556
   101
                 Node s, Node t,
kpeter@2556
   102
                 Supply flow_value ) :
kpeter@2556
   103
      MinCostFlowImpl( graph, lower, capacity, cost,
kpeter@2556
   104
                       s, t, flow_value ) {}
deba@2440
   105
kpeter@2581
   106
    /// Simple constructor (without lower bounds).
kpeter@2556
   107
    MinCostFlow( const Graph &graph,
kpeter@2556
   108
                 const CapacityMap &capacity,
kpeter@2556
   109
                 const CostMap &cost,
kpeter@2556
   110
                 Node s, Node t,
kpeter@2556
   111
                 Supply flow_value ) :
kpeter@2556
   112
      MinCostFlowImpl( graph, capacity, cost,
kpeter@2556
   113
                       s, t, flow_value ) {}
deba@2440
   114
deba@2440
   115
  }; //class MinCostFlow
deba@2440
   116
deba@2440
   117
  ///@}
deba@2440
   118
deba@2440
   119
} //namespace lemon
deba@2440
   120
deba@2440
   121
#endif //LEMON_MIN_COST_FLOW_H