Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
<-- Under Construction --> | ||||||||
Deleted: | ||||||||
< < | Looping in AMPL | |||||||
Added: | ||||||||
> > | Looping in AMPLfor LoopsIn AMPL you can create basic for loops by creating a set automatically and looping over elements in the set. To loop over a set you use thefor keyword and the in keyword.
for {<element> in <SET>} <a statement>;Now <a statement> is repeated for each element in <SET> . If you need to do more than one statement you can use { and } :
for {<element> in <SET>} { <some statements> } let Loops | |||||||
Coming soon! | ||||||||
Added: | ||||||||
> > | Under Construction>“Looping” let Statements In the same way you can printf over specified subsets, you can use a let statement to “loop” over a set and change the data. Syntax: To change data values for a set you use the let keyword, the set and the := operator let {e in SET} <parameter, usually involving e> := <expression, often involving e>; Consider the following possibility for American Steel. American Steel can get a 5% discount with their transportation provider out of Chicago as long as they commit to at least 1000 tonnes along each route. This change can be easily incorporated using two “looping” let statements. let {n in NODES : (‘Chicago’, n) in ARCS} Cost[‘Chicago’, n] := 0.95 * Cost[‘Chicago’, n]; let {n in NODES : (‘Chicago’, n) in ARCS} Min[‘Chicago’, n] := max(1000, Min[‘Chicago’, n]); Conditional Loops AMPL allows us to repeat a loop depending on a condition. Syntax: We can loop subject to a condition using the repeat keyword, the while or until keyword and the { and } operators. repeat while | |||||||
-- TWikiAdminGroup - 18 Mar 2008 |
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
<-- Under Construction --> Looping in AMPLComing soon! -- TWikiAdminGroup - 18 Mar 2008 |