Option itemname < or <= itemname2

Top  Previous  Next

An option command exists which allows one to rapidly count the number of elements in a particular slice of a parameter.  The general format of this command is

 

Option item1 < item2 ;

or

Option item1 <= item2 ;

 

Where item1 and item2 are GAMS sets or parameters with conforming domain declarations.  The dimensionality of item1 has to be equal or less than the dimensionality of item2.  If the item1 dimensionality is less than the item2 dimension, the operation performed is an aggregation or projection depending on the data type of the left side.  In all cases, indices are permuted according to the domain definitions.  If a symbol has identical domain definitions they are permuted right to left (if < is used) or left to right (if <= is used).

Examples:

Suppose we have Q(I,J,K) and want to know how many elements exist for a set element I across all combinations of the subscripts J and K.  This can be done using the option command (project.gms)

 

set i /1*3/

 j /1*3/

 k /1*3/;

Parameter Q(I,J,K) / 1.1.1 1, 1.2.3 3, 2.1.1 4/   ;

Parameter Elementcount(I) ;

option elementcount< Q  ;

display elementcount;

 

Whereupon the elementcount parameter would contain a count of the number of nonzero elements in Q associated with each element of the set I.  Similarly one could develop a count of the number of nonzero entries within Q for each pairing of the elements J and K across all values of the subscript I. by inserting

 

Parameter Elcount(J,K) ;

option elcount< Q  ;

display elcount

 

This also works for sets (project.gms)

 

Set  i, fromto(i,i), tofrom(i,i);

alias(i,ii);

parameter in(i),out(i);

option tofrom < fromto, in < fromto, out <= fromto;

 

which is equivalent to

 

tofrom(i,ii) = fromto(ii,i);

in(i) = sum(fromto(ii,i),1);

out(i) = sum(fromto(i,ii), 1);