Reputation: 31850
When writing MiniZinc models, I often declare multiple variables like this:
var int: dog;
var int: cat;
var int: bird;
var int: mammal;
var int: horse;
I tried to declare all of these variables on one line, but it produced a syntax error:
var int: dog, cat, bird, mammal, horse;
Is it possible to declare all of these variables in a more concise way, using just one statement?
Upvotes: 0
Views: 616
Reputation: 6854
There is no enumeration type or similar in MiniZinc. There are some hints that at some type of enumerations will be included in a future release, though I'm note sure if it will work with decision variables ("var int"), perhaps it will just parameter (constant) variables.
Here are some hopefully relevant side notes.
What I tend to do is use an array of decision variables:
int: n = 5;
array[1..n] of var int: x;
And then one can use x[1] etc. Explicit arrays are also often needed - or at least convenient - in the model to simplify certain constraints such as "all_different" etc.
But it's often better to use the named variables in the constraints.
If you also want to use the names variables in your model, you have to define them with their names and connect them to the "x" array.
var int: dog = x[1];
var int: cat = x[2];
var int: bird = x[3];
var int: mammal = x[4];
var int: horse = x[5];
Or connect then in another way:
int: n = 5;
var int: dog;
var int: cat;
var int: bird;
var int: mammal;
var int: horse;
array[1..n] of var int: x = [dog,cat,bird,mammal,horse];
[And I usually define as small domains as possible for the variables, e.g. "var 1..10: dogs", etc.]
Upvotes: 1