Initialize only certain elements of array in dzn file

Sergio

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?

hakank

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Array Only Prints Certain Elements and Not Others

How to apply rules to only certain elements in array

Permute only certain elements in an array in python

How to initialize only few elements of an array with some values?

Overflow only certain elements

What's the fastest way to only rotate certain elements in an array?

Return only elements of an array in an object that contain a certain value

How to pick only certain elements from an array in Ruby?

Write only certain elements / columns of a 2 dimensional array back to worksheet

How to access only certain elements in a 2d array in Javascript?

How to extract only certain elements from JSON file and append to csv?

How to initialize array elements with their indices

Initialize struct with array of n elements

Display array rows only if a file path has a certain extension

How to load .txt file as a numpy array such that it only reads in certain lines?

How to remove certain elements from an array into a new array and leave the others only the original array?

How can I filter only certain elements of an XML file and write to another XML file using a batch file

React JS: Only map certain elements of an array within JSX tag, where the elements to map are iterated

What is the fastest way to initialize an array in C with only two bytes for all elements?

How to count certain elements in array?

Fill array with elements at certain positions

Displaying certain elements of a structure array

Displaying certain array elements in ngFor

How to replace only the first n elements in a numpy array that are larger than a certain value?

Only unique elements in an array

Any shortcut to initialize all array elements to zero?

initialize std::array without copying/moving elements

Initialize all the elements of an array to the same number

Initialize an Array with optional elements depending on conditions