Breaking News

Main Menu

Microsoft Solver Foundation Tutorial Pdf

вторник 24 марта admin 75

Introduction

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.

Excel plug-in

MSF includes a simple modeling language OML. This language can be used from theMSF API but also from the Excel plug-in. Here we make available a documentdescribing experiences with and hints for using the Excel/OML combination. Wedo this using a number of small models. Note that MSF also contains a wealth ofAPI's to be called from user programs.

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.

Simple transportation model

Model number one of the GAMS model ibrary is thistransportation model from the famous book by George Dantzig (LinearProgramming and Extensions, Princeton University Press, 1963). It has beenslightly changed to introduce dual degeneracy, so several optimal solutionsexist. Although this linear programming problem is very small it demonstratesindexing and scalable formulations. We argue that OML is a step forward fromusing Excel Solver as it shows rather than hides the structure of the model.
  • tnsport.gms: Transportation model written in GAMS
  • Trnsport with Solver.zip: The model organized for Excel/Solver
  • Trnsport with OML.zip: The model formatted for Excel/OML

Sparse data models

GAMS andExcel work with sparse data: missing data or empty cells are considered to bezero when using operations such as summations. The Data Binding facility in theMSF Excel plug-in requires a 'dense' data representation. Here we show twopossible solutions: first in the diet model we augment the data with the zerovalues. In the maximum flow network model we show how we can enumerate the setof arcs so we don't need to specify non-existing arcs.
  • stigler1939.gms: Diet model in GAMS
  • Stigler Diet Model.zip: Diet model in OML
  • maxflow.gms: Max-flow model in GAMS
  • maxflow.zip: Max-flow model in OML

CSP Model: Magic Squares

Constructing Magic Squares is difficult to model efficientlyusing Mixed Integer Programming. A magic square has numbers 1,.,n2placed on the board such that the rows, the columns and the diagonals add up tothe same value. The problem can be expressed much more natural with a CSPsolver using the all-different constraint. Some non-standard solveroptions were required to achieve better performance.
  • Magic Squares.zip: Magic Squares Model

CSP Model: The Social Golfer Problem

Constructing a schedule for a golf trip where players don't play each othermore than once is a difficult problem. Here are some formulations for N=16golfers playing 5 rounds with 4 foursomes. These models solve fairly easily.The same problem with N=32 golfers, 10 rounds is very difficult and I was notable to solve that instance.

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.

  • Golfer1.zip: Social Golfer formulation 1
  • Golfer2.zip: Social Golfer formulation 2

Traveling Salesman Problem

Thetraveling salesman problem (TSP) is a famous difficult problem. A salesman hasto visit a number of cities and return to the starting point. The goal is tominimize the total distance traveled. The TSP problem is probably the moststudied problem in the OR field. Here we solve a small instance as a MIP.

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.

  • Burma14.zip: 14 city TSP problem from TSPLIB

CSP Model: Langford's Problem

Computing Langford sequences can be specified easily usingthe all-different constraint. The problem is to place the numbers(1,1,2,2,3,3,4,4) such that equal numbers k have k other numbers in between,e.g. (4,1,3,1,2,4,3,2).
  • Langford.zip: Langford's Problem

CSP Model: Tiling Squares

Tiling squares with an upper limit on how many duplicate tiles can be used. The (7x7)problem below is easy we assume we know that we can cover the (7x7) are withtiles (4x4), (3x3), (3x3), (2x2), (2x2), (2x2), (1x1), (1x1), (1x1). The (9x9)problem is more difficult: we have an inventory of three tiles of each size(1x1) through (8x8) but not every tile has to be used. The big (19x19) problemis solved with a pool of just two tiles of each size (1x1) through (16x16).Modeling tricks to reduce symmetry are applied to be able to solve the largerinstances.
  • Tiling7x7.zip: Tiling Squares (7x7)
  • Tiling9x9.zip: id. size (9x9)
  • Tiling19x19.zip: id. size (19x19)

QP: Efficient Porfolio Frontier

Quadratic Programming (QP) models can be used to model aportfolio optimization problem. When we want to draw an efficient frontier asimple algorithm is to solve several QP's. Unfortunately there are no loopingconstructs in OML: we can form and solve only a single model with the Excelplug-in. In this example we combine the QP's into a single large QP.
  • Frontier.zip: standard formulation
  • Frontier2.zip: alternative formulation

QP vs LP: Optimal Porfolio Selection

In this model we compare an LPformulation with a QP formulation for the portfolio model. The multiple modelsare handled by a piece of C# code which is compiled into a DLL. Inside the C# codewe express the models in OML. The DLL is called from Excel via some VBA code.The output reports in the form of graphs are created in Excel.
  • OMLFromCSharp.zip: sources

Column Generation: Cutting Stock example

