20 std::vector<double>
A;
21 std::vector<double>
B;
22 std::vector<double>
C;
23 std::vector<double>
Obs;
48 times =
seed / 1048576;
50 result =
static_cast<double>(
seed);
51 result = result / 1048576.0;
62 for (
int i = 0; i <
nobs; ++i)
65 for (
int j = 0; j <
dimx; ++j)
69 O +=
A[k] * Xtarg +
B[k] * std::pow(Xtarg, 2);
86 for (
int i = 0; i <
dimx; ++i)
89 varx.push_back(varidx);
91 for (
int i = 0; i <
nobs; ++i)
107 for (
int i = 0; i <
nobs; ++i)
109 std::vector<int> varidx(
varx.begin(),
varx.end());
110 std::vector<double> coeffs(
dimx, 0.0);
111 std::vector<int> nlf(
dimx, 1);
114 varidx.push_back(
varres[i]);
115 coeffs.push_back(-1.0);
125 std::vector<int> objVarIdx(
varres.begin(),
varres.end());
126 std::vector<double> objCoeffs(
nobs, 1.0);
127 std::vector<int> objNlf(
nobs, 1);
142 int FDEval(
const double x[],
double *g,
double jac[],
int rowno,
const int jacnum[],
int mode,
143 int ignerr,
int *errcnt,
int numvar,
int numjac,
int thread)
override
150 if (mode == 1 || mode == 3)
153 for (
int i = 0; i <
nobs; i++)
155 sum += pow(x[
varres[i]], 2);
162 if (mode == 2 || mode == 3)
164 for (
int i = 0; i <
nobs; i++)
177 if (mode == 1 || mode == 3)
179 int k = rowno *
dimx;
181 for (
int i = 0; i <
dimx; i++)
183 sum +=
A[k] * x[
varx[i]] +
B[k] * pow(x[
varx[i]], 2);
191 if (mode == 2 || mode == 3)
193 int k = rowno *
dimx;
194 for (
int i = 0; i <
dimx; i++)
209 int SDDirIni(
const double x[],
const double dx[],
const int rowlist[],
int listsize,
210 int numthread,
int newpt,
int *nodrv,
int numvar)
override
216 for (
int i = 0; i <
nobs; i++)
218 for (
int j = 0; j <
dimx; j++)
220 C[k] = 2.0 *
B[k] * dx[
varx[j]];
231 int SDDir(
const double x[],
const double dx[],
double d2g[],
int rowno,
const int jacnum[],
232 int *nodrv,
int numvar,
int numjac,
int thread)
override
239 for (
int i = 0; i <
dimx; i++)
241 for (
int i = 0; i <
nobs; i++)
249 int k = rowno *
dimx;
250 for (
int i = 0; i <
dimx; i++)
255 for (
int i = 0; i <
nobs; i++)
281 conopt.setMessageHandler(msghandler);
287 conopt.loadModel(modeldata);
289#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
290 std::string license = CONOPT_LICENSE_TEXT;
291 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
301 if (!(
conopt.solutionStatus() == 1 &&
conopt.modelStatus() == 2))
305 else if (fabs(
conopt.objectiveValue() - 19.4443) > 0.001)
static constexpr double Infinity
std::vector< int > varres
std::vector< double > Obs
double rndx()
Defines a pseudo random number between 0 and 1.
std::vector< int > consresidual
Leastsq10_ModelData(int numobs, int dimensionx)
void defineData()
Defines the data for the problem.
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 SDDirIni(const double x[], const double dx[], const int rowlist[], int listsize, int numthread, int newpt, int *nodrv, int numvar) override
called by CONOPT before a sequence of 2DDir calls each time either the point or the direction changes...
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 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 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)