不应该查看的列是"域外"



我得到以下域外错误,请参阅下文。问题是,在引用的行中,q来自Qualities集合,该集合甚至不包含LAT值。如何防止这种情况发生,并将所有数据保存在一个表中?我一直在尝试使用单独的latdata表来解决这个问题,但这对我来说是丑陋和多余的

$ glpsol -m ron.mod
GLPSOL: GLPK LP/MIP Solver, v4.60
Parameter(s) specified in the command line:
 -m ron.mod
Reading model section from ron.mod...
Reading data section from ron.mod...
86 lines were read
Generating req...
ron.mod:20: cannot convert LAT to floating-point number
MathProg model processing error
MacBook-Air-van-Ron:examples raarts$ glpsol -m ron.mod
GLPSOL: GLPK LP/MIP Solver, v4.60
Parameter(s) specified in the command line:
 -m ron.mod
Reading model section from ron.mod...
Reading data section from ron.mod...
86 lines were read
Generating req...
ron.mod:20: data[DO_MINI,LAT] out of domain
MathProg model processing error

ron.mod的来源如下:

set AllProducts;
/* all products */
set Qualities;
/* minrequired */
param data{prod in AllProducts, {"price"} union Qualities};
param latdata{prod in AllProducts, "LAT"};
param maxallowed{"LAT"};
set Product := setof{ prod in AllProducts: latdata[prod, "LAT"] <= maxallowed["LAT"]} prod;
param minrequired{q in Qualities};
var x{p in Product}, integer, >= 0;
subject to req{q in Qualities}: sum{p in Product} data[p,q] * x[p] >= minrequired[q];
minimize cost: sum{p in Product} x[p] * data[p, "price"];
solve;
printf "aantal product         CPU   RAM    DISK  PR/STUK   TOTAALn";
printf{p in Product: x[p] != 0} "%6d %-12s %6d %6d %6d %8.2f %8.2fn", x[p], p, data[p,"CPU"] * x[p], data[p,"RAM"] * x[p], data[p,"DISK"] * x[p],data[p,"price"], data[p,"price"] * x[p];
printf                    "%6s %-12s %6d %6d %6d %8.2s %8.2fn", "", "", sum{p in Product} data[p,"CPU"] * x[p], sum{p in Product} data[p,"RAM"] * x[p], sum{p in Product} data[p,"DISK"] * x[p], "", sum{p in Product} data[p,"price"] * x[p];
data;
param data :    price  CPU     RAM     DISK    LAT :=
DO_MINI        5.00    1      512      20       2 
DO_SMALL      10.00    2     1024      30       2
DO_MEDIUM     15.00    2     2048      40       2
DO_LARGE      25.00    3     4096      75       2
SW_MINI        5.00    1     1024      10       3 
SW_SMALL      10.00    2     1024      15       3
SW_MEDIUM     15.00    2     2048      25       3
SW_LARGE      25.00    3     4096      50       3
BP_LARGE       5.00    3     4096      50       20
;
param latdata : LAT :=
DO_MINI         2  
DO_SMALL        2
DO_MEDIUM       2
DO_LARGE        2
SW_MINI         3  
SW_SMALL        3
SW_MEDIUM       3
SW_LARGE        3
BP_LARGE        20 
;
set AllProducts :=
DO_MINI   
DO_SMALL  
DO_MEDIUM 
DO_LARGE  
SW_MINI   
SW_SMALL  
SW_MEDIUM 
SW_LARGE  
BP_LARGE  
;
param minrequired :=
CPU                15
RAM             64000
DISK             1250
;
param maxallowed :=
LAT                 5
;
set Qualities :=
CPU
RAM
DISK
;
end;

通过在data参数中允许"LAT",可以将所有数据保存在一个表中:

param data{prod in AllProducts, {"price", "LAT"} union Qualities};

然后latdata可以简单地从中复制LAT数据:

param latdata{prod in AllProducts} = data[prod, "LAT"];

这将解决域外错误,因为('DO_MINI', 'LAT')将在data的索引集中,从而使此数据语句有效:

param data :    price  CPU     RAM     DISK    LAT :=
DO_MINI        5.00    1      512      20       2  # <- data[DO_MINI, LAT]
...

相关内容

  • 没有找到相关文章

最新更新