S_S
S_S

Reputation: 1402

Mixed Integer Quadratic Programming using Opti Toolbox in MATLAB

I wish to solve a mixed integer quadratic program with linear constraints using OPTI toolbox in MATLAB. I want some of my decision variables to be continuous and some decision variables to be binary. How do I specify this?

Upvotes: 2

Views: 1516

Answers (1)

Ioannis
Ioannis

Reputation: 5388

I want some of my decision variables to be continuous and some decision variables to be binary. How do I specify this?

The way to specify which variables are of which type is shown at the bottom of this page.

Quoting:

Example 5: Specifying Long Integer Variable Strings

A common question we get is how to specify xtype when you have lots of integer variables. Assuming your variables are ordered (i.e. continuous, integer and binary variables are in consecutive groups), the following example shows a shorthand trick to enter them.

% Objective
nC = 10; %Number of Continuous Variables
nI = 10; %Number of Integer Variables
nB = 10; %Number of Binary Variables

% Build xtype vector
xtype = [repmat('C',1,nC),repmat('I',1,nI),repmat('B',1,nB)]

So xtype is a vector with as many components as variables, and each component defines the type of each variable, which can be

  • Continuous ('C')
  • Integer ('I')
  • Binary ('B')

After specifying xtype, you need to pass it to the OPTI object as shown in this example:

% Objective
H = [1 -1; -1  2];          %Objective Function (min 0.5x'Hx + f'x)
f = -[2 6]';                

% Constraints
A = [1,1; -1,2; 2, 1];      %Linear Inequality Constraints (Ax <= b)
b = [2;2;3];    
lb = [0;0];                 %Bounds on x (lb <= x)

% Integer Constraints - We do it as above (using repmat) in your case
xtype = 'IC';

% Create OPTI Object
Opt = opti('qp',H,f,'ineq',A,b,'lb',lb,'xtype',xtype)

% Solve the MIQP problem
[x,fval,exitflag,info] = solve(Opt)

I hope this helps!

Upvotes: 2

Related Questions