CONOPT
Loading...
Searching...
No Matches
largeres1.cpp
Go to the documentation of this file.
1
7
8#include <stdlib.h>
9#include <stdio.h>
10#include <math.h>
11#include <string.h>
12#include <iostream>
13#include "conopt.hpp"
14
16{
17public:
18 int varidx;
20
22
27 {
28 /* */
29 /* Information about Variables: */
30 /* Default: Lower = -Inf, Curr = 0, and Upper = +inf. */
31 /* Default: the status information in Vsta is not used. */
32 /* */
33 /* Initial value = 35.0 */
34 /* */
36
37 /* */
38 /* Information about Constraints: */
39 /* Default: Rhs = 0 */
40 /* Default: the status information in Esta and the function */
41 /* value in FV are not used. */
42 /* Default: Type: There is no default. */
43 /* 0 = Equality, */
44 /* 1 = Greater than or equal, */
45 /* 2 = Less than or equal, */
46 /* 3 = Non binding. */
47 /* */
48 /* Constraint 0 */
49 /* Rhs = 10.0 and type Equality */
50 /* */
52 /* */
53 /* Nonlinearity Structure: L = 0 are linear and NL = 1 are nonlinear */
54 /* X[0] */
55 /* 0: NL */
56 /* */
57
58 /* setting the objective variable */
60
61 /* setting the optimisation direction */
63 }
64
69 int FDEval(const double x[], double *g, double jac[], int rowno, const int jacnum[], int mode,
70 int ignerr, int *errcnt, int numvar, int numjac, int thread) override
71 {
72 /* */
73 /* Row 0: exp(x) = 10 */
74 /* */
75
76 if (rowno == considx)
77 {
78 /* */
79 /* Mode = 1 or 3. Function value: g = P * Out */
80 /* */
81 if (mode == 1 || mode == 3)
82 *g = exp(x[varidx]);
83 /* */
84 /* Mode = 2 or 3: Derivative values: */
85 /* */
86 if (mode == 2 || mode == 3)
87 {
88 jac[varidx] = exp(x[varidx]);
89 }
90 }
91 return 0;
92 }
93};
94
95#include "std.cpp"
96
101int main(int argc, char **argv)
102{
103 int COI_Error = 0;
104
105 // getting the program name from the executable path
106 std::string pname = getProgramName(argv[0]);
107
108 // initialising the Conopt Object
110 LR1_ModelData modeldata;
111 Tut_MessageHandler msghandler(pname);
112
113 // adding the message handler to the conopt interface
114 conopt.setMessageHandler(msghandler);
115
116 // building the model
117 modeldata.buildModel();
118
119 // loading the model in the conopt object
120 conopt.loadModel(modeldata);
121
122 // Disable debug output for function values
123 conopt.debugFV(0);
124
125#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
126 std::string license = CONOPT_LICENSE_TEXT;
127 COI_Error += conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
128#endif
129
130 if (COI_Error)
131 cpp_log(
132 conopt, "Skipping COI_Solve due to license error. COI_Error = " + std::to_string(COI_Error), COI_Error);
133
134 COI_Error = conopt.solve(); /* Optimize */
135
136 printf("After solving. COI_Error =%d\n", COI_Error);
137 if (COI_Error != 400)
138 {
139 cpp_log(conopt, "Expected return code 400, Saw", COI_Error);
140 }
141
142 cpp_log(conopt, "Successful Solve", 0);
143}
The Conopt class.
Definition conopt.hpp:27
static constexpr double Infinity
Definition conopt.hpp:30
char pname[MAXLINE]
Definition comdecl.h:10
int COI_Error
Definition comdecl.h:15
CONOPT C++ interface header file. This is the main object for the CONOPT C++ interface.
int main(int argc, char **argv)
Main program. A simple setup and call of CONOPT.
int 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) override
defines the nonlinearities of the model by returning numerical values.
Definition largeres1.cpp:69
void buildModel()
adds the variables and constraints for the problem
Definition largeres1.cpp:26
int addVariable(double lower, double upper, double curr=0, int varstatus=-1)
adds a variable to the model. The non-zero coefficients are added later.
void setObjectiveElement(ConoptObjectiveElement elem, int elemindex)
sets the index for the objective variable or constraint
int addConstraint(ConoptConstraintType constype, double rhs, int slackstatus=-1)
adds a constraint to the problem. The non-zero coefficients are added later
void setOptimizationSense(ConoptSense sense)
sets the optimisation direction.
void cpp_log(Conopt &conopt, std::string msg, int code)
Definition std.cpp:111
std::string getProgramName(char *execname)
Definition std.cpp:95