Difference: SetsInAMPL (8 vs. 9)

Revision 92008-03-11 - MichaelOSullivan

Line: 1 to 1
 
META TOPICPARENT name="AMPLSyntax"
<-- Ready to Review - done - Lauren-->

Sets in AMPL

Line: 246 to 246
 Return to top

Efficient Generation of Sets

Changed:
<
<
When creating models, generating sets by looping over all possibilities and removing those that don't fit some conditions (e.g., like the TIME_ARCS statement) can take a long time if there are many possibilities. This is time that could be spent solving the model! If possible you should try to create sets by building them up from smaller building block, rather than by creating an enormous set and pruning it. For example, instead of using this statement
# The set of time-staged arcs set TIME_ARCS within TIME_NODES cross TIME_NODES :=   { (m, t) in TIME_NODES, (n, u) in TIME_NODES :     ( ( (m, n) in ARCS) and (t = u) ) or # The arcs used for transportation     ( (m = n) and (ord(t, MONTHS) + 1 = ord(u, MONTHS)) )}; # The arcs used for storage 
to create TIME_ARCS you could use these statement
set TRANSPORT_ARCS := union {t in MONTHS, (m, n) in ARCS} {(m, t, n, t)}; set STORAGE_ARCS := union {t in MONTHS, (m, n) in ARCS : t <> last(MONTHS)}   {(m, t, n, next(t, MONTHS)}; set TIME_ARCS within TIME_NODES cross TIME_NODES := TRANSPORT_ARCS union STORAGE_ARCS; 
Rather than looping over all possibilities and only keeping those that are appropriate, the new statement only loops over smaller sets that can be used to build up the TIME_NODES set efficiently.

Return to top

-- MichaelOSullivan - 27 Feb 2008

>
>
When creating models, generating sets by looping over all possibilities and removing those that don't fit some conditions (e.g., like the TIME_ARCS statement) can take a long time if there are many possibilities. This is time that could be spent solving the model! If possible you should try to create sets by building them up from smaller building block, rather than by creating an enormous set and pruning it. For example, instead of using this statement
# The set of time-staged arcs
set TIME_ARCS within TIME_NODES cross TIME_NODES :=
   { (m, t) in TIME_NODES, (n, u) in TIME_NODES :
     ( ( (m, n) in ARCS) and (t = u) ) or # The arcs used for transportation
     ( (m = n) and (ord(t, MONTHS) + 1 = ord(u, MONTHS)) )}; # The arcs used for storage

to create TIME_ARCS you could use these statements

set TRANSPORT_ARCS := union {t in MONTHS, (m, n) in ARCS} {(m, t, n, t)};
set STORAGE_ARCS := union {t in MONTHS, (m, n) in ARCS : t <> last(MONTHS)}
   {(m, t, n, next(t, MONTHS)};

set TIME_ARCS within TIME_NODES cross TIME_NODES := TRANSPORT_ARCS union STORAGE_ARCS;

Rather than looping over all possibilities and only keeping those that are appropriate, the new statement only loops over smaller sets that can be used to build up the TIME_NODES set efficiently.

Return to top

-- MichaelOSullivan - 27 Feb 2008

 
META FILEATTACHMENT attachment="latexa4ed27399944f27be0955f861782ef5e.png" attr="h" comment="" date="1204112900" name="latexa4ed27399944f27be0955f861782ef5e.png" stream="GLOB(0xa5f5874)" tmpFilename="latexa4ed27399944f27be0955f861782ef5e.png" user="MichaelOSullivan" version="1"
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback