CONOPT
Loading...
Searching...
No Matches
square2.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 Sq_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 /* Information about Variables: */
24 /* Default: Lower = -Inf, Curr = 0, and Upper = +inf. */
25 /* Default: the status information in Vsta is not used. */
26 /* */
27 /* Model x0 + x1 = 10 */
28 /* x0 - x1 = 0 */
29 /* x0 + x1 <= 9 */
30 /* */
31 /* Information about Constraints: */
32 /* Default: Rhs = 0 */
33 /* Default: the status information in Esta and the function */
34 /* value in FV are not used. */
35 /* Default: Type: There is no default. */
36 /* 0 = Equality, */
37 /* 1 = Greater than or equal, */
38 /* 2 = Less than or equal, */
39 /* 3 = Non binding. */
40 /* */
41 /* Constraint 0 */
42 /* Rhs = 10 and type Eguality */
43 /* */
44 RHS[0] = 10 ;
45 TYPE[0] = 0 ;
46 /* */
47 /* Constraint 1 */
48 /* Rhs = 0 and type Equality */
49 /* */
50 TYPE[1] = 0 ;
51 /* */
52 /* Constraint 2 */
53 /* Rhs = 9 and type Less Than Inequality */
54 /* */
55 RHS[2] = 9 ;
56 TYPE[2] = 2 ;
57 /* */
58 /* Information about the Jacobian. We use the standard method with */
59 /* Rowno, Value, Nlflag and Colsta and we do not use Colno. */
60 /* */
61 /* Colsta = Start of column indices (No Defaults): */
62 /* Rowno = Row indices */
63 /* Value = Value of derivative (by default only linear */
64 /* derivatives are used) */
65 /* Nlflag = 0 for linear and 1 for nonlinear derivative */
66 /* (not needed for completely linear models) */
67 /* */
68 /* Indices */
69 /* X[0] X[1] */
70 /* 0: 0 3 */
71 /* 1: 1 4 */
72 /* 2: 2 5 */
73 /* */
74 COLSTA[0] = 0 ;
75 COLSTA[1] = 3 ;
76 COLSTA[2] = 6 ;
77 ROWNO[0] = 0 ;
78 ROWNO[1] = 1 ;
79 ROWNO[2] = 2 ;
80 ROWNO[3] = 0 ;
81 ROWNO[4] = 1 ;
82 ROWNO[5] = 2 ;
83 /* */
84 /* Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear */
85 /* Although the model is linear we label constraint 1 and 2 as nonlinear */
86 /* X[0] X[1] */
87 /* 0: L L */
88 /* 1: NL NL */
89 /* 2: NL NL */
90 /* */
91 NLFLAG[0] = 0 ;
92 NLFLAG[1] = 1 ;
93 NLFLAG[2] = 1 ;
94 NLFLAG[3] = 0 ;
95 NLFLAG[4] = 1 ;
96 NLFLAG[5] = 1 ;
97 /* */
98 /* Value (Linear only) */
99 /* X[0] X[1] */
100 /* 0: 1 1 */
101 /* 1: NL NL */
102 /* 2: NL NL */
103 /* */
104 VALUE[0] = 1. ;
105 VALUE[3] = 1. ;
106
107 return 0;
108}
109
110
111
116int COI_CALLCONV Sq_FDEval( const double X[], double* G, double JAC[], int ROWNO, const int JACNUM[], int MODE,
117 int IGNERR, int* ERRCNT, int NUMVAR, int NUMJAC, int THREAD, void* USRMEM )
118{
119 /* */
120 /* Row 0: linear */
121 /* */
122 if ( ROWNO == 0 ) {
123 return 1; /* This should not happen */
124 }
125 /* */
126 /* Row 1: The function appers as nonlinear */
127 /* */
128 else if ( ROWNO == 1 ) {
129 /* */
130 /* Mode = 1 or 3: Function value */
131 /* */
132 if ( MODE == 1 || MODE == 3 )
133 *G = X[0] - X[1];
134 /* */
135 /* Mode = 2 or 3: Derivatives */
136 /* */
137 if ( MODE == 2 || MODE == 3 ) {
138 JAC[0] = 1.;
139 JAC[1] = -1.;
140 }
141 }
142 /* */
143 /* Row 2: The function appers as nonlinear */
144 /* */
145 else if ( ROWNO == 2 ) {
146 /* */
147 /* Mode = 1 or 3: Function value */
148 /* */
149 if ( MODE == 1 || MODE == 3 )
150 *G = X[0] + X[1];
151 /* */
152 /* Mode = 2 or 3: Derivatives */
153 /* */
154 if ( MODE == 2 || MODE == 3 ) {
155 JAC[0] = 1.;
156 JAC[1] = 1.;
157 }
158 }
159 return 0;
160}
161
162#include "std.c"
163
166int main(int argc, char** argv)
167{
168 c_log( "Starting to execute", START );
169
170 /*
171 Tell CONOPT about the sizes in the model
172 */
173 COI_Error += COIDEF_NumVar ( CntVect, 2 ); /* 2 variables */
174 COI_Error += COIDEF_NumCon ( CntVect, 3 ); /* 3 constraints */
175 COI_Error += COIDEF_NumNz ( CntVect, 6 ); /* 6 nonzeros in the Jacobian */
176 COI_Error += COIDEF_NumNlNz ( CntVect, 4 ); /* 4 of which are nonlinear */
177 COI_Error += COIDEF_DebugFV ( CntVect, 0 ); /* 0 means no debugging, 1 each iter */
178 COI_Error += COIDEF_StdOut ( CntVect, 0 ); /* 1 means Allow output to StdOut */
179 COI_Error += COIDEF_Square ( CntVect, 1 ); /* 1 means Square system */
180 COI_Error += COIDEF_Optfile ( CntVect, "square.opt"); /* Register the options file */
181 /*
182 Register the necessary callback routines with CONOPT
183 */
184 COI_Error += COIDEF_Message ( CntVect, &Std_Message ); /* Register the callback Message */
185 COI_Error += COIDEF_ErrMsg ( CntVect, &Std_ErrMsg ); /* Register the callback ErrMsg */
186 COI_Error += COIDEF_Status ( CntVect, &Std_Status ); /* Register the callback Status */
187 COI_Error += COIDEF_Solution ( CntVect, &Std_Solution ); /* Register the callback Solution */
188 COI_Error += COIDEF_ReadMatrix( CntVect, &Sq_ReadMatrix); /* Register the callback ReadMatrix */
189 COI_Error += COIDEF_FDEval ( CntVect, &Sq_FDEval); /* Register the callback FDEval */
190
191#if defined(LICENSE_INT_1) && defined(LICENSE_INT_2) && defined(LICENSE_INT_3) && defined(LICENSE_TEXT)
192 COI_Error += COIDEF_License ( CntVect, LICENSE_INT_1, LICENSE_INT_2, LICENSE_INT_3, LICENSE_TEXT);
193#endif
194
195 if ( COI_Error ) {
196 printf("Skipping COI_Solve due to setup errors. COI_Error = %d\n",COI_Error);
197 c_log( "Skipping Solve due to setup errors", COI_Error);
198 }
199 COI_Error = COI_Solve ( CntVect ); /* Optimize */
200 printf("After solving. COI_Error =%d\n",COI_Error);
201 if ( COI_Error ) {
202 c_log( "Errors encountered during solution", COI_Error); }
203 else if ( stacalls == 0 || solcalls == 0 ) {
204 c_log( "Status or Solution routine was not called", -1); }
205 else if ( sstat != 1 || mstat < 4 || mstat > 5 ) {
206 c_log( "Solver or Model status not as expected (1,4) or (1,5)", -1); }
207
208 c_log( "Successful Solve", OK );
209}
C language header file for direct linking against the COI library generated by apiwrapper for GAMS Ve...
int stacalls
Definition comdecl.h:4
coiHandle_t CntVect
Definition comdecl.h:14
#define START
Definition comdecl.h:13
int solcalls
Definition comdecl.h:5
int mstat
Definition comdecl.h:7
#define OK
Definition comdecl.h:12
int sstat
Definition comdecl.h:8
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_Square(coiHandle_t cntvect, int square)
square models.
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.
int COI_CALLCONV COI_Solve(coiHandle_t cntvect)
method for starting the solving process of CONOPT.
int main(int argc, char **argv)
Main program. A simple setup and call of CONOPT.
Definition square2.c:166
int COI_CALLCONV Sq_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 square2.c:19
int COI_CALLCONV Sq_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 square2.c:116
int COI_CALLCONV Sq_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 square.c:19
int COI_CALLCONV Sq_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 square.c:102
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