Developing with Solver Foundation Services (SFS)

Solver Foundation 3.0

You can access the Microsoft Solver Foundation by using the Solver Foundation Services (SFS) level or by using the solver-specific APIs. We recommend the SFS level for modeling, data binding for parameters and decisions by using LINQ, educational use, automatic selection of a suitable solver, and construction of models that may require more than one solver. Using the Solver Foundation Services can make models more maintainable, and you can use third-party solvers without changing your code. The SFS provides a clean API for defining optimization models. You can build and improve your model without worrying about the details of solver capabilities.

When you use a Solver Foundation project template, the target .NET Framework must be .NET Framework 4. There is no support for .NET Framework 4 Client Profile in Microsoft Solver Foundation 3.0.

Microsoft Solver Foundation includes built-in solvers and the ability to add solvers provided by third-parties. Gurobi Optimization supplies a Mixed Integer Programming (MIP) solver, which is included as the default MIP solver in the Solver Foundation Services (SFS) layer of Microsoft Solver Foundation. For more information, see the Gurobi Solver Programming Primer in the Program Files\Microsoft Solver Foundation\3.0.1.nnnn\Documents folder.

The following table shows the complete list of third-party solvers that can be used in Microsoft Solver Foundation.

Additionally, you can create your own solvers and integrate it into Microsoft Solver Foundation by implementing interfaces such as ILinearModel, ITermModel or INonlinearModel. For more information, see the MSF MILP Solver Plugin SDK document in the \Installation Folder\Microsoft Solver Foundation\3.0.1.nnnn\Documents folder.

Changing the Default Solver

To register a solver or change the default solver, add a file called app.config to the Visual Studio solution. A solver can be registered more than once, as long as the capability of the solver is different.

More than one solver can be registered for the same capability. If the Solve method is not passed any directive instance, the first registered solver for the requested capability is used. If there are no registered solvers for the requested capability, the default Solver Foundation solver is used. If the Solve method is passed a directive instance, that particular solver is invoked if the solver is registered with that capability.

The following table lists the elements of the configuration file.






Defines the configuration for Microsoft Solver Foundation.



Groups all the solvers. All solvers must have a unique combination of solver name and capability.



Optional. The description of the solver.


Required. Describes the capability of the solver.

  • LP: linear programming.

  • MILP: mixed integer linear programming.

  • QP: quadratic programming.

  • MIQP: mixed integer quadratic programming.

  • CP: constraint programming.

  • NLP: non-linear programming

  • MINLP: mixed integer non-linear programming


Optional. The name of the interface to use for the solver and model type, typically used for a non-linear solver. Valid interfaces include ITermSolver and INonlinearSolver. If no interface is specified, ILinearSolver is the default interface.


Required. The fully qualified name of the solver.


Required. The name of the solver class that implements the ILinearSolver, ILinearModel, ISolver, ITermModel, INonlinearModel, ITermSolver, or the INonlinearSolver interface.


Optional. The name of the directive class for the solver. If missing, the solver is assumed to only support the Directive class instance.


Required. The name of the solver-specific parameter class that implements the ISolverParameters class.

The following XML shows the contents of an app.config file for a Microsoft Solver Foundation project.

<?xml version="1.0" encoding="utf-8" ?>
      requirePermission="true" />

      <MsfPluginSolver name="solver1"
        parameterclass="SampleMilpSolvers.Solver1Parameter" />
      <MsfPluginSolver name="solver2"
        parameterclass="SampleMilpSolvers.Solver2Parameter" />
        parameterclass="SampleMilpSolvers.Solver2Parameter" />
      <MsfPluginSolver name=”solver4”
        parameterclass="SolverFoundation.Plugin.Solver4.Solver4Parameter" />

SFS uses the following process to select a solver:

  1. Analyzes the current model.

  2. Determines the model that matches the current model.

    The model type can be LP, MILP, QP, MIQP, CP, NLP, or MINLP. The most specific matching model is selected. For example, if both QP and NLP match, QP is selected because it is a more specific type.

  3. Examines the configuration file for all solvers.

  4. Selects the first solver in the configuration file that matches the model type.

  5. Determines which interface is supported by the selected solver.

  6. If a solver implements ITermSolver or INonlinearSolver, which are typically implemented for NLP solvers, SFS determines whether the solver can support additional capabilities required by the model. If the solver cannot support the additional capabilities, it tests the next solver in the configuration file.

  7. If a match is found, SFS sends the model to the solver. If SFS cannot find a match, an error occurs.

Solvers are prioritized for consideration based on the order in which they appear in the configuration file.

Additional considerations for solver selection include the following:

  • Directives override the solver selection logic and instruct SFS to use a specific solver. You can use a directive to force the selection of a lower priority solver or a Solver Foundation solver over a higher priority solver that is registered in the configuration file. For example, by using a directive you can specify the Solver Foundation CP solver instead of a registered third-party solver.

  • If a solver implements more than one interface for a model type, you must create multiple MsfPluginSolver entries in the configuration file. You can specify only one interface for each solver.

    Tip Tip

    If a solver implements multiple interfaces, test whether the solver works using ILinearModel as the interface. If this interface works, use ILinearModel.

  • A third-party solver that implements ITermModel and supports the CP model type can be registered. Registration of CP model types in the configuration file was not supported prior to Microsoft Solver Foundation 3.0.

The Solver Foundation solvers do not use a configuration file. They use an internal configuration, similar to the configuration file above, to match a model to a solver. If no configuration file is present, SFS uses the internal configuration. If a configuration file is present and no matching solver is found, SFS tries to match the model by using this internal configuration. Conceptually, this works as if the configuration file is appended with the internal configuration.

The following table shows the prioritization of the solvers in the internal configuration. If no directive is provided, or if a generic directive is provided, the first installed solver for the matching model type is used. If a directive is provided, the first installed solver that takes the specified directive for that model type is used.

Model type







Gurobi directive, MixedIntegerProgrammingDirective



Interior point method




Gurobi directive, MixedIntegerProgrammingDirective


SimplexDirective , MixedIntegerProgrammingDirective


Interior point method



Gurobi directive



Gurobi directive


Constraint satisfaction programming



Hybrid local search


Compact quasi-Newton



Hybrid local search


For information on using non-linear programming and the hybrid local search solver, see Solving Nonlinear Models using the Default Solver.

You can use data binding and solving events to track progress. Any event handlers that you write must be thread-safe because the SFS may call an event from multiple threads. We recommend that you implement any necessary locking.

Data Binding Events

You can use the DataBindingEventArgs object to find solver information during data binding. For more information, see How to: Respond to the Solver Data Binding Event.

Solving Events

The SolvingEventArgs object can be used to screen for a specific type of event, such as an improved incumbent solution. Make sure that more events are not fired after the CancelAll method is called on an event object. For more information, see How to: Respond to the Solving Event from a Solver.

If you are creating a third-party solver plug-in, you must implement the ISolverEvents interface, which defines the Solving property. To retrieve the values of the Solving property, implement the ISolverProperties interface or override these methods by inheriting from the LinearModel object. If the third-party solver plug-in does not support get or set accessors on a property, we recommend that you throw the NotSupportedException exception.

You can use Solver Foundation to programmatically access report information. For more information, see How to: Create a Solver Report. In addition, you can add custom properties on third-party solvers and include the values of those properties in results. For more information, see How to: Create a Custom Solver Report using the SFS APIs.

If you are creating a third-party solver plug-in, you can subclass the LinearReport class and then implement the IReportProvider interface, which defines the GetReport method. Then, the plug-in could create an instance of the specific solver report and return that instance.