-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector valued constraints + funccache #8
Comments
The |
OK, thanks, that's what I thought more or less, as it only apears in the Dispose(). Any idea why the code posted above might not work properly? |
It gives an error or doesn't execute correctly? I might need to see your new method footprints as well. |
No errors, it executes, but the result of the optimization ignores the constraints. My guess is somewhere they receive only 0.0 all the time as constraint value, having them generally active for all x, and I figured most likely somewhere in the solver code, as I am least familiar with that ;) I'll post the rest of the code tomorrow. |
OK so as already defined:
Then from NLopt: [DllImport("libnlopt-0.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern NloptResult nlopt_add_inequality_mconstraint(IntPtr opt, uint m, nlopt_mfunc fc, IntPtr data, double[] tolerances); The signatures of my custom function: private double[] computeConstraintValues(double[] x) And the call / assignment of the constraint: solver.AddLessOrEqualZeroConstraints(computeConstraintValues, nConstraints, Enumerable.Repeat<double>(0.001, (int)nConstraints).ToArray()); Did I miss anything? |
Thanks to a colleague I finally figured it out, the mfunc definition actually needs to be: nlopt_mfunc mfunc = (_m, result, _n, values, gradient, data) =>
{
if (gradient != null)
throw new InvalidOperationException("Expected the constraint to handle the gradient.");
double[] returnData = constraint.Invoke(values);
Array.Copy(returnData, result, result.Length);
}; |
Hi, I wanted to add a vector valued constraint, doesn't seem to work properly though. Basically it runs, but seems to ignore the constraints. Maybe related to that: what is the point of _funcCache? It seems, that it is never called or used? As this here requires an nlopt_mfunc, I had to change the dictionary type to <Delegate, Delegate>, would this cause the problem?
The text was updated successfully, but these errors were encountered: