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

- How dense is the product of Sparse Matrices? (5)
- Testing and mocking your C# code with F# (5)
- Field notes from the F# tour (2)
- Throttling F# Events using the Reactive Extensions (3)

Comment RSSHow To Reverse Aging wrote: Hello, I enjoy reading all of your article. I want... [More]

thetaoofbadassus.tumblr.com wrote: I have read so many articles about the blogger lov... [More]

reverseagingprocess.newsvine.com wrote: Normally I do not read post on blogs, however I wo... [More]

How To Cure Herpes wrote: Thanks for finally writing about > Throttling F... [More]