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

f 1 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus 1 right-parenthesis squared plus left-parenthesis x 1 minus x 2 right-parenthesis squared and f 2 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus x 2 right-parenthesis squared plus left-parenthesis x 2 minus 3 right-parenthesis squared

subject to 0 less-than-or-equal-to x 1 comma x 2 less-than-or-equal-to 5 period

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

Results from optimization.solveBlackbox

Problem Summary
Problem TypeNLP
Number of Variables2
Continuous Variables2
Integer Variables0
Number of Constraints0
Linear Constraints0
Nonlinear Constraints0
Number of Objectives2

Option Summary
Convergence Tolerance1E-6
Cache Max Size500000
Cache Tolerance1E-9
Feasibility Tolerance0.001
Max Func Evaluations120000
Max Iterations10
Max Time1.797693E308
Num Global Solvers1
Num Local Solvers4
Population Size20
Seed1
Log Frequency1
Log Level1

Solution Summary
Solution StatusGenerations complete
Nondominated43
Progress0.02042862
Iterations10
Evaluations158
Cached Evaluations20


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

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

f 1 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus 1 right-parenthesis squared plus left-parenthesis x 1 minus x 2 right-parenthesis squared and f 2 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus x 2 right-parenthesis squared plus left-parenthesis x 2 minus 3 right-parenthesis squared

subject to 0 less-than-or-equal-to x 1 comma x 2 less-than-or-equal-to 5 period

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

f 1 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus 1 right-parenthesis squared plus left-parenthesis x 1 minus x 2 right-parenthesis squared and f 2 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus x 2 right-parenthesis squared plus left-parenthesis x 2 minus 3 right-parenthesis squared

subject to 0 less-than-or-equal-to x 1 comma x 2 less-than-or-equal-to 5 period

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

f 1 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus 1 right-parenthesis squared plus left-parenthesis x 1 minus x 2 right-parenthesis squared and f 2 left-parenthesis x right-parenthesis equals left-parenthesis x 1 minus x 2 right-parenthesis squared plus left-parenthesis x 2 minus 3 right-parenthesis squared

subject to 0 less-than-or-equal-to x 1 comma x 2 less-than-or-equal-to 5 period

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')
)
Last updated: April 22, 2022