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.
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
using System;
using mosek.fusion;
namespace mosek.fusion.example
{
public class opt_server_sync
{
public static void Main(string[] args)
{
if (args.Length<1) {
Console.WriteLine("Missing argument, syntax is:");
Console.WriteLine(" opt_server_sync host [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(Console.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();
Console.WriteLine("x1,x2,x3 = {0}, {1}, {2}", solx[0], solx[1], solx[2]);
}
}
}