16.10 Nonlinear extensions

16.10.1 Separable Convex Optimization (SCopt)

SCopt is an easy-to-use interface to the nonlinear optimizer when solving separable convex problems. See Section 8.1 for a tutorial and example code. As currently implemented, SCopt can handle only the nonlinear expressions \(x\ln (x)\), \(e^x\), \(\ln (x)\), and \(x^g\). However, it should be fairly easy to extend the interface to other nonlinear function of a single variable if needed.

The code using the SCopt interface must include scopt-ext.h and must be linked with scopt-ext.c. Both extension files can be found in the examples/c directory.

All the linear data of the problem, such as \(c\) and \(A\), is inputted to MOSEK as usual, i.e. using the relevant functions in the MOSEK API. Every nonlinear expression added to the objective should be specified by a 5-tuple of parameters:

opro[k] oprjo[k] oprfo[k] oprgo[k] oprho[k] Expression added in objective
MSK_OPR_ENT j \(f\) \(g\) \(h\) \(f x_j \ln (x_j)\)
MSK_OPR_EXP j \(f\) \(g\) \(h\) \(f e^{g x_j + h}\)
MSK_OPR_LOG j \(f\) \(g\) \(h\) \(f \ln (g x_j +h)\)
MSK_OPR_POW j \(f\) \(g\) \(h\) \(f (x_j+h)^g\)

Every nonlinear expression added to the constraints should be specified by a 6-tuple of parameters:

oprc[k] opric[k] oprjc[k] oprfc[k] oprgc[k] oprhc[k] Expression added to constraint \(i\)
MSK_OPR_ENT i j \(f\) \(g\) \(h\) \(f x_j \ln (x_j)\)
MSK_OPR_EXP i j \(f\) \(g\) \(h\) \(f e^{g x_j + h}\)
MSK_OPR_LOG i j \(f\) \(g\) \(h\) \(f \ln (g x_j +h)\)
MSK_OPR_POW i j \(f\) \(g\) \(h\) \(f (x_j+h)^g\)

In each case opr specifies the kind of expression to be added, oprf, oprg and oprh are the parameters and opri, oprj determine the variable and/or constraint to be considered. The concrete API specification follows.

MSKscopre

Type of nonlinear term in the SCopt interface.

MSK_OPR_ENT (0)

Entropy function \(f x \ln (x)\)

MSK_OPR_EXP (1)

Exponential function \(f e^{g x + h}\)

MSK_OPR_LOG (2)

Logarithm \(f \ln (g x + h)\)

MSK_OPR_POW (3)

Power function \(f (x+h)^g\)

MSK_scbegin
MSKrescodee MSK_scbegin(
   MSKtask_t task,
   int       numopro,
   int       *opro,
   int       *oprjo,
   double    *oprfo,
   double    *oprgo,
   double    *oprho,
   int       numoprc,
   int       *oprc,
   int       *opric,
   int       *oprjc,
   double    *oprfc,
   double    *oprgc,
   double    *oprhc,
   schand_t  *sch)

Define the nonlinear part of the problem in the format specified by the SCopt interface. The o arguments describe the nonlinear terms added to the objective and the c arguments describe the nonlinear terms added to the constraints. Multiple terms involving the same variable and constraint are possible, they will be added up.

Parameters:
 
  • task (MSKtask_t) – The optimization task. (input)
  • numopro (int) – Number of nonlinear terms in the objective. (input)
  • opro (MSKscopre*) – List of function indicators defining the objective terms. (input)
  • oprjo (int*) – List of variable indexes for the objective terms. (input)
  • oprfo (double*) – List of \(f\) values for the objective terms. (input)
  • oprgo (double*) – List of \(g\) values for the objective terms. (input)
  • oprho (double*) – List of \(h\) values for the objective terms. (input)
  • numopro – Number of nonlinear terms in the constraints.
  • oprc (MSKscopre*) – List of function indicators defining the constraint terms. (input)
  • opric (int*) – List of constraint indexes for the constraint terms. (input)
  • oprjc (int*) – List of variable indexes for the constraint terms. (input)
  • oprfc (double*) – List of \(f\) values for the constraint terms. (input)
  • oprgc (double*) – List of \(g\) values for the constraint terms. (input)
  • oprhc (double*) – List of \(h\) values for the constraint terms. (input)
  • sch (void* by reference) – A handle to the nonlinear data part. (output)
MSK_scend
MSKrescodee MSK_scend(
   MSKtask_t task,
   schand_t  *sch)

Remove all non-linear separable terms from the task.

Parameters:
 
  • task (MSKtask_t) – The optimization task. (input)
  • sch (void* by reference) – A handle to the nonlinear data part. (input/output)
Return:
 

(MSKrescodee) – The function response code.

