8.1 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.

8.1.1 Solver termination

If an error occurs during optimization then the method Model.Solve will throw an exception of type OptimizeError. The method FusionRuntimeException.ToString will produce a description of the error, if available. More about exceptions in Sec. 8.2 (Errors and exceptions).

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. 8.3 (Input/Output).

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

8.1.2 Available solutions

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

  • basic solution from the simplex optimizer,

  • interior-point solution from the interior-point optimizer,

  • integer solution from the mixed-integer optimizer.

Under standard parameters settings the following solutions will be available for various problem types:

Table 8.1 Types of solutions available from MOSEK

Simplex optimizer

Interior-point optimizer

Mixed-integer optimizer

Linear problem

SolutionType.Basic

SolutionType.Interior

Conic (nonlinear) problem

SolutionType.Interior

Problem with integer variables

SolutionType.Integer

For linear problems the user can force a specific optimizer choice making only one of the two solutions available. For example, if the user disables basis identification, then only the interior point solution will be available for a linear problem. Numerical issues may cause one of the solutions to be unknown even if another one is feasible.

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.

The user will always need to specify which solution should be accessed.

Moreover, the user may be oblivious to the actual solution type by always referring to SolutionType.Default, which will automatically select the best available solution, if there is more than one. Moreover, the method Model.SelectedSolution can be used to fix one solution type for all future references.

8.1.3 Problem and solution status

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

Problem status

Problem status (ProblemStatus, retrieved with Model.GetProblemStatus) 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 ProblemStatus.PrimalAndDualFeasible.

  • 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 (SolutionStatus, retrieved with Model.GetPrimalSolutionStatus and Model.GetDualSolutionStatus) provides the information about what the solution values actually contain. The most important broad categories of values are:

  • optimal (SolutionStatus.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 — the status was not determined, typically because of numerical issues, stall etc. Some solution is available, but its quality is not guaranteed.

  • undefined — this type of solution is not available at all.

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 8.2 Continuous problems (solution status for SolutionType.Interior or SolutionType.Basic)

Outcome

Problem status

Solution status (primal)

Solution status (dual)

Optimal

ProblemStatus.PrimalAndDualFeasible

SolutionStatus.Optimal

SolutionStatus.Optimal

Primal infeasible

ProblemStatus.PrimalInfeasible

SolutionStatus.Undefined

SolutionStatus.Certificate

Dual infeasible (unbounded)

ProblemStatus.DualInfeasible

SolutionStatus.Certificate

SolutionStatus.Undefined

Uncertain (stall, numerical issues, etc.)

ProblemStatus.Unknown

SolutionStatus.Unknown

SolutionStatus.Unknown

Table 8.3 Integer problems (solution status for SolutionType.Integer, others undefined)

Outcome

Problem status

Solution status (primal)

Solution status (dual)

Integer optimal

ProblemStatus.PrimalFeasible

SolutionStatus.Optimal

SolutionStatus.Undefined

Infeasible

ProblemStatus.PrimalInfeasible

SolutionStatus.Undefined

SolutionStatus.Undefined

Integer feasible point

ProblemStatus.PrimalFeasible

SolutionStatus.Feasible

SolutionStatus.Undefined

No conclusion

ProblemStatus.Unknown

SolutionStatus.Unknown

SolutionStatus.Undefined

8.1.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:

Remark

By default only optimal solutions are returned. An attempt to access a solution with an incompatible status will result in an exception. This can be changed by choosing another level of acceptable solutions with the method Model.AcceptedSolutionStatus. In particular, this method must be called to enable retrieving suboptimal solutions and infeasibility certificates. For instance, one could write

              M.AcceptedSolutionStatus(fusion.AccSolutionStatus.Feasible);

The current setting of acceptable solutions can be checked with Model.GetAcceptedSolutionStatus.

8.1.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 8.1 Sample framework for checking optimization result. Click here to download.
    public static void Main(String[] argv) {
      Model M = new Model();

      // (Optional) set a log stream
      // M.SetLogHandler(Console.Out);
      
      // (Optional) uncomment to see what happens when solution status is unknown
      // M.SetSolverParam("intpntMaxIterations", 1);

      // In this example we set up a small conic problem
      SetupExample(M);

      // Optimize
      try 
      {
        M.Solve();

        // We expect solution status OPTIMAL (this is also default)
        M.AcceptedSolutionStatus(AccSolutionStatus.Optimal);

        Variable x = M.GetVariable("x");
        long xsize = x.GetSize();
        double[] xVal = x.Level();
        Console.Write("Optimal value of x = ");
        for(int i = 0; i < xsize; ++i)
          Console.Write(xVal[i] + " ");
        Console.WriteLine("\nOptimal primal objective: " + M.PrimalObjValue());
        // .. continue analyzing the solution

      }
      catch (OptimizeError e)
      {
        Console.WriteLine("Optimization failed. Error: " + e.ToString());
      }
      catch (SolutionError)
      {
        // The solution with at least the expected status was not available.
        // We try to diagnoze why.
        Console.WriteLine("Requested solution was not available.");
        ProblemStatus prosta = M.GetProblemStatus();
        switch(prosta)
        {
          case ProblemStatus.DualInfeasible:
            Console.WriteLine("Dual infeasibility certificate found.");
            break;

          case ProblemStatus.PrimalInfeasible:
            Console.WriteLine("Primal infeasibility certificate found.");
            break;

          case ProblemStatus.Unknown:
            // The solutions status is unknown. The termination code
            // indicates why the optimizer terminated prematurely.
            Console.WriteLine("The solution status is unknown.");
            StringBuilder symname = new StringBuilder();
            StringBuilder desc = new StringBuilder();
            Env.getcodedesc((rescode)M.GetSolverIntInfo("optimizeResponse"), symname, desc);
            Console.WriteLine("  Termination code: {0} {1}", symname, desc);
            break;

          default:
            Console.WriteLine("Another unexpected problem status: " + prosta);
            break;
        }
      }
      catch (Exception e)
      {
        Console.WriteLine("Unexpected error: " + e.ToString());
      }

      M.Dispose();
    }