GoldfarbIdnani Class 
Namespace: Accord.Math.Optimization
public class GoldfarbIdnani : BaseGradientOptimizationMethod, IOptimizationMethod, IOptimizationMethod<GoldfarbIdnaniStatus>
The GoldfarbIdnani type exposes the following members.
Name  Description  

GoldfarbIdnani(QuadraticObjectiveFunction, LinearConstraintCollection) 
Constructs a new GoldfarbIdnani class.
 
GoldfarbIdnani(QuadraticObjectiveFunction, IEnumerableLinearConstraint) 
Constructs a new GoldfarbIdnani class.
 
GoldfarbIdnani(QuadraticObjectiveFunction, Double, Double, Int32) 
Constructs a new instance of the GoldfarbIdnani class.
 
GoldfarbIdnani(Double, Double, Double, Double, Int32) 
Constructs a new instance of the GoldfarbIdnani class.

Name  Description  

ActiveConstraints  
ConstraintMatrix 
Gets the constraint matrix A for the problem.
 
ConstraintTolerances 
Gets the constraint tolerances b for the problem.
 
ConstraintValues 
Gets the constraint values b for the problem.
 
Deletions  
Function 
Gets or sets the function to be optimized.
(Inherited from BaseOptimizationMethod.)  
Gradient 
Gets or sets a function returning the gradient
vector of the function to be optimized for a
given value of its free parameters.
(Inherited from BaseGradientOptimizationMethod.)  
Iterations  
Lagrangian 
Gets the Lagrangian multipliers for the
last solution found.
 
LinearTerms 
Gets the vector of linear terms of the
quadratic optimization problem.
 
MaxIterations 
Gets or sets the maximum number of iterations that should be
performed before the method terminates. If set to zero, the
method will run to completion. Default is 0.
 
NumberOfConstraints 
Gets the total number of constraints in the problem.
 
NumberOfEqualities 
Gets how many constraints are inequality constraints.
 
NumberOfVariables 
Gets the number of variables (free parameters)
in the optimization problem.
(Inherited from BaseOptimizationMethod.)  
QuadraticTerms 
Gets the matrix of quadratic terms of
the quadratic optimization problem.
 
