19#include <adolc/adolc.h>
23 bool operator() (
const std::pair<int, int> a,
const std::pair<int, int> b)
const {
24 return a.first < b.first || (a.first == b.first && a.second < b.second);
81 else if ( rowno == 1 ) {
107 for (
int c = 0; c < numcons; c++)
120 ax =
new adouble[numvar];
121 for (
int i = 0; i < numvar; i++)
150 unsigned int** hesspat;
151 std::set<std::pair<int, int>,
PairComp> hesspairs;
152 std::vector<int> rowidx;
153 std::vector<int> colidx;
155 x =
new double[numvar];
156 hesspat =
new unsigned int*[numvar];
157 for (
int i = 0; i < numvar; i++)
158 hesspat[i] =
new unsigned int[numvar];
161 for (
int i = 0; i < numvar; i++)
165 for (
int c = 0; c < numcons; c++)
168 hess_pat(c, numvar, x, hesspat, 0);
170 for (
unsigned int i = 0; i < numvar; i++)
172 for (
unsigned int j = 0; j < hesspat[i][0]; j++)
175 if (hesspat[i][j + 1] <= i)
176 hesspairs.insert(std::make_pair(i, hesspat[i][j + 1]));
181 for (
const auto &p : hesspairs)
183 rowidx.push_back(p.first);
184 colidx.push_back(p.second);
187 for (
int i = numvar - 1; i >= 0; i--)
233 addConstraint(
ConoptConstraintType::Free, -0.1, {0, 1, 2, 3}, {-1, -1, 0, 0}, {0, 0, 1, 1});
238 addConstraint(
ConoptConstraintType::Eq, 0.0, {0, 1, 2}, {0, 0, -1}, {1, 1, 0});
262 int FDEval(
const double x[],
double* g,
double jac[],
int rowno,
const int jacnum[],
int mode,
int ignerr,
263 int* errcnt,
int numvar,
int numjac,
int thread)
266 if (mode == 1 || mode == 3)
267 function(rowno, 1, numvar,
const_cast<double*
>(x), g);
270 if (mode == 2 || mode == 3)
271 gradient(rowno, numvar, x, jac);
280 int SDLagrVal(
const double x[],
const double u[],
const int hsrw[],
const int hscl[],
double hsvl[],
281 int* nodrv,
int numvar,
int numcon,
int nhess)
286 hessres =
new double*[numvar];
287 for(
int i = 0; i < numvar; i++)
288 hessres[i] =
new double[numvar];
290 for(
int c = 0; c < numcon; c++)
293 hessian(c, numvar,
const_cast<double*
>(x), hessres);
295 for(
int i = 0; i < nhess; i++)
297 hsvl[i] += u[c]*hessres[hsrw[i]][hscl[i]];
301 for (
int i = numvar - 1; i >= 0; i--)
324 conopt.setMessageHandler(msghandler);
330 conopt.loadModel(modeldata);
332#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
333 std::string license = CONOPT_LICENSE_TEXT;
334 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
343 if (
conopt.modelStatus() != 2 ||
conopt.solutionStatus() != 1 )
347 else if ( fabs(
conopt.objectiveValue() - 0.572943 ) > 0.000001 )
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()
void computeHessianStructure()
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)
bool operator()(const std::pair< int, int > a, const std::pair< int, int > b) const
int main(int argc, char **argv)