CONOPT
Loading...
Searching...
No Matches
largeres2.c
Go to the documentation of this file.
1
6
7#include <stdlib.h>
8#include <stdio.h>
9#include <math.h>
10#include <string.h>
11#include "coiheader.h"
12#include "comdecl.h"
13
14
19int COI_CALLCONV LR_ReadMatrix( double LOWER[], double CURR[], double UPPER[], int VSTA[], int TYPE[], double RHS[],
20 int ESTA[], int COLSTA[], int ROWNO[], double VALUE[],
21 int NLFLAG[], int NUMVAR, int NUMCON, int NUMNZ, void* USRMEM )
22{
23 /* */
24 /* Information about Variables: */
25 /* Default: Lower = -Inf, Curr = 0, and Upper = +inf. */
26 /* Default: the status information in Vsta is not used. */
27 /* */
28 /* Initial value = 100.0 */
29 /* */
30 CURR[0] = 100.0 ;
31 /* */
32 /* Information about Constraints: */
33 /* Default: Rhs = 0 */
34 /* Default: the status information in Esta and the function */
35 /* value in FV are not used. */
36 /* Default: Type: There is no default. */
37 /* 0 = Equality, */
38 /* 1 = Greater than or equal, */
39 /* 2 = Less than or equal, */
40 /* 3 = Non binding. */
41 /* */
42 /* Constraint 0 */
43 /* Rhs = 10.0 and type Equality */
44 /* */
45 RHS[0] = 10.0 ;
46 TYPE[0] = 0 ;
47 /* */
48 /* Information about the Jacobian. We use the standard method with */
49 /* Rowno, Value, Nlflag and Colsta and we do not use Colno. */
50 /* */
51 /* Colsta = Start of column indices (No Defaults): */
52 /* Rowno = Row indices */
53 /* Value = Value of derivative (by default only linear */
54 /* derivatives are used) */
55 /* Nlflag = 0 for linear and 1 for nonlinear derivative */
56 /* (not needed for completely linear models) */
57 /* */
58 /* Indices */
59 /* X[0] */
60 /* 0: 0 */
61 /* */
62 COLSTA[0] = 0 ;
63 COLSTA[1] = 1 ;
64 ROWNO[0] = 0 ;
65 /* */
66 /* Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear */
67 /* X[0] */
68 /* 0: NL */
69 /* */
70 NLFLAG[0] = 1 ;
71 /* */
72 /* Value (Linear only) */
73 /* X[0] */
74 /* 0: NL */
75 /* */
76 return 0;
77}
78
79
80
85int COI_CALLCONV LR_FDEval( const double X[], double* G, double JAC[], int ROWNO, const int JACNUM[], int MODE,
86 int IGNERR, int* ERRCNT, int NUMVAR, int NUMJAC, int THREAD, void* USRMEM )
87{
88 /* */
89 /* Row 0: exp(x) = 10 */
90 /* */
91
92 if ( ROWNO == 0 ) {
93 /* */
94 /* Mode = 1 or 3. Function value: G = P * Out */
95 /* */
96 if ( MODE == 1 || MODE == 3 )
97 *G = exp(X[0]);
98 /* */
99 /* Mode = 2 or 3: Derivative values: */
100 /* */
101 if ( MODE == 2 || MODE == 3 ) {
102 JAC[0] = exp(X[0]);
103 }
104 }
105 return 0;
106}
107
108#include "std.c"
109
112int main(int argc, char** argv)
113{
114 c_log( "Starting to execute", START );
115
116 /*
117 Tell CONOPT about the sizes in the model
118 */
119 COI_Error += COIDEF_NumVar ( CntVect, 1 ); /* 1 variables */
120 COI_Error += COIDEF_NumCon ( CntVect, 1 ); /* 1 constraints */
121 COI_Error += COIDEF_NumNz ( CntVect, 1 ); /* 1 nonzeros in the Jacobian */
122 COI_Error += COIDEF_NumNlNz ( CntVect, 1 ); /* 1 of which are nonlinear */
123 COI_Error += COIDEF_OptDir ( CntVect, 1 ); /* Maximize */
124 COI_Error += COIDEF_ObjVar ( CntVect, 0 ); /* Objective is variable 0 */
125 COI_Error += COIDEF_DebugFV ( CntVect, 0 ); /* 0 means no debugging, 1 each iter */
126 COI_Error += COIDEF_StdOut ( CntVect, 0 ); /* 1 means Allow output to StdOut */
127 COI_Error += COIDEF_Optfile ( CntVect, "largeres.opt"); /* Register the options file */
128 /*
129 Register the necessary callback routines with CONOPT
130 */
131 COI_Error += COIDEF_Message ( CntVect, &Std_Message ); /* Register the callback Message */
132 COI_Error += COIDEF_ErrMsg ( CntVect, &Std_ErrMsg ); /* Register the callback ErrMsg */
133 COI_Error += COIDEF_Status ( CntVect, &Std_Status ); /* Register the callback Status */
134 COI_Error += COIDEF_Solution ( CntVect, &Std_Solution ); /* Register the callback Solution */
135 COI_Error += COIDEF_ReadMatrix( CntVect, &LR_ReadMatrix); /* Register the callback ReadMatrix */
136 COI_Error += COIDEF_FDEval ( CntVect, &LR_FDEval); /* Register the callback FDEval */
137
138#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
139 COI_Error += COIDEF_License ( CntVect, LICENSE_INT_1, LICENSE_INT_2, LICENSE_INT_3, LICENSE_TEXT);
140#endif
141
142 if ( COI_Error ) {
143 printf("Skipping COI_Solve due to setup errors. COI_Error = %d\n",COI_Error);
144 c_log( "Skipping Solve due to setup errors",COI_Error);
145 }
146 COI_Error = COI_Solve ( CntVect ); /* Optimize */
147 printf("After solving. COI_Error =%d\n",COI_Error);
148 if ( COI_Error != 400 ) {
149 c_log( "Expected return code 400, Saw", COI_Error); }
150
151 c_log( "Successful Solve", OK );
152}
C language header file for direct linking against the COI library generated by apiwrapper for GAMS Ve...
coiHandle_t CntVect
Definition comdecl.h:14
#define START
Definition comdecl.h:13
#define OK
Definition comdecl.h:12
int COI_Error
Definition comdecl.h:15
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.
int COI_CALLCONV COIDEF_Optfile(coiHandle_t cntvect, const char *optfile)
define callback routine for defining an options file.
int COI_CALLCONV COIDEF_DebugFV(coiHandle_t cntvect, int debugfv)
turn Debugging of FDEval on and off.
int COI_CALLCONV COIDEF_License(coiHandle_t cntvect, int licint1, int licint2, int licint3, const char *licstring)
define the License Information.
int COI_CALLCONV COIDEF_StdOut(coiHandle_t cntvect, int tostdout)
allow output to StdOut.
int COI_CALLCONV COIDEF_ObjVar(coiHandle_t cntvect, int objvar)
defines the Objective Variable.
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_OptDir(coiHandle_t cntvect, int optdir)
defines the Optimization Direction.
int COI_CALLCONV COIDEF_NumNlNz(coiHandle_t cntvect, int numnlnz)
defines the Number of Nonlinear Nonzeros.
int COI_CALLCONV COI_Solve(coiHandle_t cntvect)
method for starting the solving process of CONOPT.
int COI_CALLCONV LR_ReadMatrix(double LOWER[], double CURR[], double UPPER[], int VSTA[], int TYPE[], double RHS[], int ESTA[], int COLSTA[], int ROWNO[], double VALUE[], int NLFLAG[], int NUMVAR, int NUMCON, int NUMNZ, void *USRMEM)
Define information about the model.
Definition largeres1.c:19
int COI_CALLCONV LR_FDEval(const double X[], double *G, double JAC[], int ROWNO, const int JACNUM[], int MODE, int IGNERR, int *ERRCNT, int NUMVAR, int NUMJAC, int THREAD, void *USRMEM)
Compute nonlinear terms and non-constant Jacobian elements.
Definition largeres1.c:85
int COI_CALLCONV LR_ReadMatrix(double LOWER[], double CURR[], double UPPER[], int VSTA[], int TYPE[], double RHS[], int ESTA[], int COLSTA[], int ROWNO[], double VALUE[], int NLFLAG[], int NUMVAR, int NUMCON, int NUMNZ, void *USRMEM)
Define information about the model.
Definition largeres2.c:19
int main(int argc, char **argv)
Main program. A simple setup and call of CONOPT.
Definition largeres2.c:112
int COI_CALLCONV LR_FDEval(const double X[], double *G, double JAC[], int ROWNO, const int JACNUM[], int MODE, int IGNERR, int *ERRCNT, int NUMVAR, int NUMJAC, int THREAD, void *USRMEM)
Compute nonlinear terms and non-constant Jacobian elements.
Definition largeres2.c:85
int COI_CALLCONV Std_Status(int MODSTA, int SOLSTA, int ITER, double OBJVAL, void *USRMEM)
Definition std.c:45
int COI_CALLCONV Std_Message(int SMSG, int DMSG, int NMSG, char *MSGV[], void *USRMEM)
Definition std.c:8
void c_log(char *msgt, int code)
Definition std.c:202
int COI_CALLCONV Std_ErrMsg(int ROWNO, int COLNO, int POSNO, const char *MSG, void *USRMEM)
Definition std.c:26
int COI_CALLCONV Std_Solution(const double XVAL[], const double XMAR[], const int XBAS[], const int XSTA[], const double YVAL[], const double YMAR[], const int YBAS[], const int YSTA[], int NUMVAR, int NUMCON, void *USRMEM)
Definition std.c:77