Using External Data Sets (lsoe07)
/**********************************************************************/
/* */
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: lsoe07 */
/* TITLE: Using External Data Sets (lsoe07) */
/* PRODUCT: OR */
/* SYSTEM: ALL */
/* KEYS: OR */
/* PROCS: OPTLSO, FCMP, PRINT */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: Example 7 from the OPTLSO chapter of the */
/* Local Search Optimization book. */
/* */
/**********************************************************************/
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;
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;
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;