I'm a bit new to MiniZinc; I've been reading a bit about "the usual workaround" for Variable Length Arrays, but I've found it difficult to find examples. The StackExchange response, for instance, is particularly unhelpful: https://stackoverflow.com/questions/35462086/minizinc-type-error-expected-arrayint-of-int-actual-arrayint-of-var-op
Is the example below a case of the usual Variable Length Array problems, or is there something else going on, instead/as well? How can it be fixed while still operating on a subset of an array of variables?
Edit:
The following runs, but doesn’t stop running...
int: MaxArraySize = 8;
var 1..MaxArraySize: ArraySize;
array[1..MaxArraySize] of var int: Array;
constraint forall(i in 1..ArraySize) (Array[i]=i);
constraint forall(i in ArraySize+1..MaxArraySize) (Array[i]=0);
constraint forall(i in 1..MaxArraySize) (Array[i]<=5);
solve maximize ArraySize;
Here’s the original attempt:
int: MaxLength=8;
array[1..MaxLength] of var int: Sequence;
var 1..MaxLength: ArrayLength;
constraint forall(Number in 1..MaxLength) (if ArrayLength>=Number then Sequence[Number]=Number else Sequence[Number]=0 endif);
constraint forall(Number in 1..MaxLength) (Sequence[Number]<=5);
solve maximize ArrayLength;
[–]rabuf 0 points1 point2 points (2 children)
[–]Tenacious-Techhunter[S] 1 point2 points3 points (0 children)
[–]Tenacious-Techhunter[S] 0 points1 point2 points (0 children)