|
The conditional alternative: the tuple |
Top Previous Next |
|
Often the conditionals required in a model are complex and are used in a repetitive manner. It is sometimes simpler to establish a tuple that encapsulates the conditionals and only use that tuple instead of the complex set of conditionals. Example: In the model below the logical condition in red that appears repetitively can be replaced with the tuple making the model visually simpler plus potentially easier to maintain. (tuple.gms)
TCOSTEQ.. TCOST =E= SUM((PLANT,MARKET) $( supply(plant) and demand(market) and distance(plant,market)) , SHIPMENTS(PLANT,MARKET)* COST(PLANT,MARKET)); SUPPLYEQ(PLANT).. SUM(MARKET $( supply(plant) and demand(market) and distance(plant,market)) ,SHIPMENTS(PLANT, MARKET)) =L= SUPPLY(PLANT); DEMANDEQ(MARKET).. SUM(PLANT $( supply(plant) and demand(market) and Distance(plant,market)) , SHIPMENTS(PLANT, MARKET)) =G= DEMAND(MARKET);
where the alternative with the tuple is
set thistuple(plant,market) thistuple expressing conditional; thistuple(plant,market)$( supply(plant) and demand(market) and distance(plant,market)) =yes; TCOSTEQ2.. TCOST =E= SUM(thistuple(plant,market) , SHIPMENTS(PLANT,MARKET)* COST(PLANT,MARKET)); SUPPLYEQ2(PLANT).. SUM(thistuple(plant,market) ,SHIPMENTS(PLANT, MARKET)) =L= SUPPLY(PLANT); DEMANDEQ2(MARKET).. SUM(thistuple(plant,market) , SHIPMENTS(PLANT, MARKET)) =G= DEMAND(MARKET); Notes:
|