Unfortunately, the optimization converges with an x vector which
violates the constraints, but the "last_optimize_result()" says
"FTOL_REACHED"! Does either the way I define or add the functions
cause the violations?
Hey, with your hints I get my program to run correctly: I didn't
calculate the *proper* gradient of the constraint functions. The way I
called the functions to get the difference quotient was wrong. Because I
make use of add_*_mconstraint, the constraint function has to look as
follows:
<code>
void confun_m(unsigned int m, double* result, unsigned int n, const
double* x, double* grad, void* f_data) {
confun_m_data_t* data = (confun_m_data_t*) (f_data);
unsigned int i, j;
// calculate the result somehow
for (i = 0; i < m; ++i) {
result[i] = 0;
for (j = 0; j < n; ++j)
result[i] += data->some_value[j] * x[j];
}
// calculate gradient
if (grad) {
double* x1 = (double*) std::malloc(n * sizeof(double));
double* f1 = (double*) std::malloc(m * sizeof(double));
std::memcpy(x1, x, n * sizeof(double));
for (j = 0; j < n; ++j) {
x1[j] += data->delta_x;
confun_m(m, f1, n, x1, NULL, data);
for (i = 0; i < m; ++i)
grad[i * n + j] = (f1[i] - result[i]) /
data->delta_x;
x1[j] -= data->delta_x;
}
std::free(x1);
std::free(f1);
}
}
</code>
Thank you for your great help.
Best regards,
Tobias Schmidt
--
Tobias Schmidt, B.Sc.
Student and research assistant
Automation Lab.
Institute for Computer Engineering
Heidelberg University
B6, 26, B0.19
D-68131 Mannheim
Germany
Tel. +49-621-181-2664
URL: http://proaut.ziti.uni-heidelberg.de
URL: http://www.ziti.uni-heidelberg.de
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss