CONOPT
Loading...
Searching...
No Matches
Overview over CONOPT routines – Fortran users

To start CONOPT you will in general have to go through 7 steps:

  1. Create and initialize a control vector where you can register size characteristics and callback routines for your model. The control vector can also be used to register other information such as user memory and working memory. The standard declaration and execution sections for this task are:
    Integer :: CntSize
    Integer, Dimension(:), Allocatable :: CntVect
    Integer :: COIDEF_Size
    Integer :: COIDEF_Ini
    Integer :: COI_Error
    ..
    CntSize = coidef_size()
    Allocate( CntVect(CntSize) )
    coiHandle_t CntVect
    Definition comdecl.h:14
    int COI_Error
    Definition comdecl.h:15
    integer function coidef_size()
    returns the size the Control Vector must have, measured in standard Integer units.
    Definition coistart.f90:176
    integer function coidef_ini(cntvect)
    initializes the Control Vector by placing default values in the various positions.
    Definition coistart.f90:201
    where COI_Error represent an error return code.


  1. Define the basic sizes of the model. Declarations and execution are:
    INTEGER :: COIDEF_NumVar
    INTEGER :: COIDEF_NumCon
    INTEGER :: COIDEF_NumNz
    INTEGER :: COIDEF_NumNLNZ
    ..
    integer function coidef_numvar(cntvect, numvar)
    defines the number of variables in the model.
    Definition coistart.f90:358
    integer function coidef_numnz(cntvect, numnz)
    defines the number of nonzero elements in the Jacobian.
    Definition coistart.f90:437
    integer function coidef_numnlnz(cntvect, numnlnz)
    defines the Number of Nonlinear Nonzeros.
    Definition coistart.f90:476
    integer function coidef_numcon(cntvect, numcon)
    defines the number of constraints in the model.
    Definition coistart.f90:398
    where the error return codes are accumulated into COI_Error. COI_Error can be tested at any point in the program.


  1. Define that you use Fortran vectors with first index 1 and that you use Fortran argument passing conventions:
    INTEGER :: COIDEF_Base
    INTEGER :: COIDEF_Fortran
    ..
    integer function coidef_base(cntvect, base)
    define the Base index for vectors.
    Definition coistart.f90:743
    integer function coidef_fortran(cntvect)
    define Fortran Conventions for Argument Passing.
    Definition coistart.f90:779

  2. Define the optimization direction and the objective function or the objective variable:
    INTEGER :: COIDEF_OptDir
    INTEGER :: COIDEF_ObjCon
    -or-
    INTEGER :: COIDEF_ObjVar
    ..
    -or-
    integer function coidef_objcon(cntvect, objcon)
    defines the Objective Constraint.
    Definition coistart.f90:629
    integer function coidef_optdir(cntvect, optdir)
    defines the Optimization Direction.
    Definition coistart.f90:552
    integer function coidef_objvar(cntvect, objvar)
    defines the Objective Variable.
    Definition coistart.f90:586
    Note
    The index of the objective is interpreted according to the base defined in coidef_base().
    The routines used above are all described in section The Control Vector where a number of similar optional routines also are described.


  1. Register your callback routines. The standard declaration and execution sections for this task are:

    Integer, External :: My_ReadMatrix
    Integer, External :: My_FDEval
    Integer, External :: My_Status
    Integer, External :: My_Solution
    Integer, External :: My_Message
    Integer, External :: My_ErrMsg
    .. etc. for optional callback routines
    Integer :: COIDEF_ReadMatrix
    Integer :: COIDEF_FDEval
    Integer :: COIDEF_Status
    Integer :: COIDEF_Solution
    Integer :: COIDEF_Message
    Integer :: COIDEF_ErrMsg
    .. etc. for registration routines for optional callback routines
    .. etc. for registration of optional callback routines
    integer function coidef_fdeval(cntvect, coi_fdeval)
    define callback routine for performing function and derivative evaluations.
    integer function coidef_errmsg(cntvect, coi_errmsg)
    define callback routine for returning error messages for row, column or Jacobian elements.
    integer function coidef_message(cntvect, coi_message)
    define callback routine for handling messages returned during the solution process.
    integer function coidef_readmatrix(cntvect, coi_readmatrix)
    define callback routine for providing the matrix data to CONOPT.
    integer function coidef_status(cntvect, coi_status)
    define callback routine for returning the completion status.
    integer function coidef_solution(cntvect, coi_solution)
    define callback routine for returning the final solution values.

    The list above includes all mandatory callback routines.

    Note
    FDEval only is mandatory for nonlinear models.


  2. Register your CONOPT license. The license consists of a string defining the user and three integers with information about the type and date of the license:
    Integer :: COIDEF_License
    ..
    “Lic_String”)
    integer function coidef_license(cntvect, licint1, licint2, licint3, licstring)
    define the License Information.
    Definition coistart.f90:680
    The license routines are described in section The Control Vector. The license is usually distributed in the form of an include file named conoptf.lic that contains the call to coidef_license() with the correct license information. If you add a copy of this file to the directory with your other Fortran files then you can in most cases replace the license calls with
    Include ‘conoptf.lic’


  1. Call CONOPT. The standard call is:

    Integer :: COI_Solve, RetCode
    ..
    RetCode = coi_solve( CntVect )
    integer function coi_solve(cntvect)
    method for starting the solving process of CONOPT.
    Definition coistart.f90:14

    coi_solve() will start CONOPT. CONOPT will allocate the necessary memory and it will call the user defined callback routine registered with coidef_readmatrix(), here called My_ReadMatrix, to set up the model. During the optimization, CONOPT will repeatedly need information about the nonlinear functions and their first derivatives and for this purpose it will call the user defined callback registered with coidef_fdeval(), here called My_FDEval. During the optimization CONOPT will send messages to the modeler using the callback routine registered with coidef_message(), here called My_Message, and it may also call the error message routine registered with coidef_errmsg(), here called My_ErrMsg. When the optimization is finished, CONOPT will call two output routines that return the solution to the modeler. They are registered with coidef_status() and coidef_solution() and are here called My_Status and My_Solution. Finally, coi_solve() will return.

    Several optional callback routines may be called if they have been registered. They can provide more information about the model from the modeler to CONOPT or more information about the solution process from CONOPT to the modeler.