7.7 Integer Optimization

An optimization problem where one or more of the variables are constrained to integer values is called a (mixed) integer optimization problem. MOSEK supports integer variables in combination with linear, quadratic and quadratically constrtained and conic problems (except semidefinite). See the previous tutorials for an introduction to how to model these types of problems.

7.7.1 Basic linear example

We use the example

(7.17)\[\begin{split}\begin{array}{lccl} \mbox{maximize} & x_0 + 0.64 x_1 & & \\ \mbox{subject to} & 50 x_0 + 31 x_1 & \leq & 250, \\ & 3 x_0 - 2 x_1 & \geq & -4, \\ & x_0, x_1 \geq 0 & & \mbox{and integer} \end{array}\end{split}\]

to demonstrate how to set up and solve a problem with integer variables. It has the structure of a linear optimization problem except for integrality constraints on the variables. Therefore, only the specification of the integer constraints requires something new compared to the linear optimization problem discussed previously.

First, the integrality constraints are imposed by modifying any existing domain with Domain.Integral:

        Variable x = M.Variable("x", 2, Domain.Integral(Domain.GreaterThan(0.0)));

Another way to do this is to use the method Variable.MakeInteger on a selected variable.

Next, the example demonstrates how to set various useful parameters of the mixed-integer optimizer. See Sec. 13.5 (The Mixed-Integer optimizer) for details.

        // Set max solution time
        M.SetSolverParam("mioMaxTime", 60.0);
        // Set max relative gap (to its default value)
        M.SetSolverParam("mioTolRelGap", 1e-4);
        // Set max absolute gap (to its default value)
        M.SetSolverParam("mioTolAbsGap", 0.0);

The complete source for the example is listed in Listing 7.12.

Listing 7.12 How to solve problem (7.17). Click here to download.
using System;
using mosek.fusion;

namespace mosek.fusion.example
{
  public class milo1
  {
    public static void Main(string[] args)
    {
      double[][] A =
      { new double[] { 50.0, 31.0 },
        new double[] { 3.0,  -2.0 }
      };
      double[] c = { 1.0, 0.64 };
      using (Model M = new Model("milo1"))
      {
        Variable x = M.Variable("x", 2, Domain.Integral(Domain.GreaterThan(0.0)));

        // Create the constraints
        //      50.0 x[0] + 31.0 x[1] <= 250.0
        //       3.0 x[0] -  2.0 x[1] >= -4.0
        M.Constraint("c1", Expr.Dot(A[0], x), Domain.LessThan(250.0));
        M.Constraint("c2", Expr.Dot(A[1], x), Domain.GreaterThan(-4.0));

        // Set max solution time
        M.SetSolverParam("mioMaxTime", 60.0);
        // Set max relative gap (to its default value)
        M.SetSolverParam("mioTolRelGap", 1e-4);
        // Set max absolute gap (to its default value)
        M.SetSolverParam("mioTolAbsGap", 0.0);

        // Set the objective function to (c^T * x)
        M.Objective("obj", ObjectiveSense.Maximize, Expr.Dot(c, x));

        // Solve the problem
        M.Solve();

        // Get the solution values
        double[] sol = x.Level();
        Console.WriteLine("x1,x2 = {0}, {1}", sol[0], sol[1]);
        double miorelgap = M.GetSolverDoubleInfo("mioObjRelGap");
        double mioabsgap = M.GetSolverDoubleInfo("mioObjAbsGap");
        Console.WriteLine("MIP rel gap = {0} ({0})", miorelgap, mioabsgap);
      }
    }
  }
}

7.7.2 Specifying an initial solution (hot-start)

It is a common strategy to provide a starting feasible point (if one is known in advance) to the mixed-integer solver. This is known as hot-start or warm-start. The feasible point may come from the user’s prior knowledge of the model, a heuristic, or a solution from a preceding solve if the problem was modified so that the solution remains feasible. Using hot-start allows the solver to skip worse solutions and potentially get closer to the optimum faster.

There are two modes for MOSEK to utilize an initial solution.

  • A complete solution. MOSEK will first try to check if the current value of the primal variable solution is a feasible point. The solution can either come from a previous solver call or can be entered by the user, however the full solution with values for all variables (both integer and continuous) must be provided. This check is always performed and does not require any extra action from the user. The outcome of this process can be inspected via information items "mioInitialFeasibleSolution" and "mioInitialFeasibleSolutionObj", and via the Initial feasible solution objective entry in the log.

  • A partial integer solution. MOSEK can also try to construct a feasible solution by fixing integer variables to the values provided by the user (rounding if necessary) and optimizing over the remaining continuous variables. In this setup the user must provide initial values for all integer variables. This action is only performed if the parameter mioConstructSol is switched on. The outcome of this process can be inspected via information items "mioConstructSolution" and "mioConstructSolutionObj", and via the Construct solution objective entry in the log.

In the following example we focus on inputting a partial integer solution.

(7.18)\[\begin{split}\begin{array} {ll} \mbox{maximize} & 7 x_0 + 10 x_1 + x_2 + 5 x_3 \\ \mbox{subject to} & x_0 + x_1 + x_2 + x_3 \leq 2.5\\ & x_0,x_1,x_2 \in \integral \\ & x_0,x_1,x_2,x_3 \geq 0 \end{array}\end{split}\]

Solution values can be set using Variable.SetLevel . If the solution to be used as hot-start happens to come from a previous solve of the same model/task then it will be used by the solver automatically and does not have to be input explicitly through the API again.

