user1067305
user1067305

Reputation: 3481

Why is this MiniZinc declaration "unexpected"?

I'm a MiniZinc newbie trying to generalize the toy program in the MiniZinc tutorial for coloring the map of Australia, by using arrays.

Here is the program with my 2 array declarations:

% Colouring Australia using nc colours

int: nc = 3;   /* number of colours */
int: ns = 7;  % number of states

  % I added these 2 lines, and changed nothing else so far
array[1..ns] of string: names = ["wa","nt","sa","q","nsw","v","t"]; 
var array[1..ns] of 1..nc: colours;

var 1..nc: wa;  % the color assigned to each state, to be calculated
var 1..nc: nt;
var 1..nc: sa;
var 1..nc: q;
var 1..nc: nsw;
var 1..nc: v;
var 1..nc: t;

constraint wa != nt;  % adjacent states
constraint wa != sa;
constraint nt != sa;
constraint nt != q;
constraint sa != q;
constraint sa != nsw;
constraint sa != v;
constraint q != nsw;
constraint nsw != v;

solve satisfy;

The first array statement was accepted by the compiler without complaint. The second array statement gave the syntax error message: "unexpected array", but didn't complain of the syntax itself.

Order of statements is supposed to be irrelevant, so it can't be that. Replacing 1..nc with int still gives the error.

What makes it "unexpected"? Why was the first array Not unexpected?

How Should I be defining an array of decision variables?

Upvotes: 0

Views: 501

Answers (1)

hakank
hakank

Reputation: 6854

The syntax for declaring an array of decision variables is

 array[1..ns] of var 1..nc: colours;

i.e. "var" is placed before the domain (not before "array").

Upvotes: 1

Related Questions