MSK_scwrite
MSKrescodee MSK_scwrite(
   MSKtask_t task,
   schand_t  sch,
   char      *filename)

Write the problem to an SCopt file and a normal problem file.

Parameters:
 
  • task (MSKtask_t) – The optimization task. (input)
  • sch (void*) – A handle to the nonlinear data part. (input)
  • filename (char*) – Any string. The nonlinear part of the problem is written to filename.sco and the linear part to filename.mps. (input)
Return:
 

(MSKrescodee) – The function response code.

MSK_scread
MSKrescodee MSK_scread(
   MSKtask_t task,
   schand_t  *sch,
   char      *filename)

Read a problem from files written by MSK_scwrite.

Parameters:
 
  • task (MSKtask_t) – The optimization task. (input)
  • sch (void* by reference) – A handle to the nonlinear data part. (output)
  • filename (char*) – Any valid file name. (input)
Return:
 

(MSKrescodee) – The function response code.

16.10.2 Exponential optimization

MOSEK has an extension for exponential optimization problems (EXPopt). See Section 8.2 for a tutorial and code examples. The code using this interface must include expopt.h and must be linked with expopt.c, dgopt.c and scopt-ext.c. These files can be found in the examples/c directory.

MSK_expoptsetup
MSKrescodee MSK_expoptsetup(
    MSKtask_t     expopttask,
    MSKint32t     solveform,
    MSKint32t     numcon,
    MSKint32t     numvar,
    MSKint32t     numter,
    MSKidxt       *subi,
    double        *c,
    MSKidxt       *subk,
    MSKidxt       *subj,
    double        *akj,
    MSKint32t     numanz,
    expopthand_t  *expopthnd)

Sets up an exponential optimization problem.

Parameters:
 
  • expopttask (MSKtask_t) – The optimization task.
  • solveform (MSKint32t) – If 0 solver is chosen freely, 1: solve dual, -1: solve primal
  • numcon (MSKint32t) – Number of constraints
  • numvar (MSKint32t) – Number of variables
  • numter (MSKint32t) – Number of exponential terms
  • subi (MSKint32t*) – The constraint where the term belongs. Zero denotes the objective.
  • c (double* ) – The \(c\) coefficients of nonlinear terms.
  • subk (MSKint32t*) – Term indices.
  • subj (MSKint32t*) – Variable indices.
  • akj (double* ) – akj[i] is coefficient of variable subj[i] in term subk[i], i.e. \(a_{\mathtt{subk}[i],\mathtt{subj}[i]} = \mathtt{akj}[i].\)
  • numanz (MSKint32t) – Number of linear terms in the exponents, i.e. the length of subk, subj and akj.
  • expopthnd (void**) – Data structure containing the nonlinear information.
Return:
 

(MSKrescodee) – The function response code.

MSK_expoptimize
MSKrescodee MSK_expoptimize(
    MSKtask_t    expopttask,
    MSKprostae   *prosta,
    MSKsolstae   *solsta,
    double       *objval,
    double       *xx,
    double       *y,
    expopthand_t *expopthnd)

Solves an exponential optimization problem.

Parameters:
 
  • expopttask (MSKtask_t) – The optimization task.
  • prosta (*MSKprostae) – Problem status.
  • solsta (*MSKsolstae) – Solution status.
  • objval (double* ) – Objective value.
  • xx (double* ) – Primal solution values.
  • y (double* ) – Dual solution values (only when dual form is used).
  • expopthnd (void**) – Data structure containing the nonlinear information.
Return:
 

(MSKrescodee) – The function response code.

MSK_expoptread
MSKrescodee MSK_expoptread(
    MSKenv_t      env,
    const char    *filename,
    MSKint32t     *numcon,
    MSKint32t     *numvar,
    MSKint32t     *numter,
    MSKidxt       **subi,
    double        **c,
    MSKidxt       **subk,
    MSKidxt       **subj,
    double        **akj,
    MSKint32t     *numanz)

Reads an exponential optimization problem from a file and saves it into arrays suitable for MSK_expoptsetup. The user must manually free the memory allocated by this function.

Parameters:
 
  • env (MSKenv_t) – The environment.
  • filename (char*) – Any valid file name.
  • numcon (MSKint32t*) – Number of constraints
  • numvar (MSKint32t*) – Number of variables
  • numter (MSKint32t*) – Number of exponential terms
  • subi (MSKint32t**) – The constraint where the term belongs. Zero denotes the objective.
  • c (double** ) – The \(c\) coefficients of nonlinear terms.
  • subk (MSKint32t**) – Term indices.
  • subj (MSKint32t**) – Variable indices.
  • akj (double** ) – akj[i] is coefficient of variable subj[i] in term subk[i], i.e. \(a_{\mathtt{subk}[i],\mathtt{subj}[i]} = \mathtt{akj}[i].\)
  • numanz (MSKint32t*) – Number of linear terms in the exponents, i.e. the length of subk, subj and akj.
