7.6 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.6.1 Example MILO1¶
We use the example
to demonstrate how to set up and solve a problem with integer variables. It has the structure of a linear optimization problem (see Sec. 7.1 (Linear Optimization)) 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.4 (The Optimizer for Mixed-integer Problems) 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.9.
7.6.2 Specifying an initial solution¶
It is a common strategy to provide a starting feasible point (if one is known in advance) to the mixed-integer solver. This can in many cases reduce solution time.
It is not necessary to specify the whole solution. MOSEK will attempt to use it to speed up the computation. MOSEK will first try to construct a feasible solution by fixing integer variables to the values provided by the user (rounding if necessary) and optimizing over the continuous variables. The outcome of this process can be inspected via information items "mioConstructSolution"
and "mioConstructSolutionObj"
, and via the Construct solution objective
entry in the log. We concentrate on a simple example below.
Solution values can be set using Variable.setLevel
.
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 );
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:
int constr = M.getSolverIntInfo("mioConstructSolution");
double constrVal = M.getSolverDoubleInfo("mioConstructSolutionObj");
System.out.println("Initial solution utilization: " + constr);
System.out.println("Initial solution objective: " + constrVal);
7.6.3 Example MICO1¶
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:
The canonical conic formulation of (7.12) suitable for Fusion API for Java is
package com.mosek.fusion.examples;
import mosek.fusion.*;
public class mico1 {
public static void main(String[] args)
throws SolutionError {
Model M = new Model("mico1");
try {
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();
System.out.printf("x, y = %f, %f\n", x.level()[0], y.level()[0]);
} finally {
M.dispose();
}
}
}
Error and solution status handling were omitted for readability.