15#include <adolc/adolc.h>
70 else if ( rowno == 1 ) {
92 for (
int c = 0; c < numcons; c++)
105 ax =
new adouble[numvar];
106 for (
int i = 0; i < numvar; i++)
158 addConstraint(
ConoptConstraintType::Free, -0.1, {0, 1, 2, 3}, {-1, -1, 0, 0}, {0, 0, 1, 1});
163 addConstraint(
ConoptConstraintType::Eq, 0.0, {0, 1, 2}, {0, 0, -1}, {1, 1, 0});
187 int FDEval(
const double x[],
double* g,
double jac[],
int rowno,
const int jacnum[],
int mode,
int ignerr,
188 int* errcnt,
int numvar,
int numjac,
int thread)
191 if (mode == 1 || mode == 3)
192 function(rowno, 1, numvar,
const_cast<double*
>(x), g);
195 if (mode == 2 || mode == 3)
196 gradient(rowno, numvar, x, jac);
205 int SDLagrVal(
const double x[],
const double u[],
const int hsrw[],
const int hscl[],
double hsvl[],
206 int* nodrv,
int numvar,
int numcon,
int nhess)
211 hessres =
new double*[numvar];
212 for(
int i = 0; i < numvar; i++)
213 hessres[i] =
new double[numvar];
215 for(
int c = 0; c < numcon; c++)
218 hessian(c, numvar,
const_cast<double*
>(x), hessres);
220 for(
int i = 0; i < nhess; i++)
222 hsvl[i] += u[c]*hessres[hsrw[i]][hscl[i]];
226 for (
int i = numvar - 1; i >= 0; i--)
249 conopt.setMessageHandler(msghandler);
255 conopt.loadModel(modeldata);
257#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
258 std::string license = CONOPT_LICENSE_TEXT;
259 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
268 if (
conopt.modelStatus() != 2 ||
conopt.solutionStatus() != 1 )
272 else if ( fabs(
conopt.objectiveValue() - 0.572943 ) > 0.000001 )
int main(int argc, char **argv)
CONOPT C++ interface header file. This is the main object for the CONOPT C++ interface.
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)
defines the nonlinearities of the model by returning numerical values.
void buildModel()
adds the variables and constraints for the problem
void evaluateNonlinearExpression(adouble *x, adouble *g, int rowno, int numvar)
void initialiseAutoDiff()
int SDLagrVal(const double x[], const double u[], const int hsrw[], const int hscl[], double hsvl[], int *nodrv, int numvar, int numcon, int nhess)
Computes and returns the numerical values of the Hessian.
void evaluateNonlinearExpression(adouble *x, adouble *g, int rowno, int numvar)
void initialiseAutoDiff()
void buildModel()
adds the variables and constraints for the problem
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 setSDLagrangianStructure(const std::vector< int > &rownum, const std::vector< int > &colnum)
sets the structure of the second derivatives of the Lagrangian
int numCons() const
returns the number of constraints in the model
int numVar() const
returns the number of variables in the model
const ConoptVariable & getVariable(int index) const
returns a reference to the variable object
void cpp_log(Conopt &conopt, std::string msg, int code)
std::string getProgramName(char *execname)