MiniZinc - 多个设施的任务调度 - 累积 'var opt error'
MiniZinc - Task scheduling on multiple facilities - cumulative 'var opt error'
我是 MiniZinc 的新手,在执行以下 CP 公式时遇到问题(可以找到问题的完整公式 here (page 4/16))
我的实现看起来像下面的代码,但我遇到了以下错误:MiniZinc: type error: no function or predicate with this signature found: 'comulative(array[int] of var opt int,array[int] of var opt int,array[int] of var opt int,int)'
.
这是因为数组理解受某些变量的影响,在本例中为变量 x
。
对于如何使 cumulative
约束与选项变量一起使用或任何可能的解决方法,您有什么建议吗?
提前感谢您的帮助:-)
include "cumulative.mzn";
include "element.mzn";
int: numJ; % number of tasks
int: numI; % number of facilities
% Tasks
set of int: Tasks = 1..numJ;
% Facilities
set of int: Facilities = 1..numI;
% Max consumptions of facilities
array[Facilities] of int: C;
array[Tasks] of int: d; % due times
array[Tasks] of int: r; % release times
array[Facilities, Tasks] of int: c; % c[i,j] = consumption of task j at facility i
array[Facilities, Tasks] of int: p; % p[i,j] = processing time of task i at facility j
array[Facilities, Tasks] of int: F; % F[i,j] = fixed cost paid when task j is assigned to facility i
% start time's domain is an interval <0, maximum of due times>
array[Tasks] of var 0..max(d): s;
% assign task to a facility
% x[3] = 1 --> task 3 is assigned to facility 1
array[Tasks] of var 1..numI: x;
% something like a temporary processing time
% im not really sure about this
array[Tasks] of var 0..max(p): u;
constraint forall(j in Tasks)(
element(
x[j],
[p[i,j] | i in Facilities],
u[j]
)
);
constraint forall(i in Facilities)(
comulative(
[s[j] | j in Tasks where x[j] == i],
[p[i,j] | j in Tasks where x[j] == i],
[c[i,j] | j in Tasks where x[j] == i],
C[i]
)
);
% A task cant start before its release time
constraint forall(j in Tasks)(s[j] >= r[j]);
% A task cant run longer than its due time
constraint forall(j in Tasks)(s[j] <= d[j] - u[j]);
% Minimize total cost
solve minimize sum(j in Tasks)(F[x[j],j]);
output [ "start: ", "\n", show(s), "\n", "facility: ", "\n" , show(x) , "\n"];
简单数据集:
C = [8, 8, 6, 5];
numJ = 12;
numI = 4;
r = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2];
d = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3];
c = [|8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |];
p = [|1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |];
F = [|0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, |];
尽管您提到您已经找到了解决方案,但这里有一个使用累积的版本(在 "cumulative_opt.mzn" 中选择版本)。
include "globals.mzn"; % includes the file "cumulative_opt.mzn"
% ....
constraint forall(i in Facilities)(
cumulative(
% [s[j] | j in Tasks where x[j] == i], % original
% [p[i,j] | j in Tasks where x[j] == i], % original
% [c[i,j] | j in Tasks where x[j] == i], % original
[s[j] | j in Tasks where x[j] == i],
[p[i,j] | j in Tasks], % <-- no condition clause here
[c[i,j] | j in Tasks], % <-- no condition clause here
C[i]
)
);
我想到了这个解决方案,我希望它比具有累积约束的解决方案更容易理解。
array[Facilities, 0..max(d)] of var 0..max(C): facilityUsageAtTime;
constraint forall(i in Facilities) (
forall(tt in 0..max(d)) (
facilityUsageAtTime[i,tt] = sum(j in Tasks where x[j] == i /\ s[j] <= tt /\ tt < s[j] + p[x[j], j])(c[x[j],j]) /\
facilityUsageAtTime[i,tt] <= C[i]
)
);
它受到 @hakank 发布的答案的极大启发
我是 MiniZinc 的新手,在执行以下 CP 公式时遇到问题(可以找到问题的完整公式 here (page 4/16))
我的实现看起来像下面的代码,但我遇到了以下错误:MiniZinc: type error: no function or predicate with this signature found: 'comulative(array[int] of var opt int,array[int] of var opt int,array[int] of var opt int,int)'
.
这是因为数组理解受某些变量的影响,在本例中为变量 x
。
对于如何使 cumulative
约束与选项变量一起使用或任何可能的解决方法,您有什么建议吗?
提前感谢您的帮助:-)
include "cumulative.mzn";
include "element.mzn";
int: numJ; % number of tasks
int: numI; % number of facilities
% Tasks
set of int: Tasks = 1..numJ;
% Facilities
set of int: Facilities = 1..numI;
% Max consumptions of facilities
array[Facilities] of int: C;
array[Tasks] of int: d; % due times
array[Tasks] of int: r; % release times
array[Facilities, Tasks] of int: c; % c[i,j] = consumption of task j at facility i
array[Facilities, Tasks] of int: p; % p[i,j] = processing time of task i at facility j
array[Facilities, Tasks] of int: F; % F[i,j] = fixed cost paid when task j is assigned to facility i
% start time's domain is an interval <0, maximum of due times>
array[Tasks] of var 0..max(d): s;
% assign task to a facility
% x[3] = 1 --> task 3 is assigned to facility 1
array[Tasks] of var 1..numI: x;
% something like a temporary processing time
% im not really sure about this
array[Tasks] of var 0..max(p): u;
constraint forall(j in Tasks)(
element(
x[j],
[p[i,j] | i in Facilities],
u[j]
)
);
constraint forall(i in Facilities)(
comulative(
[s[j] | j in Tasks where x[j] == i],
[p[i,j] | j in Tasks where x[j] == i],
[c[i,j] | j in Tasks where x[j] == i],
C[i]
)
);
% A task cant start before its release time
constraint forall(j in Tasks)(s[j] >= r[j]);
% A task cant run longer than its due time
constraint forall(j in Tasks)(s[j] <= d[j] - u[j]);
% Minimize total cost
solve minimize sum(j in Tasks)(F[x[j],j]);
output [ "start: ", "\n", show(s), "\n", "facility: ", "\n" , show(x) , "\n"];
简单数据集:
C = [8, 8, 6, 5];
numJ = 12;
numI = 4;
r = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2];
d = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3];
c = [|8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |];
p = [|1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |];
F = [|0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, |1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, |1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, |1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, |];
尽管您提到您已经找到了解决方案,但这里有一个使用累积的版本(在 "cumulative_opt.mzn" 中选择版本)。
include "globals.mzn"; % includes the file "cumulative_opt.mzn"
% ....
constraint forall(i in Facilities)(
cumulative(
% [s[j] | j in Tasks where x[j] == i], % original
% [p[i,j] | j in Tasks where x[j] == i], % original
% [c[i,j] | j in Tasks where x[j] == i], % original
[s[j] | j in Tasks where x[j] == i],
[p[i,j] | j in Tasks], % <-- no condition clause here
[c[i,j] | j in Tasks], % <-- no condition clause here
C[i]
)
);
我想到了这个解决方案,我希望它比具有累积约束的解决方案更容易理解。
array[Facilities, 0..max(d)] of var 0..max(C): facilityUsageAtTime;
constraint forall(i in Facilities) (
forall(tt in 0..max(d)) (
facilityUsageAtTime[i,tt] = sum(j in Tasks where x[j] == i /\ s[j] <= tt /\ tt < s[j] + p[x[j], j])(c[x[j],j]) /\
facilityUsageAtTime[i,tt] <= C[i]
)
);
它受到 @hakank 发布的答案的极大启发