This section describes techniques for converting PROC NLP models to PROC OPTMODEL models. Example 5.8 also demonstrates how to rewrite a PROC NLP model for use with PROC OPTMODEL.
To illustrate the basics, consider the following first version of the PROC NLP model for the example “Simple Pooling Problem” in Chapter 7: The NLP Procedure in SAS/OR User's Guide: Mathematical Programming Legacy Procedures:
proc nlp all; parms amountx amounty amounta amountb amountc pooltox pooltoy ctox ctoy pools = 1; bounds 0 <= amountx amounty amounta amountb amountc, amountx <= 100, amounty <= 200, 0 <= pooltox pooltoy ctox ctoy, 1 <= pools <= 3; lincon amounta + amountb = pooltox + pooltoy, pooltox + ctox = amountx, pooltoy + ctoy = amounty, ctox + ctoy = amountc; nlincon nlc1-nlc2 >= 0., nlc3 = 0.; max f; costa = 6; costb = 16; costc = 10; costx = 9; costy = 15; f = costx * amountx + costy * amounty - costa * amounta - costb * amountb - costc * amountc; nlc1 = 2.5 * amountx - pools * pooltox - 2. * ctox; nlc2 = 1.5 * amounty - pools * pooltoy - 2. * ctoy; nlc3 = 3 * amounta + amountb - pools * (amounta + amountb); run;
These statements define a model that has bounds, linear constraints, nonlinear constraints, and a simple objective function. The following statements are a straightforward conversion of the PROC NLP statements to PROC OPTMODEL form:
proc optmodel; var amountx init 1 >= 0 <= 100, amounty init 1 >= 0 <= 200; var amounta init 1 >= 0, amountb init 1 >= 0, amountc init 1 >= 0; var pooltox init 1 >= 0, pooltoy init 1 >= 0; var ctox init 1 >= 0, ctoy init 1 >= 0; var pools init 1 >=1 <= 3; con amounta + amountb = pooltox + pooltoy, pooltox + ctox = amountx, pooltoy + ctoy = amounty, ctox + ctoy = amountc; number costa, costb, costc, costx, costy; costa = 6; costb = 16; costc = 10; costx = 9; costy = 15; max f = costx * amountx + costy * amounty - costa * amounta - costb * amountb - costc * amountc; con nlc1: 2.5 * amountx - pools * pooltox - 2. * ctox >= 0, nlc2: 1.5 * amounty - pools * pooltoy - 2. * ctoy >= 0, nlc3: 3 * amounta + amountb - pools * (amounta + amountb) = 0; solve; print amountx amounty amounta amountb amountc pooltox pooltoy ctox ctoy pools;
The PROC OPTMODEL variable declarations are split into individual declarations because PROC OPTMODEL does not permit name lists in its declarations. In the OPTMODEL procedure, you specify variable bounds as part of the variable declaration instead of in a separate BOUNDS statement. The PROC NLP statements are as follows:
parms amountx amounty amounta amountb amountc pooltox pooltoy ctox ctoy pools = 1; bounds 0 <= amountx amounty amounta amountb amountc, amountx <= 100, amounty <= 200, 0 <= pooltox pooltoy ctox ctoy, 1 <= pools <= 3;
The following PROC OPTMODEL statements are equivalent to the preceding PROC NLP statements:
var amountx init 1 >= 0 <= 100, amounty init 1 >= 0 <= 200; var amounta init 1 >= 0, amountb init 1 >= 0, amountc init 1 >= 0; var pooltox init 1 >= 0, pooltoy init 1 >= 0; var ctox init 1 >= 0, ctoy init 1 >= 0; var pools init 1 >= 1 <= 3;
The linear constraints are declared in the PROC NLP model by using the following statement:
lincon amounta + amountb = pooltox + pooltoy, pooltox + ctox = amountx, pooltoy + ctoy = amounty, ctox + ctoy = amountc;
The following linear constraint declarations in the PROC OPTMODEL model are quite similar to the PROC NLP LINCON declarations:
con amounta + amountb = pooltox + pooltoy, pooltox + ctox = amountx, pooltoy + ctoy = amounty, ctox + ctoy = amountc;
But PROC OPTMODEL provides much more flexibility in defining linear constraints. For example, a coefficient can be a named parameter or any other expression that evaluates to a constant.
The cost
parameters are declared explicitly in the PROC OPTMODEL model. Unlike the DATA step or the NLP procedure, PROC OPTMODEL requires
names to be declared before they are used. There are multiple ways to set the values of these parameters. The preceding example
uses assignments. You could make the values part of the declaration by using the INIT expression clause or the = expression clause. You could also read the values from a data set by using the READ DATA statement.
In the original PROC NLP statements, the assignment to a parameter such as costa
occurs every time the objective function is evaluated. However, the assignment occurs just once in the PROC OPTMODEL statements,
when the assignment statement is processed. This works because the values are constant. But the PROC OPTMODEL statements permit
the parameters to be reassigned later so that you can interactively modify the model.
The following statements define the objective f
in the PROC NLP model:
max f; . . . f = costx * amountx + costy * amounty - costa * amounta - costb * amountb - costc * amountc;
The PROC OPTMODEL version of the objective is defined by using the same expression text, as follows:
max f = costx * amountx + costy * amounty - costa * amounta - costb * amountb - costc * amountc;
But the MAX statement and the assignment to the name f
in the PROC NLP statements are combined in PROC OPTMODEL. There are advantages and disadvantages to this approach. The PROC
OPTMODEL formulation is much closer to the mathematical formulation of the model. However, if multiple intermediate variables
are used to structure the objective, then multiple IMPVAR declarations are required.
In the PROC NLP model, the nonlinear constraints use the following syntax:
nlincon nlc1-nlc2 >= 0., nlc3 = 0.; . . . nlc1 = 2.5 * amountx - pools * pooltox - 2. * ctox; nlc2 = 1.5 * amounty - pools * pooltoy - 2. * ctoy; nlc3 = 3 * amounta + amountb - pools * (amounta + amountb);
In the PROC OPTMODEL model, the equivalent statements are as follows:
con nlc1: 2.5 * amountx - pools * pooltox - 2. * ctox >= 0, nlc2: 1.5 * amounty - pools * pooltoy - 2. * ctoy >= 0, nlc3: 3 * amounta + amountb - pools * (amounta + amountb) = 0;
The nonlinear constraints in PROC OPTMODEL use the same syntax as linear constraints. In fact, if the variable pools
were declared as a parameter, then all the preceding constraints would be linear. The nonlinear constraint in PROC OPTMODEL
combines the NLINCON statement of PROC NLP with the assignment in the PROC NLP statements. Objective names can be used in
nonlinear constraint expressions to structure the formula as they are in objective expressions,
The PROC OPTMODEL model does not use a RUN statement to invoke the solver. Instead the solver is invoked interactively by the SOLVE statement in PROC OPTMODEL. By default, the OPTMODEL procedure prints much less information about the optimization process. Generally this information consists of messages from the solver (such as the termination reason) and a short status display. The PROC OPTMODEL statements add a PRINT statement in order to display the variable estimates from the solver.