Listing 7.13 Implementation of problem (7.18) specifying an initial solution. Click here to download.
        // Assign values to integer variables.
        // We only set a slice of x     
        double[] init_sol = { 1, 1, 0 };
        x.Slice(0,3).SetLevel( init_sol );

        // Request constructing the solution from integer variable values
        M.SetSolverParam("mioConstructSol", "on");

A more advanced application of Variable.SetLevel is presented in the case study on Multiprocessor scheduling.

The log output from the optimizer will in this case indicate that the inputted values were used to construct an initial feasible solution:

Construct solution objective       : 1.950000000000e+01

The same information can be obtained from the API:

Listing 7.14 Retrieving information about usage of initial solution Click here to download.
        int constr = M.GetSolverIntInfo("mioConstructSolution");
        double constrVal = M.GetSolverDoubleInfo("mioConstructSolutionObj");
        Console.WriteLine("Construct solution utilization: " + constr);
        Console.WriteLine("Construct solution objective: " +  constrVal);

7.7.3 Basic conic example

Integer variables can also be used arbitrarily in conic problems (except semidefinite). We refer to the previous tutorials for how to set up a conic optimization problem. Here we present sample code that sets up a simple optimization problem:

(7.19)\[\begin{split}\begin{array}{ll} \mbox{minimize} & x^2+y^2 \\ \mbox{subject to} & x \geq e^y+3.8, \\ & x, y \ \mbox{integer}. \end{array}\end{split}\]

The canonical conic formulation of (7.19) suitable for Fusion API for .NET is

(7.20)\[\begin{split}\begin{array}{llr} \mbox{minimize} & t & \\ \mbox{subject to} & (t,x,y)\in\Q^3 & (t\geq\sqrt{x^2+y^2}) \\ & (x-3.8, 1, y) \in\EXP & (x-3.8\geq e^y) \\ & x, y \ \mbox{integer}, & \\ & t\in\real. \end{array}\end{split}\]
Listing 7.15 Implementation of problem (7.20). Click here to download.
using System;
using mosek.fusion;

namespace mosek.fusion.example
{
  public class mico1
  {
    public static void Main(string[] args)
    {
      using (Model M = new Model("mico1"))
      {
        Variable x = M.Variable(Domain.Integral(Domain.Unbounded()));
        Variable y = M.Variable(Domain.Integral(Domain.Unbounded()));
        Variable t = M.Variable();

        M.Constraint(Expr.Vstack(t, x, y), Domain.InQCone());
        M.Constraint(Expr.Vstack(Expr.Sub(x, 3.8), 1, y), Domain.InPExpCone());

        M.Objective(ObjectiveSense.Minimize, t);

        M.Solve();

        Console.WriteLine("x, y = {0}, {1}", x.Level()[0], y.Level()[0]);
      }
    }
  }
}

Error and solution status handling were omitted for readability.

7.7.4 Fixed problem and dual values

The dual solution is not defined for mixed-integer problems, but in some cases the user may want to obtain some dual information (shadow prices). One typical strategy is to compute shadow price information under the assumption that the combinatorial decisions (integer variable values) do not change, that is:

  • solve the mixed-integer model (to some feasible solution, not necessarily optimal),

  • fix all integer variables to their values in the solution,

  • solve the fixed model as a continuous problem and extract the dual values.

Fusion API for .NET facilitates the construction of the fixed model with Model.GetFixedModel.

As an example we consider a toy production planning model with two plants with maximum capacities 70, 80 units and a demand of 100 units:

(7.21)\[\begin{split}\begin{array}{ll} \mbox{minimize} & 10x_1 + 14x_2 + 500s_1 + 300s_2 \\ \mbox{subject to} & x_1+x_2\geq 100, \\ & 0 \leq x_1 \leq 70s_1, \\ & 0 \leq x_2 \leq 80s_2, \\ & s_1,s_2 \in \{0,1\}. \end{array}\end{split}\]

We begin by solving the mixed-integer problem and verifying that it has a feasible solution with \(s_1=s_2=1\) i.e. both plants active with production levels \((x_1,x_2)=(70,30)\). Then, assuming no modifications are made to the problem structure or numerical data, we can immediately construct and solve the fixed integer model and retrieve its solution as shown below.

Listing 7.16 Solving the fixed integer model for (7.21). Click here to download.
        /* F is the continuous fixed model */
        using (Model F = M.GetFixedModel())
        {
          F.Solve();

          if (F.GetProblemStatus() != ProblemStatus.PrimalAndDualFeasible)
            throw new System.Exception("Unsuitable problem status, exiting");

          Constraint demand = F.GetConstraint("demand");
          Constraint production = F.GetConstraint("production");
          Variable xfix = F.GetVariable("x");

          Console.WriteLine("xfix = {0}, {1}", xfix.Level()[0], xfix.Level()[1]);
          Console.WriteLine("demand dual = {0}", demand.Dual()[0]);
          Console.WriteLine("production dual = {0}, {1}", production.Dual()[0], production.Dual()[1]);

For instance, the shadow price for the first plant’s production constraint is \(-4\), corresponding to the fact that increasing the capacity of the first plant by 1 unit would allow shifting one production unit form plant 2 to plant 1, reducing the objective cost by \(14-10=4\).

Note that the solution of the mixed-integer problem will typically have small violations, which implies that the fixed model may be declared (borderline) infeasible. To avoid this effect, the fixing algorithm will by default introduce small perturbations of bounds in order to make the fixed problem strictly feasible. If needed this can be controlled by setting the parameter fixingMethod in the original task prior to fixing.