Return:
 

(MSKrescodee) – The function response code.

MSK_expoptwrite
MSKrescodee MSK_expoptwrite(
    MSKenv_t      env,
    MSKint32t     numcon,
    MSKint32t     numvar,
    MSKint32t     numter,
    MSKidxt       *subi,
    double        *c,
    MSKidxt       *subk,
    MSKidxt       *subj,
    double        *akj,
    MSKint32t     numanz)

Write an exponential optimization problem to a file.

Parameters:
 
  • env (MSKenv_t) – The environment.
  • filename (char*) – Any valid file name.
  • solveform (MSKint32t) – If 0 solver is chosen freely, 1: solve dual, -1: solve primal
  • numcon (MSKint32t) – Number of constraints
  • numvar (MSKint32t) – Number of variables
  • numter (MSKint32t) – Number of exponential terms
  • subi (MSKint32t*) – The constraint where the term belongs. Zero denotes the objective.
  • c (double* ) – The \(c\) coefficients of nonlinear terms.
  • subk (MSKint32t*) – Term indices.
  • subj (MSKint32t*) – Variable indices.
  • akj (double* ) – akj[i] is coefficient of variable subj[i] in term subk[i], i.e. \(a_{\mathtt{subk}[i],\mathtt{subj}[i]} = \mathtt{akj}[i].\)
  • numanz (MSKint32t) – Number of linear terms in the exponents, i.e. the length of subk, subj and akj.
Return:
 

(MSKrescodee) – The function response code.

MSK_expoptfree
MSKrescodee MSK_expoptfree(
   MSKtask_t    expopttask,
   expopthand_t *expopthnd)

Free the data structures allocated by a call to MSK_expoptsetup.

Parameters:
 
  • expopttask (MSKtask_t) – The optimization task.
  • expopthnd (void**) – Data structure containing the nonlinear information.
Return:
 

(MSKrescodee) – The function response code.

16.10.3 Dual geometric optimization

MOSEK has an extension for dual geometric optimization (DGopt). See Section 8.3 for a tutorial and code examples. The code using this interface must include dgopt.h and must be linked with dgopt.c and scopt-ext.c. These files can be found in the examples/c directory.

MSK_dgosetup
MSKrescodee  MSK_dgosetup(
    MSKtask_t task,
    MSKintt   numvar,
    MSKintt   numcon,
    MSKintt   t,
    double    *v,
    MSKintt   *p,
    dgohand_t *nlh)

Sets up the objective in a dual geometric optimization problem

\[f(x) = \sum_{j=0}^{n-1} x_j \ln \left( \frac{v_j}{x_j} \right) + \sum_{i=1}^t \left( \sum_{j=p_i}^{p_{i+1}-1} x_j \right) \ln \left( \sum_{j=p_i}^{p_{i+1}-1} x_j \right)\]
Parameters:
 
  • task (MSKtask_t) – The optimization task.
  • numvar (MSKint32t) – The number of variables \(n\).
  • numcon (MSKint32t) – The number of variables in the primal formulation of the problem (\(p_1\)).
  • t (MSKint32t) – The number of constraints in the primal formulation of the problem (\(t\)).
  • v (double* ) – Coefficients \(v_i\).
  • p (MSKint32t*) – Term indices \(p_i\).
  • nlh (void**) – Data structure containing the nonlinear information.
Return:
 

(MSKrescodee) – The function response code.

MSK_dgoread
MSKrescodee  MSK_dgoread(
    MSKtask_t task,
    char      *filename,
    MSKintt   *numvar,
    MSKintt   *numcon,
    MSKintt   *t,
    double    **v,
    MSKintt   **p)

Reads the data of a dual geometric problem in the format suitable for MSK_dgosetup.

Parameters:
 
  • task (MSKtask_t) – The optimization task.
  • filename (char*) – Any valid file name.
  • numvar (MSKint32t*) – The number of variables \(n\).
  • numcon (MSKint32t*) – The number of variables in the primal formulation of the problem (\(p_1\)).
  • t (MSKint32t*) – The number of constraints in the primal formulation of the problem (\(t\)).
  • v (double** ) – Coefficients \(v_i\).
  • p (MSKint32t**) – Term indices \(p_i\).
Return:
 

(MSKrescodee) – The function response code.

MSK_freedgo
MSKrescodee MSK_freedgo(
   MSKtask_t task,
   dgohand_t  *nlh)

Free the data structures allocated by a call to MSK_dgosetup.

Parameters:
 
  • task (MSKtask_t) – The optimization task.
  • nlh (void**) – Data structure containing the nonlinear information.
Return:
 

(MSKrescodee) – The function response code.