|
Sameas |
Top Previous Next |
|
One may wish to do conditional processing dependent upon the text defining a name of a set element matching the text for a particular text string or matching up with the text for a name of a set element in another set. This can be done in GAMS using the sameas command. SAMEAS(setelement,othersetelement) or sameas(asetelement,"text") returns an indicator that is true if the text giving the name of setelement is the same as the text for othersetelement and a false otherwise. Similarly sameas(asetelement,"texttotest") returns an indicator that is true if the text giving the name of asetelement is the same as the texttotest and false otherwise. SAMEAS can also be used as a set. Examples: The following red use of sameas will only permit the case of cityI and cityj to be part of the sum where the elements for both are boston and do not require the sets to be subsets of each other. The blue use will only operate for the element of I associated with the name "new york".
Set cityI / "new york", Chicago, boston/; Set cityj /boston/; Scalar ciz,cir,cirr; ciZ=sum(sameas(cityI,cityj),1); ciR=sum((cityI,cityj)$ sameas(cityI,cityj),1); ciRR=sum(sameas(cityI,"new york"),1); Note: The above examples show that sameas can be used as a tuple or a multidimensional set. |