I have say n jobs and m machines and have a jobtype array with type of job. If the job is of specific type in job type array , i have to assign even numbered machine among the available else to the odd numbered machine. Is it possible with minizinc? Snippet I tried given below:
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
)
which is giving the following warning
WARNING: undefined result becomes false in Boolean context
(array access out of bounds)
TIA
Here is one model that might be what you want, i.e. to assign even numbered machines to the jobs marked as "NC". The important constraint is the following, which might be the one you want. Here we use a temporary decision variable w
in the range of 1..num_workers
, and then ensure that for the NC jobs the machine number must be even:
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
)
Here is the full model - as I imagined it - with 7 jobs and 7 workers. I assume that a worker/machine can only be assigned to at most one job. Well, it's a lot of guesswork...
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
];
The model yields 144 different solutions. Here's the first:
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")