lemon/min_cost_flow.h
author kpeter
Mon, 25 Feb 2008 12:35:06 +0000
changeset 2579 691ce54544c5
parent 2576 ae092c63d3ba
child 2581 054566ac0934
permissions -rw-r--r--
Bug fixes in min cost flow files.
Use enum type instead of static constants in NetworkSimplex to avoid
linker errors.
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@2576
    46
  /// which can be used exactly the same way except for the fact that
kpeter@2576
    47
  /// \ref CycleCanceling does not provide dual solution (node
kpeter@2576
    48
  /// potentials) since it is a pure primal method.
kpeter@2576
    49
  /// - \ref CapacityScaling The capacity scaling algorithm.
kpeter@2576
    50
  /// - \ref CostScaling The cost scaling algorithm.
kpeter@2576
    51
  /// - \ref CycleCanceling A cycle-canceling algorithm.
kpeter@2576
    52
  /// - \ref NetworkSimplex The network simplex algorithm.
kpeter@2576
    53
  ///
kpeter@2576
    54
  /// \tparam Graph The directed graph type the algorithm runs on.
kpeter@2576
    55
  /// \tparam LowerMap The type of the lower bound map.
kpeter@2576
    56
  /// \tparam CapacityMap The type of the capacity (upper bound) map.
kpeter@2576
    57
  /// \tparam CostMap The type of the cost (length) map.
kpeter@2576
    58
  /// \tparam SupplyMap The type of the supply map.
deba@2440
    59
  ///
deba@2440
    60
  /// \warning
kpeter@2576
    61
  /// - Edge capacities and costs should be \e non-negative \e integers.
kpeter@2576
    62
  /// - Supply values should be \e signed \e integers.
kpeter@2576
    63
  /// - \c LowerMap::Value must be convertible to \c CapacityMap::Value.
kpeter@2576
    64
  /// - \c CapacityMap::Value and \c SupplyMap::Value must be
kpeter@2576
    65
  ///   convertible to each other.
kpeter@2576
    66
  /// - All value types must be convertible to \c CostMap::Value, which
kpeter@2576
    67
  ///   must be signed type.
deba@2440
    68
  ///
deba@2440
    69
  /// \author Peter Kovacs
deba@2440
    70
kpeter@2533
    71
  template < typename Graph,
kpeter@2533
    72
             typename LowerMap = typename Graph::template EdgeMap<int>,
kpeter@2533
    73
             typename CapacityMap = LowerMap,
kpeter@2533
    74
             typename CostMap = typename Graph::template EdgeMap<int>,
kpeter@2533
    75
             typename SupplyMap = typename Graph::template NodeMap
kpeter@2533
    76
                                  <typename CapacityMap::Value> >
deba@2440
    77
  class MinCostFlow :
kpeter@2556
    78
    public NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    79
                           CostMap, SupplyMap >
deba@2440
    80
  {
deba@2440
    81
    typedef NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    82
                            CostMap, SupplyMap > MinCostFlowImpl;
deba@2440
    83
    typedef typename Graph::Node Node;
deba@2440
    84
    typedef typename SupplyMap::Value Supply;
deba@2440
    85
deba@2440
    86
  public:
deba@2440
    87
kpeter@2556
    88
    /// General constructor of the class (with lower bounds).
kpeter@2556
    89
    MinCostFlow( const Graph &graph,
kpeter@2556
    90
                 const LowerMap &lower,
kpeter@2556
    91
                 const CapacityMap &capacity,
kpeter@2556
    92
                 const CostMap &cost,
kpeter@2556
    93
                 const SupplyMap &supply ) :
kpeter@2556
    94
      MinCostFlowImpl(graph, lower, capacity, cost, supply) {}
deba@2440
    95
kpeter@2556
    96
    /// General constructor of the class (without lower bounds).
kpeter@2556
    97
    MinCostFlow( const Graph &graph,
kpeter@2556
    98
                 const CapacityMap &capacity,
kpeter@2579
    99
                 const CostMap &cost,
kpeter@2556
   100
                 const SupplyMap &supply ) :
kpeter@2556
   101
      MinCostFlowImpl(graph, capacity, cost, supply) {}
deba@2440
   102
kpeter@2556
   103
    /// Simple constructor of the class (with lower bounds).
kpeter@2556
   104
    MinCostFlow( const Graph &graph,
kpeter@2556
   105
                 const LowerMap &lower,
kpeter@2556
   106
                 const CapacityMap &capacity,
kpeter@2579
   107
                 const CostMap &cost,
kpeter@2556
   108
                 Node s, Node t,
kpeter@2556
   109
                 Supply flow_value ) :
kpeter@2556
   110
      MinCostFlowImpl( graph, lower, capacity, cost,
kpeter@2556
   111
                       s, t, flow_value ) {}
deba@2440
   112
kpeter@2556
   113
    /// Simple constructor of the class (without lower bounds).
kpeter@2556
   114
    MinCostFlow( const Graph &graph,
kpeter@2556
   115
                 const CapacityMap &capacity,
kpeter@2556
   116
                 const CostMap &cost,
kpeter@2556
   117
                 Node s, Node t,
kpeter@2556
   118
                 Supply flow_value ) :
kpeter@2556
   119
      MinCostFlowImpl( graph, capacity, cost,
kpeter@2556
   120
                       s, t, flow_value ) {}
deba@2440
   121
deba@2440
   122
  }; //class MinCostFlow
deba@2440
   123
deba@2440
   124
  ///@}
deba@2440
   125
deba@2440
   126
} //namespace lemon
deba@2440
   127
deba@2440
   128
#endif //LEMON_MIN_COST_FLOW_H