CONOPT
|
Model with derivatives that become constant after other variables are fixed. The model is similar to postmo01 but the bounds are changed.
This is a CONOPT implementation of the GAMS model:
!! e1: log(x1) =E= x2; !! e2: exp(x3) =E= x1; !! max x2 !! 0.01 <= x1 x1.l = 1 !! -1000 <= x2 <= 1; x2.l = 0 !! -2 <= x3 <= +inf; x3.l = 0; !!
The bounds on x2 prevent e1 from being posttriangular immediately. However, due to the monotonicity the bounds can be transferred to x1. Similarly, the bounds on x1 can be moved to x2 and the model ends with one variable and no constraints.
The transfer of bounds work as follows: e1: the inverval -1000 <= x2 <= 1
is transferred to exp(-1000) <= x1 <= exp(1) = 2.718
where only the upper bound is tighter than the input bound. e2: the inverval 0.01 <= x1 <= exp(1)
from before is transferred to -4.605 <= x3 <= 1
where again only the upper bound is tighter that the input bound.
The expected solution is x2=1
(at upper bound), x1=exp(x2)=exp(1)
, and x3= log(x1) = 1
;
For more information about the individual callbacks, please have a look at the source code.
Definition in file postmo04.f90.
Functions/Subroutines | |
program | postmo04 |
Main program. A simple setup and call of CONOPT. | |
integer function | con_readmatrix (lower, curr, upper, vsta, type, rhs, esta, colsta, rowno, value, nlflag, n, m, nz, usrmem) |
Define information about the model. | |
integer function | con_fdeval (x, g, jac, rowno, jcnm, mode, ignerr, errcnt, n, nz, thread, usrmem) |
Compute nonlinear terms and non-constant Jacobian elements. | |
integer function | con_fdinterval (xmin, xmax, gmin, gmax, jmin, jmax, rowno, jcnm, mode, pinf, n, nj, usrmem) |
Evaluating nonlinear functions and derivatives on an interval. Used in preprocessing. | |
program postmo04 |
Main program. A simple setup and call of CONOPT.
Definition at line 36 of file postmo04.f90.
integer function con_readmatrix | ( | real*8, dimension(n), intent(inout) | lower, |
real*8, dimension(n), intent(inout) | curr, | ||
real*8, dimension(n), intent(inout) | upper, | ||
integer, dimension(n), intent(inout) | vsta, | ||
integer, dimension(m), intent(out) | type, | ||
real*8, dimension(m), intent(inout) | rhs, | ||
integer, dimension(m), intent(inout) | esta, | ||
integer, dimension(n+1), intent(inout) | colsta, | ||
integer, dimension(nz), intent(out) | rowno, | ||
real*8, dimension(nz), intent(inout) | value, | ||
integer, dimension(nz), intent(inout) | nlflag, | ||
integer, intent(in) | n, | ||
integer, intent(in) | m, | ||
integer, intent(in) | nz, | ||
real*8, dimension(*) | usrmem ) |
Define information about the model.
where:
LOWER
: Vector of lower bounds on the variables. CONOPT will fill the vector with a special internal value that represent minus infinity or no lower bound before issuing the callback.CURR
: Vector of initial values of the variables. CONOPT will fill the vector with the default initial value of zero before issuing the callback.UPPER
: Vector of upper bounds on the variables. CONOPT will fill the vector with a special internal value that represent plus infinity or no upper bound before issuing the callback.VSTA
: Vector of initial status values for the variable. VSTA
is only used if coidef_inistat() was called with IniStat = 1 or 2
.
If IniStat = 1
the value of VSTA
must be defined as:
CURR = LOWER
or CURR = UPPER
) or super-basic, andand if IniStat = 2
the value of VSTA
must be defined as:
IniStat = 1
is simple to implement by hand, while IniStat = 2
is consistent with the output status defined in the Solution
callback method. Note that if the numerical value in CURR
are inconsistent with the status value, the numerical values will be used.
If IniStat = 0 (the default value) CONOPT will not use VSTA
and you do not have to define it.
TYPE
: Vector of equation types. The values of TYPE have the following meaning:
There is no default value for TYPE
so it must be defined for all constraints. Note that CONOPT does not accept ranges.
RHS
: Vector of right hand sides values. The default value is zero.ESTA
: Vector of initial status values for the slacks in the constraints. ESTA
is only used if coidef_inistat() was called with IniStat = 1 or 2
.
If IniStat = 1
the value of ESTA
must be defined as:
and if IniStat = 2
the value of ESTA
must be defined as:
Again, IniStat = 1
is simple to implement by hand, while IniStat = 2
is consistent with the output status defined in Solution
callback method.
If IniStat = 0
(the default value) then CONOPT will not use ESTA
.
COLSTA
: Vector of start of column pointers. All non-zero Jacobian elements must be sorted by column, i.e. all elements in column i
comes before all elements in column i+1
. COLSTA
points to the first element in each column. If you have selected Base = 1
(Fortran conventions) then COLSTA
must therefore satisfy: COLSTA(1) = 1
and COLSTA(N+1) = NZ+1
. If you have selected Base = 0
(C conventions) then COLSTA
must therefore satisfy: COLSTA[0] = 0
and COLSTA[N] = NZ
. COLSTA
must in both cases be increasing.ROWNO
: Vector of row or equation numbers of the non-zeros. The numbers must be in the range 1 through M inclusive if you have defined Base = 1
(Fortran conventions) and in the range 0 to M-1 inclusive if you have defined Base = 0
(C conventions). Although the columns are sorted, the rows do not have to be sorted within each column.VALUE
: Vector of values of the Jacobian elements. VALUE
must be defined for all constant Jacobian elements, i.e. elements for which the following NLFLAG = 0
. VALUE
does not have to be defined for varying Jacobian elements.NLFLAG
: Vector of nonlinearity flags:
NLFLAG
is not read if the model is linear, i.e. if NLNZ = 0
, otherwise it must be defined. Note that if you have an LP model, you should probably select a specialized LP algorithm instead of CONOPT.
N
: Number of variables as defined in coidef_numvar().M
: Number of constraints as defined in coidef_numcon().NZ
: Number of Jacobian elements as defined in coidef_numnz().USRMEM
: User memory as defined in coidef_usrmem() (Only for Fortran and C API).The lower bounds in LOWER
must be less than or equal to the upper bounds in UPPER
. Some of the bounds may be -INF
or +INF
, which are the bounds CONOPT assigns by default. If a bound is infinite, the user should normally not change the corresponding entry in LOWER
or UPPER
. If it is more convenient for the modeler to assign a value representing infinity it should be done using the values that are present in LOWER
and UPPER
when ReadMatrix
is called, for example taken from the first element before any assignments are done. As an alternative, you may define the numerical value of Infinity to be used by the solution algorithm in option RTMAXV
and store the same value in UPPER
and -RTMAXV
in LOWER
.
The values in CURR
, both those defined by the modeler and those defined by default, are without warning moved to the nearest bound if they are outside the bounds.
LOWER
and UPPER
. Definition at line 141 of file postmo04.f90.
integer function con_fdeval | ( | real*8, dimension(n), intent(in) | x, |
real*8, intent(inout) | g, | ||
real*8, dimension(n), intent(inout) | jac, | ||
integer, intent(in) | rowno, | ||
integer, dimension(nz), intent(in) | jcnm, | ||
integer, intent(in) | mode, | ||
integer, intent(in) | ignerr, | ||
integer, intent(inout) | errcnt, | ||
integer, intent(in) | n, | ||
integer, intent(in) | nz, | ||
integer, intent(in) | thread, | ||
real*8, dimension(*) | usrmem ) |
Compute nonlinear terms and non-constant Jacobian elements.
where:
X
: Vector with the point of evaluation. The point is provided by CONOPT.G
: Scalar function value: The value of G
must be returned by the modeler if MODE = 1 or 3
, otherwise it will be ignored. If FVincLin
defined in coidef_fvinclin() is 0, the default value, then G
should return the sum of the nonlinear terms in row number ROWNO
, and if FVincLin
is 1 then G
should return the sum of both linear and nonlinear terms. The nonlinear terms are defined as all terms that correspond to Jacobian elements with NLFLAG = 1
when loading the model. Constant terms in nonlinear constraints may be included in G
provided RHS
in ReadMatrix
is adjusted correspondingly. Constant terms in linear constraints may also be defined here provided FVforAll
is given the non default value 1 in coidef_fvforall(). In summary, G
should include the following, depending on FVincLin
and FVforAll
:FVforAll \ FVincLin | 0 | 1 |
---|---|---|
0 | G includes nonlinear terms only. FDEval is only called for nonlinear rows. | G includes linear and nonlinear terms. FDEval is only called for nonlinear rows. |
1 | G includes nonlinear and constant terms. FDEval is called for all rows. | G includes linear, nonlinear, and constant terms. FDEval is called for all rows. |
JAC
: Vector of Jacobian values. All the nonlinear Jacobian values in row number ROWNO
(and only these) should be evaluated. The indices in JAC
are the indices of the variables, i.e. the derivative with respect to X(I)
should be returned in JAC(I)
. JAC
must be returned by the modeler if MODE = 2 or 3
; otherwise it must be ignored.ROWNO
: Scalar with the number of the row for which nonlinearities are to be evaluated. Is provided by CONOPT. Note that if FVforAll = 0
, the default value, then FDEval
will only be called for nonlinear rows, and constant terms in linear rows must therefore be included in RHS
in ReadMatrix
. If FVforAll = 1
then FDEval
will be called for all rows, and the linear constraints must return any constant term that is not included in the right hand side. CONOPT will initialize G
to zero so FDEval
can just return for linear rows without constant terms. In summary, FDEval
will be called for the following values of ROWNO, depending on FVforAll
:
The row numbers are consistent with the Base selected by the modeler.
JCNM
: Vector with a list of column numbers for the nonlinear nonzero Jacobian elements in the current row. It is only defined when MODE = 2 or 3
. JCNM
and NJ
are provided for modelers that may find this information useful; it can be ignored by others. The numbers are consistent with the Base
(Fortran or C conventions) selected by the modeler.MODE
: Scalar indicator for mode of evaluation, provided by CONOPT:ROWNO
and return the value in G
.ROWNO
and return them in JAC
.IGNERR
: Scalar that indicates whether CONOPT assumes the point to be safe (0)
or potentially unsafe (1)
. During certain parts of the optimization CONOPT will make very long steps and it is not unlikely that one of the constraints is not defined. If an error is encountered while IGNERR
is 1, this error is not included in the ErrLim
limit, and the modeler may skip any error messages that otherwise should be issued from FDEval
.ERRCNT
: Scalar Function Evaluation Error Indicator. FDEval
must set this argument to 1 each time a function value cannot be computed. The counts are accumulated by CONOPT (except when IGNERR
= 1). If their sum exceeds the ErrLim
value defined in coidef_errlim(), CONOPT will stop the optimization, communicate the solution to the modeler with solver status SOLSTA = 5
(Evaluation Error Limit) in callback routine Status, and return control to the modeler. If ERRCNT
has been set by FDEval
then G
and JAC
will not be used and CONOPT will in general try to backtrack to a "safe" point. Note that CONOPT assumes that all functions are defined for all values of the variables between their bounds. CONOPT will never call FDEval
with X
outside the bounds specified in ReadMatrix
. Also see the Progress
callback routine for an alternative way of stopping CONOPT.NEWPT
: Scalar new point indicator, provided by CONOPT:
ROWNO
has changed but the nonlinear variables in X
have not changed. Some variables that are linear in all constraints may also have been changed.NEWPT
is provided by CONOPT as a service to the modeler. It may be used to calculate and reuse terms that depend on X
but are common among several equations, e.g. when some of the equations represent simultaneous sets of differential equations solved by an expensive integration routine.
N
: Number of variables as defined in coidef_numvar().NJ
: Number of nonlinear nonzero Jacobian elements in the current row and number of elements in the JCNM
vector. JCNM
is only defined when MODE = 2 or 3
; when MODE = 1
then NJ
has the value 1 and JCNM
points to a random vector.THREAD
: In some multi-threading environments multiple copies of FDEval
can be called at the same time, (see Multi Threading). THREAD
will hold the number of the thread for the current call of FDEval
. THREAD
is in the interval from 0 to the maximum number of threads allowed for FDEval
.USRMEM
: User memory as defined in coidef_usrmem() (Only for Fortran and C API).You should notice the difference between the ERRCNT
and the return code of FDEval
. A nonzero value returned in ERRCNT
indicates that the current point defined in X
is bad. The function value G
or the derivatives JAC
could not be computed and CONOPT should try to backtrack to a safe point. A nonzero value returned as the value of FDEval
indicates that there is a serious or permanent error and there is no reason to continue the optimization. The return code on FDEval
can for example be used if a data file is not found, or if FDEval
is called with a value of ROWNO
that was not expected.
Definition at line 242 of file postmo04.f90.
integer function con_fdinterval | ( | real*8, dimension(n), intent(in) | xmin, |
real*8, dimension(n), intent(in) | xmax, | ||
real*8, intent(inout) | gmin, | ||
real*8, intent(inout) | gmax, | ||
real*8, dimension(n), intent(inout) | jmin, | ||
real*8, dimension(n), intent(inout) | jmax, | ||
integer, intent(in) | rowno, | ||
integer, dimension(nj), intent(in) | jcnm, | ||
integer, intent(in) | mode, | ||
real*8, intent(in) | pinf, | ||
integer, intent(in) | n, | ||
integer, intent(in) | nj, | ||
real*8, dimension(*), intent(inout) | usrmem ) |
Evaluating nonlinear functions and derivatives on an interval. Used in preprocessing.
where:
XMIN
: Vector of lower bound on the variables. Provided by CONOPT.XMAX
: Vector of upper bound on the variables. Provided by CONOPTGMIN
: Scalar. If MODE = 1 or 3
then a lower bound on the function value in constraint ROWNO
may be returned in GMIN
.GMAX
: Scalar. If MODE = 1 or 3
then a upper bound on the function value in constraint ROWNO
may be returned in GMAX
.JMIN
: If MODE = 2 or 3
then a lower bound on the derivatives of the function value in constraint ROWNO
with respect to the variable I
may be returned in JMIN(I)
.JMAX
: If MODE = 2 or 3
then an upper bounds on the derivatives of the function value in constraint ROWNO
with respect to the variable I
may be returned in JMAX(I)
.ROWNO
: The number of the current constraint. FDInterval
will only be called for nonlinear constraints.JCNM
: List of column numbers for the nonlinear nonzero Jacobian elements in the current row. It is only defined when MODE = 2 or 3
. When MODE = 1
NJ
has the value 1 and JCNM
points to a random vector. JCNM
and NJ
are provided for modelers that may find this information useful; it can be ignored by others.MODE
: Indicator for mode of evaluation, provided by CONOPT:ROWNO
and return the interval in [GMIN, GMAX]
.ROWNO
and return the intervals in [JMIN, JMAX]
.MODE = 3
is not used).PINF
: Plus Infinity. XMAX
uses the special PINF
to represent no upper bound and XMIN
uses -PINF
to represent no lower bound. Provided by CONOPT.N
: Number of variables in the model.NJ
: Number of nonlinear nonzero Jacobian elements in the current row and number of elements in the JCNM
vector. JCNM
is only defined when MODE = 2 or 3
; when MODE = 1
then NJ
has the value 1 and JCNM
points to a random vector.USRMEM
: User memory as defined in coidef_usrmem() (Only for Fortran and C API).There are a few points to note:
FDInterval
works on one constraint at a time.GMIN
to –PINF
, GMAX
to +PINF
and similarly for the relevant elements in JMIN
and JMAX
. Therefore, if you do not have a bound on a function or a derivative value or if the value is infinite, then ignore the return value (or use –PINF
and +PINF
).FDInterval
does not use FVincLin
and FVforAll
which means that GMIN
and GMAX
only should include information about nonlinear terms.ERRCNT
in FDEval
. If there are potential function evaluation errors in an interval this will usually translate into the lower and/or upper bounds being infinite. Definition at line 306 of file postmo04.f90.