53 void buildModel(
int T,
const std::vector<double> &
xkeep,
const std::vector<int> &xstat,
54 const std::vector<int> &estat)
60 for (
int t = 0; t <
T; t++)
61 demand.push_back(1.0 + 2.3 * pow(1.015, t));
88 for (
int t = 0; t <
T; t++)
92 vartd.push_back(varidx);
96 varcs.push_back(varidx);
100 vars.push_back(varidx);
105 vard.push_back(varidx);
113 varr.push_back(varidx);
117 varp.push_back(varidx);
130 if (
xkeep.size() > 0)
132 for (
size_t i = 0; i <
xkeep.size(); i++)
164 for (
size_t i = 0; i < xstat.size(); i++)
186 std::vector<double> objcoeff;
187 std::vector<int> objnlflag(
T, 0);
188 for (
int t = 0; t <
T; ++t)
190 objcoeff.push_back(pow(1.05, 1 - (t + 1)));
196 for (
int t = 0; t <
T; t++)
222 {
vartd[t],
vartd[t - 1],
varp[t]}, {1.0, -0.87, 0.13}, {0, 0, 0});
238 {
vars[t],
vars[t - 1],
varp[t],
varcs[t]}, {1.0, -0.75, 0.0, 0.0}, {0, 0, 1, 1});
266 {1.0, -1.0, 1.0}, {0, 0, 0});
282 {1.0, -1.0, 1.0}, {0, 0, 0});
288 {
varrev[t],
vard[t],
varp[t],
varr[t]}, {1.0, 0.0, 0.0, 0.0}, {0, 1, 1, 1});
298 if (estat.size() > 0)
301 for (
size_t i = 0; i < estat.size(); i++)
367 std::vector<int> hsrow;
368 std::vector<int> hscol;
370 for (
int t = 0; t <
T; ++t)
378 hscol.push_back(
varcs[t]);
379 hsrow.push_back(
varcs[t]);
380 hscol.push_back(
varcs[t]);
381 hsrow.push_back(
varp[t]);
384 hscol.push_back(
vard[t]);
385 hsrow.push_back(
vard[t]);
388 hscol.push_back(
vard[t]);
389 hsrow.push_back(
varp[t]);
390 hscol.push_back(
varr[t]);
391 hsrow.push_back(
varr[t]);
400 int FDEval(
const double x[],
double *g,
double jac[],
int rowno,
const int jacnum[],
int mode,
401 int ignerr,
int *errcnt,
int numvar,
int numjac,
int thread)
override
415 auto conspair = itr->second;
419 int consset = conspair.first;
420 int t = conspair.second;
428 h1 = (1.1 + 0.1 * x[
varp[t]]);
429 h2 = pow(1.02, -x[
varcs[t]] / 7.0);
430 if (1 == mode || 3 == mode)
432 if (2 == mode || 3 == mode)
434 jac[
varcs[t]] = h1 * h2 * log(1.02) / 7.0;
435 jac[
varp[t]] = -h2 * 0.1;
442 if (1 == mode || 3 == mode)
444 if (2 == mode || 3 == mode)
459 int SDLagrVal(
const double x[],
const double u[],
const int hsrw[],
const int hscl[],
460 double hsvl[],
int *nodrv,
int numvar,
int numcon,
int nhess)
override
466 for (
int t = 0; t <
T; t++)
475 h2 = pow(1.02, -cs / 7.0);
477 hsvl[hessidx] = -h1 * h2 * pow(log(1.02) / 7.0, 2) * u[
constseq[t]];
478 hsvl[hessidx + 1] = 0.1 * h2 * (log(1.02) / 7.) * u[
constseq[t]];
481 hsvl[hessidx + 2] = -250.0 / pow(r, 2) * u[
constdrev[t]];
482 hsvl[hessidx + 3] = -1.0 * u[
constdrev[t]];
483 hsvl[hessidx + 4] = 500.0 * d / pow(r, 3) * u[
constdrev[t]];
507 conopt.setMessageHandler(msghandler);
512 for (
int i = 16; i <= 20; i++)
518 auto xstat =
conopt.getVariableStatus();
519 auto estat =
conopt.getConstraintStatus();
525 conopt.loadModel(modeldata);
527#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
528 std::string license = CONOPT_LICENSE_TEXT;
529 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
535 "Skipping COI_Solve due to setup errors. COI_Error = " + std::to_string(
COI_Error));
549 conopt.sendMessage(
"After solving. COI_Error = " + std::to_string(
COI_Error));
556 else if (
conopt.modelStatus() < 6 ||
conopt.modelStatus() > 7 ||
557 conopt.solutionStatus() != 5)
559 cpp_log(
conopt,
"Incorrect Model or Solver Status during first solve", -1);
572 conopt.sendMessage(
"After solving. COI_Error = " + std::to_string(
COI_Error));
574 if (
conopt.modelStatus() != 2 ||
conopt.solutionStatus() != 1)
static constexpr double Infinity
std::vector< int > constseq
std::vector< int > constreq
std::map< int, std::pair< int, int > > consmapping
std::vector< int > varrev
std::vector< int > consttdeq
std::vector< int > constdrev
std::vector< double > demand
std::vector< int > constcseq
std::vector< int > hessianstart
std::vector< int > constdeq
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) override
defines the nonlinearities of the model by returning numerical values.
int main(int argc, char **argv)
Main program. A simple setup and call of CONOPT.
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(int T, const std::vector< double > &xkeep, const std::vector< int > &xstat, const std::vector< int > &estat)
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
const ConoptConstraint & getConstraint(int index) const
returns a reference to the constraint object
const ConoptVariable & getVariable(int index) const
returns a reference to the variable object
double xkeep[Tmax *Tmax *Vpp]
void cpp_log(Conopt &conopt, std::string msg, int code)
std::string getProgramName(char *execname)