当输入是数组时,gmpl(glpsol)参数错误

时间:2014-10-11 08:57:40

标签: ampl glpk mathprog

我正在尝试用glpsol来解决最小化问题。我有真实世界的数据,我一直在努力包含这些数据。我试图使用-d data.dat包含数据但没有成功,我尝试将所有数据重写为param值,但是我收到一个错误:      data.dat:7: oh[0] already defined

我的代码:

param n:=23;
param m_mascobe;
param m_oh;
param m_proteini;
param m_kalcij;
param m_zelezo;

param energija{i in 1..n};
param mascobe{i in 1..n};
param oh{i in 1..n};
param proteini{i in 1..n};
param kalcij{i in 1..n};
param zelezo{i in 1..n};
param enice{i in 1..n};
param max_kol{i in 1..n};
param cene{i in 1..n};

 display n;
var kolicina{i in 1..n};

minimize kalorije: sum{i in 1..n} energija[i]*kolicina[i]/100;
subject to mascobei: sum{i in 1..n} mascobe[i]*kolicina[i]/100>=m_mascobe;
subject to ohji: sum{i in 1..n} oh[i]*kolicina[i]/100>=m_oh;
subject to proteinii: sum{i in 1..n} proteini[i]*kolicina[i]/100>=m_proteini;
subject to kalciji: sum{i in 1..n} kalcij[i]*kolicina[i]/100>=m_kalcij;
subject to zelezoi: sum{i in 1..n} zelezo[i]*kolicina[i]/100>=m_zelezo;

solve;

data;

param m_mascobe:= 70;
param m_oh:= 310;
param m_proteini:= 50;
param m_kalcij:= 1;
param m_zelezo:= 0.018;

param oh:=  64 13.81 21.55 0 0 4.52 1.43 47.51 41.29 0.06 0 28.59 55 23.71 8 3.35 5.8 3.55 18 7.68 0.88 26.54 60;
param proteini:=  15.5 0.26 1.96 17.17 17.18 3.22 24.99 10.91 12.95 0.85 18.5 2.38 9 8.86 2 1.25 1.28 0.46 1 0.67 13.63 5.33 4;
param kalcij:=  54 6 5 18 15 113 731 142 107 24 66 3 220 27 16 52 40 4 10 16 59 15 116;
param zelezo:=  4.7 0.12 0.35 1.94 1.05 0.03 0.44 3.46 2.43 0.02 1.4 1.49 4 2.1 0.79 0.83 0.47 0.02 0.4 0.41 1.98 1.06 3.6;
param enice:=    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1;
param max_kol:= 100 400 100 100 100 200 30 50 100 20 500 150 30 50 200 200 200 200 100 100 50 150 30;
param cene:=    0.109 0.09 0.169 0.974 0.688 0.1 1.2 0.246 0.246 0.932 1.3 0.15 0.96 0.34 0.14 0.2 0.17 0.23 0.12 0.3 0.1 0.3 0.9;
param energija:= 369 52 93 254 236 60 357 266 247 717 305 130 563 132 37 17 25 43 69 32 196 124 399;
param mascobe:= 6.1 0.17 0.1 20 17.99 3.25 27.8 3.64 3.35 81.11 25.1 0.21 33 0.54 0 0.2 0.1 0 0 0.3 15.31 0.54 16;


end;

我刚开始使用glpsol。我一直在阅读文档,但无法弄清楚出了什么问题。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

glpk给出的错误相当令人困惑,但这里的问题是缺少参数oh和其他参数的数据中的键。正确的语法如下:

param oh:=
  1 64
  2 13.81
  3 21.55
  4 0
  5 0
  ...

注意每个值前面的键1,2。该格式在AMPL书的Section 9.2 Data in lists中描述(glpk使用基于AMPL modeling language的子集的MathProg。)