How to: Use Unconstrained Non-Linear Programming
You can use the compact quasi-Newton solver (CompactQuasiNewtonSolver) for unconstrained non-linear programming. For example, you can find the global minimum of a two-dimensional Rosenbrock function created by mathematician Howard Rosenbrock in 1960.
To solve a 2-D Rosenbrock function
Create a Console Application named Rosenbrock.
Add a reference to Microsoft Solver Foundation on the .NET tab.
Add the following Imports or using statements to the top of the Program code file.
using Microsoft.SolverFoundation.Common; using Microsoft.SolverFoundation.Solvers;
In the Main method, add a solver by typing the following:
CompactQuasiNewtonSolver solver = new CompactQuasiNewtonSolver(2);
Set the delegate for getting the value and gradient at each point.
solver.GradientAndValueAtPoint = TwoDimensionalRosenbrockFunction;
Solve the model and get the report.
CompactQuasiNewtonSolutionQuality solutionQuality = solver.Solve(new CompactQuasiNewtonSolverParams()); Console.Write(solver.ToString());
Define the TwoDimensionalRosenbrockFunction function outside of the Main method.
private static double TwoDimensionalRosenbrockFunction(double[] point, double[] gradient) { double value = (100 * Math.Pow(point[1] - Math.Pow(point[0], 2), 2)) + Math.Pow(1 - point[0], 2); gradient[0] = 400 * point[0] * (Math.Pow(point[0], 2) - point[1]) + 2 * (point[0] - 1); gradient[1] = 200 * (point[1] - Math.Pow(point[0], 2)); return value; }
Press F5 to build and run the code.
The command window shows the following results.
Minimize problem
Dimensions = 2
Starting point = 0, 0
Solution quality is: LocalOptima
Number of iterations performed: 21
Finishing point =0.999999997671584, 0.999999995285991
Finishing value =5.74844710320033E-18
See Also
Tasks
How to: Use Linear Programming using the Solver Foundation Services APIs