A remarkable algorithm to solve Cutting Stock problems is based on Column Generation, where newvariables (columns) are added to an LP model. In the document above a simple implementationof a column generation approach is implemented using MSF. The method is applied to a standardcutting stock problem where rolls of raw material have to be cut while minimizing waste.

Job Shop Scheduling

Job Shop Scheduling problems can be difficult to solve. An example is ft10 with 10 jobs and 10 machines.An optimal solution for this problem was not known for 25 years. Nowadays with the best MIP solverssuch as Gurobi and Cplex we can solve this problem formulated as a standard MIP model in less than 5 minutes.Some VBA code has been developed to produce GANTT charts in Excel.

Home

Microsoft Solver Foundation?

Microsoft Solver Foundation is an extensible .NET framework that helps you model and solve complex problems by:

  • Modeling and solving scenarios by using constraints, goals, and data.
  • Programming in the Optimization Modeling Language (OML), in C# imperatively, in F# functionally, or in any .NET Framework language.
  • Integrating third-party solvers, such as Gurobi, Mosek™, FICO™ Xpress, LINDO, CPLEX®, and lp_solve.
  • Using familiar interfaces in Microsoft Office Excel and SharePoint to create and solve models.

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

Introduction

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.

Microsoft Foundation Solver and lpsolve

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:

  • Copy the compiled lpsolve plugin wrapper code i.e LpSolvePlugIn.dll and the lpsolve library i.e lpsolve55.dll to the binDebug, binRelease folder. As an alternative, MSF has created a registry key 'HKEY_LOCAL_MACHINESOFTWAREMicrosoftMicrosoft Solver Foundation' with a string value PluginDirectory. The lpsolve plugin can also installed in this folder. MSF will search first in the folder of the executable that embeds Solver Foundation, and then in the plug-in directory specified in the registry key. In 64-bit machines, Solver Foundation will also create the same registry key for 32-bit apps. The key will be stored under 'HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoft'
  • Add a new file App.config to the project or edit the existing App.config and paste the solver registration contents as below:
    {Version} must be replaced by the version of MSF that is used. For example 2.0.2.8632 or 2.0.3.9657

LpSolveDirective object

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:

ArithmeticGet 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.
GetSensitivityWhether to generate sensitivity information at report. The default is False.
LpSolveLogFuncA log callback function to allow lp_solve to return information to the application. See put_logfunc
LpSolveMsgFuncA message callback function to allow lp_solve to return information to the application. See put_msgfunc
LpSolveAntiDegenSee set_anti_degen
LpSolveBasiscrashSee set_basiscrash
LpSolveBbDepthlimitSee set_bb_depthlimit
LpSolveBbFloorfirstSee set_bb_floorfirst
LpSolveBbRuleSee set_bb_rule
LpSolveBreakAtFirstSee set_break_at_first
LpSolveBreakAtValueSee set_break_at_value
LpSolveDebugSee set_debug
LpSolveEpsbSee set_epsb
LpSolveEpsdSee set_epsd
LpSolveEpselSee set_epsel
LpSolveEpsintSee set_epsint
LpSolveEpsperturbSee set_epsperturb
LpSolveEpspivotSee set_epspivot
LpSolveImproveSee set_improve
LpSolveInfiniteSee set_infinite
LpSolveLogFileSee set_outputfile
LpSolveMaxpivotSee set_maxpivot
LpSolveMipGapAbsSee set_mip_gap
LpSolveMipGapRelSee set_mip_gap
LpSolveNegrangeSee set_negrange
LpSolveObjBoundSee set_obj_bound
LpSolveObjInBasisSee set_obj_in_basis
LpSolvePivotingSee set_pivoting
LpSolvePresolveSee set_presolve
LpSolvePresolveMaxLoopsSee set_presolve
LpSolveReadParamsRead all settings from a file. See read_params
LpSolveScalelimitSee set_scalelimit
LpSolveScalingSee set_scaling
LpSolveSimplextypeSee set_simplextype
LpSolveSolutionlimitSee set_solutionlimit
LpSolveTimeoutSee set_timeout
LpSolveTraceSee set_trace
LpSolveVerboseSee set_verbose
MaximumGoalCountGet 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.
TimeLimitGet 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).
WaitLimitGet and set the amount of time (in milliseconds) the SFS will wait for a result after requesting a timeout/abort.

LpSolveSolver object (API)

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:

LpSolveLogFuncA log callback function to allow lp_solve to return information to the application. See put_logfunc
LpSolveMsgFuncA message callback function to allow lp_solve to return information to the application. See put_msgfunc
LpSolvePrintDebugDumpSee print_debugdump
LpSolveWriteLpSee write_lp
LpSolveWriteMPSSee write_mps
LpSolveWriteParamsSee write_params
LpSolveWriteXLISee 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.

SFS examples

Example1

This gives as output:

Example2

This gives as output:

Example3

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()

Example4

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:

API examples

Example5

This gives as output:

Example6

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.

Example7

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