How to: Use Linear Programming using the Solver Foundation Solver APIs
You can use linear programming to minimize or maximize functions. In this example, an oil refinery must procure crude oil from two sources. The objective is to minimize the purchase cost of crude oils that differ in quality and to meet minimum production levels of 2,000 barrels of gasoline, 1,500 barrels of jet fuel, and 500 barrels of machine lubricant. Meanwhile, the suppliers cannot exceed their maximum daily production of crude oil. The following table shows the costs and capabilities of the two different crude oils.
Source: 
Saudi Arabia refining 
Venezuela refining 

Cost: 
$20 per barrel 
$15 per barrel 
Maximum daily production: 
9,000 barrels 
6,000 barrels 
Refining percentages: 
30% gasoline 40% jet fuel 20% lubricant 10% waste 
40% gasoline 20% jet fuel 30% lubricant 10% waste 
The following steps show how to use Solver Foundation to create and solve the refining model by developing directly against the simplex solver.
To use linear programming and the solver APIs to create the model

Create a console application named PetroChem.

Add a reference to Microsoft Solver Foundation on the .NET tab of the Add Reference dialog box.

Add the following Imports or using statements to the top of the Program code file.

In the Main method, use the following code to add a solver.

Add variables and their lower and upper bounds to the solver. The sources of crude oil are Saudi Arabia and Venezuela. In the following code, the AddVariable method is used to add these sources. Their maximum daily production of crude oil is defined by the SetBounds method.

Add three row identifiers for the gasoline, jet fuel, and machine lubricant constraints. Then add a row identifier to the model to represent the minimum cost of refining.

Add coefficients to the constraint rows and set bounds. In the following code, the refining capabilities of each crude oil for the two suppliers are added as decimals. For example, the Saudi Arabian crude oil produces 30% gasoline and the Venezuelan crude oil produces 40% gasoline. The SetCoefficient method is used to set these values. The SetBounds method is used to set the minimum production levels of 2,000 barrels of gasoline, 1,500 barrels of jet fuel, and 500 barrels of machine lubricant.
solver.SetCoefficient(gasoline, savid, 0.3); solver.SetCoefficient(gasoline, vzvid, 0.4); solver.SetBounds(gasoline, 2000, Rational.PositiveInfinity); solver.SetCoefficient(jetfuel, savid, 0.4); solver.SetCoefficient(jetfuel, vzvid, 0.2); solver.SetBounds(jetfuel, 1500, Rational.PositiveInfinity); solver.SetCoefficient(machinelubricant, savid, 0.2); solver.SetCoefficient(machinelubricant, vzvid, 0.3); solver.SetBounds(machinelubricant, 500, Rational.PositiveInfinity);

Add the costs of the crude oils to the model. Specify that the solver should minimize the goal by setting the third parameter to true. A value of false maximizes the goal.

Solve the model and get the report.
solver.Solve(new SimplexSolverParams()); Console.WriteLine("SA {0}, VZ {1}, Gasoline {2}, Jet Fuel {3}, Machine Lubricant {4}, Cost {5}", solver.GetValue(savid).ToDouble(), solver.GetValue(vzvid).ToDouble(), solver.GetValue(gasoline).ToDouble(), solver.GetValue(jetfuel).ToDouble(), solver.GetValue(machinelubricant).ToDouble(), solver.GetValue(cost).ToDouble()); Console.ReadLine();

Press F5 to build and run the code.
The Command window shows the following results.
SA 2000, VZ 3500, Gasoline 2000, Jet Fuel 1500, Machine Lubricant 1450, Cost 92500