Solver Advanced Tutorial - Using the LP Coefficient Matrix DirectlyUsing the LP Coefficient Matrix DirectlyIn 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:
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:
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(). |
