This example illustrates the use of external data sets that are specified in the OBJECTIVE= option. The Bard function (Moré, Garbow, and Hillstrom 1981) is a least squares problem that has parameters and functions
where
with , , and
The minimum function value = 4.107E–3 occurs at the point . In this example, the additional variable bounds for are added.
There are three approaches to specifying the objective function. The first approach assumes that the necessary data are stored within the FCMP function. In this case, you can specify the objective function without using an external data set, as follows:
data vardata; input _id_ $ _lb_ _ub_ ; datalines; x1 -1000 1000 x2 -1000 1000 x3 -1000 1000 ; data objdata; input _id_ $ _function_ $ _sense_ $; datalines; f bard min ; proc fcmp outlib=sasuser.myfuncs.mypkg; function bard(x1, x2, x3); array y[15] /nosym (0.14 0.18 0.22 0.25 0.29 0.32 0.35 0.39 0.37 0.58 0.73 0.96 1.34 2.10 4.39); fx = 0; do k=1 to 15; vk = 16 - k; wk = min(k,vk); fxk = y[k] - (x1 + k/(vk*x2 + wk*x3)); fx = fx + fxk**2; end; return (0.5*fx); endsub; run; options cmplib = sasuser.myfuncs; proc optlso primalout = solution variables = vardata objective = objdata; performance nthreads=2; run; proc print data=solution; run;
Output 3.7.1 shows the output from running these steps.
Output 3.7.1: Using External Data Sets
This approach is cumbersome if the size of the required data increases. A second approach for medium-sized data sets is to use the READ_ARRAY statement within the FCMP function definition. Because the environment might be distributed, PROC OPTLSO requires a list of all data sets that are used in FCMP function definitions to ensure that the corresponding data sets are available. This list should be specified by using the READARRAY statement.
data barddata; input y @@; datalines; 0.14 0.18 0.22 0.25 0.29 0.32 0.35 0.39 0.37 0.58 0.73 0.96 1.34 2.10 4.39 ; data vardata; input _id_ $ _lb_ _ub_ ; datalines; x1 -1000 1000 x2 -1000 1000 x3 -1000 1000 ; data objdata; input _id_ $ _function_ $ _sense_ $; datalines; f bard min ; proc fcmp outlib=sasuser.myfuncs.mypkg; function bard(x1, x2, x3); array y[15] /nosym; rc = read_array('barddata', y); fx = 0; do k=1 to 15; dk = (16-k)*x2 + min(k,16-k)*x3; fxk = y[k] - (x1 + k/dk); fx = fx + fxk**2; end; return (0.5*fx); endsub; run; options cmplib = sasuser.myfuncs; proc optlso primalout = solution variables = vardata objective = objdata; readarray barddata; run; proc print data=solution; run;
Output 3.7.2 shows the output from running these statements.
Output 3.7.2: Using External Data Sets (II)
The preceding approach can be prohibitive if the size of the data set is large. As a third approach to specifying the objective
function, PROC OPTLSO provides an alternate data input gateway that is described in the OBJECTIVE=
data set, as shown in the following statements:
data vardata; input _id_ $ _lb_ _ub_ ; datalines; x1 -1000 1000 x2 -1000 1000 x3 -1000 1000 ; data barddata; k = _n_; input y @@; datalines; 0.14 0.18 0.22 0.25 0.29 0.32 0.35 0.39 0.37 0.58 0.73 0.96 1.34 2.10 4.39 ;
data objdata; input _id_ $ _function_ $ _sense_ $ _dataset_ $; datalines; fx bard min barddata ; proc fcmp outlib=sasuser.myfuncs.mypkg; function bard(x1, x2, x3, k, y); vk = 16 - k; wk = min(k,vk); fxk = y - (x1 + k/(vk*x2 + wk*x3)); return (0.5*fxk**2); endsub; run; options cmplib = sasuser.myfuncs; proc optlso primalout = solution variables = vardata objective = objdata; performance nodes=2 nthreads=8; run; proc print data=solution; run;
Output 3.7.3 shows the output from running these statements.
Output 3.7.3: Using External Data Sets (III)
Problem Summary | |
---|---|
Problem Type | NLP |
Objective Definition Set | OBJDATA |
Variables | VARDATA |
Number of Variables | 3 |
Integer Variables | 0 |
Continuous Variables | 3 |
Number of Constraints | 0 |
Linear Constraints | 0 |
Nonlinear Constraints | 0 |
Objective Definition Source | OBJDATA |
Objective Sense | Minimize |
Objective Data Set | barddata |