mf_
mf_

Reputation: 13

MiniZinc basic problem. n Workers and n Tasks

I am learning Minizinc for the first time and am kind of stuck on a very basic problem. It involves n workers and n tasks. I am given a 2D-profit matrix where profit[w,t] will give the profit for worker w and task t. The assignment problem's aim is to maximize the profit.

I have tried the following:

include "all_different.mzn";
include "globals.mzn";

int: n = 4;
array [1..n,1..n] of int: profit =
 [| 7,1,3,4 |
    8,2,5,1 |
    4,3,7,2 |
    3,1,6,3 |];

set of int: WORKERS = 1..n;
set of int: TASKS = 1..n;

array[WORKERS] of var TASKS: task;
constraint alldifferent(task);
constraint maximize sum(w in WORKERS) (profit[w,task[w]]);

But this does not work, because the maximize function is not set up that way, however I do not know what else to do. Any tips/solutions? Thanks :)

Upvotes: 0

Views: 122

Answers (1)

hakank
hakank

Reputation: 6854

You are almost there. The problem is in the last line which should be solve, not constraint:

solve maximize sum(w in WORKERS) (profit[w,task[w]]);

The output is:

task: [4, 1, 2, 3]
----------
==========

Upvotes: 1

Related Questions