Loading [MathJax]/extensions/TeX/AMSsymbols.js

Monday, February 18, 2019

Porting Fusion for MATLAB code

Fusion for MATLAB is discontinued starting with MOSEK version 9. If you wish to continue using MOSEK in MATLAB through the Fusion interface, this document describes how to adapt existing code to use the standard Fusion for Java.

First, use mosek.jar instead of mosekmatlab.jar in the Java path in MATLAB, for instance:
javaaddpath mosek/9.0/tools/platform/linux64x86/bin/mosek.jar
view raw javapath.m hosted with ❤ by GitHub
Next, every time you explicitly index into an object of a class from mosek.fusion use 0-based indexing, standard for Java, instead of 1-based indexing familiar from MATLAB. This applies to classes such as Variable, Expression, Matrix and to all operations such as index, pick, slice. For example, if you define a variable 
x = M.variable('x', 4, Domain.greaterThan(0.0));
view raw matlabvar.m hosted with ❤ by GitHub
then its individual entries are
x.index(0), x.index(1), x.index(2), x.index(3)
view raw matlabvar2.m hosted with ❤ by GitHub
whereas in the old interface they would be indexed from 1 through 4.

This applies only to indexing Java objects from mosek.fusion. Nothing changes with regard to MATLAB arrays, so operations which don't use explicit indexes are not affected, and whenever the input/output of a method is a MATLAB array, it will be 1-based indexed as always. So the following piece of code works both in the old and new regime:
import mosek.fusion.*;
c = [ 3.0, 1.0, 5.0, 1.0 ];
A = [ 3.0, 1.0, 2.0, 0.0 ; ...
2.0, 1.0, 3.0, 1.0 ; ...
0.0, 2.0, 0.0, 3.0 ];
b = [ 2.0, 5.0, 3.0 ];
M = Model();
x = M.variable(4, Domain.greaterThan(0.0));
M.objective('obj', ObjectiveSense.Maximize, Expr.dot(c, x));
M.constraint(Expr.mul(A, x), Domain.lessThan(b));
M.solve();
disp(['x = ' mat2str(x.level()',7)]);
view raw matlabfusion.m hosted with ❤ by GitHub

Finally note that Java 1.8+ is required.