Optimization with IronPython

Microsoft Solver Foundation is a set of development tools for mathematical optimization and modeling that relies on a managed execution environment and the common language runtime. Solver Foundation makes it easier to build and solve real-world optimization models by providing a .Net API and Solver Foundation Services runtime for model creation, reporting, and analysis; a declarative modeling language (OML) for specifying optimization models; and built-in solvers that cover most types of commonly solved optimization models. You can also use Solver Foundation with popular commercial and open source solvers such as Gurobi, Frontline Solver SDK, Ziena KNITRO, and lp_solve.

Building a model is as simple as declaring the output decisions to be solved for, the goal to be optimized, and the constraints that must be honored. In this production planning model we have two crude oil refineries located in Saudi Arabia and Venezuela that produce gasoline, jet fuel, and lubricant. The goal is to minimize production costs that depend on location. Customer demand for each product must be met, but each refinery has a limited production capacity. The code to build and solve the model is as follows:

m = model() # a Solver Foundation model
sa = m.real(lower = 0, upper = 9000) # Saudi Arabia production is between 0 and 9000
vz = m.real(lower = 0, upper = 6000)
m.greaterequal(const(0.3) * sa + const(0.4) * vz, 1900) # gasoline production at least 1900
m.greaterequal(const(0.4) * sa + const(0.2) * vz, 1500) # jet fuel production at least 1500
m.greaterequal(const(0.2) * sa + const(0.3) * vz, 500) # lubricant production at least 500
m.minimize(const(20)*sa + const(15)*vz) # minimize production costs
s = m.solve()

The Express version of Solver Foundation is available here, and the Standard version is available for MSDN subscribers. The Solver Foundation installation includes Iron Python samples, and the Solver Foundation MSDN site includes source source for the Solver Foundation IronPython package.

Last edited Mar 2, 2011 at 10:11 PM by Ptools, version 6


No comments yet.