The minimum cost flow problem is to find a feasible flow of minimum total cost from a set of supply nodes to a set of demand nodes in a network with capacity constraints (lower and upper bounds) and arc costs [1].
Formally, let  be a digraph,
 be a digraph,  ,
,  denote the lower and upper bounds for the flow values on the arcs, for which
 denote the lower and upper bounds for the flow values on the arcs, for which  must hold for all
 must hold for all  ,
,  denotes the cost per unit flow on the arcs and
 denotes the cost per unit flow on the arcs and  denotes the signed supply values of the nodes. If
 denotes the signed supply values of the nodes. If  , then
, then  is a supply node with
 is a supply node with  supply, if
 supply, if  , then
, then  is a demand node with
 is a demand node with  demand. A minimum cost flow is an
 demand. A minimum cost flow is an  solution of the following optimization problem.
 solution of the following optimization problem.
![\[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \]](form_22.png) 
![\[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \geq sup(u) \quad \forall u\in V \]](form_23.png) 
![\[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \]](form_24.png) 
The sum of the supply values, i.e.  must be zero or negative in order to have a feasible solution (since the sum of the expressions on the left-hand side of the inequalities is zero). It means that the total demand must be greater or equal to the total supply and all the supplies have to be carried out from the supply nodes, but there could be demands that are not satisfied. If
 must be zero or negative in order to have a feasible solution (since the sum of the expressions on the left-hand side of the inequalities is zero). It means that the total demand must be greater or equal to the total supply and all the supplies have to be carried out from the supply nodes, but there could be demands that are not satisfied. If  is zero, then all the supply/demand constraints have to be satisfied with equality, i.e. all demands have to be satisfied and all supplies have to be used.
 is zero, then all the supply/demand constraints have to be satisfied with equality, i.e. all demands have to be satisfied and all supplies have to be used.
LEMON contains several algorithms for solving this problem, for more information see Minimum Cost Flow Algorithms.
A feasible solution for this problem can be found using Circulation.
The dual solution of the minimum cost flow problem is represented by node potentials  . An
. An  primal feasible solution is optimal if and only if for some
 primal feasible solution is optimal if and only if for some  node potentials the following complementary slackness optimality conditions hold.
 node potentials the following complementary slackness optimality conditions hold.
 arcs:
 arcs: , then
, then  ;
; , then
, then  ;
; , then
, then  .
. nodes:
 nodes: ;
; , then
, then  .
.Here  denotes the reduced cost of the arc
 denotes the reduced cost of the arc  with respect to the potential function
 with respect to the potential function  , i.e.
, i.e. 
![\[ cost^\pi(uv) = cost(uv) + \pi(u) - \pi(v).\]](form_39.png) 
All algorithms provide dual solution (node potentials), as well, if an optimal flow is found.
The above definition is actually more general than the usual formulation of the minimum cost flow problem, in which strict equalities are required in the supply/demand contraints.
![\[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \]](form_22.png) 
![\[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) = sup(u) \quad \forall u\in V \]](form_40.png) 
![\[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \]](form_24.png) 
However, if the sum of the supply values is zero, then these two problems are equivalent. The algorithms in LEMON support the general form, so if you need the equality form, you have to ensure this additional contraint manually.
Another possible definition of the minimum cost flow problem is when there are "less or equal" (LEQ) supply/demand constraints, instead of the "greater or equal" (GEQ) constraints.
![\[ \min\sum_{uv\in A} f(uv) \cdot cost(uv) \]](form_22.png) 
![\[ \sum_{uv\in A} f(uv) - \sum_{vu\in A} f(vu) \leq sup(u) \quad \forall u\in V \]](form_41.png) 
![\[ lower(uv) \leq f(uv) \leq upper(uv) \quad \forall uv\in A \]](form_24.png) 
It means that the total demand must be less or equal to the total supply (i.e.  must be zero or positive) and all the demands have to be satisfied, but there could be supplies that are not carried out from the supply nodes. The equality form is also a special case of this form, of course.
 must be zero or positive) and all the demands have to be satisfied, but there could be supplies that are not carried out from the supply nodes. The equality form is also a special case of this form, of course.
You could easily transform this case to the GEQ form of the problem by reversing the direction of the arcs and taking the negative of the supply values (e.g. using ReverseDigraph and NegMap adaptors). However NetworkSimplex algorithm also supports this form directly for the sake of convenience.
Note that the optimality conditions for this supply constraint type are slightly differ from the conditions that are discussed for the GEQ form, namely the potentials have to be non-negative instead of non-positive. An  feasible solution of this problem is optimal if and only if for some
 feasible solution of this problem is optimal if and only if for some  node potentials the following conditions hold.
 node potentials the following conditions hold.
 arcs:
 arcs: , then
, then  ;
; , then
, then  ;
; , then
, then  .
. nodes:
 nodes: ;
; , then
, then  .
.  1.8.5
 1.8.5