This chapter provides information about additional problem classes and functionality provided in the .NET API.
Network flow problems are a special class of linear optimization problems which has many applications. A network consists of a set of points connected by a set of lines. Usually the points and lines are called nodes and arcs. Arcs may have an direction on them. The network is directed if all arcs are directed. The class of network flow problems is defined as follows.
Let be a directed network of nodes
and arcs
. Associated with every arc
is a cost
and a capacity
. Moreover, associated with each node
in the network is a lower limit
and an upper limit
on the demand (supply) of the node. The minimum cost of a network flow problem can be stated as follows:
![]() |
(6.1.1) |
A classical example of a network flow problem is the transportation problem where the objective is to distribute goods from warehouses to customers at lowest possible total cost, see [7] for a detailed application reference.
The above graph formulation of the network flow problem implies the structural properties. Each variable appears in exactly two constraints with a numerical value of either or
.
It is well-known that problems with network flow structure can be solved efficiently with a specialized version of the simplex method. MOSEK includes such a network simplex implementation which can be called either directly using mosek.Task.netoptimize or indirectly by letting the standard simplex optimizer extract the embedded network. This section shows how to solve a network problem by a direct call to mosek.Task.netoptimize. For further details on how to exploit embedded network in the standard simplex optimizer, see Section 8.3.1.
The following is an example of a linear network optimization problem:
![]() |
(6.1.2) |
having the bounds .
The corresponding graph is displayed in fig.6.1.
In this section we will show how to solve (6.1.2) with the network optimizer.
The .NET program included below, which solves this problem, is distributed with MOSEK and can be found in the directory
There are a few important differences between the linear network optimization example in section 6.1.1.1 and the general linear optimization problem in section 5.2.
Often problems contains both large parts with network structure and some non-network constraints or variables — such problems are said to have embedded network structure.
A linear optimization with embedded network structure problem can be written as :
![]() |
(6.2.1) |
Where the constraints
![]() |
(6.2.2) |
defines a network as explained in section 6.1, and the constraints
![]() |
(6.2.3) |
defines the general non-network linear constraints. As an example consider the small linear optimization problem
![]() |
(6.2.4) |
with the bounds
![]() |
Recalling the network flow problem structural properties from section 6.1.1, each variable should appear in exactly two constraints with coefficients of either or
.
At first glance it does not seem to contain any network structure, but if we scale constraints 1-4 by respectively 2.0, 2.0, 4.0, 4.0 and columns 1-2 by -1.0, 0.1 we get the following problem :
![]() |
(6.2.5) |
with the bounds
![]() |
This corresponds to the network flow problem in section 6.1.1 plus one extra non-network constraint. We cannot use the network optimizer directly on the above problem since the last constraint destroys the network property. Finding the largest possible network structure in a linear optimization problem is computationally difficult, so MOSEK offers a heuristic mosek.Task.netextraction that attempts to find suitable scaling factors maximizing numbers of network constraints and variables. Assuming that the embedded network structure is dominant and the problem has few non-network constraints, we can exploit this structure and potentially speed up the optimization. Since the network constraints can be handled efficiently by the specialized network optimizer, the following idea is used:
An embedded network can be exploited by this scheme in two ways:
The first method is more difficult than the second, but also offers much more flexibility. In 6.2.1 the first method is demonstrated by a code example below. For further details on exploiting embedded network structure in the standard simplex optimizer, see section 8.3.1.
MOSEK is distributed with some network examples which can be found in the directory
mosek\6\tools\examples
The example given in this section demonstrates how to extract and optimize embedded network structure in a arbitrary linear optimization problem. The following idea is used
In the above example we only optimize the embedded network problem. We still need to use the found network solution as a hot-start for the simplex optimizer and solve the original problem. This involves unscaling the network solution back to same unit measure as the original problem. In the example
we show how to convert the network solution into a valid hot-start for the simplex optimizer.
A linear optimization problem always has an optimal solution which is also a basic solution. In an optimal basic solution there are exactly m basic variables where m is the number of rows in the constraint matrix A. Define
![]() |
as a matrix consisting of the columns of A corresponding to the basic variables.
The basis matrix B is always non-singular, i.e.
![]() |
or equivalently that exists. This implies that the linear systems
![]() |
(6.3.1) |
and
![]() |
(6.3.2) |
each has a unique solution for all w.
MOSEK provides functions for solving the linear systems (6.3.1) and (6.3.2) for an arbitrary w.
To use the solutions to (6.3.1) and (6.3.2) it is important to know how the basis matrix B is constructed.
Internally MOSEK employs the linear optimization problem
![]() |
(6.3.3) |
where
![]() |
The basis matrix is constructed of m columns taken from
![]() |
If variable is a basis variable, then the j'th column of A denoted
will appear in B. Similarly, if
is a basis variable, then the i'th column of -I will appear in the basis. The ordering of the basis variables and therefore the ordering of the columns of B is arbitrary. The ordering of the basis variables may be retrieved by calling the function:
mosek.Task.initbasissolve(int[] basis);
This function initializes data structures for later use and returns the indexes of the basic variables in the array basis. The interpretation of the basis is as follows. If
![]() |
then the i'th basis variable is . Moreover, the i'th column in B will be the i'th column of -I. On the other hand if
![]() |
then the i'th basis variable is variable
![]() |
and the i'th column of B is the column
![]() |
For instance if and
, then since
, the first basis variable is
. Therefore, the first column of B is the fourth column of -I. Similarly, if
, then the second variable in the basis is
. Hence, the second column of B is identical to
.
Consider the linear optimization problem:
![]() |
(6.3.4) |
Suppose a call to mosek.Task.initbasissolve returns an array basis so that
basis[0] = 1, basis[1] = 2.
Then the basis variables are and
and the corresponding basis matrix B is
![]() |
(6.3.5) |
Please note the ordering of the columns in B.
The following program demonstrates the use of mosek.Task.solvewithbasis.
In the example above the linear system is solved using the optimal basis for (6.3.4) and the original right-hand side of the problem. Thus the solution to the linear system is the optimal solution to the problem. When running the example program the following output is produced.
basis[0] = 1 Basis variable no 0 is xc1. basis[1] = 2 Basis variable no 1 is x0. Solution to Bx = b: x0 = 2.000000e+00 xc1 = -4.000000e+00 Solution to B^Tx = c: x1 = -1.000000e+00 x0 = 1.000000e+00
Please note that the ordering of the basis variables is
![]() |
and thus the basis is given by:
![]() |
(6.3.6) |
It can be verified that
![]() |
is a solution to
![]() |
MOSEK can be used to solve an arbitrary (rectangular) linear system
![]() |
using the mosek.Task.solvewithbasis function without optimizing the problem as in the previous example. This is done by setting up an A matrix in the task, setting all variables to basic and calling the mosek.Task.solvewithbasis function with the b vector as input. The solution is returned by the function.
Below we demonstrate how to solve the linear system
![]() |
(6.3.7) |
with b=(1,-2) and b=(7,0).
The most important step in the above example is the definition of the basic solution using the mosek.Task.putsolutioni function, where we define the status key for each variable. The actual values of the variables are not important and can be selected arbitrarily, so we set them to zero. All variables corresponding to columns in the linear system we want to solve are set to basic and the slack variables for the constraints, which are all non-basic, are set to their bound.
The program produces the output:
Solution to Bx = b: x1 = 1 x0 = 3 Solution to Bx = b: x1 = 7 x0 = 7
and we can verify that is indeed a solution to (6.3.7).