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

- It takes one to know one (3)
- Create optimization programs dynamically with C# and the Microsoft Solver Foundation (8)
- Management, the Gordon Ramsay way (4)
- VSTO add-in with multiple assemblies (5)

Comment RSSRon wrote: Statistics are used much like a drunk uses a lampp... [More]

Ron wrote: I just started tinkering with Solver the other day... [More]

bryan tyler nelson wrote: I do not even understand how I stopped up right he... [More]

prestamo wrote: What i do not realize is in truth how you are now ... [More]