While most of my posts tend to focus on software development, my background is in optimization. Unfortunately, I don’t get to use these two skillsets together too often, because most projects require fairly basic modeling, and because the tools they require do not always integrate well together.

Luckily, the project I am currently working on involved performing some optimization, from within a .NET application, which gave me an opportunity to investigate the **Microsoft Solver Foundation**, which comes with a free solver and provides a framework for leveraging existing commercial solvers.

What is a solver? In a nutshell, it is an algorithm designed to identify optimal input values to maximize a function, while satisfying constraints. Certain classes of problems can be solved very efficiently using known algorithms, while others require the use of heuristics – but in general, if you find yourself asking “what is the best combination of values for this situation”, chances are, a solver is the tool you should be using.

Rather than go into theory, let’s look at an illustration, which will hopefully give you a sense for what the Microsoft Solver Foundation can do for you, and how you can leverage it in your .NET applications.

## The problem: cheap imports from Gadgetistan

Imagine the following situation. You are an enterprising individual, and realize that there is good money to be made by importing goods from the Republic of Gadgetistan, the neighboring country. You break the piggybank, invest in an old truck, drive over there and get ready to buy a truckload of the local specialties, **Widgets**, **Sprockets** and **Gizmos**.

The truck didn’t come cheap, so you have only **200 Rublars** (the official currenty of Gadgetistan) left in your wallet – this is your **Budget Constraint**.

The truck user manual is very clear – the **Capacity** of your truck is **500 Kilograms**. One pound more, and your wonderful truck could collapse in a sad heap of scrap metal. This is your **Capacity Constraint**.

A bit of market research yielded the following information about the main product: the buying **Cost**, the reselling **Price**, and the **Weight** for a unit of each of the main goods from Gadgetistan.

| **Cost (Rublars)** | **Price (Rublars)** | **Weight (Kgs)** |

**Widget** | 10 | 30 | 50 |

**Sprocket** | 15 | 30 | 20 |

**Gizmo** | 25 | 60 | 80 |

Your problem at that point is simple: how many units of each product should you carry in your truck, to make the most of your trip?

More...

## Comments

- Using FSI to execute F# code from a .NET app (8)
- Excel ScatterPlot with labels, colors and markers (29)
- S-shaped market adoption curve (37)
- Plot functions from F# to Excel (4)

Comment RSSDave Thomas wrote: If anyones interested I wrote a couple of article ... [More]

Ron wrote: Mathias, That was just what I was looking for. T... [More]

Mathias wrote: Hi Scott, I don't know of an existing implementati... [More]

Mathias wrote: Damn - that is a bit strange, I will look into it.... [More]