在帶有數組集的 minizinc 中使用 forall(不連續)

盧卡斯·桑托斯

我正在嘗試使用 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在minizinc中将forall()谓词用作没有'constraint'的赋值语句

如何在帶有構造函數的類組件中使用 t() 函數?

為什麼我的平台在使用帶有數組列表的 for 循環(訪問多個平台)時不繪製

當我有一個帶有 id 的數組時,如何使用 angular 發布一個帶有某個對象的數組

为什么MiniZinc有时不使用求解器定义的常规约束?

使用带有 Minizinc 的 OR-Tools 求解器时如何解决这个问题?

MYSQL:在帶有別名的 SELECT 中使用數學

在 Handlebars 中使用帶有按鈕的 Javascript 函數

使用 RegEx 提取 3 個連續數字

在Minizinc中如何使用热启动?

使用Minizinc在表中选择匹配的原料

使用 Arduino 和 C++ 在一個函數中輸出帶有數組的參數

帶有連接結果集的表函數的返回類型

我想在c#中使用foreach循環一個一個讀取帶有特定json對像數組的json文件數據

Minizinc中回文的有效谓词

使用帶有 OR 條件的 Sumproduct 進行計數不會返回所需的結果

即使數字不連續,如何從 Python 中的字符串中提取所有數字?

通過 n 對帶有 zip 的函數進行連續元素配對的通用函數

如何在MiniZinc中使用特定数字域初始化变量?

插入空行,其中列中的值在數據框中不連續或在 R 中

Python Minizinc 有时会给出与 Minizinc IDE 不同的结果

如何在 MYSQL 中使用帶有內連接的子查詢?

Minizinc“ int:x的变量集”,而不是“ int:x的变量集”

javascript - console.log 打印一個帶有括號“[]”的數組,而不僅僅是內容

使用嵌套數組生成帶有地圖的可觸摸不透明度

Minizinc:连续输出int决策变量集的值

如何在java腳本中使用find方法查找所有數組而不僅僅是第一次出現?

如何在 JavaScript 中連續映射數組?

MySQL 按連續值分組併計數