Description
This test model is based on the chance model from GAMSLIB. Contributer: Michael Bussieck Date: 11/19/2010
Small Model of Type : GAMS
Category : GAMS Test library
Main file : lindorng.gms
$title Test for LindoGlobal's CheckRange Option (LINDORNG,SEQ=505)
$onText
This test model is based on the chance model from GAMSLIB.
Contributer: Michael Bussieck
Date: 11/19/2010
$offText
$eolCom !
sets f feeds / barley, oats, sesame, grnd-meal /
n nutrients / protein, fats /
nn(n) subset of n;
parameters price(f) feed prices (fgld per ton) / barley 24.55
oats 26.75
sesame 39.00
grnd-meal 40.50 /
req(n) requirements (pct) / protein = 21, fats = 5 /
table char(*,n,f) feed characteristics (pct)
barley oats sesame grnd-meal
mean.protein 12.0 11.9 41.8 52.1
mean.fats 2.3 5.6 11.1 1.3
variance.protein .28 .19 20.5 .62
variables x(f) feed mix (pct)
cost total cost per ton
positive variable x;
equations cdef cost definition
mc mix constraint
cc(n) nutrient balance;
cdef.. cost =e= sum(f, price(f)*x(f));
mc.. sum(f, x(f)) =e= 1;
cc(nn(n)).. sum(f, char("mean",n,f)*x(f)) - 1.645*sqrt(sum(f, char("variance",n,f)*sqr(x(f)))) =g= req(n);
models chance chance model / mc, cc, cdef /
option nlp=lindoglobal, optcr=0; nn(n) = yes;
solve chance minimizing cost using nlp;
parameter xsol(f); xsol(f) = x.l(f);
* Now evaluate at optimum point the ranges
chance.optfile=1; cost.lo=0; ! prevent reformulation
$echo checkrange range.gdx > lindoglobal.opt
solve chance minimizing cost using nlp;
set hdr / lo, hi /;
parameter cdef_cost(hdr)
cdef_x (f,hdr)
mc_x (f,hdr)
cc_x (n,f,hdr);
Parameter pickf(f);
variable z;
equation defz; defz.. z =e= sum(f$pickf(f), x(f));
model m1 / mc, defz /;
model m2 / cc, defz /;
model m3 / cdef, defz /;
* mc
alias (f,ff), (np,n); x.fx(f) = xsol(f);
loop(ff,
pickf(ff) = 1; x.lo(ff) = 0; x.up(ff)=inf;
solve m1 min z using nlp; mc_x(ff,'lo') = z.l; if (mc_x(ff,'lo')<-1e12, mc_x(ff,'lo')=-inf);
solve m1 max z using nlp; mc_x(ff,'hi') = z.l; if (mc_x(ff,'hi')> 1e12, mc_x(ff,'hi')= inf);
pickf(ff) = 0; x.fx(ff) = xsol(ff));
* cc
nn(n) = no;
loop((np,ff),
nn(np) = yes; pickf(ff) = 1; x.lo(ff) = 0; x.up(ff)=inf;
solve m2 min z using nlp; cc_x(np,ff,'lo') = z.l; if (m2.modelstat=18 or cc_x(np,ff,'lo')<-1e12, cc_x(np,ff,'lo')=-inf);
solve m2 max z using nlp; cc_x(np,ff,'hi') = z.l; if (m2.modelstat=18 or cc_x(np,ff,'hi')> 1e12, cc_x(np,ff,'hi')= inf);
nn(np) = no; pickf(ff) = 0; x.fx(ff) = xsol(ff));
* cdef
cost.fx = cost.l;
loop(ff,
pickf(ff) = 1; x.lo(ff) = 0; x.up(ff)=inf;
solve m3 min z using nlp; cdef_x (ff,'lo') = z.l; if (cdef_x (ff,'lo')<-1e12, cdef_x (ff,'lo')=-inf);
solve m3 max z using nlp; cdef_x (ff,'hi') = z.l; if (cdef_x (ff,'hi')> 1e12, cdef_x (ff,'hi')= inf);
pickf(ff) = 0; x.fx(ff) = xsol(ff));
cost.lo=0; cost.up=inf;
solve m3 min cost using nlp; cdef_cost('lo') = cost.l; if (cdef_cost('lo')<-1e12, cdef_cost('lo')=-inf);
solve m3 max cost using nlp; cdef_cost('hi') = cost.l; if (cdef_cost('hi')> 1e12, cdef_cost('hi')= inf);
execute_unload 'rangeWant.gdx' cdef_cost, cdef_x, mc_x, cc_x;
execute 'gdxdiff range.gdx rangeWant.gdx Eps=1e-4 > %system.nullfile%';
abort$errorlevel 'range.gdx and rangeWant.gdx differ';