Open olumide-x opened 1 year ago
I'd say dont rely on the pointers, just cache the input values and the associated objective and constraints values and in your case maybe it will be easier to use add_inequality_mconstraint to return all constraints at once
I hadn't thought about void add_equality_mconstraint
. Thanks.
Problem though is that my x
is typically high dimensional vector which be expensive to cache as well as lookup.
If only I could get my hands on the iteration index.
Minor question. The signature of the function passed to add_equality_mconstraint
is
void constraintsFunc(unsigned m, double* result, unsigned n, const double* x, double* grad, void* data)
Where m
is the number of constraints, n
the number of variables. What is the size of grad
? My guess is m*n
. Is this correct? If so n what order should the derivatives of the constraints be written to grad
? The derivatives of constraint 1, the the derivatives of constraint 2 etc.
yes, per constraint then per variable; this is explained in the doc: https://nlopt.readthedocs.io/en/latest/NLopt_Reference/#vector-valued-constraints
The problem that I am trying to solve is associated with a large data structure that should be accessed as infrequently as possible. This is why I would like to compute and cache my objective and constraints values as shown in Problem::update() below
What I am not sure about is whether my assumption that:
An idea that's just popped to mind is to use constraint and objective functions of the form
double func(unsigned n, const double* x, double* grad, void* data);
and current and previous pointers x in order to determine whether Problem::update() should be called. This would solve the problem of needing to know whether the constraint or objective functions gets called first. However I am not sure whether my assumption about whether the same pointer x is passed to all functions is valid.