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