在 Minizinc 中使用累积全局约束时出错

问题描述 投票:0回答:1

我正在 MiniZinc 中编码,并且在使用累积约束时遇到问题。我将其定义如下:

cumulative(
            [start[i] | i in 1..n_tasks],        
            [duration[i] | i in 1..n_tasks],     
            [res_req[r, i] | i in 1..n_tasks],    
            res_cap[r]                          
        )

但是有一些问题:

错误:Gecode:Int::cumulative:数量超出限制 =====错误===== 进程以非零退出代码 1 结束。

你能告诉我如何解决吗?

非常感谢。以下是我的完整代码

include "globals.mzn";

int: n_tasks;
int: n_res;

array [1..n_tasks] of int: duration;
array [1..n_res, 1..n_tasks] of int: res_req;
array [1..n_res] of int: res_cap;
array [1..n_tasks] of set of int: suc;

array [1..n_tasks] of var int: start;  
array [1..n_tasks] of var int: end;    
var int: makespan;                

constraint forall(i in 1..n_tasks) (end[i] = start[i] + duration[i]);

constraint forall(i in 1..n_tasks)(start[i] >= 0);

makespan = (max(i in 1..n_tasks)(end[i]));

constraint
    forall(r in 1..n_res) (
        cumulative(
            [start[i] | i in 1..n_tasks],        
            [duration[i] | i in 1..n_tasks],     
            [res_req[r, i] | i in 1..n_tasks],    
            res_cap[r]                          
        )
    );

solve minimize makespan;

output
[
  "makespan: " ++ show(makespan) ++ "\n" ++
  "[start-(dur)-end]:"
] ++
[
  if i = 1 then "\n" else " " endif ++
    "[" ++ show(start[i]) ++ "-(" ++ show(duration[i]) ++ ")-" ++ show(end[i]) ++ "]"
  | i in 1..n_tasks
];

这里是相同的数据

% The number of resources
n_res = 4;

% The resource capacity
res_cap = [ 10, 12, 16, 10 ];

%%%%%%%%%% Tasks %%%%%%%%%%%%%
% The number of tasks
n_tasks = 30;

% The task durations
duration = [ 10, 4, 1, 3, 5, 10, 1, 4, 6, 8, 7, 7, 4, 3, 10, 3, 4, 3, 7, 5, 1, 10, 8, 1, 6, 4, 7, 6, 9, 4 ];

% The resource requirements for each task 
res_req = array2d(1..n_res, 1..n_tasks,
    [5, 10, 5, 0, 3, 0, 0, 5, 1, 2, 0, 10, 0, 9, 3, 10, 0, 6, 0, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 9,
     0, 0, 0, 0, 0, 0, 4, 0, 4, 0, 10, 0, 6, 0, 5, 4, 1, 6, 6, 0, 8, 0, 0, 0, 3, 0, 9, 7, 0, 0,
     0, 5, 1, 10, 0, 5, 0, 0, 4, 0, 7, 0, 0, 3, 0, 3, 0, 0, 0, 5, 2, 0, 8, 0, 0, 4, 0, 0, 4, 1,
     8, 0, 0, 5, 0, 0, 0, 7, 8, 1, 6, 5, 0, 10, 0, 10, 1, 1, 0, 0, 1, 1, 2, 8, 8, 0, 0, 0, 4, 7]);

我尝试了不同的方法来定义累积约束,但仍然不起作用。但是,如果我使用另一个带有“start”和 res_req[r,i] 的全局约束,它就可以工作!

我使用 Gecode 6.3.0 运行

constraints global minizinc
1个回答
0
投票

定义变量数组开始不是 int 类型,而是定义间隔。例如

数组 [1..n_tasks] of var 0..1000: start;

© www.soinside.com 2019 - 2024. All rights reserved.