The OPTMODEL Procedure

Nil Values

The evaluation of certain PROC OPTMODEL expressions can produce a special value, the nil value, that is distinct from any other value of the expression’s type. A nil value represents the lack of any ordinary value. You can use nil values to check for undefined parameters or to reset the effects of previous assignments or initializations.

Nil values are allowed for the following expressions:

  • the operands of an equality comparison operator, = or tilde=. Nil values are equal only to nil values.

  • the second and third operands of an IF-THEN/ELSE expression

  • the right-hand-side expression of an assignment statement. Assigning a nil value resets the effect of previous initializations or assignments of the target location.

  • a parenthesized value expression for a PUT statement. Nil values are skipped on output.

  • a parenthesized value expression for a PRINT statement. Nil values create an empty cell in the output.

Note: The initializers list from the INIT [ initializers ] clause for an array parameter declaration is evaluated at most once, except for any default element value. If an array element is assigned a nil value after the initializers are evaluated, then the default element value is used.

The _NIL_ keyword evaluates to a nil value in expressions. Nil values can also be generated when an identifier expression references an undefined parameter value. An identifier expression evaluates to a nil value instead of reporting an error when it is used as the operand of an equality comparison or as the right-hand-side expression of an assignment statement with a NUMBER, STRING, or SET parameter target. The nil value is generated when the identifier expression is used either directly or via the second or third operand of an IF-THEN/ELSE expression.

Note: Undefined parameter values are treated as errors when an identifier expression is used as the operand of a compound comparison (like b in (0 tilde= b <= 10)) where one of the operators that are using the value is not an equality comparison.

The following code demonstrates some uses of nil values:

proc optmodel;
   num a{1..2};
   a[1] = 1;
   put (a[1] = _nil_)=; /* false, defined */
   put (a[2] = _nil_)=; /* true, undefined */
   put ((if a[1] then _nil_ else 2) = a[1])= /* false */;
   put ((if a[1] then _nil_ else 2) = a[2])= /* true */;
   a[1] = a[2]; /* now a[1] is undefined */
   put (a[1] = _nil_)=; /* true, undefined */

   /* array initialization list is evaluated at most once */
   num b{1..3} init [1 2 3 [*] 7];
   put b[*];     /* evaluates the initialization list */
   b[1] = _nil_; /* reset b[1] */
   put b[*];     /* b[1] replaced by the default value */

   var x init (rand('UNIFORM')) >= 0 <= 10;
   put x=;       /* initialized to a random value */
   x = _nil_;    /* discard the current value */
   put x=;       /* initialized to a new random value */
   put x.ub=;    /* the declared bound */
   x.ub = 1;     /* override the declared bound */
   put x.ub=;    /* the overridden bound */
   x.ub = _nil_; /* reverse the override */
   put x.ub=;    /* the declared bound again */

   /* nil values print as empty cells */
   print {i in 1..3, j in 1..3}(if i+j-1=3 then _nil_ else 1/(i+j-1));

This code produces the output in Figure 34.

Figure 34: Nil Values

a[1] = _NIL_=0                                                                  
a[2] = _NIL_=1                                                                  
IF a[1] THEN _NIL_ ELSE 2 = a[1]=0                                              
IF a[1] THEN _NIL_ ELSE 2 = a[2]=1                                              
a[1] = _NIL_=1                                                                  
1 2 3                                                                           
7 2 3                                                                           
x=0.5832970655                                                                  
x=0.9936253726                                                                  
x.UB=10                                                                         
x.UB=1                                                                          
x.UB=10                                                                         

 123
11.000.50 
20.50 0.25
3 0.250.20


Last updated: March 04, 2026