20 std::vector<double>
A;
21 std::vector<double>
B;
22 std::vector<double>
Obs;
46 times =
seed / 1048576;
48 result =
static_cast<double>(
seed);
49 result = result / 1048576.0;
60 for (
int i = 0; i <
nobs; ++i)
63 for (
int j = 0; j <
dimx; ++j)
67 O +=
A[k] * Xtarg +
B[k] * std::pow(Xtarg, 2);
85 for (
int i = 0; i <
dimx; ++i)
88 varx.push_back(varidx);
90 for (
int i = 0; i <
nobs; ++i)
106 for (
int i = 0; i <
nobs; ++i)
108 std::vector<int> varidx(
varx.begin(),
varx.end());
109 std::vector<double> coeffs(
dimx, 0.0);
110 std::vector<int> nlf(
dimx, 1);
113 varidx.push_back(
varres[i]);
114 coeffs.push_back(-1.0);
124 std::vector<int> objVarIdx(
varres.begin(),
varres.end());
125 std::vector<double> objCoeffs(
nobs, 1.0);
126 std::vector<int> objNlf(
nobs, 1);
141 int FDEval(
const double x[],
double *g,
double jac[],
int rowno,
const int jacnum[],
int mode,
142 int ignerr,
int *errcnt,
int numvar,
int numjac,
int thread)
override
149 if (mode == 1 || mode == 3)
152 for (
int i = 0; i <
nobs; i++)
154 sum += pow(x[
varres[i]], 2);
161 if (mode == 2 || mode == 3)
163 for (
int i = 0; i <
nobs; i++)
176 if (mode == 1 || mode == 3)
178 int k = rowno *
dimx;
180 for (
int i = 0; i <
dimx; i++)
182 sum +=
A[k] * x[
varx[i]] +
B[k] * pow(x[
varx[i]], 2);
190 if (mode == 2 || mode == 3)
192 int k = rowno *
dimx;
193 for (
int i = 0; i <
dimx; i++)
208 int SDDir(
const double x[],
const double dx[],
double d2g[],
int rowno,
const int jacnum[],
209 int *nodrv,
int numvar,
int numjac,
int thread)
override
216 for (
int i = 0; i <
dimx; i++)
218 for (
int i = 0; i <
nobs; i++)
226 int k = rowno *
dimx;
227 for (
int i = 0; i <
dimx; i++)
232 for (
int i = 0; i <
nobs; i++)
258 conopt.setMessageHandler(msghandler);
264 conopt.loadModel(modeldata);
266#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
267 std::string license = CONOPT_LICENSE_TEXT;
268 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
278 if (!(
conopt.solutionStatus() == 1 &&
conopt.modelStatus() == 2))
282 else if (fabs(
conopt.objectiveValue() - 19.4443) > 0.001)
static constexpr double Infinity
void defineData()
Defines the data for the problem.
Leastsq5_ModelData(int numobs, int dimensionx)
double rndx()
Defines a pseudo random number between 0 and 1.
std::vector< double > Obs
std::vector< int > varres
std::vector< int > consresidual
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()
adds the variables and constraints for the problem
int SDDir(const double x[], const double dx[], double d2g[], int rowno, const int jacnum[], int *nodrv, int numvar, int numjac, int thread) override
computes the directional second derivative for a single constraint
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.
void setSDEvaluationType(ConoptSDEvaluationType sdevaltype)
informs CONOPT of the method for evaluating the second derivative
void cpp_log(Conopt &conopt, std::string msg, int code)
std::string getProgramName(char *execname)