MathProg max()函数抱怨错误的参数

时间:2015-06-21 20:25:26

标签: solver ampl glpk mathprog

我正在尝试为截止日期的schedulling问题制作一个模型。数学解决方案众所周知,可在此处找到:http://www.stomp9.fr/master/benchmarc.pdf

我的代码看起来很好,但我在第20行遇到错误,说max()的参数无效。我已经在示例中阅读了手册和lookead,但它看起来还不错。

有人对这个问题有所了解吗?

# $ glpsol -m file.mod [-d arquivo-dados] -o file.mod.out.txt

param d; # Due Date
param R; # "BigR"
param n; # n-1 tasks
param N; # n   tasks

set TASKS;

param p{ TASKS };
param a{ TASKS };
param b{ TASKS };

# Contraint 6
var   s{ TASKS } >= 0;
var   E{ TASKS } >= 0;
var   T{ TASKS } >= 0;

# Contraints 2 and 3
# Payoff {s in STATES[nPeriods]} : C[nPeriods,s] >= max(0, S[nPeriods,s] - Kstrike);
EARLYS { t in TASKS } : E[t] = max(0, d - (s[t] + p[t])    );
TARDIS { t in TASKS } : T[t] = max(0,     (s[t] + p[t]) - d);

# Constraint 7
var   X{ TASKS, TASKS } binary;

# Constraints 4 and 5
s.t. iB4k { i in 1..n, k in n+1..N  }: s[i] + p[i] <= s[k] + R * (1 - X[i,k]);
s.t. kB4i { i in 1..n, k in n+1..N  }: s[k] + p[k] <= s[1] + R *      X[i,k];

minimize penaltyes: sum{ t in TASKS } ( a[t]*E[t] + b[t]*T[t]);

solve;

printf "DueDate = %4d\n", d;
printf "BigR    = %4d\n", R;
printf { t in TASKS } "p[%2d] a[%2d] b[%2d]\n", p[t], a[t], b[t];

data;

param d :=  23; # Due Date
param R := 117; # "BigR" => Whole schedule time + 1
param n :=   9; # n-1 tasks
param N :=  10; # n   tasks

param: TASKS :   p     a      b :=
           1    20     4      5
           2     6     1     15
           3    13     5     13
           4    13     2     13
           5    12     7      6
           6    12     9      8
           7    12     5     15
           8     3     6      1
           9    12     6      8
          10    13    10      1;

end;

1 个答案:

答案 0 :(得分:2)

有些朋友帮助我发现错误:我无法使用max和变量。他指出,一旦我已经确定T [t]和E [t]都是&gt; = 0,就不必有max。

所以我刚刚删除了max()并修复了我在搜索错误时所引入的其他小错误(好吧,这就是我们选择的生活;)及其运行。工作示例如下(我更改了截止日期)

# $ glpsol -m file.mod [-d arquivo-dados] -o file.mod.out.txt
# mathematical formulation: http://www.stomp9.fr/master/benchmarc.pdf

param d; # Due Date

set TASKS;

param p{ TASKS };      # Processing time
param a{ TASKS };      # earlyness penalty
param b{ TASKS };      # tardiness penalty

param R := sum{ t in TASKS } p[t]; # "BigR"

# Contraint 6
var   s{ TASKS } >= 0; # start
var   E{ TASKS } >= 0; # Earliness
var   T{ TASKS } >= 0; # Tardiness

# Constraint 7
var   X{ TASKS, TASKS } binary;

# Constraints 4 and 5
s.t. iB4k { i in TASKS, k in TASKS : i < k } : s[i] + p[i] <= s[k] + R * (1 - X[i,k]);
s.t. kB4i { i in TASKS, k in TASKS : i < k } : s[k] + p[k] <= s[i] + R *      X[i,k];

# Contraints 2 and 3
s.t. EARLYS { t in TASKS } : E[t] >= d - (s[t] + p[t])    ;
s.t. TARDIS { t in TASKS } : T[t] >=     (s[t] + p[t]) - d;

minimize penaltyes: sum{ t in TASKS } ( a[t]*E[t] + b[t]*T[t]);

solve;

printf "DueDate = %4d\n", d;
printf "BigR    = %4d\n", R;
printf { t in TASKS } "p[%2d] a[%2d] b[%2d]\n", p[t], a[t], b[t];

data;

param d :=  92; # Due Date

param: TASKS :   p     a      b :=
           1    20     4      5
           2     6     1     15
           3    13     5     13
           4    13     2     13
           5    12     7      6
           6    12     9      8
           7    12     5     15
           8     3     6      1
           9    12     6      8
          10    13    10      1;

end;