The OPTMODEL procedure creates a macro variable named _OROPTMODEL_. You can inspect the execution of the most recently invoked solver from the value of the macro variable. The macro variable is defined at the start of the procedure and updated after each SOLVE statement is executed. The OPTMODEL procedure also updates the macro variable when an error is detected.
The _OROPTMODEL_ value is a string that consists of several "KEYWORD=value" items in sequence, separated by blanks; for example:
STATUS=OK ALGORITHM=DS SOLUTION_STATUS=OPTIMAL OBJECTIVE=119302.04331 PRIMAL_INFEASIBILITY=3.552714E-13 DUAL_INFEASIBILITY=2.273737E-13 BOUND_INFEASIBILITY=0 ITERATIONS=82 PRESOLVE_TIME=0.02 SOLUTION_TIME=0.05
The information contained in _OROPTMODEL_ varies according to which solver was last called. For lists of keywords and possible values, see the individual solver chapters.
If a value has not been computed, then the corresponding element is not included in the value of the macro variable. When PROC OPTMODEL starts, for example, the macro variable value is set to "STATUS=OK" because no SOLVE statement has been executed. If the STATUS= indicates an error, then the other values from the solver might not be available, depending on when the error occurred.
In addition to creating the macro variable _OROPTMODEL_, the OPTMODEL procedure creates several predeclared parameters to provide simple access to solver status values. These parameters are declared as follows:
string _STATUS_; string _SOLUTION_STATUS_; set<string> _OROPTMODEL_STR_KEYS_; set<string> _OROPTMODEL_NUM_KEYS_; string _OROPTMODEL_STR_{_OROPTMODEL_STR_KEYS_}; number _OROPTMODEL_NUM_{_OROPTMODEL_NUM_KEYS_};
The value of _STATUS_ is equal to the STATUS= component of the _OROPTMODEL_ macro variable. The value of _STATUS_ is initially "OK". The value is updated during the SOLVE statement and after statement execution errors.
The value of _SOLUTION_STATUS_ is equal to the SOLUTION_STATUS= component of the _OROPTMODEL_ macro variable. The value is initially an empty string. The value is updated during the SOLVE statement.
You can use the remaining status parameters to access all the components of the _OROPTMODEL_ macro variable. The following statements demonstrate these parameters:
proc optmodel printlevel=0; var x init 1 >= 0.001; min z=sin(x)/x; solve; for {k in /STATUS SOLUTION_STATUS ALGORITHM/} put _OROPTMODEL_STR_[k]=; for {k in /OBJECTIVE ITERATIONS/} put _OROPTMODEL_NUM_[k]=;
These statements produce the output in Figure 5.69.
The _OROPTMODEL_STR_ array contains the same character component values that are found in the _OROPTMODEL_ macro variable. Specify the component name as the array index. For example, the indices "STATUS" and "SOLUTION_STATUS" select array elements that hold the STATUS= and SOLUTION_STATUS= component values, respectively. The set _OROPTMODEL_STR_KEYS_ contains the component indices that you can use with _OROPTMODEL_STR_. The OPTMODEL procedure updates the _OROPTMODEL_STR_ and _OROPTMODEL_STR_KEYS_ parameters during the execution of the SOLVE statement and after any execution errors occur.
The _OROPTMODEL_NUM_ array contains the numeric component values that are displayed in the _OROPTMODEL_ macro variable. For example, the index "OBJECTIVE" selects the array element that holds the objective value when a solution is available. The set _OROPTMODEL_NUM_KEYS_ contains the component indices that you can use with _OROPTMODEL_NUM_. The OPTMODEL procedure updates the _OROPTMODEL_NUM_ and _OROPTMODEL_NUM_KEYS_ parameters during the execution of the SOLVE statement and after any execution errors occur.
PROC OPTMODEL reads a complete statement, such as a DO statement , before executing any code in it. But macro language statements are processed as the code is read. So you must be careful when using the _OROPTMODEL_ macro variable in code that involves SOLVE statements nested in loops or DO statements. The following statements demonstrate one example of this behavior:
proc optmodel; var x, y; min z=x**2 + (x*y-1)**2; for {n in 1..3} do; fix x=n; solve; %put Line 1 &_OROPTMODEL_; put 'Line 2 ' (symget("_OROPTMODEL_")); end; quit;
In the preceding statements the %PUT statement is executed once, before any SOLVE statements are executed. It displays PROC OPTMODEL’s initial setting of the macro variable. But the PUT statement is executed after each SOLVE statement and indicates the expected solution status.