The following optimization problem is discussed in Haverly (1978) and Liebman et al. (1986). This example illustrates how to use PROC FCMP to define nonlinear constraints and use an MPS data set to define linear constraints. Minimize
subject to
and
In the following steps, the linear component of the problem definition is first described in PROC OPTMODEL and then saved
as an MPS data set. Because the objective is linear, no FCMP objective function needs to be used. In the second section of
steps, the nonlinear constraints are defined by using FCMP functions, and their corresponding names and lower and upper bounds
are stored in the data set condata
. The OPTLSO procedure is then called with the options NLINCON=CONDATA and MPSDATA=NLCEX.
As in Using MPS Format, you can use the macro definition lsompsmod
to strip brackets from the resulting data set:
%macro lsompsmod(setold,setnew); data &setnew(drop=i); set &setold; array FC{*} _CHARACTER_; do i=1 to dim(FC); FC[i] = compress(FC[i], "[]"); end; run; %mend;
proc optmodel; var x{1..10} >= 0; x[10].lb = 1; x[10].ub = 3; x[1].ub = 100; x[2].ub = 200; con x[3] + x[4] = x[6] + x[7], x[6] + x[8] = x[1], x[7] + x[9] = x[2], x[8] + x[9] = x[5]; max f = 9*x[1] + 15*x[2] - 6*x[3] - 16*x[4] - 10*x[5]; save mps nlcexOld; quit; %lsompsmod(nlcexOld, nlcex); proc fcmp outlib=sasuser.myfuncs.mypkg; function nlc1(x1,x6,x8,x10); return (2.5*x1 - x10*x6 - 2*x8); endsub; function nlc2(x2,x7,x9,x10); return (1.5*x2 - x10*x7 - 2*x9); endsub; function nlc3(x3,x4,x10); return (3*x3 + x4 - x10*(x3 + x4)); endsub; run; data condata; input _id_ $ _lb_ _ub_; datalines; nlc1 0 . nlc2 0 . nlc3 0 0 ;
options cmplib = sasuser.myfuncs; proc optlso primalout = solution mpsdata = nlcex nlincon = condata logfreq = 10; performance nthreads=2; run; proc print data=solution; run;
Output 3.6.1 shows the ODS tables that are produced from running these steps.
Output 3.6.1: Using Nonlinear Constraints: ODS Tables
Performance Information | |
---|---|
Execution Mode | Single-Machine |
Number of Threads | 2 |
Problem Summary | |
---|---|
Problem Type | NLP |
MPS Data Set | NLCEX |
Nonlinear Constraints | CONDATA |
Number of Variables | 10 |
Integer Variables | 0 |
Continuous Variables | 10 |
Number of Constraints | 7 |
Linear Constraints | 4 |
Nonlinear Constraints | 3 |
Objective Definition Source | NLCEX |
Objective Sense | Maximize |
Solution Summary | |
---|---|
Solution Status | Function convergence |
Objective | 400.00410273 |
Infeasibility | 0.0006837888 |
Iterations | 18 |
Evaluations | 2029 |
Cached Evaluations | 399 |
Global Searches | 1 |
Population Size | 160 |
Seed | 1 |
Obs | _sol_ | _id_ | _value_ |
---|---|---|---|
1 | 0 | _obj_ | 400.004 |
2 | 0 | _inf_ | 0.001 |
3 | 0 | x1 | 0.000 |
4 | 0 | x2 | 200.000 |
5 | 0 | x3 | 0.000 |
6 | 0 | x4 | 99.999 |
7 | 0 | x5 | 100.001 |
8 | 0 | x6 | 0.000 |
9 | 0 | x7 | 99.999 |
10 | 0 | x8 | 0.000 |
11 | 0 | x9 | 100.001 |
12 | 0 | x10 | 1.000 |
13 | 0 | f | 400.004 |
14 | 0 | nlc1 | 0.000 |
15 | 0 | nlc2 | -0.001 |
16 | 0 | nlc3 | 0.000 |
Output 3.6.2 shows the iteration log from running these steps.
Output 3.6.2: Using Nonlinear Constraints: Log
NOTE: The OPTLSO procedure is executing in single-machine mode. |
NOTE: The OPTLSO algorithm is using up to 2 threads. |
NOTE: The problem has 10 variables (0 integer, 10 continuous). |
NOTE: The problem has 7 constraints (4 linear, 3 nonlinear). |
NOTE: The problem has 3 FCMP function definitions. |
NOTE: The deterministic parallel mode is enabled. |
Best |
Iteration Objective Infeasibility Evals Time |
1 0 0 170 0 |
11 400.004102732759 0.00068378879313 1259 0 |
18 400.004102732759 0.00068378879313 2029 0 |
NOTE: Function convergence criteria reached. |
NOTE: There were 3 observations read from the data set WORK.CONDATA. |
NOTE: The data set WORK.SOLUTION has 16 observations and 3 variables. |