lemon/min_cost_flow.h
author kpeter
Thu, 28 Feb 2008 02:57:36 +0000
changeset 2583 7216b6a52ab9
parent 2579 691ce54544c5
child 2588 4d3bc1d04c1d
permissions -rw-r--r--
Small fixes and doc improvements in MinMeanCycle.
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@2576
    47
  /// - \ref CapacityScaling The capacity scaling algorithm.
kpeter@2576
    48
  /// - \ref CostScaling The cost scaling algorithm.
kpeter@2576
    49
  /// - \ref CycleCanceling A cycle-canceling algorithm.
kpeter@2576
    50
  /// - \ref NetworkSimplex The network simplex algorithm.
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
deba@2440
    65
kpeter@2533
    66
  template < typename Graph,
kpeter@2533
    67
             typename LowerMap = typename Graph::template EdgeMap<int>,
kpeter@2581
    68
             typename CapacityMap = typename Graph::template EdgeMap<int>,
kpeter@2533
    69
             typename CostMap = typename Graph::template EdgeMap<int>,
kpeter@2581
    70
             typename SupplyMap = typename Graph::template NodeMap<int> >
deba@2440
    71
  class MinCostFlow :
kpeter@2556
    72
    public NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    73
                           CostMap, SupplyMap >
deba@2440
    74
  {
deba@2440
    75
    typedef NetworkSimplex< Graph, LowerMap, CapacityMap,
kpeter@2556
    76
                            CostMap, SupplyMap > MinCostFlowImpl;
deba@2440
    77
    typedef typename Graph::Node Node;
deba@2440
    78
    typedef typename SupplyMap::Value Supply;
deba@2440
    79
deba@2440
    80
  public:
deba@2440
    81
kpeter@2581
    82
    /// General constructor (with lower bounds).
kpeter@2556
    83
    MinCostFlow( const Graph &graph,
kpeter@2556
    84
                 const LowerMap &lower,
kpeter@2556
    85
                 const CapacityMap &capacity,
kpeter@2556
    86
                 const CostMap &cost,
kpeter@2556
    87
                 const SupplyMap &supply ) :
kpeter@2556
    88
      MinCostFlowImpl(graph, lower, capacity, cost, supply) {}
deba@2440
    89
kpeter@2556
    90
    /// General constructor of the class (without lower bounds).
kpeter@2556
    91
    MinCostFlow( const Graph &graph,
kpeter@2556
    92
                 const CapacityMap &capacity,
kpeter@2579
    93
                 const CostMap &cost,
kpeter@2556
    94
                 const SupplyMap &supply ) :
kpeter@2556
    95
      MinCostFlowImpl(graph, capacity, cost, supply) {}
deba@2440
    96
kpeter@2581
    97
    /// Simple constructor (with lower bounds).
kpeter@2556
    98
    MinCostFlow( const Graph &graph,
kpeter@2556
    99
                 const LowerMap &lower,
kpeter@2556
   100
                 const CapacityMap &capacity,
kpeter@2579
   101
                 const CostMap &cost,
kpeter@2556
   102
                 Node s, Node t,
kpeter@2556
   103
                 Supply flow_value ) :
kpeter@2556
   104
      MinCostFlowImpl( graph, lower, capacity, cost,
kpeter@2556
   105
                       s, t, flow_value ) {}
deba@2440
   106
kpeter@2581
   107
    /// Simple constructor (without lower bounds).
kpeter@2556
   108
    MinCostFlow( const Graph &graph,
kpeter@2556
   109
                 const CapacityMap &capacity,
kpeter@2556
   110
                 const CostMap &cost,
kpeter@2556
   111
                 Node s, Node t,
kpeter@2556
   112
                 Supply flow_value ) :
kpeter@2556
   113
      MinCostFlowImpl( graph, capacity, cost,
kpeter@2556
   114
                       s, t, flow_value ) {}
deba@2440
   115
deba@2440
   116
  }; //class MinCostFlow
deba@2440
   117
deba@2440
   118
  ///@}
deba@2440
   119
deba@2440
   120
} //namespace lemon
deba@2440
   121
deba@2440
   122
#endif //LEMON_MIN_COST_FLOW_H