Cobyla - how to define a constraint with a variable

I am trying to use the Cobyla class from the C # consent library to solve a non-linear optimization problem with constraints. It works correctly when the constraint is constant, for example:

NonlinearConstraint(2, x => x[0] + x[1] <= 100.0)

I need to use a variable in a constraint (the value must be changed by the user), for example:

double limit = 100.0; 
NonlinearConstraint(2, x => x[0] + x[1] <= limit) 

But that will not work. I get an exception:

An unhandled exception of type "System.NullReferenceException" occurred in Accord.Math.dll

Can someone show me examples of how to correctly define NonlinearConstraintwith a variable?

+4
source share

Source: https://habr.com/ru/post/1649869/


All Articles