25 std::vector<double>
Q;
47 for (
int i = 0; i <
nvar; ++i)
76 for (
int i = 0; i <
nvar; ++i)
80 std::vector<int> varIdx(
nvar);
81 std::vector<double> ones(
nvar, 1.0);
82 std::vector<int> nlflags_free(
nvar, 1);
83 std::vector<int> nlflags_sum(
nvar, 0);
85 for (
int i = 0; i <
nvar; ++i)
114 int FDEval(
const double x[],
double *g,
double jac[],
int rowno,
const int jacnum[],
int mode,
115 int ignerr,
int *errcnt,
int numvar,
int numjac,
int thread)
override
120 if (mode == 1 || mode == 3)
123 for (
int k = 0; k <
nqnz; ++k)
130 sum += 2.0 * (x[i] -
Target[i]) * qi * (x[j] -
Target[j]);
136 if (mode == 2 || mode == 3)
138 for (
int i = 0; i < numvar; ++i)
141 for (
int k = 0; k <
nqnz; ++k)
146 jac[i] += qi * (x[i] -
Target[i]);
149 jac[i] += qi * (x[j] -
Target[j]);
150 jac[j] += qi * (x[i] -
Target[i]);
163 int SDLagrVal(
const double x[],
const double u[],
const int hsrw[],
const int hscl[],
164 double hsvl[],
int *nodrv,
int numvar,
int numcon,
int nhess)
override
168 for (k = 0; k <
nqnz; k++)
169 hsvl[k] =
Q[k] * u[0];
195 conopt.setMessageHandler(msghandler);
201 conopt.loadModel(modeldata);
203#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
204 std::string license = CONOPT_LICENSE_TEXT;
205 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
211 "Skipping COI_Solve due to setup errors. COI_Error = " + std::to_string(
COI_Error));
217 conopt.sendMessage(
"After solving. COI_Error = " + std::to_string(
COI_Error));
218 if (
conopt.modelStatus() != 2 ||
conopt.solutionStatus() != 1)
220 else if (fabs(
conopt.objectiveValue() - 59978.0) > 0.001)
static constexpr double Infinity
std::vector< double > Target
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.
int SDLagrVal(const double x[], const double u[], const int hsrw[], const int hscl[], double hsvl[], int *nodrv, int numvar, int numcon, int nhess) override
Computes and returns the numerical values of the Hessian.
void buildModel()
adds the variables and constraints for the problem
QP3_ModelData(int numvar)
the constructor for the QP instance model data.
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
void cpp_log(Conopt &conopt, std::string msg, int code)
std::string getProgramName(char *execname)