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);
138 int FDEval(
const double x[],
double *g,
double jac[],
int rowno,
const int jacnum[],
int mode,
139 int ignerr,
int *errcnt,
int numvar,
int numjac,
int thread)
override
146 if (mode == 1 || mode == 3)
149 for (
int i = 0; i <
nobs; i++)
151 sum += pow(x[
varres[i]], 2);
158 if (mode == 2 || mode == 3)
160 for (
int i = 0; i <
nobs; i++)
173 if (mode == 1 || mode == 3)
175 int k = rowno *
dimx;
177 for (
int i = 0; i <
dimx; i++)
179 sum +=
A[k] * x[
varx[i]] +
B[k] * pow(x[
varx[i]], 2);
187 if (mode == 2 || mode == 3)
189 int k = rowno *
dimx;
190 for (
int i = 0; i <
dimx; i++)
220 conopt.setMessageHandler(msghandler);
226 conopt.loadModel(modeldata);
228#if defined(CONOPT_LICENSE_INT_1) && defined(CONOPT_LICENSE_INT_2) && defined(CONOPT_LICENSE_INT_3) && defined(CONOPT_LICENSE_TEXT)
229 std::string license = CONOPT_LICENSE_TEXT;
230 COI_Error +=
conopt.setLicense(CONOPT_LICENSE_INT_1, CONOPT_LICENSE_INT_2, CONOPT_LICENSE_INT_3, license);
240 if (!(
conopt.solutionStatus() == 1 &&
conopt.modelStatus() == 2))
244 else if (fabs(
conopt.objectiveValue() - 19.4443) > 0.001)
static constexpr double Infinity
void defineData()
Defines the data for the problem.
std::vector< int > varres
std::vector< double > Obs
Leastsq_ModelData(int numobs, int dimensionx)
std::vector< int > consresidual
double rndx()
Defines a pseudo random number between 0 and 1.
CONOPT C++ interface header file. This is the main object for the CONOPT C++ interface.
void buildModel()
adds the variables and constraints for the problem
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 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 cpp_log(Conopt &conopt, std::string msg, int code)
std::string getProgramName(char *execname)