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