7.2 Accessing the solution

This section contains important information about the status of the solver and the status of the solution, which must be checked in order to properly interpret the results of the optimization.

7.2.1 Solver termination

The optimizer provides two status codes relevant for error handling:

  • Response code of type rescode. It indicates if any unexpected error (such as an out of memory error, licensing error etc.) has occurred. The expected value for a successful optimization is MSK_RES_OK.

  • Termination code: It provides information about why the optimizer terminated, for instance if a predefined time limit has been reached. These are not errors, but ordinary events that can be expected (depending on parameter settings and the type of optimizer used).

If the optimization was successful then the method optimize returns normally and its output is the termination code. If an error occurs then the method throws an exception, which contains the response code. See Sec. 7.3 (Errors and exceptions) for how to access it.

If a runtime error causes the program to crash during optimization, the first debugging step is to enable logging and check the log output. See Sec. 7.4 (Input/Output).

If the optimization completes successfully, the next step is to check the solution status, as explained below.

7.2.2 Available solutions

MOSEK uses three kinds of optimizers and provides three types of solutions:

Which solution(s) are returned depends on the problem type, optimizer selection and additional settings. In the majority of cases only one solution is available.

Under standard parameters settings each problem type implies a default optimizer and a default output solution:

Table 7.1 Types of solutions available from MOSEK

Type of problem

Default optimizer

Default output solution

Linear problem

interior-point (with basis identification)

basic

Nonlinear continuous problem
(conic, quadratic, SDP)

interior-point (conic)

interior-point

Mixed-integer problem

mixed-integer optimizer

integer

A problem with affine conic constraints (ACC) is treated as nonlinear conic, even if all the ACCs only involve linear domains.

For nonlinear and mixed-integer problems both the optimizer and output solution are uniquely determined. For linear problems there are more choices.

Table 7.2 Types of modifications available for linear problems

Settings

Optimizer

Output solution

Parameter to set

default interior-point

interior-point

basic

use any simplex solver

simplex

basic

MSK_IPAR_OPTIMIZER

disable basis identification,
need only interior-point solution

interior-point

interior-point

MSK_IPAR_INTPNT_BASIS

need interior-point and basis sol.

interior-point

basic, interior-point

MSK_IPAR_REQUEST_INTPNT

Not all components of a solution are always available. For example, there is no dual solution for integer problems and no dual conic variables from the simplex optimizer.

7.2.3 Problem and solution status

Assuming that the optimization terminated without errors, the next important step is to check the problem and solution status and availability of solutions. There is one for every type of solution, as explained above.

Problem status

Problem status (prosta) determines whether the problem is certified as feasible. Its values can roughly be divided into the following broad categories:

  • feasible — the problem is feasible. For continuous problems and when the solver is run with default parameters, the feasibility status should ideally be MSK_PRO_STA_PRIM_AND_DUAL_FEAS.

  • primal/dual infeasible — the problem is infeasible or unbounded or a combination of those. The exact problem status will indicate the type of infeasibility.

  • unknown — the solver was unable to reach a conclusion, most likely due to numerical issues.

Solution status

Solution status (solsta) provides the information about what the solution values actually contain. The most important broad categories of values are:

  • optimal (MSK_SOL_STA_OPTIMAL) — the solution values are feasible and optimal.

  • certificate — the solution is in fact a certificate of infeasibility (primal or dual, depending on the solution).

  • unknown/undefined — the solver could not solve the problem or this type of solution is not available for a given problem.

Problem and solution status for each solution can be retrieved with getprosta and getsolsta, respectively.

The solution status determines the action to be taken. For example, in some cases a suboptimal solution may still be valuable and deserve attention. It is the user’s responsibility to check the status and quality of the solution.

Typical status reports

Here are the most typical optimization outcomes described in terms of the problem and solution statuses. Note that these do not cover all possible situations that can occur.

Table 7.3 Continuous problems (solution status for interior-point and basic solution)

Outcome

