To start CONOPT you will in general have to go through 7 steps:
- 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:
..
int CntSize;
..
CntSize = COIDEF_Size();
CntVect = (
int *)malloc( CntSize*
sizeof(
int) );
- Define the basic sizes of the model. Declarations and execution are shown below. Note that the sizes are passed to
COIDEF_Xx
routines by address and it is therefore convenient to declare variables and pass their address: int NumVar, NumCon, NumNZ, NumNlNz;
..
NumVar = XX; NumCon = YY; NumNZ = ZZ; NumNlNz = UU;
int COI_CALLCONV COIDEF_NumVar(coiHandle_t cntvect, int numvar)
defines the number of variables in the model.
int COI_CALLCONV COIDEF_NumNz(coiHandle_t cntvect, int numnz)
defines the number of nonzero elements in the Jacobian.
int COI_CALLCONV COIDEF_NumCon(coiHandle_t cntvect, int numcon)
defines the number of constraints in the model.
int COI_CALLCONV COIDEF_NumNlNz(coiHandle_t cntvect, int numnlnz)
defines the Number of Nonlinear Nonzeros.
- Define that you use C vectors with first index 0 and that you use C argument passing conventions:
int Base;
..
Base = 0;
int COI_CALLCONV COIDEF_Base(coiHandle_t cntvect, int base)
define the Base index for vectors.
int COI_CALLCONV COIDEF_C(coiHandle_t cntvect)
define C Conventions for Argument Passing.
Define the optimization direction and the objective function or the objective variable:
int OptDir;
int ObjCon;
-or-
int ObjVar;
..
OptDir = -1 or +1; ObjCon = XX; -or- ObjVar = XX;
-or-
int COI_CALLCONV COIDEF_ObjVar(coiHandle_t cntvect, int objvar)
defines the Objective Variable.
int COI_CALLCONV COIDEF_ObjCon(coiHandle_t cntvect, int objcon)
defines the Objective Constraint.
int COI_CALLCONV COIDEF_OptDir(coiHandle_t cntvect, int optdir)
defines the Optimization Direction.
- 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.
Register your callback routines. The standard execution section for this task is:
.. etc. for registration of optional callback routines
int COI_CALLCONV COIDEF_ReadMatrix(coiHandle_t cntvect, COI_READMATRIX_t coi_readmatrix)
define callback routine for providing the matrix data to CONOPT.
int COI_CALLCONV COIDEF_Message(coiHandle_t cntvect, COI_MESSAGE_t coi_message)
define callback routine for handling messages returned during the solution process.
int COI_CALLCONV COIDEF_Solution(coiHandle_t cntvect, COI_SOLUTION_t coi_solution)
define callback routine for returning the final solution values.
int COI_CALLCONV COIDEF_Status(coiHandle_t cntvect, COI_STATUS_t coi_status)
define callback routine for returning the completion status.
int COI_CALLCONV COIDEF_ErrMsg(coiHandle_t cntvect, COI_ERRMSG_t coi_errmsg)
define callback routine for returning error messages for row, column or Jacobian elements.
int COI_CALLCONV COIDEF_FDEval(coiHandle_t cntvect, COI_FDEVAL_t coi_fdeval)
define callback routine for performing function and derivative evaluations.
where My_ReadMatrix
, My_FDEval
, ... etc are procedures that conveniently can be placed before the procedure in which the registration above takes place. The list above includes all mandatory callback routines.
- Note
FDEval
only is mandatory for nonlinear models.
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:
char LicString[] = "Lic_String";
int LicCode1 = 451;
int LicCode2 = 44;
int LicCode3 = 543;
..
LicString,strlen(LicString));
int COI_CALLCONV COIDEF_License(coiHandle_t cntvect, int licint1, int licint2, int licint3, const char *licstring)
define the License Information.
The license routines are described in section The Control Vector. The license is usually distributed in the form of an include file named conoptc.lic
that contains the correct version of the first four lines. If you add a copy of this file to the directory with your other C files then you can in most cases replace the four license defining lines by
Call CONOPT. The standard call is:
int COI_CALLCONV COI_Solve(coiHandle_t cntvect)
method for starting the solving process of CONOPT.
COI_Solve() will start CONOPT. CONOPT will allocate 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.