protected void Create(int numberOfVariables,
Func<double[], double> function, ConstraintType shouldBe, double value,
Func<double[], double[]> gradient, double tolerance)
{
if (gradient != null)
{
double[] probe = new double[numberOfVariables];
double[] g = gradient(probe);
if (g.Length != numberOfVariables)
throw new DimensionMismatchException("gradient",
"The length of the gradient vector must match the number of variables in the objective function.");
}
this.NumberOfVariables = numberOfVariables;
this.ShouldBe = shouldBe;
this.Value = value;
this.Tolerance = tolerance;
this.Function = function;
this.Gradient = gradient;
}