Hi there,
The library was originally C++ and I have ported it to C#. I want to swap out the numerical solver for something more maintainable and was hoping to use the accord solver here. However my first try ended up with a runtime error that I'm not sure about. I have the following code snippet.
public static Result solve (bool isFine, IEnumerable<Constraint> cons)
{
var constraints = cons.ToArray ();
// Get the parameters that need solving
Parameter[] x = constraints.SelectMany (p=>p)
.Distinct ()
.Where(p=>p.free==true)
.ToArray ();
var f = new NonlinearObjectiveFunction
( x.Length
, args => {
int i = 0;
foreach (var arg in args) {
x[i].Value = arg;
}
return calc (constraints);
});
// Now we can start stating the constraints
var nlConstraints = x.Select (p =>
new NonlinearConstraint(f,
// 1st contraint: x should be greater than or equal to 0
function: (args) => p.Value,
shouldBe: ConstraintType.GreaterThanOrEqualTo,
value: 0
)).ToList ();
// Finally, we create the non-linear programming solver
var solver = new AugmentedLagrangianSolver(x.Length, nlConstraints);
// And attempt to solve the problem
double minValue = solver.Minimize(f);
return Result.succsess;
}
I have a framework for building geometric constraints and a function called calc which returns the current
error on the constraints. The above is a naive first attempt to wrap my framework to make it accord
compatibile. However when I run my tests they all fail with the same error

which seems to suggest I have not set the gradient of the objective function. However in the API the gradient is
optional and I thought the algorithm would try to estimate the gradient if it was missing. I cannot calculate it
manually because the function is not trivially differentiable as it is a function of many geometric constraints
that are put together interactively.
Perhapps I am doing something obviously wrong and somebody can point it out.
Regards
Brad