6.6 MOSEK OptServer¶
MOSEK provides an easy way to offload optimization problem to a remote server. This section demonstrates related functionalities from the client side, i.e. sending optimization tasks to the remote server and retrieving solutions.
Setting up and configuring the remote server is described in a separate manual for the OptServer.
The URL
of the remote server required in all client-side calls should be a string of the form http://host:port
or https://host:port
.
6.6.1 Synchronous Remote Optimization¶
In synchronous mode the client sends an optimization problem to the server and blocks, waiting for the optimization to end. Once the result has been received, the program can continue. This is the simplest mode all it takes is to provide the address of the server before starting optimization. The rest of the code remains untouched.
Note that it is impossible to recover the job in case of a broken connection.
Source code example
function opt_server_sync(url, cert)
% Here we can set up a model
model = mosekmodel(...
objsense = "min", ...
objective = [ 1, 2 ]', ...
numvar = 2, ...
F = [ 1 0 ; ...
0 1 ; ...
3 -1 ], ...
domain = [ mosekdomain("greater than", rhs = 2), ...
mosekdomain("greater than", rhs = 3), ...
mosekdomain("less than", rhs = 1) ]);
% Set up the certificate path, if using TLS, otherwise ignore
if exist('cert','var')
param = ["MSK_SPAR_REMOTE_TLS_CERT_PATH", cert ];
else
param = [];
end
% Optimize using the remote server
model.solve(param = param, optserver = url);
% Use the optimal solution
if model.hassolution("interior")
xx = model.getsolution("interior", "x");
disp(xx);
end