Initialize only certain elements of array in dzn f

2019-08-20 22:33发布

问题:

I'm messing arround with minizinc and I want to have a static mzn file where I make the solving using only the dzn. For a better understanding of the question, here's a sample:

include "globals.mzn";
include "data.dzn";
int: time;
int: n;
int: l=n*n;
array[1..4,0..time,1..l] of var bool: X;
solve satisfy;

I now want to initialize only few elements of X using the dzn file (the other elements should be vars).

The dzn would look like this

time=1;
n=3;
X[4,1,7]=true;

Since this initialization is impossible, I also tried using X=array3d(1..4,0..time,1..l,[false,...,false] where every element other than the element in position (4,1,7) is false. However this initializes every element and I cannot obtain the result I wish since it cannot satisfy the constraints I have.

Is there a way to initialize only one or some elements of this array using the dzn file?

回答1:

One way to do this is to use the anonymous variable (_) in the data matrix in the dzn file. Here is a simple example:

% mzn file 
include "data.dzn";
int: time;
int: n;
array[1..time,1..n] of var bool: X;
solve satisfy;

And the data file:

% data.dzn
time=3;
n=2;
X = array2d(1..3,1..2,
   [_,_,
   _,_,
   _,false
   ]);

Note that this approach requires at least one non-anonymous value, otherwise this message is thrown: array literal must contain at least one non-anonymous variable.



标签: minizinc