7.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.
7.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
library("Rmosek")
opt_server_sync <- function(filename, url, cert)
{
# Read problem
r <- mosek_read(filename, list(verbose=1, usesol=FALSE, useparam=TRUE))
stopifnot(identical(r$response$code, 0))
prob <- r$prob
# Set remote OptServer parameters
prob$sparam <- list(REMOTE_OPTSERVER_HOST = url, # address of the server
REMOTE_TLS_CERT_PATH = cert) # certificate, only for HTTPS
# Solve problem using the remote server
r <- mosek(prob, list(verbose=10))
stopifnot(identical(r$response$code, 0))
sol <- r$sol
# Print solution
print(sol)
}