需要花费无限时间才能满足约束条件并产生输出的问题

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

我正在编写一个Minizinc程序,用于安排工人去餐厅做日常工作。限制是每个工人每周只能连续工作五天,并且每天对每天的最低要求都存在于下面代码的数组'minempl_perday'中。]

任务是在满足上述所有约束的同时,最大程度地减少雇用人员的数量。它存储在变量'nb_personnes'中。

代码运行没有错误,但是它无限运行,没有任何输出。有人可以帮我解决吗?

include "globals.mzn";

int: n_jour = 7; 
int: maxpersonnes = 40;
var 1..maxpersonnes : nb_personnes ;

set of int: jours = 1..n_jour;
array[1..n_jour] of int: minempl_perday = [14,13,15,16,19,18,11] ;
%set of int var: personnes = 1..n_personnes;

array[1..maxpersonnes, jours] of var 0..1: planning;

% Now pad all remaining rows to 0
constraint forall(i in nb_personnes+1..maxpersonnes,j in jours)(planning[i,j]=0);

% Constraints

% Each value of every point in array can only be 1 or 0
%constraint forall(p in 1..nb_personnes, d in jours)(planning[p,d] = 1 \/ planning[p,d] = 0);

% Each employee only works 5 days a week.
%constraint forall(p in 1..nb_personnes)(forall(d in jours))(sum(planning[p][d]) = 5); 
constraint forall(p in 1..nb_personnes)(sum(d in jours)(planning[p,d]) = 5);

% Minimum number of employees respected each day
constraint forall(i in 1..n_jour )(sum(p in 1..nb_personnes)(planning[p,i]) >= minempl_perday[i]);


% Five days consecutive worked by every employee
% First day - monday
constraint forall(p in 1..nb_personnes)(if planning[p,1] = 1 /\ planning[p,7] = 0 then planning[p,2] = 1 /\ planning[p,3]= 1 /\ planning[p,4] = 1/\ planning[p,5] = 1 endif);

% First day - tuesday
constraint forall(p in 1..nb_personnes)(if planning[p,2] = 1 /\ planning[p,1] = 0 then planning[p,3] = 1 /\ planning[p,4]= 1 /\ planning[p,5] = 1/\ planning[p,6] = 1 endif);

% First day - wednesday
constraint forall(p in 1..nb_personnes)(if planning[p,3] = 1 /\ planning[p,2] = 0 then planning[p,4] = 1 /\ planning[p,5]= 1 /\ planning[p,6] = 1/\ planning[p,7] = 1 endif);

% First day - tnursday
constraint forall(p in 1..nb_personnes)(if planning[p,4] = 1 /\ planning[p,3] = 0 then planning[p,5] = 1 /\ planning[p,6]= 1 /\ planning[p,7] = 1/\ planning[p,1] = 1 endif);

% First day - friday
constraint forall(p in 1..nb_personnes)(if planning[p,5] = 1 /\ planning[p,4] = 0 then planning[p,6] = 1 /\ planning[p,7]= 1 /\ planning[p,1] = 1/\ planning[p,2] = 1 endif);

% First day - saturday
constraint forall(p in 1..nb_personnes)(if planning[p,6] = 1 /\ planning[p,5] = 0 then planning[p,7] = 1 /\ planning[p,1]= 1 /\ planning[p,2] = 1/\ planning[p,3] = 1 endif);

% First day - sunday
constraint forall(p in 1..nb_personnes)(if planning[p,7] = 1 /\ planning[p,6] = 0 then planning[p,1] = 1 /\ planning[p,2]= 1 /\ planning[p,3] = 1/\ planning[p,4] = 1 endif);


% Minimize the nb_personnes such that all the constraints of above are satisfied
solve minimize(nb_personnes);

output [show(planning[p,j])++" "++
     if j==n_jour 
       then "\n" 
       else "" 
     endif 
     |p in 1..maxpersonnes, j in jours];

我正在编写一个Minizinc程序,用于安排工人去餐厅做日常工作。约束条件是每个工人每周只能连续工作五天,并且每天的最低工作量...

scheduling constraint-programming minizinc
1个回答
0
投票

[使用优化(最小化或最大化)时,建议使用-a选项查看所有中间解决方案。如果没有此选项,则仅显示最后的最佳解决方案。

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