Frontline Systems, Excel Solver, optimization software, Solver Excel, simulation software
Solver.com
From Frontline Systems, developers of the Excel Solver.

Solver tutorials

Learn to use optimization for resource allocation, and Monte Carlo simulation for risk analysis of your models.


 

Solver Advanced Tutorial - Using the LP Coefficient Matrix Directly

Using the LP Coefficient Matrix Directly

In our earlier Visual Basic code example for the Product Mix problem, we defined a VB function FuncEval() that computed the objective and constraint left hand side values for any given values of the decision variables.  We called the Solver DLL loadnlp() function, passing the address of FuncEval().

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 FuncEval() 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 FuncEval() 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 in the Solver DLL products.  The Simplex method for solving linear programming problems works directly with the objective gradient and Jacobian matrix.  Instead of writing a FuncEval() function and passing work arrays called obj() and matval() to loadnlp(), you can simply store the constant objective gradient values in obj(), the constant Jacobian values in matval(), and call the loadlp() function, passing these arrays as arguments:

'Define the Product Mix problem as an LP
lp = loadlp(PROBNAME, 3, 5, -1, obj, rhs, _
  sense, NullL, NullL, NullL, matval, _
  x, lb, ub, NullD, 15)
'Find and retrieve the optimal solution
optimize lp
solution lp, stat, objval, x, _
  NullD, NullD, NullD

Note that loadlp() does not take an argument such as FuncEval(), and you don't have to write this function.  As shown here, you can use most other Solver DLL functions with problems defined via calls to either loadlp() or loadnlp().

How is a linear programming model handled 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 loadnlp().  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 called loadlp().

Next:  Handling Sparsity in the Jacobian Directly >

<< Back to Tutorial Start


To Learn More:

For instant access to our white papers, example models, full-text User Guides, and to download free 15-day trial versions of our software products whenever you're ready, register now with no obligation.

User type
Email address
Name
First Last
Company
University
Phone

Trial version passwords are sent to the above email address. Our Privacy Policy protects you.