8.9 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
.
8.9.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
package com.mosek.fusion.examples;
import mosek.fusion.*;
public class opt_server_sync {
public static void main(String[] args) throws SolutionError {
if (args.length<1) {
System.out.println("Missing argument, syntax is:");
System.out.println(" java com.mosek.fusion.examples.opt_server_sync addr [certpath]");
return;
}
String serveraddr = args[0];
String tlscert = (args.length==2) ? args[1] : "";
// Setup a simple test problem
Model M = new Model("testOptServer");
Variable x = M.variable("x", 3, Domain.greaterThan(0.0));
M.constraint("lc", Expr.dot(new double[] {1.0, 1.0, 2.0}, x), Domain.equalsTo(1.0));
M.objective("obj", ObjectiveSense.Minimize, Expr.sum(x));
// Attach log handler
M.setLogHandler(new java.io.PrintWriter(System.out));
// Set OptServer URL
M.optserverHost(serveraddr);
// Path to certificate, if any
M.setSolverParam("remoteTlsCertPath", tlscert);
// Solve the problem on the OptServer
M.solve();
// Get the solution
double[] solx = x.level();
System.out.printf("x1,x2,x3 = %e, %e, %e\n", solx[0], solx[1], solx[2]);
}
}