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

  1. Create a Console Application named Rosenbrock.

  2. Add a reference to Microsoft Solver Foundation on the .NET tab.

  3. Add the following Imports or using statements to the top of the Program code file.

    using Microsoft.SolverFoundation.Common;
    using Microsoft.SolverFoundation.Solvers;
    
  4. In the Main method, add a solver by typing the following:

    CompactQuasiNewtonSolver solver = new CompactQuasiNewtonSolver(2);
    
  5. Set the delegate for getting the value and gradient at each point.

    solver.GradientAndValueAtPoint = TwoDimensionalRosenbrockFunction;
    
  6. Solve the model and get the report.

    CompactQuasiNewtonSolutionQuality solutionQuality =
      solver.Solve(new CompactQuasiNewtonSolverParams());
    Console.Write(solver.ToString());
    
  7. 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;
    }
    
  8. 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

Concepts

Developing with Solver Foundation Services (SFS)