CONOPT
|
Functions | |
void | PD_ModelData::buildModel () |
adds the variables and constraints for the problem | |
int | PD_ModelData::FDEval (const double x[], double *g, double jac[], int rowno, const int jacnum[], int mode, int ignerr, int *errcnt, int numvar, int numjac, int thread) override |
defines the nonlinearities of the model by returning numerical values. | |
int | main (int argc, char **argv) |
Main program. A simple setup and call of CONOPT. | |
This is a CONOPT implementation of the Pindyck model from the GAMS model library. The GAMS model follows as documentation:
!! $Ontext !! !! This model finds the optimal pricing and extraction of oil for !! the opec cartel. !! !! Reference: Pindyck R S, Gains to Producers from the !! Cartelization of Exhaustible Resources, Review of !! Economics and Statistics, Volume 60, pp 238-251, 1978. !! !! $Offtext !! !! Sets t overall time horizon / 1974*1990 / !! to(t) optimization period / 1975*1990 / !! !! Parameter demand(t) equilibrium world demand for fixed prices; !! demand(to) = 1. + 2.3*1.015**(ord(to)-1); !! !! Variables p(t) world price of oil !! td(t) total demand for oil !! s(t) supply of oil by non-opec contries !! cs(t) cummulative supply by non-opec contries !! d(t) demand for opec-oil !! r(t) opec reserves !! rev(t) revenues in each period !! profit !! !! Positive Variables p,td,s,cs,d,r !! !! Equations tdeq(t) total demand equation !! seq(t) supply equation for non-opec contries !! cseq(t) accounting equation for cummulative supply !! deq(t) demand equation for opec !! req(t) accounting equation for opec reserves !! drev(t) yearly objective function value !! tprofit total objective function; !! !! $Double !! !! tdeq(t-1).. td(t) =e= 0.87*td(t-1) - 0.13*p(t) + demand(t); !! seq(t-1).. s(t) =e= 0.75*s(t-1) + (1.1+0.1*p(t))*1.02**(-cs(t)/7); !! cseq(t-1).. cs(t) =e= cs(t-1) + s(t); !! deq(to).. d(to) =e= td(to) - s(to); !! req(t-1).. r(t) =e= r(t-1) - d(t); !! drev(to).. rev(to) =e= d(to)*(p(to)-250/r(to)); !! tprofit.. profit =e= sum(to,rev(to)*1.05**(1-ord(to))); !! !! $Single !! !! * !! * fixed initial conditions !! * !! td.fx('1974') = 18; s.fx ('1974') = 6.5; !! r.fx ('1974') = 500; cs.fx('1974') = 0.0; !! !! td.l(to) = 18; s.l(to)= 7; cs.l(to) = 7*ord(to); !! d.l (to) = td.l(to)-s.l(to); p.l(to) = 14; !! !! Loop(t$to(t), r.l(t) = r.l(t-1)-d.l(t) ); !! !! Display td.l, s.l, cs.l, d.l, r.l; !! !! Model robert / all / Solve robert maximizing profit using nlp; !!
For more information about the individual callbacks, please have a look at the source code.
|
inline |
adds the variables and constraints for the problem
Define the information for the columns.
We should not supply status information, VSTA.
We order the variables as follows: 0: td, 1: cs, 2: s, 3: d, 4: r, 5: p, and 6: rev. All variables for period 1 appear first followed by all variables for period 2 etc.
td, cs, s, and d have lower bounds of 0, r and p have lower bounds of 1, and rev has no lower bound. All have infinite upper bounds (default). The initial value of td is 18, s is 7, cs is 7*t, d is td-s, p is 14, and r is r(t-1)-d. No initial value for rev.
All variables are created for each of the 16 periods [1975..1990]. Unlike GAMS which uses set t
[1974..1990] and excludes d, p, rev in the first year while fixing the values of the other variables for the first year, we create all variables uniformly across all periods. And to remain consistent with the GAMS model:
Definition at line 45 of file pindyck.cpp.
|
inlineoverridevirtual |
defines the nonlinearities of the model by returning numerical values.
It must be defined by the modeler if the model is nonlinear. The routine is called repeatedly during the optimization so it should be implemented efficiently. Some arguments are provided by CONOPT. The remaining arguments must be defined by the modeler. Note that FDEval
works on one row or equation at a time.
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 conopt::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 conopt::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
: - <b>0:</b> Called for all nonlinear rows only. - <b>1:</b> Called for all rows. 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 conopt::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 conopt::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 conopt::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.
Reimplemented from ConoptModelData.
Definition at line 229 of file pindyck.cpp.
int main | ( | int | argc, |
char ** | argv ) |
Main program. A simple setup and call of CONOPT.
Definition at line 290 of file pindyck.cpp.