6. Advanced API tutorial


This chapter provides information about additional problem classes and functionality provided in the .NET API.

6.1. Linear network flow problems

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 [[MathCmd 125]] be a directed network of nodes [[MathCmd 126]] and arcs [[MathCmd 127]]. Associated with every arc [[MathCmd 128]] is a cost [[MathCmd 129]] and a capacity [[MathCmd 130]]. Moreover, associated with each node [[MathCmd 131]] in the network is a lower limit [[MathCmd 132]] and an upper limit [[MathCmd 133]] on the demand (supply) of the node. The minimum cost of a network flow problem can be stated as follows:

\begin{math}\nonumber{}\begin{array}{lcccccl}\nonumber{}\mbox{minimize} &  &  & \sum \limits _{{(i,j)\in{}\mathcal{A}}}c_{{ij}}x_{{ij}} &  &  & \\\nonumber{}\mbox{subject to} & l^{c}_{{i}} & \leq{} & \sum \limits _{{\lbrace{}j:(i,j)\in{}\mathcal{A}\rbrace{}}}x_{{ij}}-\sum \limits _{{\lbrace{}j:(j,i)\in{}\mathcal{A}\rbrace{}}}x_{{ji}} & \leq{} & u^{c}_{{i}} & \forall i\in{}\mathcal{N},\\\nonumber{} & l^{x}_{{ij}} & \leq{} & x_{{ij}} & \leq{} & u^{x}_{{ij}} & \forall (i,j)\in{}\mathcal{A}.\end{array}\end{math} (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 [[MathCmd 135]] or [[MathCmd 136]].

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.

6.1.1. A linear network flow problem example

The following is an example of a linear network optimization problem:

\begin{math}\nonumber{}\begin{array}{lccccccccccccl}\nonumber{}\mbox{maximize} & x_{0} &  &  & + & x_{2} & + &  & - & x_{4} & + & x_{5} &  & \\\nonumber{}\mbox{subject to} & -x_{0} &  &  &  &  & + & x_{3} &  &  &  &  & = & 1,\\\nonumber{} &  &  &  &  & x_{2} & - & x_{3} & + & x_{4} & + & x_{5} & = & -2,\\\nonumber{} & x_{0} & - & x_{1} &  &  &  &  & - & x_{4} & - & x_{5} & = & 0,\\\nonumber{} &  &  & x_{1} & - & x_{2} & + &  &  &  &  &  & = & 0,\end{array}\end{math} (6.1.2)

having the bounds [[MathCmd 138]].

The corresponding graph [[MathCmd 125]] is displayed in fig.6.1.

Figure 6.1: Simple network.

6.1.1.1. Source code

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

6.1.1.2. Example code comments

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.

  • MOSEK allows that network problems can be inputted and optimized using one function call to the function mosek.Task.netoptimize. This is more efficient and uses less memory than a call to the standard optimizer.
  • Since we know that each column of matrix A has two non-zeroes, it can be stored in two arrays, from and to, specifying the origin and destination of the arcs (variables), see graph in fig.fig-network.
  • The solution is written directly to skc, skx, xc, xx, y, slc, suc, slx and sux by mosek.Task.netoptimize.

6.2. Embedded network flow problems

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 :

\begin{math}\nonumber{}\begin{array}{lccccl}\nonumber{}\mbox{minimize} &  &  & c^{T}x+c^{f} &  & \\\nonumber{}\mbox{subject to} & l^{c}_{N} & \leq{} & Nx & \leq{} & u^{c}_{N},\\\nonumber{} & l^{c} & \leq{} & Ax & \leq{} & u^{c},\\\nonumber{} & l^{x} & \leq{} & x & \leq{} & u^{x},\end{array}\end{math} (6.2.1)

Where the constraints

\begin{math}\nonumber{}\begin{array}{lcccl}\nonumber{}l^{c}_{N} & \leq{} & Nx & \leq{} & u^{c}_{N}\end{array}\end{math} (6.2.2)

defines a network as explained in section 6.1, and the constraints

\begin{math}\nonumber{}\begin{array}{lcccl}\nonumber{}l^{c} & \leq{} & Ax & \leq{} & u^{c}\end{array}\end{math} (6.2.3)

defines the general non-network linear constraints. As an example consider the small linear optimization problem

\begin{math}\nonumber{}\begin{array}{lccccccccccccl}\nonumber{}\mbox{maximize} & -x_{0} &  &  & + & x_{2} &  &  & - & x_{4} & + & x_{5} &  & \\\nonumber{}\mbox{subject to} & 0.50x_{0} &  &  &  &  & + & 0.50x_{3} &  &  &  &  & = & 0.5,\\\nonumber{} &  &  &  &  & 0.50x_{2} & - & 0.50x_{3} & + & 0.50x_{4} & + & 0.50x_{5} & = & -1,\\\nonumber{} & -0.25x_{0} & + & -2.50x_{1} & + &  &  &  & - & 0.25x_{4} & - & 0.25x_{5} & = & 0,\\\nonumber{} &  &  & 2.50x_{1} & - & 0.25x_{2} &  &  &  &  &  &  & = & 0,\\\nonumber{} &  & - & x_{1} & + & x_{2} & + & x_{3} &  &  & + & x_{5} & \geq{} & 6,\end{array}\end{math} (6.2.4)

with the bounds

\begin{displaymath}\nonumber{}-\infty \leq{}x_{0}\leq{}0,0\leq{}x_{j}\leq{}\infty \mbox{ for }j=1\ldots 5.\end{displaymath}

Recalling the network flow problem structural properties from section 6.1.1, each variable should appear in exactly two constraints with coefficients of either [[MathCmd 135]] or [[MathCmd 136]].

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 :

\begin{math}\nonumber{}\begin{array}{lccccccccccccl}\nonumber{}\mbox{maximize} & x_{0} &  &  & + & x_{2} & + &  & - & x_{4} & + & x_{5} &  & \\\nonumber{}\mbox{subject to} & -x_{0} &  &  &  &  & + & x_{3} &  &  &  &  & = & 1,\\\nonumber{} &  &  &  &  & x_{2} & - & x_{3} & + & x_{4} & + & x_{5} & = & -2,\\\nonumber{} & x_{0} & - & x_{1} &  &  &  &  & - & x_{4} & - & x_{5} & = & 0,\\\nonumber{} &  &  & x_{1} & - & x_{2} & + &  &  &  &  &  & = & 0,\\\nonumber{} &  &  & x_{1} & + & x_{2} & + & x_{3} &  &  & + & x_{5} & \geq{} & 6,\end{array}\end{math} (6.2.5)

with the bounds

\begin{displaymath}\nonumber{}0\leq{}x_{j}\leq{}\infty \mbox{ for }j=0\ldots 5.\end{displaymath}

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.

6.2.1. Example: Exploit embedded network flow structure in the simplex optimizer

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.

6.3. Solving linear systems involving the basis matrix

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

\begin{displaymath}\nonumber{}B\in{}\mathbb{R}^{{m\times m}}\end{displaymath}

as a matrix consisting of the columns of A corresponding to the basic variables.

The basis matrix B is always non-singular, i.e.

\begin{displaymath}\nonumber{}\det (B)\not=0\end{displaymath}

or equivalently that [[MathCmd 151]] exists. This implies that the linear systems

\begin{math}\nonumber{}B\bar{x}=w\end{math} (6.3.1)

and

\begin{math}\nonumber{}B^{T}\bar{x}=w\end{math} (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.

6.3.1. Identifying the basis

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

\begin{math}\nonumber{}\begin{array}{lccccl}\nonumber{}\mbox{maximize} &  &  & c^{T}x &  & \\\nonumber{}\mbox{subject to} &  &  & Ax-x^{c} & = & 0\\\nonumber{} & l^{x} & \leq{} & x & \leq{} & u^{x},\\\nonumber{} & l^{c} & \leq{} & x^{c} & \leq{} & u^{c}.\end{array}\end{math} (6.3.3)

where

\begin{displaymath}\nonumber{}x^{c}\in{}\mathbb{R}^{{m}}\mbox{ and }x\in{}\mathbb{R}^{n}.\end{displaymath}

The basis matrix is constructed of m columns taken from

\begin{displaymath}\nonumber{}[\begin{array}{cc}\nonumber{}A & -I\end{array}].\end{displaymath}

If variable [[MathCmd 157]] is a basis variable, then the j'th column of A denoted [[MathCmd 158]] will appear in B. Similarly, if [[MathCmd 159]] 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

\begin{displaymath}\nonumber{}\mathtt{basis}[i]<\mathtt{numcon},\end{displaymath}

then the i'th basis variable is [[MathCmd 159]]. Moreover, the i'th column in B will be the i'th column of -I. On the other hand if

\begin{displaymath}\nonumber{}\mathtt{basis}[i]\geq{}\mathtt{numcon},\end{displaymath}

then the i'th basis variable is variable

\begin{displaymath}\nonumber{}x_{{\mathtt{basis}[i]-\mathtt{numcon}}}\end{displaymath}

and the i'th column of B is the column

\begin{displaymath}\nonumber{}A_{{:,(\mathtt{basis}[i]-\mathtt{numcon})}}.\end{displaymath}

For instance if [[MathCmd 165]] and [[MathCmd 166]], then since [[MathCmd 167]], the first basis variable is [[MathCmd 168]]. Therefore, the first column of B is the fourth column of -I. Similarly, if [[MathCmd 169]], then the second variable in the basis is [[MathCmd 170]]. Hence, the second column of B is identical to [[MathCmd 171]].

6.3.2. An example

Consider the linear optimization problem:

\begin{math}\nonumber{}\begin{array}{lccl}\nonumber{}\mbox{minimize} & x_{0}+x_{1} &  & \\\nonumber{}\mbox{subject to} & x_{0}+2x_{1} & \leq{} & 2,\\\nonumber{} & x_{0}+x_{1} & \leq{} & 6,\\\nonumber{} & x_{0},x_{1}\geq{}0. &  &\end{array}\end{math} (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 [[MathCmd 173]] and [[MathCmd 12]] and the corresponding basis matrix B is

\begin{math}\nonumber{}\left[\begin{array}{cc}\nonumber{}0 & 1\\\nonumber{}-1 & 1\end{array}\right].\end{math} (6.3.5)

Please note the ordering of the columns in B.

The following program demonstrates the use of mosek.Task.solvewithbasis.

/* Copyright: Copyright (c) 1998-2011 MOSEK ApS, Denmark. All rights reserved. File : solvebasis.cs Purpose : To demonstrate the usage of MSK_solvewithbasis on the problem: maximize x0 + x1 st. x0 + 2.0 x1 <= 2 x0 + x1 <= 6 x0 >= 0, x1>= 0 The problem has the slack variables xc0, xc1 on the constraints and the variabels x0 and x1. maximize x0 + x1 st. x0 + 2.0 x1 -xc1 = 2 x0 + x1 -xc2 = 6 x0 >= 0, x1>= 0, xc1 <= 0 , xc2 <= 0 */ using System; class msgclass : mosek.Stream { string prefix; public msgclass (string prfx) { prefix = prfx; } public override void streamCB (string msg) { Console.Write ("{0}{1}", prefix,msg); } } public class lo1 { public static void Main () { const int NUMCON = 2; const int NUMVAR = 2; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; double[] c = {1.0, 1.0}; int[] ptrb = {0, 2}; int[] ptre = {2, 3}; int[] asub = {0, 1, 0, 1}; double[] aval = {1.0, 1.0, 2.0, 1.0}; mosek.boundkey[] bkc = {mosek.boundkey.up, mosek.boundkey.up}; double[] blc = {-infinity, -infinity}; double[] buc = {2.0, 6.0}; mosek.boundkey[] bkx = {mosek.boundkey.lo, mosek.boundkey.lo}; double[] blx = {0.0, 0.0}; double[] bux = {+infinity, +infinity}; mosek.Task task = null; mosek.Env env = null; double[] w1 = {2.0, 6.0}; double[] w2 = {1.0, 0.0}; try { // Make mosek environment. env = new mosek.Env (); // Direct the env log stream to the user specified // method env_msg_obj.streamCB env.set_Stream (mosek.streamtype.log, new msgclass ("[env]")); // Initialize the environment. env.init (); // Create a task object linked with the environment env. task = new mosek.Task (env, NUMCON,NUMVAR); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream (mosek.streamtype.log, new msgclass ("[task]")); task.inputdata(NUMCON,NUMVAR, c, 0.0, ptrb, ptre, asub, aval, bkc, blc, buc, bkx, blx, bux); task.putobjsense(mosek.objsense.maximize); try { task.optimize(); } catch (mosek.Warning w) { Console.WriteLine("Mosek warning:"); Console.WriteLine (w.Code); Console.WriteLine (w); } int[] basis = new int[NUMCON]; task.initbasissolve(basis); //List basis variables corresponding to columns of B int[] varsub = {0,1}; for (int i = 0; i < NUMCON; i++) { if (basis[varsub[i]] < NUMCON) Console.WriteLine ("Basis variable no {0} is xc{1}", i, basis[i]); else Console.WriteLine ("Basis variable no {0} is x{1}", i, basis[i] - NUMCON); } // solve Bx = w1 // varsub contains index of non-zeros in b. // On return b contains the solution x and // varsub the index of the non-zeros in x. int nz = 2; task.solvewithbasis(0, ref nz, varsub, w1); Console.WriteLine ("nz = {0}", nz); Console.WriteLine ("Solution to Bx = w1:\n"); for (int i = 0; i < nz; i++) { if (basis[varsub[i]] < NUMCON) Console.WriteLine ("xc {0} = {1}", basis[varsub[i]], w1[varsub[i]] ); else Console.WriteLine ("x{0} = {1}", basis[varsub[i]] - NUMCON, w1[varsub[i]]); } // Solve B^Tx = w2 nz = 1; varsub[0] = 0; task.solvewithbasis(1, ref nz, varsub, w2); Console.WriteLine ("\nSolution to B^Tx = w2:\n"); for (int i = 0; i < nz; i++) { if (basis[varsub[i]] < NUMCON) Console.WriteLine ("xc {0} = {1}", basis[varsub[i]], w2[varsub[i]]); else Console.WriteLine ("x {0} = {1}", basis[varsub[i]] - NUMCON, w2[varsub[i]]); } } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); } if (task != null) task.Dispose (); if (env != null) env.Dispose (); } }

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

\begin{displaymath}\nonumber{}\left[\begin{array}{c}\nonumber{}x^{c}_{1}\\\nonumber{}x_{0}\end{array}\right]\end{displaymath}

and thus the basis is given by:

\begin{math}\nonumber{}B=\left[\begin{array}{cc}\nonumber{}0 & 1\\\nonumber{}-1 & 1\end{array}\right]\end{math} (6.3.6)

It can be verified that

\begin{displaymath}\nonumber{}\left[\begin{array}{c}\nonumber{}x^{c}_{1}\\\nonumber{}x_{0}\end{array}\right]=\left[\begin{array}{c}\nonumber{}-4\\\nonumber{}2\end{array}\right]\end{displaymath}

is a solution to

\begin{displaymath}\nonumber{}\left[\begin{array}{cc}\nonumber{}0 & 1\\\nonumber{}-1 & 1\end{array}\right]\left[\begin{array}{c}\nonumber{}x^{c}_{1}\\\nonumber{}x_{0}\end{array}\right]=\left[\begin{array}{c}\nonumber{}2\\\nonumber{}6\end{array}\right].\end{displaymath}

6.3.3. Solving arbitrary linear systems

MOSEK can be used to solve an arbitrary (rectangular) linear system

\begin{displaymath}\nonumber{}Ax=b\end{displaymath}

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

\begin{math}\nonumber{}\left[\begin{array}{cc}\nonumber{}0 & 1\\\nonumber{}-1 & 1\end{array}\right]\left[\begin{array}{c}\nonumber{}x_{0}\\\nonumber{}x_{1}\end{array}\right]=\left[\begin{array}{c}\nonumber{}b_{1}\\\nonumber{}b_{2}\end{array}\right]\end{math} (6.3.7)

with b=(1,-2) and b=(7,0).

/* Copyright: Copyright (c) 1998-2011 MOSEK ApS, Denmark. All rights reserved. File : solvelinear.c Purpose : To demonstrate the usage of MSK_solvewithbasis when solving the linear system: 1.0 x1 = b1 -1.0 x0 + 1.0 x1 = b2 with two different right hand sides b = (1.0, -2.0) and b = (7.0, 0.0) */ using System; class msgclass : mosek.Stream { string prefix; public msgclass (string prfx) { prefix = prfx; } public override void streamCB (string msg) { Console.Write ("{0}{1}", prefix,msg); } } public class solvelinear { static public void put_a(mosek.Task task, double[][] aval, int[][] asub, int[] ptrb, int[] ptre, int numvar, int[] basis ) { // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; mosek.stakey[] skx = new mosek.stakey [numvar]; mosek.stakey[] skc = new mosek.stakey [numvar]; for (int i=0;i<numvar ;++i) { skx[i] = mosek.stakey.bas; skc[i] = mosek.stakey.fix; } task.append(mosek.accmode.var,numvar); task.append(mosek.accmode.con,numvar); for (int i=0;i<numvar ;++i) task.putavec(mosek.accmode.var, i, asub[i], aval[i]); for (int i=0 ; i<numvar ;++i) task.putbound(mosek.accmode.con, i, mosek.boundkey.fx, 0.0, 0.0); for (int i=0 ; i<numvar ;++i) task.putbound(mosek.accmode.var, i, mosek.boundkey.fr, -infinity, infinity); task.makesolutionstatusunknown(mosek.soltype.bas); /* Define a basic solution by specifying status keys for variables & constraints. */ for (int i=0 ; i<numvar ;++i) task.putsolutioni ( mosek.accmode.var, i, mosek.soltype.bas, skx[i], 0.0, 0.0, 0.0, 0.0); for (int i=0 ; i<numvar ;++i) task.putsolutioni ( mosek.accmode.con, i, mosek.soltype.bas, skc[i], 0.0, 0.0, 0.0, 0.0); task.initbasissolve(basis); } public static void Main () { const int NUMCON = 2; const int NUMVAR = 2; int numvar = 2; int numcon = 2; /* we must have numvar == numcon */ double[][] aval = new double[NUMVAR][]; aval[0] = new double[] {-1.0 }; aval[1] = new double[] {1.0, 1.0}; int[][] asub = new int[NUMVAR][]; asub[0] = new int[] {1}; asub[1] = new int[] {0,1}; int [] ptrb = {0,1}; int [] ptre = {1,3}; int[] bsub = new int[numvar]; double[] b = new double[numvar]; int[] basis = new int[numvar]; mosek.Task task = null; mosek.Env env = null; try { // Make mosek environment. env = new mosek.Env (); // Direct the env log stream to the user specified // method env_msg_obj.streamCB env.set_Stream (mosek.streamtype.log, new msgclass ("[env]")); // Initialize the environment. env.init (); // Create a task object linked with the environment env. task = new mosek.Task (env, NUMCON,NUMVAR); // Directs the log task stream to the user specified // method task_msg_obj.streamCB task.set_Stream (mosek.streamtype.log, new msgclass ("[task]")); /* Put A matrix and factor A. Call this function only once for a given task. */ put_a( task, aval, asub, ptrb, ptre, numvar, basis ); /* now solve rhs */ b[0] = 1; b[1] = -2; bsub[0] = 0; bsub[1] = 1; int nz = 2; task.solvewithbasis(0,ref nz,bsub,b); Console.WriteLine ("\nSolution to Bx = b:\n\n"); /* Print solution and show correspondents to original variables in the problem */ for (int i=0;i<nz;++i) { if (basis[bsub[i]] < numcon) Console.WriteLine ("This should never happen\n"); else Console.WriteLine ("x{0} = {1}\n",basis[bsub[i]] - numcon , b[bsub[i]] ); } b[0] = 7; bsub[0] = 0; nz = 1; task.solvewithbasis(0,ref nz,bsub,b); Console.WriteLine ("\nSolution to Bx = b:\n\n"); /* Print solution and show correspondents to original variables in the problem */ for (int i=0;i<nz;++i) { if (basis[bsub[i]] < numcon) Console.WriteLine ("This should never happen\n"); else Console.WriteLine ("x{0} = {1}\n",basis[bsub[i]] - numcon , b[bsub[i]] ); } } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); } if (task != null) task.Dispose (); if (env != null) env.Dispose (); } }

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 [[MathCmd 182]] is indeed a solution to (6.3.7).

Wed Feb 29 16:04:36 2012