|
Loop |
Top Previous Next |
|
The Loop statement allows one to execute a group of statements for each element of a set. The syntax of the Loop statement is,
Loop((sets_to_vary), statement or statements to execute );
If the sets_to_vary contains one set, then the statement can be
Loop(set_to_vary, statement or statements to execute );
The Loop statement causes GAMS to execute the statement or statements for each member of sets_to_vary in turn. The order of evaluation is determined by the contents of the UEL list as discussed in the Rules for Item Capitalization and Ordering chapter. Example: The following syntax would cause the model to be solved for each element within the set I. In that Loop I first revise some data in the model in accordance with the ith element of savparam. In turn the objective value would be saved in the ith element of data.
Loop (i, problemdata=savparam(i); Solve mymodel using lp maximizing profit; Data(i)=profit.l; ) ; Notes:
problemdata=savparam("corn"); Solve mymodel using lp maximizing profit; Data("corn")=profit.l;
and on the second pass as If it were problemdata=savparam("wheat"); Solve mymodel using lp maximizing profit; Data("wheat")=profit.l;
|