lemon/min_cost_flow.h
author alpar
Fri, 08 Feb 2008 09:52:48 +0000
changeset 2566 f75c05a5bbe6
parent 2553 bfced05fa852
child 2576 ae092c63d3ba
permissions -rw-r--r--
Doc improvments backported from hg 9df0fe5e5109
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@2556
    39
  /// \note \ref MinCostFlow is just an alias for \ref NetworkSimplex,
kpeter@2556
    40
  /// which is the most efficient implementation for the minimum cost
kpeter@2556
    41
  /// flow problem in the LEMON library according to our benchmark
kpeter@2556
    42
  /// tests.
deba@2440
    43
  ///
deba@2440
    44
  /// \note There are three implementations for the minimum cost flow
kpeter@2556
    45
  /// problem, that can be used exactly the same way.
kpeter@2556
    46
  /// - \ref CapacityScaling
kpeter@2556
    47
  /// - \ref CycleCanceling
kpeter@2556
    48
  /// - \ref NetworkSimplex
kpeter@2556
    49
  ///
kpeter@2556
    50
  /// \note For the detailed documentation of this class see
kpeter@2556
    51
  /// \ref NetworkSimplex.
deba@2440
    52
  ///
deba@2440
    53
  /// \param Graph The directed graph type the algorithm runs on.
deba@2440
    54
  /// \param LowerMap The type of the lower bound map.
deba@2440
    55
  /// \param CapacityMap The type of the capacity (upper bound) map.
deba@2440
    56
  /// \param CostMap The type of the cost (length) map.
deba@2440
    57
  /// \param SupplyMap The type of the supply map.
deba@2440
    58
  ///
deba@2440
    59
  /// \warning
kpeter@2556
    60
  /// - Edge capacities and costs should be non-negative integers.
kpeter@2556
    61
  ///   However \c CostMap::Value should be signed type.
kpeter@2509
    62
  /// - Supply values should be signed integers.
deba@2440
    63
  /// - \c LowerMap::Value must be convertible to
kpeter@2556
    64
  ///   \c CapacityMap::Value and \c CapacityMap::Value must be
kpeter@2556
    65
  ///   convertible to \c SupplyMap::Value.
deba@2440
    66
  ///
deba@2440
    67
  /// \author Peter Kovacs
deba@2440
    68
kpeter@2533
    69
  template < typename Graph,
kpeter@2533
    70
             typename LowerMap = typename Graph::template EdgeMap<int>,
kpeter@2533
    71
             typename CapacityMap = LowerMap,
kpeter@2533
    72
             typename CostMap = typename Graph::template EdgeMap<int>,
kpeter@2533
    73
             typename SupplyMap = typename Graph::template NodeMap
kpeter@2533
    74
                                  <typename CapacityMap::Value> >
deba@2440
    75
  class MinCostFlow :
kpeter@2556
    76
    public NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    77
                           CostMap, SupplyMap >
deba@2440
    78
  {
deba@2440
    79
    typedef NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    80
                            CostMap, SupplyMap > MinCostFlowImpl;
deba@2440
    81
    typedef typename Graph::Node Node;
deba@2440
    82
    typedef typename SupplyMap::Value Supply;
deba@2440
    83
deba@2440
    84
  public:
deba@2440
    85
kpeter@2556
    86
    /// General constructor of the class (with lower bounds).
kpeter@2556
    87
    MinCostFlow( const Graph &graph,
kpeter@2556
    88
                 const LowerMap &lower,
kpeter@2556
    89
                 const CapacityMap &capacity,
kpeter@2556
    90
                 const CostMap &cost,
kpeter@2556
    91
                 const SupplyMap &supply ) :
kpeter@2556
    92
      MinCostFlowImpl(graph, lower, capacity, cost, supply) {}
deba@2440
    93
kpeter@2556
    94
    /// General constructor of the class (without lower bounds).
kpeter@2556
    95
    MinCostFlow( const Graph &graph,
kpeter@2556
    96
                 const CapacityMap &capacity,
kpeter@2556
    97
                 const CostMap &_ost,
kpeter@2556
    98
                 const SupplyMap &supply ) :
kpeter@2556
    99
      MinCostFlowImpl(graph, capacity, cost, supply) {}
deba@2440
   100
kpeter@2556
   101
    /// Simple constructor of the class (with lower bounds).
kpeter@2556
   102
    MinCostFlow( const Graph &graph,
kpeter@2556
   103
                 const LowerMap &lower,
kpeter@2556
   104
                 const CapacityMap &capacity,
kpeter@2556
   105
                 const CostMap &_ost,
kpeter@2556
   106
                 Node s, Node t,
kpeter@2556
   107
                 Supply flow_value ) :
kpeter@2556
   108
      MinCostFlowImpl( graph, lower, capacity, cost,
kpeter@2556
   109
                       s, t, flow_value ) {}
deba@2440
   110
kpeter@2556
   111
    /// Simple constructor of the class (without lower bounds).
kpeter@2556
   112
    MinCostFlow( const Graph &graph,
kpeter@2556
   113
                 const CapacityMap &capacity,
kpeter@2556
   114
                 const CostMap &cost,
kpeter@2556
   115
                 Node s, Node t,
kpeter@2556
   116
                 Supply flow_value ) :
kpeter@2556
   117
      MinCostFlowImpl( graph, capacity, cost,
kpeter@2556
   118
                       s, t, flow_value ) {}
deba@2440
   119
deba@2440
   120
  }; //class MinCostFlow
deba@2440
   121
deba@2440
   122
  ///@}
deba@2440
   123
deba@2440
   124
} //namespace lemon
deba@2440
   125
deba@2440
   126
#endif //LEMON_MIN_COST_FLOW_H