0

我说过 n 个工作和 m 个机器,并且有一个工作类型的 jobtype 数组。如果作业是作业类型数组中的特定类型,我必须将可用的其他机器中的偶数机器分配给奇数机器。minizinc可以吗?我试过的片段如下:

forall(w in 1..num_workers) (
    if jobtype[job] == "NC" then assignment[job,(w mod 2 ==0)]=1
     else assignment[job,(w mod 2 !=0)]=1 endif
)

这是给出以下警告

WARNING: undefined result becomes false in Boolean context
(array access out of bounds)

TIA

4

1 回答 1

1

这是您可能想要的一种模型,即将编号为偶数的机器分配给标记为“NC”的作业。重要的约束如下,这可能是您想要的。w这里我们使用范围内的临时决策变量1..num_workers,然后确保对于 NC 作业,机器编号必须是偶数:

forall(job in 1..num_jobs) (
    let { var 1..num_workers: w; } in
    % Jobs with NC must be assigned to even numbered workers (machines)
   if jobtype[job] == "NC" then w mod 2 == 0 else w mod 2 == 1 endif
   /\ assignment[job,w]=1
)

这是完整的模型 - 正如我想象的那样 - 有 7 个工作和 7 个工人。我假设一个工人/机器最多只能分配一个工作。好吧,这是很多猜测......

int: num_workers = 7;
int: num_jobs = 7;
array[1..num_jobs] of string: jobtype = ["NC","X","NC","X","X","NC","X"];
% decision variables
array[1..num_jobs, 1..num_workers] of var 0..1: assignment;
solve satisfy;
constraint
   forall(job in 1..num_jobs) (
     let { var 1..num_workers: w; } in
     % Jobs with NC must be assigned to even numbered workers (machines)
     if jobtype[job] == "NC" then w mod 2 == 0 else w mod 2 == 1 endif
     /\
     assignment[job,w]=1
   )
  /\ % at most one worker for each job (or perhaps not)
  forall(job in 1..num_jobs) (
     sum([assignment[job,worker] | worker in 1..num_workers]) <= 1 
  )
  /\ % and at most one job per worker (or perhaps not)
  forall(worker in 1..num_workers) (
    sum([assignment[job,worker] | job in 1..num_jobs]) <= 1
  )
;

output [
  if w == 1 then "\n" else " " endif ++
    show(assignment[j,w]) 
  ++ if w == num_workers then " (\(jobtype[j]))" else "" endif
  | j in 1..num_jobs, w in 1..num_workers
];

该模型产生 144 种不同的解决方案。这是第一个:

0 0 0 0 0 1 0 ("NC")
0 0 0 0 0 0 1 ("X")
0 0 0 1 0 0 0 ("NC")
0 0 0 0 1 0 0 ("X")
0 0 1 0 0 0 0 ("X")
0 1 0 0 0 0 0 ("NC")
1 0 0 0 0 0 0 ("X")
于 2017-06-29T19:27:30.880 回答