Download LINDO API USER MANUAL

Transcript
SOLVING NONLINEAR PROGRAMS
369
The length of the objective is calculated as the difference of the current count of codes and the
beginning position:
/* Length of objective */
objs_length[iobj] = ikod - objs_beg[iobj];
Since there is only a single objective, the constraint rows are developed. The first constraint row,
constraint 0, is a simple linear equation constrained to less-than-or-equal-to zero:
/*
* Instruction code of constraint 0:
*
* x0 + x1 - 4 <= 0;
*/
For this constraint, the type of constraint must first be defined to be less-than-or-equal-to:
/* Constraint type */
ctype[icon]= 'L';
/* less or than or equal to */
The beginning position of the constraint in the instruction list vector is set at the current count on the
instruction code:
/* Beginning position of constraint 0 */
cons_beg[icon]= ikod;
Again, following the principles of postfix, the corresponding instruction list of this constraint function
is placed into the code vector accordingly:
/* Instruction
code[ikod++]=
code[ikod++]=
code[ikod++]=
code[ikod++]=
code[ikod++]=
code[ikod++]=
code[ikod++]=
code[ikod++]=
list code */
EP_PUSH_VAR;
0;
EP_PUSH_VAR;
1;
EP_PLUS;
EP_PUSH_NUM;
3;
EP_MINUS;
At the end, the length of the current instruction list is set:
/* Length of constraint 0 */
cons_length[icon] = ikod - cons_beg[icon];
The count on constraint rows is then incremented by one:
/* Increment the constraint count */
icon++;
Following the same rule, the instruction lists for constraint 1, 2, 3, 4, and 5 can also be built
accordingly. After completely specifying the instruction lists and their related information, this model
definition segment is finished by declaring the total number of codes in the instruction lists:
/* Total number of items in the instruction list */
lsize = ikod;
LINDO API provides an user option in dealing with the model, which is linearization. To use this
option, it should be specified before you call LSloadInstruct to load nonlinear codes. The example
model contains nonlinear components of abs(), if(), complementary constraint, and x* y (where x
and/or y are binary 0/1 variables). All of these nonlinear components are linearizable. Therefore, if the