The OPTMODEL Procedure

FOR Statement

FOR { index-set } statement;

The FOR statement executes its substatement for each member of the specified index-set. The index set can declare local dummy parameters. You can reference the value of these parameters in the substatement. For example, consider the following code:

    proc optmodel;
        for {i in 1..2, j in {'a', 'b'}} put i= j=;
 

This code produces the output in Output 6.17.

                                                                                
                                                                                 
                                                                                 
 i=1 j=a                                                                         
 i=1 j=b                                                                         
 i=2 j=a                                                                         
 i=2 j=b                                                                         
 


Figure 6.17: FOR Statement Output

As another example, the following code sets the current values for variable x to random values between 0 and 1:

  
    proc optmodel; 
       var x{1..10}; 
       for {i in 1..10} 
           x[i] = ranuni(-1);
 

Multiple statements can be controlled by specifying a DO statement group for the substatement.

CAUTION: Avoid modifying the parameters that are used by the FOR statement index set from within the substatement. The set value that is used for the left-most index set item is not affected by such changes. However, the effect of parameter changes on later index set items cannot be predicted.

Previous Page | Next Page | Top of Page