![](https://csdnimg.cn/release/download_crawler_static/10144414/bge.jpg)
2.7 Use of ADiGator
1
to Generate NLP Solver Derivatives 14
2.7 Use of ADiGator
1
to Generate NLP Solver Derivatives
As stated earlier, one of the options for generating derivatives required by the NLP solver is to use the open-
source automatic MATLAB differentiation software ADiGator.
1
The software ADiGator is described in detail
in Ref. 1 and can be found at http://sourceforge.net/projects/adigator. The option for using ADiGa-
tor is invoked by setting setup.derivatives.method = ’adigator’. Assuming the user has obtained ADiGator
from http://sourceforge.net/projects/adigator and the option setup.derivatives.method has been
set to ’adigator], the first and/or second derivative functions (depending upon which NLP solver is being used
an which derivative level is chosen) of the user-supplied optimal control functions setup.functions.continuous
setup.functions.endpoint are obtained simply by executing GPOPS − II on the user setup. At the start of
the GPOPS − II run, screen output will be displayed that provides a status of the derivative file generation.
After generating the derivative files, GPOPS − II will run in the usual mode, this time using the derivative
code generated by ADiGator instead of using the default sparse finite-difference method.
An important aspect of using ADiGator is that the user may not want to regenerate derivative code after
these files have already been generated. In GPOPS − II the following approach is used to prevent regeneration
of ADiGator derivative code and simply use the derivative files that have already been written by ADiGator.
First, suppose that the ADiGator derivative files have been generated from a run of GPOPS − II where
the option setup.derivatives.method has been set to ’adigator’. (regardless of whether the NLP solver
converges to a solution). Upon the next execution, GPOPS − II checks to see if either (1) the creation dates
of the derivatives files are earlier than the creation dates of the user continuous and endpoint function files or
(2) if any of the files that are supposed to be generated by ADiGator are missing (for example, the user may
have deleted one or more files created by ADiGator). If either of these conditions is true, then GPOPS − II
regenerates the derivative files. Otherwise, both conditions are false (that is, all files that are supposed to be
created by ADiGator exist in the directory where the example resides and the creation dates on all derivative
files is later than the creation dates of the user function files), then GPOPS − II uses the existing ADiGator
derivative files on the next run.
An alterative to having GPOPS − II automatically detect if the current derivative files are valid is to
insert the proper field names for the ADiGator derivative files into the user’s main file. Specifically, the
following fields are added to any setup structure created during the execution of GPOPS − II:
setup.adigatorgrd.continuous = @continuousF unGrd
setup.adigatorgrd.endpoint = @endpointF unGrd
setup.adigatorhes.continuous = @continuousF unHes
setup.adigatorhes.endpoint = @endpointF unHes
The first two fields, setup.adigatorgrd.continuous and setup.adigatorgrd.endpoint, correspond to the
first derivatives of the optimal control functions for use with the NLP solver, while the third and fourth fields,
setup.adigatorhes.continuous and setup.adigatorhes.endpoint, correspond to the second derivatives
of the user-defined optimal control problem functions for use with the NLP solver. Now, if a user wants to
user specific ADiGator derivative files (and, of course, does not want the derivative files to be regenerated),
the aforementioned fields should be added to the setup structure in the user’s main file. Please note that
the “setup” created by the user can have any name the user chooses (and is, thus, denoted by slanted red
letters), but any setup created by GPOPS − II has the hard-coded name setup.
Finally, a few important points should be noted when using ADiGator with GPOPS − II. The first
important point pertains to when the derivative files are regenerated. Specifically, it is recommended to
regenerate the derivative files if the user has any doubt as to whether any changes have been made to anything
in the problem setup or the associated function files. Now, recall from above that the derivative files are
generated only if GPOPS − II detects a change in either the user continuous or theuser endpoint functions
since the last time the derivative files were generated. Note, however, that this automatic detection procedure
is limited in that GPOPS − II will not detect changes in any functions upon which the user functions depend.
In other words, if the user continuous or endpoint function depends upon another function and the user has
made changes in the dependent function (but not in the actual user functions themselves), then changes
GPOPS − II will not regenerate the derivative functions using ADiGator. As a result, the user needs to
know if any changes have been made to any of these dependent functions and regenerate the derivative files
as is necessary. In this case the easiest way to regenerate the derivative files is to delete any or all of the files