doc/min_cost_flow.dox
author Alpar Juttner <alpar@cs.elte.hu>
Fri, 22 Jun 2012 16:31:05 +0200
branch1.1
changeset 788 98b306776b25
parent 661 8b0df68370a4
permissions -rw-r--r--
Merge bugfix #444 to branch 1.1
kpeter@661
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
kpeter@661
     2
 *
kpeter@661
     3
 * This file is a part of LEMON, a generic C++ optimization library.
kpeter@661
     4
 *
alpar@761
     5
 * Copyright (C) 2003-2011
kpeter@661
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
kpeter@661
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
kpeter@661
     8
 *
kpeter@661
     9
 * Permission to use, modify and distribute this software is granted
kpeter@661
    10
 * provided that this copyright notice appears in all copies. For
kpeter@661
    11
 * precise terms see the accompanying LICENSE file.
kpeter@661
    12
 *
kpeter@661
    13
 * This software is provided "AS IS" with no warranty of any kind,
kpeter@661
    14
 * express or implied, and with no claim as to its suitability for any
kpeter@661
    15
 * purpose.
kpeter@661
    16
 *
kpeter@661
    17
 */
kpeter@661
    18
kpeter@661
    19
namespace lemon {
kpeter@661
    20
kpeter@661
    21
/**
kpeter@661
    22
\page min_cost_flow Minimum Cost Flow Problem
kpeter@661
    23
kpeter@661
    24
\section mcf_def Definition (GEQ form)
kpeter@661
    25
kpeter@661
    26
The \e minimum \e cost \e flow \e problem is to find a feasible flow of
kpeter@661
    27
minimum total cost from a set of supply nodes to a set of demand nodes
kpeter@661
    28
in a network with capacity constraints (lower and upper bounds)
kpeter@661
    29
and arc costs.
kpeter@661
    30
kpeter@661
    31
Formally, let \f$G=(V,A)\f$ be a digraph, \f$lower: A\rightarrow\mathbf{R}\f$,
kpeter@661
    32
\f$upper: A\rightarrow\mathbf{R}\cup\{+\infty\}\f$ denote the lower and
kpeter@661
    33
upper bounds for the flow values on the arcs, for which
kpeter@661
    34
\f$lower(uv) \leq upper(uv)\f$ must hold for all \f$uv\in A\f$,
kpeter@661
    35
\f$cost: A\rightarrow\mathbf{R}\f$ denotes the cost per unit flow
kpeter@661
    36
on the arcs and \f$sup: V\rightarrow\mathbf{R}\f$ denotes the
kpeter@661
    37
signed supply values of the nodes.
kpeter@661
    38
If \f$sup(u)>0\f$, then \f$u\f$ is a supply node with \f$sup(u)\f$
kpeter@661
    39
supply, if \f$sup(u)<0\f$, then \f$u\f$ is a demand node with
kpeter@661
    40
\f$-sup(u)\f$ demand.
kpeter@661
    41
A minimum cost flow is an \f$f: A\rightarrow\mathbf{R}\f$ solution
kpeter@661
    42
of the following optimization problem.
kpeter@661
    43
kpeter@661
    44
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
kpeter@661
    45
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \geq
kpeter@661
    46
    sup(u) \quad \forall u\in V \f]
kpeter@661
    47
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
kpeter@661
    48
kpeter@661
    49
The sum of the supply values, i.e. \f$\sum_{u\in V} sup(u)\f$ must be
kpeter@661
    50
zero or negative in order to have a feasible solution (since the sum
kpeter@661
    51
of the expressions on the left-hand side of the inequalities is zero).
kpeter@661
    52
It means that the total demand must be greater or equal to the total
kpeter@661
    53
supply and all the supplies have to be carried out from the supply nodes,
kpeter@661
    54
but there could be demands that are not satisfied.
kpeter@661
    55
If \f$\sum_{u\in V} sup(u)\f$ is zero, then all the supply/demand
kpeter@661
    56
constraints have to be satisfied with equality, i.e. all demands
kpeter@661
    57
have to be satisfied and all supplies have to be used.
kpeter@661
    58
kpeter@661
    59
kpeter@661
    60
\section mcf_algs Algorithms
kpeter@661
    61
kpeter@661
    62
LEMON contains several algorithms for solving this problem, for more
kpeter@661
    63
information see \ref min_cost_flow_algs "Minimum Cost Flow Algorithms".
kpeter@661
    64
kpeter@661
    65
A feasible solution for this problem can be found using \ref Circulation.
kpeter@661
    66
kpeter@661
    67
kpeter@661
    68
\section mcf_dual Dual Solution
kpeter@661
    69
kpeter@661
    70
The dual solution of the minimum cost flow problem is represented by
kpeter@661
    71
node potentials \f$\pi: V\rightarrow\mathbf{R}\f$.
kpeter@661
    72
An \f$f: A\rightarrow\mathbf{R}\f$ primal feasible solution is optimal
kpeter@661
    73
if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$ node potentials
kpeter@661
    74
the following \e complementary \e slackness optimality conditions hold.
kpeter@661
    75
kpeter@661
    76
 - For all \f$uv\in A\f$ arcs:
kpeter@661
    77
   - if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$;
kpeter@661
    78
   - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
kpeter@661
    79
   - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
kpeter@661
    80
 - For all \f$u\in V\f$ nodes:
kpeter@661
    81
   - \f$\pi(u)<=0\f$;
kpeter@661
    82
   - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
kpeter@661
    83
     then \f$\pi(u)=0\f$.
alpar@761
    84
kpeter@661
    85
Here \f$cost^\pi(uv)\f$ denotes the \e reduced \e cost of the arc
kpeter@661
    86
\f$uv\in A\f$ with respect to the potential function \f$\pi\f$, i.e.
kpeter@661
    87
\f[ cost^\pi(uv) = cost(uv) + \pi(u) - \pi(v).\f]
kpeter@661
    88
kpeter@661
    89
All algorithms provide dual solution (node potentials), as well,
kpeter@661
    90
if an optimal flow is found.
kpeter@661
    91
kpeter@661
    92
kpeter@661
    93
\section mcf_eq Equality Form
kpeter@661
    94
kpeter@661
    95
The above \ref mcf_def "definition" is actually more general than the
kpeter@661
    96
usual formulation of the minimum cost flow problem, in which strict
kpeter@661
    97
equalities are required in the supply/demand contraints.
kpeter@661
    98
kpeter@661
    99
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
kpeter@661
   100
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) =
kpeter@661
   101
    sup(u) \quad \forall u\in V \f]
kpeter@661
   102
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
kpeter@661
   103
kpeter@661
   104
However if the sum of the supply values is zero, then these two problems
kpeter@661
   105
are equivalent.
kpeter@661
   106
The \ref min_cost_flow_algs "algorithms" in LEMON support the general
kpeter@661
   107
form, so if you need the equality form, you have to ensure this additional
kpeter@661
   108
contraint manually.
kpeter@661
   109
kpeter@661
   110
kpeter@661
   111
\section mcf_leq Opposite Inequalites (LEQ Form)
kpeter@661
   112
kpeter@661
   113
Another possible definition of the minimum cost flow problem is
kpeter@661
   114
when there are <em>"less or equal"</em> (LEQ) supply/demand constraints,
kpeter@661
   115
instead of the <em>"greater or equal"</em> (GEQ) constraints.
kpeter@661
   116
kpeter@661
   117
\f[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \f]
kpeter@661
   118
\f[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \leq
kpeter@661
   119
    sup(u) \quad \forall u\in V \f]
kpeter@661
   120
\f[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \f]
kpeter@661
   121
alpar@761
   122
It means that the total demand must be less or equal to the
kpeter@661
   123
total supply (i.e. \f$\sum_{u\in V} sup(u)\f$ must be zero or
kpeter@661
   124
positive) and all the demands have to be satisfied, but there
kpeter@661
   125
could be supplies that are not carried out from the supply
kpeter@661
   126
nodes.
kpeter@661
   127
The equality form is also a special case of this form, of course.
kpeter@661
   128
kpeter@661
   129
You could easily transform this case to the \ref mcf_def "GEQ form"
kpeter@661
   130
of the problem by reversing the direction of the arcs and taking the
kpeter@661
   131
negative of the supply values (e.g. using \ref ReverseDigraph and
kpeter@661
   132
\ref NegMap adaptors).
kpeter@661
   133
However \ref NetworkSimplex algorithm also supports this form directly
kpeter@661
   134
for the sake of convenience.
kpeter@661
   135
kpeter@661
   136
Note that the optimality conditions for this supply constraint type are
kpeter@661
   137
slightly differ from the conditions that are discussed for the GEQ form,
kpeter@661
   138
namely the potentials have to be non-negative instead of non-positive.
kpeter@661
   139
An \f$f: A\rightarrow\mathbf{R}\f$ feasible solution of this problem
kpeter@661
   140
is optimal if and only if for some \f$\pi: V\rightarrow\mathbf{R}\f$
kpeter@661
   141
node potentials the following conditions hold.
kpeter@661
   142
kpeter@661
   143
 - For all \f$uv\in A\f$ arcs:
kpeter@661
   144
   - if \f$cost^\pi(uv)>0\f$, then \f$f(uv)=lower(uv)\f$;
kpeter@661
   145
   - if \f$lower(uv)<f(uv)<upper(uv)\f$, then \f$cost^\pi(uv)=0\f$;
kpeter@661
   146
   - if \f$cost^\pi(uv)<0\f$, then \f$f(uv)=upper(uv)\f$.
kpeter@661
   147
 - For all \f$u\in V\f$ nodes:
kpeter@661
   148
   - \f$\pi(u)>=0\f$;
kpeter@661
   149
   - if \f$\sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \neq sup(u)\f$,
kpeter@661
   150
     then \f$\pi(u)=0\f$.
kpeter@661
   151
kpeter@661
   152
*/
kpeter@661
   153
}