Difference: LoopingInAMPL (1 vs. 5)

Revision 52008-03-18 - TWikiAdminUser

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
Changed:
<
<
<-- Under Construction -->
>
>
<-- Ready to Review -->
 

Looping in AMPL

  1. for Loops
  2. let Loops
Added:
>
>
  • Conditional Loops
  •  

    for Loops

    Line: 41 to 42
     let {n in NODES : ('Chicago', n) in ARCS} Min['Chicago', n] := max(1000, Min['Chicago', n]);
    Added:
    >
    >
    Return to top

    Conditional Loops

     
    Added:
    >
    >
    AMPL also provides syntax for repeating a loop depending on a condition (often known as while loops). These loops use a condition, the repeat keyword, the while or until keyword and the { and } operators:
    repeat while <expression> {
      <loop statements;>
    };
    
    repeat until <expression> {
      <loop statements;>
    };
    
     
    Changed:
    <
    <
    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 { }; repeat until { }; These statements check the expression before executing the loop statements. The first one continues while the expression is true, the second terminates when the expression is true. repeat { } while ; repeat { } until ; These statements check the expression after executing the loop statements. The first one continues while the expression is true, the second terminates when the expression is true.
    >
    >
    These statements check the expression before executing the loop statements. The first one continues while the expression is true, the second terminates when the expression is true. AMPL provides loops that check the expression after the loop completes:
    repeat {
      <loop statements;>
    } while <expression>;
    
    repeat {
      <loop statements;>
    } until <expression>;
    
    As before, the first loop continues while the expression is true, the second terminates when the expression is true.
     
    Added:
    >
    >
    Examples coming soon!
     
    Added:
    >
    >
    Return to top
     
    Deleted:
    <
    <
    ???Using symbolic parameters to do conditional loops over sets (see symbolic parameters)???
     -- TWikiAdminGroup - 18 Mar 2008 \ No newline at end of file

    Revision 42008-03-18 - TWikiAdminUser

    Line: 1 to 1
     
    META TOPICPARENT name="AMPLSyntax"
    <-- Under Construction -->
    Line: 24 to 24
     }
    Changed:
    <
    <
    Examples coming soon!
    >
    >
    Examples coming soon!
      Return to top
    Line: 35 to 35
     let {e in SET} <parameter, usually involving e> := <expression, often involving e>;
    Changed:
    <
    <
    Consider the following possibility for the 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]);
    >
    >
    Consider the following possibility for the American Steel problems (the American Steel transshipment problem and the American Steel planning problem respectively). 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]);
    
     

    Revision 32008-03-18 - TWikiAdminUser

    Line: 1 to 1
     
    META TOPICPARENT name="AMPLSyntax"
    <-- Under Construction -->
    Line: 24 to 24
     }
    Added:
    >
    >
    Examples coming soon!

    Return to top

     

    let Loops

    Deleted:
    <
    <
    Coming soon!
     
    Changed:
    <
    <

    Under Construction>

    >
    >
    In AMPL you can display and/or print over specified subsets and you can also "loop" over a let statement. To assign values for an entire set you use the let keyword, the set and the := operator:
    let {e in SET} <parameter, usually involving e> := <expression, often involving e>;
    
     
    Changed:
    <
    <
    “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.
    >
    >
    Consider the following possibility for the 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}

    Revision 22008-03-18 - TWikiAdminUser

    Line: 1 to 1
     
    META TOPICPARENT name="AMPLSyntax"
    <-- Under Construction -->
    Deleted:
    <
    <

    Looping in AMPL

     
    Added:
    >
    >

    Looping in AMPL

    1. for Loops
    2. let Loops

    for Loops

    In 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 the for 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 { }; repeat until { }; These statements check the expression before executing the loop statements. The first one continues while the expression is true, the second terminates when the expression is true. repeat { } while ; repeat { } until ; These statements check the expression after executing the loop statements. The first one continues while the expression is true, the second terminates when the expression is true.

    ???Using symbolic parameters to do conditional loops over sets (see symbolic parameters)???

     -- TWikiAdminGroup - 18 Mar 2008

    Revision 12008-03-18 - TWikiAdminUser

    Line: 1 to 1
    Added:
    >
    >
    META TOPICPARENT name="AMPLSyntax"
    <-- Under Construction -->

    Looping in AMPL

    Coming soon!

    -- TWikiAdminGroup - 18 Mar 2008

     
    This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2025 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
    Ideas, requests, problems regarding TWiki? Send feedback