Problem status

Solution status

Optimal

MSK_PRO_STA_PRIM_AND_DUAL_FEAS

MSK_SOL_STA_OPTIMAL

Primal infeasible

MSK_PRO_STA_PRIM_INFEAS

MSK_SOL_STA_PRIM_INFEAS_CER

Dual infeasible (unbounded)

MSK_PRO_STA_DUAL_INFEAS

MSK_SOL_STA_DUAL_INFEAS_CER

Uncertain (stall, numerical issues, etc.)

MSK_PRO_STA_UNKNOWN

MSK_SOL_STA_UNKNOWN

Table 7.4 Integer problems (solution status for integer solution, others undefined)

Outcome

Problem status

Solution status

Integer optimal

MSK_PRO_STA_PRIM_FEAS

MSK_SOL_STA_INTEGER_OPTIMAL

Infeasible

MSK_PRO_STA_PRIM_INFEAS

MSK_SOL_STA_UNKNOWN

Integer feasible point

MSK_PRO_STA_PRIM_FEAS

MSK_SOL_STA_PRIM_FEAS

No conclusion

MSK_PRO_STA_UNKNOWN

MSK_SOL_STA_UNKNOWN

7.2.4 Retrieving solution values

After the meaning and quality of the solution (or certificate) have been established, we can query for the actual numerical values. They can be accessed using:

and many more specialized methods, see the API reference.

7.2.5 Source code example

Below is a source code example with a simple framework for assessing and retrieving the solution to a conic optimization problem.

Listing 7.1 Sample framework for checking optimization result. Click here to download.
using Mosek


cqo1_ptf = "
Task ''
Objective obj
    Minimize + x4 + x5 + x6
Constraints
    c1 [1] + x1 + x2 + 2 x3
    k1 [QUAD(3)]
        @ac1: + x4
        @ac2: + x1
        @ac3: + x2
    k2 [RQUAD(3)]
        @ac4: + x5
        @ac5: + x6
        @ac6: + x3
Variables
    x4
    x1 [0;+inf]
    x2 [0;+inf]
    x5
    x6
    x3 [0;+inf]
"

try
    maketask() do task
        # Use remote server: putoptserverhost(task,"http://solve.mosek.com:30080")
        putstreamfunc(task,MSK_STREAM_LOG,msg -> print(msg))

        if length(ARGS) < 1
            readptfstring(task,cqo1_ptf)
        else
            readdata(task,ARGS[1])
        end

        # (Optional) uncomment to see what happens when solution status is unknown
        # putintparam(task,MSK_IPAR_INTPNT_MAX_ITERATIONS, 1)


        # Optimize
        trmcode = optimize(task)
        solutionsummary(task,MSK_STREAM_LOG)

        # Ensure that the interior-point solution is always present
        putintparam(task,MSK_IPAR_REQUEST_INTPNT, MSK_ON)

        # We expect solution status OPTIMAL
        solsta = getsolsta(task,MSK_SOL_ITR)

        if solsta == MSK_SOL_STA_OPTIMAL
            # Optimal solution. Fetch and print it.
            println("An optimal interior-point solution is located.")
            numvar = getnumvar(task)
            xx = getxx(task,MSK_SOL_ITR)
            println("x = $xx")
        elseif solsta == MSK_SOL_STA_DUAL_INFEAS_CER
            println("Dual infeasibility certificate found.")
        elseif solsta == MSK_SOL_STA_PRIM_INFEAS_CER
            println("Primal infeasibility certificate found.")
        elseif solsta == MSK_SOL_STA_UNKNOWN
            # The solutions status is unknown. The termination code
            # indicates why the optimizer terminated prematurely.
            println("The solution status is unknown.")
            (symname, desc) = getcodedesc(trmcode)
            println("   Termination code: $symname $desc")
        else
            println("An unexpected solution status $solsta is obtained.")
        end
    end
catch e
    println("En error occurred: $(e.rcode), $(e.msg)")
end