Solution 
Gets the current solution found, the values of
the parameters which optimizes the function.
(Inherited from BaseOptimizationMethod.)  
Status  
Token 
Gets or sets a cancellation token that can be used to
stop the learning algorithm while it is running.
(Inherited from BaseGradientOptimizationMethod.)  
Value 
Gets the output of the function at the current Solution.
(Inherited from BaseOptimizationMethod.) 
Name  Description  

Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
Maximize 
Finds the maximum value of a function. The solution vector
will be made available at the Solution property.
(Overrides BaseGradientOptimizationMethodMaximize.)  
Maximize(Double) 
Finds the maximum value of a function. The solution vector
will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
Minimize 
Finds the minimum value of a function. The solution vector
will be made available at the Solution property.
(Overrides BaseGradientOptimizationMethodMinimize.)  
Minimize(Double) 
Finds the minimum value of a function. The solution vector
will be made available at the Solution property.
(Inherited from BaseOptimizationMethod.)  
Optimize 
Not available.
(Overrides BaseOptimizationMethodOptimize.)  
ToString  Returns a string that represents the current object. (Inherited from Object.) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
ToT  Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)  
ToT  Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by Matrix.) 
References:
There are three ways to state a quadratic programming problem in this framework.
In the following section we will provide examples for those ways.
This is an example stating the problem using lambdas:
// Solve the following optimization problem: // // min f(x) = 2x²  xy + 4y²  5x  6y // // s.t. x  y == 5 (x minus y should be equal to 5) // x >= 10 (x should be greater than or equal to 10) // // In this example we will be using some symbolic processing. // The following variables could be initialized to any value. double x = 0, y = 0; // Create our objective function using a lambda expression var f = new QuadraticObjectiveFunction(() => 2 * (x * x)  (x * y) + 4 * (y * y)  5 * x  6 * y); // Now, create the constraints List<LinearConstraint> constraints = new List<LinearConstraint>() { new LinearConstraint(f, () => x  y == 5), new LinearConstraint(f, () => x >= 10) }; // Now we create the quadratic programming solver var solver = new GoldfarbIdnani(f, constraints); // And attempt solve for the min: bool success = solver.Minimize(); // The solution was { 10, 5 } double[] solution = solver.Solution; // With the minimum value 170.0 double minValue = solver.Value;
This is an example stating the problem using strings:
// Solve the following optimization problem: // // max f(x) = 2x² + xy  y² + 5y // // s.t. x + y <= 0 // y >= 0 // // Create our objective function using a text string var f = new QuadraticObjectiveFunction("2x² + xy  y² + 5y"); // Now, create the constraints List<LinearConstraint> constraints = new List<LinearConstraint>() { new LinearConstraint(f, "x + y <= 0"), new LinearConstraint(f, " y >= 0") }; // Now we create the quadratic programming solver var solver = new GoldfarbIdnani(f, constraints); // And attempt solve for the max: bool success = solver.Maximize(); // The solution was { 0.625, 0.625 } double[] solution = solver.Solution; // With the minimum value 1.5625 double maxValue = solver.Value;
And finally, an example stating the problem using matrices:
// Solve the following optimization problem: // // min f(x) = 2x²  xy + 4y²  5x  6y // // s.t. x  y == 5 (x minus y should be equal to 5) // x >= 10 (x should be greater than or equal to 10) // // Lets first group the quadratic and linear terms. The // quadratic terms are +2x², +3y² and 4xy. The linear // terms are 2x and +1y. So our matrix of quadratic // terms can be expressed as: double[,] Q = // 2x² 1xy +4y² { /* x y */ /*x*/ { +2 /*xx*/ *2, 1 /*xy*/ }, /*y*/ { 1 /*xy*/ , +4 /*yy*/ *2 }, }; // Accordingly, our vector of linear terms is given by: double[] d = { 5 /*x*/, 6 /*y*/ }; // 5x 6y // We have now to express our constraints. We can do it // either by directly specifying a matrix A in which each // line refers to one of the constraints, expressing the // relationship between the different variables in the // constraint, like this: double[,] A = { { 1, 1 }, // This line says that x + (y) ... (a) { 1, 0 }, // This line says that x alone ... (b) }; double[] b = { 5, // (a) ... should be equal to 5. 10, // (b) ... should be greater than or equal to 10. }; // Equalities must always come first, and in this case // we have to specify how many of the constraints are // actually equalities: int numberOfEqualities = 1; // Alternatively, we may use an explicit form: var constraints = new List<LinearConstraint>() { // Define the first constraint, which involves only x new LinearConstraint(numberOfVariables: 1) { // x is the first variable, thus located at // index 0. We are specifying that x >= 10: VariablesAtIndices = new[] { 0 }, // index 0 (x) ShouldBe = ConstraintType.GreaterThanOrEqualTo, Value = 10 }, // Define the second constraint, which involves x and y new LinearConstraint(numberOfVariables: 2) { // x is the first variable, located at index 0, and y is // the second, thus located at 1. We are specifying that // x  y = 5 by saying that the variable at position 0 // times 1 plus the variable at position 1 times 1 // should be equal to 5. VariablesAtIndices = new int[] { 0, 1 }, // index 0 (x) and index 1 (y) CombinedAs = new double[] { 1, 1 }, // when combined as x  y ShouldBe = ConstraintType.EqualTo, Value = 5 } }; // Now we can finally create our optimization problem var solver = new GoldfarbIdnani( function: new QuadraticObjectiveFunction(Q, d), constraints: constraints); // And attempt solve for the min: bool success = solver.Minimize(); // The solution was { 10, 5 } double[] solution = solver.Solution; // With the minimum value 170.0 double minValue = solver.Value;