|
Sameas and Diag |
Top Previous Next |
|
Sameas and diag are functions that allow comparison of set names. Suppose I wish to add up shipments within cities. Further suppose I have an array move(origins,cities) giving the amount from origins to cities. In addition the within city are those in move(origins, cities) where the origin name is the same as the cities name. (sets.gms)
Alias(origins,cities); Z=sum((origins,cities)$sameas(origins,cities),move(origins,cities)); or Z=sum((origins,cities)$diag(origins,cities),move(origins,cities));
Equivalently a statement like
Z=sum((origins,cities)$(not sameas(origins,cities)),move(origins,cities));
adds up the shipments between cities. One could also operate over particular elements using these commands
Available(resource)$(sameas(resource,"cropland") or sameas(resource,"pasture")).. Sum(activity,usage(resource,activity)*xvar(activity))=l= endowment(resource);
where the sameas command would compare the text for the element name for each elements of the set resource with the string cropland or pasture and if so operate over that part of the resource set. |