Using SNOPT7

This section serves as a reference guide to SNOPT. We recommend the user read the SNOPT7 User’s Manual for detailed information on using SNOPT.

Initializing/Finalizing

snInit

subroutine snInit
&   ( iPrint, iSumm, cw, lencw, iw, leniw, rw, lenrw )

integer
&     iPrint, iSumm, lencw, leniw, lenrw, iw(leniw)
character
&     cw(lencw)*8
double precision
&     rw(lenrw)

snInit is the initialization routine for SNOPT. The user must define the Fortran file unit numbers iPrint and iSumm for the print and summary output files. To turn off output on either of these streams, set the unit number to 0. The user must open the files for writing and associate them with the assigned unit numbers.

On exit, the workspace arrays are initialized to undefined or default values.

snInitF

subroutine snInitF
&   ( printfile, summaryfile, iPrint, iSumm,
&     cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     printfile, summaryfile
integer
&     iPrint, iSumm, lencw, leniw, lenrw, iw(leniw)
character
&     cw(lencw)*8
double precision
&     rw(lenrw)

snInitF is an alternative initialization routine for SNOPT. The user passes the filenames of the print and summary output files. To turn off output on either stream, set the filename to ''. To send the summary output to standard output, set summaryfile to screen.

On exit, the assigned Fortran file unit numbers iPrint and iSumm for the print and summary files are returned. The workspace arrays are also initialized to undefined or default values.

snEndF

subroutine snEndF
&   ( cw, lencw, iw, leniw, rw, lenrw )

integer
&     lencw, leniw, lenrw, iw(leniw)
character
&     cw(lencw)*8
double precision
&     rw(lenrw)

snEndF should be called if the user uses snInitF or snSpecF. This routine closes any opened files.

Solving with SNOPTA

subroutine snOptA
&   ( Start, nF, n, nxname, nFname,
&     ObjAdd, ObjRow, Prob, usrfun,
&     iAfun, jAvar, lenA, neA, A,
&     iGfun, jGvar, lenG, neG,
&     xlow, xupp, xnames, Flow, Fupp, Fnames,
&     x, xstate, xmul, F, Fstate, Fmul,
&     INFO, mincw, miniw, minrw,
&     nS, nInf, sInf,
&     cu, lencu, iu, leniu, ru, lenru,
&     cw, lencw, iw, leniw, rw, lenrw )

external
&     usrfun
integer
&     INFO, lenA, lencu, lencw, lenG, leniu, leniw, lenru, lenrw,
&     mincw, miniw, minrw, n, neA, neG, nF, nFname, nInf, nS,
&     nxname, ObjRow, Start, iAfun(lenA), iGfun(lenG), iu(leniu),
&     iw(leniw), jAvar(lenA), jGvar(lenG), xstate(n), Fstate(nF)
double precision
&     ObjAdd, sInf, A(lenA), F(nF), Fmul(nF), Flow(nF), Fupp(nF),
&     ru(lenru), rw(lenrw), x(n), xlow(n), xmul(n), xupp(n)
character
&     Prob*8, cu(lencu)*8, cw(lencw)*8,
&     Fnames(nFname)*8, xnames(nxname)*8

The SNOPTA interface accepts a format that allows the constraints and variables to be defined in any order. The optimization problem is assumed to be in the form

\[ \begin{align} \min_x \quad & F_{obj}(x) \\ \text{subject to} \quad\quad & l_x \le x \le u_x, \quad l \le F(x) \le u \\ \end{align} \]

where the upper and lower bounds are constant, \(F(x)\) is a vector of smooth linear and nonlinear constraint functions \(F_i(x)\), and \(F_{obj}(x)\) is one of the components of \(F\) to be minimized, as specified by the input parameter ObjRow. (The option Maximize specifies that \(F_{obj}(x)\) should be maximized instead of minimized.)

Ideally, the first derivatives (gradients) of \(F_i\) should be known and coded by the user. If only some gradients are known, snoptA estimates the missing ones by finite differences.

Note that upper and lower bounds are specified for all variables and functions. This form allows full generality in specifying various types of constraint. Special values are used to indicate absent bounds (\(l_j = -\infty\) or \(u_j = +\infty\) for appropriate \(j\)). Free variables and free constraints (“free rows”) have both bounds infinite. Fixed variables and equality constraints have \(l_j = u_j\).

In general, the components of \(F\) are structured in the sense that they are formed from sums of linear and nonlinear functions of just some of the variables. This structure can be exploited by snoptA.

The user-defined subroutine usrfun will compute the functions and (if necessary) their derivatives.

subroutine usrfun
&   ( Status, n, x,
&     needf, nF, f,
&     needG, lenG, G,
&     cu, lencu, iu, leniu, ru, lenru )

integer
&     lencu, lenG, leniu, lenru, n, needf, needG, nF, Status,
&     iu(leniu)
double precision
&     f(nF), G(lenG), ru(lenru), x(n)
character
&     cu(lencu)*8

The sparsity pattern of the Jacobian matrix of the problem must be defined in the arrays (iAfun, jAvar, A) and (iGfun, jGvar). Only nonzero elements should be defined. (iAfun, jAvar, A) defines the coordinates and (constant) values of the linear elements of the Jacobian. (iGfun, jGvar) defines the coordinates of the nonlinear elements of the Jacobian. The values themselves are computed in usrfun.

snJac

If the user does not provide derivative information, then snJac must be called to automatically determine the sparsity pattern of the Jacobian matrix.

subroutine snJac
&   ( INFO, iPrint, iSumm, nF, n, usrfun,
&     iAfun, jAvar, lenA, neA, A,
&     iGfun, jGvar, lenG, neG,
&     x, xlow, xupp, mincw, miniw, minrw,
&     cu, lencu, iu, leniu, ru, lenru,
&     cw, lencw, iw, leniw, rw, lenrw )

external
&     usrfun
integer
&     INFO, iPrint, iSumm, nF, n, neA, lenA, neG, lenG, mincw,
&     miniw, minrw, lencu, lencw, leniu, leniw, lenru, lenrw,
&     iAfun(lenA), jAvar(lenA), iGfun(lenG), jGvar(lenG),
&     iu(leniu), iw(leniw)
double precision
&     A(lenA), x(n), xlow(n), xupp(n), ru(lenru), rw(lenrw)
character
&     cu(lencu)*8, cw(lencw)*8

Solving with SNOPTB

subroutine snOptB
&   ( Start, m, n, neA, nName,
&     nnCon, nnObj, nnJac,
&     iObj, ObjAdd, Prob,
&     funcon, funobj,
&     Acol, indA, locA, bl, bu, Names,
&     hs, x, pi, rc,
&     INFO, mincw, miniw, minrw,
&     nS, nInf, sInf, Obj,
&     cu, lencu, iu, leniu, ru, lenru,
&     cw, lencw, iw, leniw, rw, lenrw )

external
&     funcon, funobj
integer
&     INFO, iObj, lencu, lencw, leniu, leniw, lenru, lenrw, m,
&     mincw, miniw, minrw, n, neA, nInf, nName, nnCon, nnJac, nnObj,
&     nS, hs(n+m), indA(neA), iu(leniu), iw(leniw), locA(n+1)
double precision
&     Obj, ObjAdd, sInf, Acol(neA), bl(n+m), bu(n+m), pi(m),
&     rc(n+m), ru(lenru), rw(lenrw), x(n+m)
character*(*)
&     Start
character
&     Prob*8, cu(lencu)*8, cw(lencw)*8, Names(nName)*8

SNOPTB solves problems of the form:

\[ \begin{align} \min_x \quad & f(x) \\ \text{subject to} \quad & l \le c(x) \le u \\ \end{align} \]

with the problem data ordered such that nonlinear constraints and variables come first.

The user-defined subroutines funcon and funobj define the nonlinear constraint and nonlinear component of the objective functions and ideally their gradients.

subroutine funcon
&   ( mode, nnCon, nnJac, neJac,
&     x, fCon, gCon, nState,
&     cu, lencu, iu, leniu, ru, lenru )

integer
&     lencu, leniu, lenru, mode, neJac, nnCon, nnJac, nState,
&     iu(leniu)
double precision
&     fCon(nnCon), ru(lenru), x(nnJac)
character
&     cu(lencu)*8
!!!double precision   gCon(nnCon,nnJac)  ! Dense  ! Choose ONE of these
double precision   gCon(neJac)        ! Sparse
subroutine funobj
&   ( mode, nnObj,
&     x, fObj, gObj, nState,
&     cu, lencu, iu, leniu, ru, lenru )

integer
&     lencu, leniu, lenru, mode, nnObj, nState, iu(leniu)
double precision
&     fObj, gObj(nnObj), ru(lenru), x(nnObj)
character
&     cu(lencu)*8

We refer the user to Section 4 of the SNOPT7 User’s Manual for detailed information on how the problem should be structured for SNOPTB.

Solving with SNOPTC

subroutine snOptC
&   ( Start, m, n, neA, nName,
&     nnCon, nnObj, nnJac,
&     iObj, ObjAdd, Prob,
&     usrfun,
&     Acol, indA, locA, bl, bu, Names,
&     hs, x, pi, rc,
&     INFO, mincw, miniw, minrw,
&     nS, nInf, sInf, Obj,
&     cu, lencu, iu, leniu, ru, lenru,
&     cw, lencw, iw, leniw, rw, lenrw )

external
&     usrfun
integer
&     INFO, iObj, lencu, leniu, lenru, lencw, leniw, lenrw,
&     mincw, miniw, minrw, m, n, neA, nName, nS, nInf, nnCon,
&     nnObj, nnJac, indA(neA), hs(n+m), locA(n+1), iu(leniu),
&     iw(leniw)
double precision
&     Obj, ObjAdd, sInf, Acol(neA), bl(n+m), bu(n+m), pi(m),
&     rc(n+m), ru(lenru), rw(lenrw), x(n+m)
character*(*)
&     Start
character
&     Prob*8, Names(nName)*8, cu(lencu)*8, cw(lencw)*8

SNOPTC is identical to SNOPTB except for the user-defined subroutines. For SNOPTC, a single user-defined subroutine usrfun is required that computes both the objective and its gradient and the constraints and the Jacobian matrix.

subroutine usrfun
&   ( mode, nnObj, nnCon, nnJac, nnL, neJac,
&     x, fObj, gObj, fCon, gCon,
&     nState, cu, lencu, iu, leniu, ru, lenru )

integer
&     lencu, leniu, lenru, mode, nnObj, nnCon, nnJac, nnL, neJac,
&     nState, iu(leniu)
double precision
&     fObj, fCon(nnCon), gObj(nnObj), ru(lenru), x(nnL)
character
&     cu(lencu)*8
!!!double precision   gCon(nnCon,nnJac)  ! Dense  ! Choose ONE of these
double precision   gCon(neJac)        ! Sparse

Setting and Getting Options

snSpec

subroutine snSpec
&   ( iSpecs, INFO, cw, lencw, iw, leniw, rw, lenrw )
integer
&     iSpecs, INFO, lencw, leniw, lenrw, iw(leniw)
double precision
&     rw(lenrw)
character
&     cw(lencw)*8

snSpec reads options from a file. iSpecs should be set by the user to the Fortran file unit number associated with the specifications file. The file should also be opened for reading. If options are successfully read, the routine returns an iExit value of 101 or 107. The workspace arrays will be appropriately updated with the options.

snSpecF

subroutine snSpecF
&   ( specsfile, INFO, cw, lencw, iw, leniw, rw, lenrw )
character*(*)
&     specsfile
integer
&     INFO, lencw, leniw, lenrw, iw(leniw)
double precision
&     rw(lenrw)
character
&     cw(lencw)*8

snSpecF is an alternative routine for reading options from a file. specsfile should be set to the specifications filename. If options are successfully read, the routine returns an iExit value of 101 or 107. The workspace arrays will be appropriately updated with the options.

snSet

subroutine snSet
&   ( option, iPrint, iSumm, Errors,
&             cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     option
integer
&     Errors, iPrint, iSumm, lencw, leniw, lenrw, iw(leniw)
double precision
&     rw(lenrw)
character
&     cw(lencw)*8

snSet is called to set an option. The input argument option should be a character string containing the keyword of the option to modify and the desired value (in character format).

snSetI

subroutine snSeti
&   ( option, ivalue, iPrint, iSumm, Errors,
&                     cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     option
integer
&     Errors, ivalue, iPrint, iSumm, lencw, leniw, lenrw, iw(leniw)
double precision
&     rw(lenrw)
character
&     cw(lencw)*8

snSetI is called to set an integer-valued option. The input argument option should be a character string containing the keyword of the option to modify. ivalue is the desired integer value.

snSetR

subroutine snSetr
&   ( option, rvalue, iPrint, iSumm, Errors,
&                     cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     option
integer
&     Errors, iPrint, iSumm, lencw, leniw, lenrw, iw(leniw)
double precision
&     rvalue, rw(lenrw)
character
&     cw(lencw)*8

snSetR is called to set an real-valued option. The input argument option should be a character string containing the keyword of the option to modify. rvalue is the desired real value.

snGetC

subroutine snGetc
&   ( option, cvalue, Errors, cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     option
integer
&     Errors, lencw, leniw, lenrw, iw(leniw)
character
&     cvalue*8, cw(lencw)*8
double precision
&     rw(lenrw)

snGetC is called to retrieve an option value. The input argument option should be a character string containing the keyword of the option to modify. cvalue is a character string containing the value of the option in character format. Errors indicates the number of errors encountered while retrieving the option value.

snGetI

subroutine snGeti
&   ( option, ivalue, Errors, cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     option
integer
&     Errors, ivalue, lencw, leniw, lenrw, iw(leniw)
character
&     cw(lencw)*8
double precision
&     rw(lenrw)

snGetI is called to retrieve an integer-valued option. The input argument option should be a character string containing the keyword of the option to modify. ivalue will contain the value of the option. Errors indicates the number of errors encountered while retrieving the option value.

snGetR

subroutine snGetr
&   ( option, rvalue, Errors, cw, lencw, iw, leniw, rw, lenrw )

character*(*)
&     option
integer
&     Errors, lencw, leniw, lenrw, iw(leniw)
character
&     cw(lencw)*8
double precision
&     rvalue, rw(lenrw)

snGetR is called to retrieve a real-valued option. The input argument option should be a character string containing the keyword of the option to modify. rvalue will contain the value of the option. Errors indicates the number of errors encountered while retrieving the option value.