Wednesday, April 15, 2015

operating on an empty set

See: http://www.johndcook.com/blog/2015/04/14/empty-sum-product/

image

Of course modeling systems should do this correctly.

GAMS

$onempty;
set e(*) / /;
display e;

scalars s,p;
s =
sum(e,1);
p =
prod(e,1);
display s,p;

Gives:

----      3 SET e 

                                                      ( EMPTY )

----      8 PARAMETER s                    =        0.000 
            PARAMETER p                    =        1.000
 

AMPL

ampl: set e = {};
ampl: param s = sum{i in e} 1;
ampl: param p = prod{i in e} 1;
ampl: display s,p;
s = 0
p = 1

No comments:

Post a Comment