After running through the tutorials, thinking I got the concepts, I set about creating my own model and immediately ran into problems. Better to get stuck in asap to realise just how little you actually know, imo.
In this example I would simply like to get an output where classes consist of students that want them, i.e. true, as represented by my array (not every student is able to attend on every day).
There could be all sorts of badness in the way the model was written...
Needless to say, I get the error WARNING: model inconsistency detected
enum Students = { Mark, Bart, Mary, Anne, Sue };
enum Classes = { Mon, Tue, Wed};
array[Students, Classes] of bool: pref =
[| true, true, false,
| false, true, true,
| true, false, true,
| true, false, false,
| false, false, true |];
constraint forall (i in Students, j in Classes)(pref[i,j]=true);
solve satisfy;
output [ " \(pref[Students,Classes]);\n" ]
Bonus would be limiting it so each Student only appears once...
Perfect outcome would be something like a list of all the combinations where students preferences are satisfied and they are in 1 class.
[Mark, Anne | Bart | Mary, Sue]
Thank you for helping me along my way!
The vital part that you might not understand is that MiniZinc is a declarative language. You do not tell it how to solve a problem, but merely specify the problem and let the language do the rest.
A MiniZinc model is specified in terms of
In your model you didn't specify any variables, merely parameters and constraints. It is said to be inconsistent because you give it an array
prefthat contains bothtrueandfalse, but then your constraint enforces that every element in the array must betrue.Likely you meant to make
prefyour set of variables and meant that your constraint should force one preference for every student:If you only want each student to have at least one preference you can use
existsinstead:This would work, but if you know, as is the case in the first solution, that the students only make one preference, then it is better to just enforce this as part of the variable type:
Then no constraint is required to ensure a student has exactly one preference.