Initialize only certain elements of array in dzn file

喜欢而已 提交于 2019-12-11 14:23:27

问题


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.



来源:https://stackoverflow.com/questions/47564111/initialize-only-certain-elements-of-array-in-dzn-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!