我正在嘗試使用 forall 實例來添加約束,但出現此錯誤,我不確定應該做什麼。
(數組切片必須是連續的)在數組推導式表達式中調用 'forall' 中的 i = {10,24} 二進制'<=' 運算符表達式在調用 'slice_1d' 中
我正在處理一個調度問題,我需要應用一個限制來確定一組任務(由 suc 確定)只能在特定任務(由 1..nTasks 確定)已經完成後開始。
模型如下
include "globals.mzn";
int: n_res;
array [1..n_res] of int: res_cap;
int: n_tasks;
array [1..n_tasks] of int: duration;
array [1..n_res, 1..n_tasks] of int: res_req;
array [1..n_tasks] of set of int: suc;
int: t_max = sum(i in 1..n_tasks)(duration[i]);
array [1..n_tasks] of var 0..t_max: start;
array [1..n_tasks] of var 0..t_max: end;
var 0..t_max: makespan;
% constraint that I can't implement. this constraint should make every task[i] to start after a set of tasks{i} are finished. The set is defined by the array suc.
constraint forall (i in suc)(end[i] <= start[i]);
constraint cumulative(start, duration, row(res_req, 1), res_cap[1]);
constraint cumulative(start, duration, row(res_req, 2), res_cap[2]);
constraint cumulative(start, duration, row(res_req, 3), res_cap[3]);
constraint cumulative(start, duration, row(res_req, 4), res_cap[4]);
constraint forall(i in 1..n_tasks)(end[i] = start[i]+duration[i]);
constraint makespan = max(i in 1..n_tasks)(end[i]);
solve minimize makespan;
數組 suc 和 1..nTasks 具有相同的行數。
我有一個一維數組,其中包含可以在 task[i] 結束後開始的特定任務集。
在較小的實例中,例如:suc = [{5, 15}, {17, 23, 28}, {10, 12}, {8}]
我需要實現的是:
結束[i] | 我在 1..nTasks <= start[i] | 我成功了
對於我發布的特定集合,可以像這樣手動完成:
end[1] <= start[5]
end[1] <= start[15]
end[2] <= start[17]
end[2] <= start[23]
end[2] <= start[28]
end[3] <= start[10]
end[3] <= start[12]
end[4] <= start[8]
我剛開始使用 minizinc 並且有些東西告訴我我錯過了一些可能很簡單的東西,但是,已經有一段時間了,我無法實現它。
如何編寫可以執行此操作的 forall 實例?
罪魁禍首是這個約束(如錯誤所示):
constraint forall (i in suc)(end[i] <= start[i]);
您嘗試將其suc
用作循環的生成器。問題是您需要為這個約束做兩件事:當前任務的開始應該在該任務的後繼任務之前。並且使用您的方法這是不可能的,因為i
將具有諸如 的值{ 10, 24 }
,但是當前任務沒有值(參考)(即 的值start[i]
)。
這是解決這個問題的一種方法:使用i in n_res
循環遍歷所有任務(i
是第 i 個任務),然後循環suc[i]
獲取每個任務的後繼任務。
constraint forall (i in 1..n_res) (
forall(s in suc[i]) (
end[i] <= start[s]
)
);
另一種可能更簡單的方法是將兩個forall
循環合併為一個循環:
constraint forall (i in 1..n_res, s in suc[i]) (
end[i] <= start[s]
);
當我運行模型時,它生成了這個解決方案:
% obj = 51
start = array1d(1..30, [7, 21, 4, 31, 6, 41, 34, 3, 35, 39, 21, 28, 47, 0, 38, 48, 44, 35, 28, 7, 10, 34, 11, 47, 41, 3, 11, 3, 22, 17]);
end = array1d(1..30, [17, 25, 5, 34, 11, 51, 35, 7, 41, 47, 28, 35, 51, 3, 48, 51, 48, 38, 35, 12, 11, 44, 19, 48, 47, 7, 18, 9, 31, 21]);
makespan = 51;
----------
% obj = 51
==========
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句