52 void buildModel(
int T,
const std::vector<double> &
xkeep,
const std::vector<int> &xstat,
53 const std::vector<int> &estat)
58 for (
int t = 0; t <
T; t++)
59 demand.push_back(1.0 + 2.3 * pow(1.015, t));
86 for (
int t = 0; t <
T; t++)
90 vartd.push_back(varidx);
94 varcs.push_back(varidx);
98 vars.push_back(varidx);
103 vard.push_back(varidx);
111 varr.push_back(varidx);
115 varp.push_back(varidx);
128 if (
xkeep.size() > 0)
130 for (
size_t i = 0; i <
xkeep.size(); i++)
162 for (
size_t i = 0; i < xstat.size(); i++)
184 std::vector<double> objcoeff;
185 std::vector<int> objnlflag(
T, 0);
186 for (
int t = 0; t <
T; ++t)
188 objcoeff.push_back(pow(1.05, 1 - (t + 1)));
194 for (
int t = 0; t <
T; t++)
220 {
vartd[t],
vartd[t - 1],
varp[t]}, {1.0, -0.87, 0.13}, {0, 0, 0});
236 {
vars[t],
vars[t - 1],
varp[t],
varcs[t]}, {1.0, -0.75, 0.0, 0.0}, {0, 0, 1, 1});
264 {1.0, -1.0, 1.0}, {0, 0, 0});
280 {1.0, -1.0, 1.0}, {0, 0, 0});
286 {
varrev[t],
vard[t],
varp[t],
varr[t]}, {1.0, 0.0, 0.0, 0.0}, {0, 1, 1, 1});
296 if (estat.size() > 0)
299 for (
size_t i = 0; i < estat.size(); i++)
329 int FDEval(
const double x[],
double *g,
double jac[],
int rowno,
const int jacnum[],
int mode,
330 int ignerr,
int *errcnt,
int numvar,
int numjac,
int thread)
override
344 auto conspair = itr->second;
348 int consset = conspair.first;
349 int t = conspair.second;
357 h1 = (1.1 + 0.1 * x[
varp[t]]);
358 h2 = pow(1.02, -x[
varcs[t]] / 7.0);
359 if (1 == mode || 3 == mode)
361 if (2 == mode || 3 == mode)
363 jac[
varcs[t]] = h1 * h2 * log(1.02) / 7.0;
364 jac[
varp[t]] = -h2 * 0.1;
371 if (1 == mode || 3 == mode)
373 if (2 == mode || 3 == mode)
402 conopt.setMessageHandler(msghandler);
404 for (
int i = 16; i <= 20; i++)
410 auto xstat =
conopt.getVariableStatus();
411 auto estat =
conopt.getConstraintStatus();
417 conopt.loadModel(modeldata);
419#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
420 std::string license = CONOPT_LICENSE_TEXT;
421 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
427 "Skipping COI_Solve due to setup errors. COI_Error = " + std::to_string(
COI_Error));
433 conopt.sendMessage(
"After solving. COI_Error = " + std::to_string(
COI_Error));
434 if (
conopt.modelStatus() != 2 ||
conopt.solutionStatus() != 1)
static constexpr double Infinity
std::vector< double > demand
std::vector< int > constcseq
std::vector< int > constseq
std::vector< int > consttdeq
std::vector< int > varrev
std::vector< int > constreq
std::vector< int > constdeq
std::vector< int > constdrev
std::map< int, std::pair< int, int > > consmapping
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.
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 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 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.
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)