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) )
    COI_Error = coidef_ini( CntVect )
    coiHandle_t CntVect
    Definition comdecl.h:14
    int COI_Error
    Definition comdecl.h:15
    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
    ..
    COI_Error = COI_Error + coidef_numvar( CntVect, XX )
    COI_Error = COI_Error + coidef_numcon( CntVect, XX )
    COI_Error = COI_Error + coidef_numnz( CntVect, XX )
    COI_Error = COI_Error + coidef_numnlnz( CntVect, XX )
    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
    ..
    COI_Error = COI_Error + coidef_base( CntVect, +1 )
    COI_Error = COI_Error + coidef_fortran( CntVect )

  2. Define the optimization direction and the objective function or the objective variable:
    INTEGER :: COIDEF_OptDir
    INTEGER :: COIDEF_ObjCon
    -or-
    INTEGER :: COIDEF_ObjVar
    ..
    COI_Error = COI_Error + coidef_optdir( CntVect, +1 or -1 )
    COI_Error = COI_Error + coidef_objcon( CntVect, XX )
    -or-
    COI_Error = COI_Error + coidef_objvar( CntVect, XX )
    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
    COI_Error = COI_Error + coidef_readmatrix(CntVect,My_ReadMatrix)
    COI_Error = COI_Error + coidef_fdeval( CntVect, My_FDEval )
    COI_Error = COI_Error + coidef_status( CntVect, My_Status )
    COI_Error = COI_Error + coidef_solution( CntVect, My_Solution )
    COI_Error = COI_Error + coidef_message( CntVect, My_Message )
    COI_Error = COI_Error + coidef_errmsg( CntVect, My_ErrMsg )
    .. etc. for registration of optional callback routines

    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
    ..
    COI_Error = COI_Error + coidef_license(CntVect,XX1,XX2,XX3, &
    “Lic_String”)
    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 )

    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.