Uvais Karni
Uvais Karni

Reputation: 65

Constraint Issue Unsatisfied MiniZinc

i have an array S[1,4,2,3,0] of index[1,2,3,4,5] and an array O[2,1,1,2] of index [1,2,3,4], from these two i have to generat an array SO[2,2,1,1,0] of index [1,2,3,4,5]. When i run with constraint forall(i in 1..5)(SO[i] = O[S[i]]); i get error unsatisfied because of no index 0 for O. Please Help me out with this i am new to minizinc and i dont find sufficient material to help

''''''

constraint forall(i in 1..5)(SO[i] = O[S[i]]);`i/p array S[1,4,2,3,0] of index[1,2,3,4,5];

Upvotes: 1

Views: 158

Answers (1)

hakank
hakank

Reputation: 6854

The problem with your model is that S[5] is 0 (zero) and there no corresponding SO[0].

I'm not sure if you thought that MiniZinc would automatically yield a 0 if the value of O[0] is missing, but MiniZinc requires that you are explicit about the indices in an array when it don't start at 1.

You can fix this by adding an index of 0 (zero) in the O array, together with array1d:

array[1..5] of int: S = [1,4,2,3,0];
array[0..4] of int: O = array1d(0..4,[0,2,1,1,2]);  # <---

array[1..5] of var 0..2: SO;

solve satisfy;

constraint forall(i in 1..5) (
                          SO[i] = O[S[i]]
                          );

The result is:

SO = array1d(1..5 ,[2, 2, 1, 1, 0]);

Upvotes: 1

Related Questions