First steps with the Microsoft Solver Foundation While most of my posts tend to focus on software development, my background is in optimization. 12-pack, take two: Microsoft Solver Foundation In our last post, we looked at a Sieve-like algorithm to help a Brewery find how closely they can ma. New release of Microsoft Solver Foundation Just saw that version 3.1 of Microsoft Solver.
Microsoft Solver Foundation isan exciting new .NET based optimization platform that includes solvers forLinear Programming (LP), Mixed Integer Programming (MIP), Quadratic Programming(QP) and CSP (Constraint Programming) problems. Included in version 1.1 is thehigh-performance state-of-the-art multi-threaded Gurobi MIP solver and plugincapabilities for third party solvers such as Cplex and Mosek. We can provideservices to help you design, prototype, develop and implement high-performance,scalable and reliable optimization models on this framework. Models developedin Microsoft Solver Foundation can be integrated seamlessly in your .NETapplications and services.
Below is a list of toy models that are discussed in the above document. Thesize of the models is kept small so they can be solved with the StandardEdition of Microsoft Solver Foundation. These small toy examples are used todemonstrate certain features of OML. Real world applications are often toolarge, too specific and too messy to be very useful for demonstrations, whilethese smaller examples show features that can be used directly in largercontexts.
The models are implemented as CSP models: they are more compactthan the corresponding MIP models. Scheduling models are a well-know applicationarea for CSP algorithms.
The current state-of-the-art MIP solvers can solve TSPs up to about 50 cities, andfind good solutions for even larger problems. Of course specialized algorithms and solvers arecapable of handling larger instances.
Microsoft Solver Foundation is an extensible .NET framework that helps you model and solve complex problems by:
Modeling and solving capabilities
Solver Foundation Services (SFS) can automatically analyze models and determine which solver is most appropriate. If you are an advanced modeler, you can choose specific solvers and solver attributes. While solving the models, SFS manages all threading, many-core, synchronization, scheduling, and model execution issues. When finished, SFS produces reports about solver behavior and results, and provides additional information about solutions, including sensitivity. Finally, SFS allows LINQ data binding of model parameters and delivery of results in multiple formats.
Program in OML, F#, C#, VB, C++, IronPython, and more
Solver Foundation supports all the .NET Framework languages and provides samples in many of them. In addition, if you prefer a modeling language, you can use Solver Foundation's type safe optimization modeling language (OML).
Integrated and Third-Party Solvers
Solver Foundation allows new or existing third-party solvers to plug into the SFS directly, avoiding the need to learn a new modeling language or the significant overhead in managing solver specific solutions. These solvers include numerical, symbolic, and search algorithms that you can use in your models. There is a collection of certified partner wrappers for Gurobi, Mosek™, FICO™ Xpress, and LINDO, as well as reference wrapper source code for CPLEX® and lp_solve.
The following system diagram describes the extensible architecture of Microsoft Solver Foundation.
For more information see Microsoft Solver Foundation blog
Solver Foundation can be approached either at the Solver Foundation Services (SFS) level or via the APIs for specific kinds of solver.
The SFS level is recommended for conceptual clarity of modeling, for ease of binding to data from various sources, for educational use, for introducing you to all the capabilities of Solver Foundation, for automatic selection of a solver to suit your model, and for construction of models which may require the use of more than one kind of solver. Solver Foundation will be heavily investing in the SFS.
The Solver-specific APIs are intended for use by experienced programmers who clearly know which kind of solver they need to use, are prepared to write code to translate a model into a sequence of API calls, and where the usage is to be embedded in an application where the application is fully responsible for capturing the model and supplying the instance data.
The advantage of using the SFS level is that code is (almost) solver independent. In the ideal case the system chooses which solver to use dependent of the model and availability of solvers. Solver choice can also be instructed via the configuration file. To have more control of the chosen solver and its parameters also a specific solver directive can be chosen in the code. Only that directive code is then solver specific.
The advantage of using the API of the specific solver is that you have more control over the solvers' specific features. But the disadvantage is that you are targetting specifically that solver and it is thus more difficult to change solver.
The Microsoft solver foundation team recommend use of the Solver Foundation Services unless you are absolutely sure you need to program direct to a specific solver API.
lpsolve is callable from Microsoft Foundation Solver via a wrapper or plugin. As such, it looks like lpsolve is fully integrated with Microsoft Foundation Solver.
This plugin acts as a bridge between Solver foundation and lpsolve.
Users of the plugin and MSF need to register the new solver in the app.config in order to use it.
To use the lpsolve plugin with MSF:
Microsoft Foundation Services can instruct the solver via a directive. All properties and methods starting with LpSolve are lp_solve specific and control the solver. All others are inherited from the base Directive object. These are the available properties and methods:
Arithmetic | Get or set the arithmetic to use for numeric solving. lp_solve only allows double arithmetic. Setting this property to something different from Double or Default will result in a NotImplementedException exception. |
GetSensitivity | Whether to generate sensitivity information at report. The default is False. |
LpSolveLogFunc | A log callback function to allow lp_solve to return information to the application. See put_logfunc |
LpSolveMsgFunc | A message callback function to allow lp_solve to return information to the application. See put_msgfunc |
LpSolveAntiDegen | See set_anti_degen |
LpSolveBasiscrash | See set_basiscrash |
LpSolveBbDepthlimit | See set_bb_depthlimit |
LpSolveBbFloorfirst | See set_bb_floorfirst |
LpSolveBbRule | See set_bb_rule |
LpSolveBreakAtFirst | See set_break_at_first |
LpSolveBreakAtValue | See set_break_at_value |
LpSolveDebug | See set_debug |
LpSolveEpsb | See set_epsb |
LpSolveEpsd | See set_epsd |
LpSolveEpsel | See set_epsel |
LpSolveEpsint | See set_epsint |
LpSolveEpsperturb | See set_epsperturb |
LpSolveEpspivot | See set_epspivot |
LpSolveImprove | See set_improve |
LpSolveInfinite | See set_infinite |
LpSolveLogFile | See set_outputfile |
LpSolveMaxpivot | See set_maxpivot |
LpSolveMipGapAbs | See set_mip_gap |
LpSolveMipGapRel | See set_mip_gap |
LpSolveNegrange | See set_negrange |
LpSolveObjBound | See set_obj_bound |
LpSolveObjInBasis | See set_obj_in_basis |
LpSolvePivoting | See set_pivoting |
LpSolvePresolve | See set_presolve |
LpSolvePresolveMaxLoops | See set_presolve |
LpSolveReadParams | Read all settings from a file. See read_params |
LpSolveScalelimit | See set_scalelimit |
LpSolveScaling | See set_scaling |
LpSolveSimplextype | See set_simplextype |
LpSolveSolutionlimit | See set_solutionlimit |
LpSolveTimeout | See set_timeout |
LpSolveTrace | See set_trace |
LpSolveVerbose | See set_verbose |
MaximumGoalCount | Get and set the maximum number of goals to optimize. lp_solve allows only one goal. If something different from 1 is specified, a NotImplementedException will be thrown. |
TimeLimit | Get and set the time-limit (in milliseconds) of Solve. No limit if it is set to a negative value. Default value is -1 (no limit). |
WaitLimit | Get and set the amount of time (in milliseconds) the SFS will wait for a result after requesting a timeout/abort. |
When the solver is called directly via the API, the LpSolveSolver object is used to build and solve the model. All properties and methods starting with LpSolve are lp_solve specific and control the solver. All others are inherited from the base object. These are the available properties and methods:
LpSolveLogFunc | A log callback function to allow lp_solve to return information to the application. See put_logfunc |
LpSolveMsgFunc | A message callback function to allow lp_solve to return information to the application. See put_msgfunc |
LpSolvePrintDebugDump | See print_debugdump |
LpSolveWriteLp | See write_lp |
LpSolveWriteMPS | See write_mps |
LpSolveWriteParams | See write_params |
LpSolveWriteXLI | See write_XLI |
The LpSolveSolver object can also be subclassed to override the LpSolveLogFunc and LpSolveMsgFunc methods. That is an alternative for providing the these functions via the LpSolveLogFunc and LpSolveMsgFunc properties. That will be shown in the examples below.
This gives as output:
This gives as output:
It is also possible to return and access the sensitivity information (from MSF version 2.1). This is demonstrated by this example. This is the same example as in the sensitivity section.
Note that GetSensitivity on the directive must be set on true to get sensitivity information. By default this is not set and as in the examples above there is no sensitivity information provided if not set.
This gives as output:
Note that sensitivity information can also be retrieved from the report in variables via the methods GetAllShadowPrices() and GetAllConstraintBoundsSensitivity()
This example is an extension to Example3. Sensitivity is not asked and thus not reported. COLFOUR is defined as integer and an extra constraint is added. This constraint will be removed afterwards. Also log and message callback functions are set to show the lp_solve optimization process.
This gives as output:
This gives as output:
This gives as output:
1902-1908: Often no serial number or model name on label, picture of Orville Gibson and lyre mandolin, date sometimes penciled under the top (must be seen with a mirror). Or serial number and model name on white paper label, number range from 0100 to 99999, hand inked or penciled 1908 to 1932, ink stamped serial number 1932 to 1947. Gibson a5 mandolin. Before mid-1950, most Gibson headstocks were thinner at the top when looked at from a side profile. After 1950, headstocks had uniform thickness. Dating a Gibson by Factory Order Number (FON) Gibson has historically used two different alpha-numerical formats to catalog its instruments: serial numbers and FONs (Factory Order Numbers). Serial Number Search Gibson Serial Numbers 1975-Present This section is designed to assist in dating and/or identifying instruments manufactured or distributed by Gibson Guitar Corp. Please note that most of this information relates to serial numbers used from 1975 to present. In 1955, Gibson forgot to put back the serial number range to 0001. So they had just put the year from 4 to 5. For this reason, the array of four-digit serial number was exceeded after 9999. Thence 5 digits and no space between the year (5) and the serial number.
This gives as output:
See also Using lpsolve from MATLAB, Using lpsolve from O-Matrix, Using lpsolve from Sysquake, Using lpsolve from Octave, Using lpsolve from FreeMat, Using lpsolve from Euler, Using lpsolve from Python, Using lpsolve from Sage, Using lpsolve from PHP, Using lpsolve from Scilab