single05.gms : Check correctness of set attributes for singleton sets

Description

This test checks that the set attributes for singleton sets are correct. This is
done for assignments and in equations, both inside and outside of a loop.

Contributor: Lutz Westermann, October 2015


Small Model of Type : GAMS


Category : GAMS Test library


Main file : single05.gms

$title 'Check correctness of set attributes for singleton sets' (SINGLE05,SEQ=687)

$onText
This test checks that the set attributes for singleton sets are correct. This is
done for assignments and in equations, both inside and outside of a loop.

Contributor: Lutz Westermann, October 2015
$offText


set           i     / 1*10 /
              im(i) / 3    /;
singleton set is(i) / 3    /;

scalar m,s;

* Check set attributes for singleton sets in simple assignments
m = sum(im,im.rev);
s = is.rev;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.pos);
s = is.pos;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.off);
s = is.off;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.uel);
s = is.uel;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.val);
s = is.val;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.len);
s = is.len;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.tval);
s = is.tval;
abort$(m<>s) 'Unexpected difference', m, s;

m = sum(im,im.tlen);
s = is.tlen;
abort$(m<>s) 'Unexpected difference', m, s;

* Check set attributes for singleton sets in simple assignments within a loop
loop(i,
  im(im)=no;
  im(i)=yes;
  is(i)=yes;

  m = sum(im,im.rev);
  s = is.rev;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.pos);
  s = is.pos;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.off);
  s = is.off;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.uel);
  s = is.uel;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.val);
  s = is.val;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.len);
  s = is.len;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.tval);
  s = is.tval;
  abort$(m<>s) 'Unexpected difference', m, s;

  m = sum(im,im.tlen);
  s = is.tlen;
  abort$(m<>s) 'Unexpected difference', m, s;
);

* Check set attributes for singleton sets in equations
variable revs, revm
         poss, posm
         offs, offm
         uels, uelm
         vals, valm
         lens, lenm
         tvals,tvalm
         tlens,tlenm
         z;
equation erevs, erevm
         eposs, eposm
         eoffs, eoffm
         euels, euelm
         evals, evalm
         elens, elenm
         etvals,etvalm
         etlens,etlenm
         obj;

obj.. z =e= 1;

erevs.. revs =e= is.rev;
erevm.. revm =e= sum(im,im.rev);

eposs.. poss =e= is.pos;
eposm.. posm =e= sum(im,im.pos);

eoffs.. offs =e= is.off;
eoffm.. offm =e= sum(im,im.off);

euels.. uels =e= is.uel;
euelm.. uelm =e= sum(im,im.uel);

evals.. vals =e= is.val;
evalm.. valm =e= sum(im,im.val);

elens.. lens =e= is.len;
elenm.. lenm =e= sum(im,im.len);

etvals.. tvals =e= is.tval;
etvalm.. tvalm =e= sum(im,im.tval);

etlens.. tlens =e= is.tlen;
etlenm.. tlenm =e= sum(im,im.tlen);

model mymodel /all/;

solve mymodel us lp max z;

abort$(revs.l<>revm.l) 'Unexpected difference', revs.l, revm.l;
abort$(poss.l<>posm.l) 'Unexpected difference', poss.l, posm.l;
abort$(offs.l<>offm.l) 'Unexpected difference', offs.l, offm.l;
abort$(uels.l<>uelm.l) 'Unexpected difference', uels.l, uelm.l;
abort$(vals.l<>valm.l) 'Unexpected difference', vals.l, valm.l;
abort$(lens.l<>lenm.l) 'Unexpected difference', lens.l, lenm.l;
abort$(tvals.l<>tvalm.l) 'Unexpected difference', tvals.l, tvalm.l;
abort$(tlens.l<>tlenm.l) 'Unexpected difference', tlens.l, tlenm.l;

* Check set attributes for singleton sets in equations within a loop
loop(i,
  im(im)=no;
  im(i)=yes;
  is(i)=yes;

  solve mymodel us lp max z;

  abort$(revs.l<>revm.l) 'Unexpected difference', revs.l, revm.l;
  abort$(poss.l<>posm.l) 'Unexpected difference', poss.l, posm.l;
  abort$(offs.l<>offm.l) 'Unexpected difference', offs.l, offm.l;
  abort$(uels.l<>uelm.l) 'Unexpected difference', uels.l, uelm.l;
  abort$(vals.l<>valm.l) 'Unexpected difference', vals.l, valm.l;
  abort$(lens.l<>lenm.l) 'Unexpected difference', lens.l, lenm.l;
  abort$(tvals.l<>tvalm.l) 'Unexpected difference', tvals.l, tvalm.l;
  abort$(tlens.l<>tlenm.l) 'Unexpected difference', tlens.l, tlenm.l;
);