How to: Use Parallel Solvers in Linear Programming
You can launch two solvers in parallel and return the result from the solver that finishes first. The following procedure extends the example in How to: Use Linear Programming using the Solver Foundation Services APIs.
To use parallel solvers
Create a Console Application named PetroChem.
Add a reference to Microsoft Solver Foundation on the .NET tab.
Add the following using statements to the top of the Program code file.
In the Main method, add the following to code to get the context environment for a solver and create a new model.
Create new decision variables that represent the two sources of crude oil: Saudi Arabia and Venezuela. Then, add the decisions to the model.
Add two constraints that define the maximum daily production levels for the two refineries.
Add three constraints that define the refining capabilities of each crude oil. The constraints are added as decimals. For example, the Saudi Arabian crude oil produces 30% gasoline and the Venezuelan crude oil produces 40% gasoline. The first half of the constraint is added as 0.3 * sa + 0.4 * vz. The second half of the constraint identifies the minimum production of 2000 barrels of gasoline. Similar constraints are added for 1500 barrels of jet fuel and 500 barrels of machine lubricant.
Add the costs of the crude oils to the model and then specify that the solver should minimize the goal by setting the second parameter to GoalKind.Minimize.
Solve the model and get the report.
Press F5 to build and run the code.
The command window shows the following results.
vz: 3500, sa: 2000
===Solver Foundation Service Report===
Model Name: Default
Capabilities Applied: LP
Solve Time (ms): 392
Total Time (ms): 561
Solve Completion Status: Optimal
Solver Selected: Microsoft.SolverFoundation.Solvers.SimplexSolver
Simplex(TimeLimit = -1, MaximumGoalCount = -1, Arithmetic = Default, Pricing = Default, IterationLimit = -1, Algorithm = Default, Basis = Default, GetSensitivity = False)
IPM(TimeLimit = -1, MaximumGoalCount = -1, Arithmetic = Default, GapTolerance =0, Algorithm = Default, IterationLimit = -1)
Variables: 2 -> 2 + 4
Rows: 6 -> 4
Eliminated Slack Variables: 0
Pricing (double): SteepestEdge
Pivot Count: 3
Phase 1 Pivots: 3 + 0
Phase 2 Pivots: 0 + 0
Factorings: 4 + 0
Degenerate Pivots: 0 (0.00 %)