## Using the LP Coefficient Matrix Directly

In our earlier Visual Basic code example for the Product Mix problem, we defined a VB.NET function NLPEvaluator_OnEvaluate() that computed the objective and constraint left hand side values for any given values of the decision variables. We assigned this function as the "Evaluator" that Solver SDK would call to compute values for the problem functions.

This approach parallels our Excel spreadsheet example, where the same objective and constraint left hand side values are computed by Excel formulas. And this general approach can be used for any type of optimization problem -- linear, smooth nonlinear, or nonsmooth.

But in a **linear programming** problem -- where the objective gradient and Jacobian matrix elements are **all constant** -- we could write a standard "Evaluator" function that would work for any model. If we set up an array obj() holding the objective gradient elements, and a two-dimensional array matval() that held the quantities of each part needed to build each product, the body of this function would contain:

`objval = 0`

'Compute objective value

For j = 0 To numcols

objval = objval + obj(j) * var(j)

Next j

For i = 0 To numrows

lhs(i) = 0

'Compute each constraint

For j = 0 To numcols

lhs(i) = lhs(i) + matval(i,j) * var(j)

Next j

Next i

In fact, **you don't have to write this code** -- it is effectively incorporated into Solver SDK Platform. The Simplex method for solving linear programming problems works directly with the objective gradient and Jacobian matrix. Instead of writing an "Evaluator" function, you can simply create a vector *fcnObj* holding the constant objective gradient values and a matrix *fcnConstr* containing the constant Jacobian values, and assign these to appropriate properties of the **Problem object**:

`'Define the Product Mix problem as an LP`

prob = New SolverPlatform.Problem

'Define the objective function gradient (one row)

Dim fcnObj As New DoubleMatrix

With fcnObj

.Create(Rows:=1, Columns:=3)

.Value(0, 0) = 450

.Value(0, 1) = 1150

.Value(0, 2) = 800`.Value(0, 3) = 400`

`prob.Model.AllLinear(Function_Type.Objective, _`

Variable_Type.Decision) = fcnObj

'Define the Jacobian matrix of constraint coefficients (detail omitted)

prob.Model.AllLinear(Function_Type.Constraint, _

Variable_Type.Decision) = fcnConstr

'Find the optimal solution

prob.Solver.Optimize()

Note that no "Evaluator" function is required -- Solver SDK uses the LP coefficient matrix directly.

You might be wondering: How is a linear programming model handled internally in Excel? **The default Solver engine** in the standard Excel Solver and the Premium Solver products handles **nonlinear problems** -- its solution approach is similar to our earlier Visual Basic example that called the function NLPEvaluator_OnEvaluate(). But if a Solver engine **specialized for LP problems** -- such as the standard LP/Quadratic Solver -- is selected, the **constant LP coefficients are extracted automatically** -- the approach is similar to the one above that uses the DoubleMatrix object.

**<< Back to: Advanced Tutorial Start**

**<< Back to: Tutorial Start**

**Next: Handling Sparsity in the Jacobian Directly >**