Initializing help system before first use

# mmnl

Topics covered in this chapter:

- New functionality for the Mosel language
  - The problem type mpproblem.nl
  - The type nlctr and its operators
  - Setting initial values
  - Example: using mmnl for QCQP
- Procedures and functions

The mmnl module extends the Mosel language with a new type for representing nonlinear expressions and constraints and also with some additional subroutines. To use this module the following line must be included in the header of the Mosel model file:

     uses 'mmnl'

The first section presents the new functionality for the Mosel language provided by mmnl, namely the new type nlctr and a set of subroutines that may be applied to objects of this type.

The following sections give detailed documentation of the subroutines (other than mathematical operators) defined by this module.

## New functionality for the Mosel language

### The problem type mpproblem.nl

This module exposes its functionality through an extension to the mpproblem problem type. As a consequence, all routines presented here are executed in the context of the current problem.

### The type nlctr and its operators

The module mmnl defines the type nlctr to represent nonlinear constraints in the Mosel Language. As shown in the following example (Section Example: using mmnl for QCQP), mmnl also defines the standard arithmetic operations that are required for working with objects of this type. By and large, these are the same operations as for linear expressions (type linctr of the Mosel language) with additionally the possibility to multiply or divide by decision variables and to use the exponential notation x^r (assuming that x is of type mpvar). Nonlinear constraints may also be defined by using overloaded versions of Mosel's arithmetic and trigonometric functions on expressions involving decision variables (see Section Procedures and functions for a complete list). This type also supports name association (see setname).

### Setting initial values

An important feature in Nonlinear Programming is the possibility to set initial values for decision variables. With mmnl this is done by the procedure setinitval. Nonlinear solvers use initial values as starting point for the search. The choice of the initial values may not only have an impact on the time spent by the solver but also, depending on the problem type, on the best (locally optimal) solution found by the solver.

The definitions of initial values can be removed with clearinitvals. It is also possible to employ the solution values obtained from the immediately preceding optimization run as initial values to the next by calling the procedure copysoltoinit.

### Example: using mmnl for QCQP

The following example shows how to solve a QCQP (Quadratically Constrained Quadratic Programming) problem with the Xpress-MP QCQP solver. To use this solver we need to load the module mmxprs in addition to mmnl since the module mmnl does not include any solver.

The problem we wish to solve is a classical NLP test problem (source: http://www.orfe.princeton.edu/~rvdb/ampl/nlmodels/ that determines the shape of a hanging chain by minimizing its potential energy. The objective function is linear and the problem has convex quadratic constraints.

    model "catenary"
     uses "mmxprs", "mmnl"

     parameters
      N = 100                       ! Number of chainlinks
      L = 1                         ! Difference in x-coordinates of endlinks
      H = 2*L/N                     ! Length of each link
     end-parameters

     declarations
      RN = 0..N
      x: array(RN) of mpvar         ! x-coordinates of endpoints of chainlinks
      y: array(RN) of mpvar         ! y-coordinates of endpoints of chainlinks
     end-declarations

     forall(i in RN) x(i) is_free
     forall(i in RN) y(i) is_free

    ! Objective: minimise the potential energy
     potential_energy:= sum(j in 1..N) (y(j-1)+y(j))/2

    ! Bounds: positions of endpoints
    ! Left anchor
      x(0) = 0; y(0) = 0
    ! Right anchor
      x(N) = L; y(N) = 0

    ! Constraints: positions of chainlinks
     forall(j in 1..N)
      Link_up(j):= (x(j)-x(j-1))^2+(y(j)-y(j-1))^2 <= H^2

    ! Setting start values
     forall(j in RN) setinitval(x(j), j*L/N)
     forall(j in RN) setinitval(y(j), 0)

     setparam("XPRS_verbose", true)
     minimise(potential_energy)

     writeln("Solution: ", getobjval)
     forall(j in RN)
      writeln(strfmt(getsol(x(j)),10,5), " ", strfmt(getsol(y(j)),10,5))
    end-model

A QCQP matrix can be exported to a text file (in MPS or LP format) by adding the following lines to your model after the problem definition:

     setparam("XPRS_loadnames", true)    ! Enable loading of names
     loadprob(potential_energy)          ! Load the problem
     writeprob("catenary.mat", "")       ! Write an MPS matrix ("l" for LP format)

Not all problems with quadratic constraints conform with the properties required by QCQP solvers. Xpress-Optimizer therefore performs a convexity check before starting the optimization. This test takes some time and if you know that your problem is convex you may disable it by setting the following parameter before starting the optimization.

     setparam("XPRS_ifcheckconvexity", false)    ! Disable convexity check

## Procedures and functions

The module mmnl overloads certain mathematical functions of the Mosel language, replacing an argument of type real by the types linctr and nlctr. The return value of these functions is of type nlctr. This means they can be used as operators in the definition of nonlinear constraints as shown in the example of Section Example: using mmnl for QCQP. The relevant functions are:

- Arithmetic functions:
  abs
    absolute value
  ceil
    rounding to the next largest integer
  exp
    natural exponent of the argument
  floor
    rounding to the next smallest integer
  ln
    natural logarithm of the argument
  log
    base 10 logarithm of the argument
  round
    rounding to the nearset integer
  sqrt
    positive square root of the argument
  sign
    sign of an expression (-1 if negative, 1 if positive, 0 otherwise)
  fmin
    Minimum value of a list of expressions (this function accepts a variable number of arguments or a list)
  fmax
    Maximum value of a list of expressions (this function accepts a variable number of arguments or a list)
- Trigonometric functions:
  arccos
    arccosine of the argument
  arcsin
    arcsine of the argument
  arctan
    arctangent of the argument
  cos
    cosine of the argument
  sin
    sine of the argument
  tan
    tangent of the argument

Since these mathematical operators are fairly self-explanatory, we shall forego any more detailed documentation of these functions.

The following list gives an overview of all other functions and procedures defined by mmnl for which we give detailed descriptions later.

clearinitvals | Delete all initial value definitions.
copysoltoinit | Copy solution values to initial values.
getsol | Get the solution value of a nonlinear constraint.
gettype | Get the type of a nonlinear constraint.
ishidden | Test whether a constraint is hidden.
pwlin | Generate a piecewise linear function.
sethidden | Hide or unhide a nonlinear constraint.
setinitval | Set an initial value (start value) for a variable.
settype | Set the type of a nonlinear constraint.

Covered Topics

- clearinitvals
- copysoltoinit
- getsol
- gettype
- ishidden
- pwlin
- sethidden
- setinitval
- settype

Parent Topic Modules

© 2001-2026 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.