i am trying to make a model in minizinc that finds 3 numbers in sequence with the MaxSUM, in arrays below:
[2,3,4,**10,22,11**,17]).
[1,2,3,4,**10,22,11**,11,10,24]).
[2,3,4,5,10,23,**10,22,11**,17]).
I want my model to output these numbers, their indices and their sum.
I tried this:
array[int] of int : list1 = [2,3,4,10,22,11,17];
array[int] of int : list2 = [1,2,3,4,10,22,11,11,10,24];
array[int] of int : list3 = [2,3,4,5,10,23,10,22,11,17];
array[1..3] of var int: values;
array[1..3] of var int: indices;
constraint forall(i in 1..3, j in list1)(
values[i]=list1[j]
);
constraint exists (i in 1..length(list1)-2)(
exists(j in 1..length(list2)-2)(
exists(k in 1..length(list3)-2)
(list1[i]=list2[j]/\list2[j]=list3[k] /\
list1[i+1]=list2[j+1]/\list2[j+1]=list3[k+1]/\
list1[i+2]=list2[j+2]/\list2[j+2]=list3[k+2]
/\values[1]=list1[i]/\values[2]=list1[i+1]/\values[3]=list1[i+2]
/\indices[1]=i/\indices[2]=j/\indices[3]=k
)));
var int: max_sum;
constraint max_sum=sum(values);
solve maximize max_sum;
but, UNSATISFIABLE :(
Here are two hints.
Hint 1: The error states that there's something wrong at line 8, where j=3. If you comment out this constraint then there's no syntax error. Since I don't understand the purpose of this constraint I can't help you there.
Hint 2: Also, if you comment out that constraint (at line 8) then it might take a long time to get a solution - depending on the solver - since you have the decision variables values
and indices
set to var int
. It's much better to state a positive domain for these two decision variables.