Optimization Action Set
Black-Box Multiobjective Optimization
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 3, Shared Concepts (SAS Optimization: Mathematical Optimization Procedures). A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
This example illustrates how to optimize a problem that contains multiple nonlinear objectives. The following optimization problem is discussed in Huband et al. (2006) and Custódio et al. (2011). This problem minimizes
The following code demonstrates how to define the two objective functions in the multiobjective optimization problem. Notice how two objectives are specified in the obj parameter and how both of the objective values are returned from the caslEval parameter string.
This example assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
proc cas noqueue;
/* The CASL code for evaluating the objectives */
source caslEval;
fx1 = (x1-1)*(x1-1) + (x1-x2)*(x1-x2);
fx2 = (x1-x2)*(x1-x2) + (x2-3)*(x2-3);
f['obj1'] = fx1;
f['obj2'] = fx2;
send_response(f);
endsource;
/* Invoke the solveBlackbox action */
optimization.solveBlackbox /
decVars = {
{name='x1', lb=0, ub=5},
{name='x2', lb=0, ub=5}
},
obj = {
{name='obj1', type='min'},
{name='obj2', type='min'}
},
func = {eval=caslEval},
nParallel = 16,
primalOut={name="p_out", replace=true}
;
run; quit;
proc sgplot data=mycas.p_out;
scatter x=obj1 y=obj2;
run;
Output 2.9.1 shows the output from running the preceding code.
Output 2.9.1: Black-Box Multiobjective Optimization
| Problem Summary | |
|---|---|
| Problem Type | NLP |
| Number of Variables | 2 |
| Continuous Variables | 2 |
| Integer Variables | 0 |
| Number of Constraints | 0 |
| Linear Constraints | 0 |
| Nonlinear Constraints | 0 |
| Number of Objectives | 2 |
| Option Summary | |
|---|---|
| Convergence Tolerance | 1E-6 |
| Cache Max Size | 500000 |
| Cache Tolerance | 1E-9 |
| Feasibility Tolerance | 0.001 |
| Max Func Evaluations | 120000 |
| Max Iterations | 10 |
| Max Time | 1.797693E308 |
| Num Global Solvers | 1 |
| Num Local Solvers | 4 |
| Population Size | 20 |
| Seed | 1 |
| Log Frequency | 1 |
| Log Level | 1 |
| Solution Summary | |
|---|---|
| Solution Status | Generations complete |
| Nondominated | 43 |
| Progress | 0.02042862 |
| Iterations | 10 |
| Evaluations | 158 |
| Cached Evaluations | 20 |
When you are solving a problem that has two objectives, it can be helpful to create a plot of the Pareto-optimal set.
Output 2.9.2 shows a plot of the Pareto-optimal set that the solveBlackbox action finds.
Output 2.9.2: Plot of Pareto-Optimal Set

Black-Box Multiobjective Optimization
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
This example illustrates how to optimize a problem that contains multiple nonlinear objectives. The following optimization problem is discussed in Huband et al. (2006) and Custódio et al. (2011). This problem minimizes
The following code demonstrates how to define the two objective functions in the multiobjective optimization problem. Notice how two objectives are specified in the obj parameter and how both of the objective values are returned from the caslEval parameter string.
This code defines the objective function in CASL syntax (CASL is the language expected by the solveBlackbox action) and then invokes the solveBlackbox action to optimize the problem:
-- The CASL code for evaluating the objectives
caslEval = [[
fx1 = (x1-1)*(x1-1) + (x1-x2)*(x1-x2);
fx2 = (x1-x2)*(x1-x2) + (x2-3)*(x2-3);
f['obj1'] = fx1;
f['obj2'] = fx2;
send_response(f);
]]
-- Invoke the solveBlackbox action
s:optimization_solveBlackbox {
decVars = {
{name='x1', lb=0, ub=5},
{name='x2', lb=0, ub=5}
},
obj = {
{name='obj1', type='min'},
{name='obj2', type='min'}
},
func = {eval=caslEval},
nParallel=16,
primalOut={name='p_out', replace=true}
}
Black-Box Multiobjective Optimization
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
This example illustrates how to optimize a problem that contains multiple nonlinear objectives. The following optimization problem is discussed in Huband et al. (2006) and Custódio et al. (2011). This problem minimizes
The following code demonstrates how to define the two objective functions in the multiobjective optimization problem. Notice how two objectives are specified in the obj parameter and how both of the objective values are returned from the caslEval parameter string.
This code defines the objective function in CASL syntax (CASL is the language expected by the solveBlackbox action) and then invokes the solveBlackbox action to optimize the problem:
s.loadactionset('optimization')
# The CASL code for evaluating the objectives
caslEval='''
fx1 = (x1-1)*(x1-1) + (x1-x2)*(x1-x2);
fx2 = (x1-x2)*(x1-x2) + (x2-3)*(x2-3);
f['obj1'] = fx1;
f['obj2'] = fx2;
send_response(f);
''';
# Invoke the solveBlackbox action
s.optimization.solveBlackBox(
vars = [
dict(name='x1', lb=0, ub=5),
dict(name='x2', lb=0, ub=5)
],
obj = [
dict(name='obj1', type='min'),
dict(name='obj2', type='min')
],
func = dict(eval=caslEval),
nParallel=16,
primalout=dict(name="pout", replace=True)
);
Black-Box Multiobjective Optimization
This section contains R code for the analysis in the CASL version of this example, which contains details about the results.
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
This example illustrates how to optimize a problem that contains multiple nonlinear objectives. The following optimization problem is discussed in Huband et al. (2006) and Custódio et al. (2011). This problem minimizes
The following code demonstrates how to define the two objective functions in the multiobjective optimization problem. Notice how two objectives are specified in the obj parameter and how both of the objective values are returned from the caslEval parameter string.
This code defines the objective function in CASL syntax (CASL is the language expected by the solveBlackbox action) and then invokes the solveBlackbox action to optimize the problem:
# The CASL code for evaluating the objectives
caslEval = "
fx1 = (x1-1)*(x1-1) + (x1-x2)*(x1-x2);
fx2 = (x1-x2)*(x1-x2) + (x2-3)*(x2-3);
f['obj1'] = fx1;
f['obj2'] = fx2;
send_response(f);
"
# Invoke the solveBlackbox action
cas.optimization.solveBlackbox(s,
decVars = list(
list(name='x1', lb=0, ub=5),
list(name='x2', lb=0, ub=5)
),
obj = list(
list(name='obj1', type='min'),
list(name='obj2', type='min')
),
func = list(eval=caslEval),
nParallel=16,
primalOut=list(name='p_out', replace='true')
)