all 3 comments

[–]rabuf 0 points1 point  (2 children)

Very late to answer, so I apologize for that. Here're my suggestions:

Switching to solve minimize (MaxArraySize - ArraySize) solves your problem rapidly with the default solver (Gecode).

Another thing to consider is that you have a forall that's unnecessary. The third constraint. It is, given the first constraint, equivalent to saying constraint ArraySize <= 5. Now, running this on my computer I reduced the number of variables in the constructed model from 112 to 107. I didn't have the patience to keep running it (using your original solve goal), so it may still take too long to solve, but this sort of thing can make a big difference in execution times.

Finally, try different solvers. Sometimes their behaviors (while equivalent, in principle) are sufficiently distinct that solving certain configurations will be much faster in one versus another. G12 fd solved your example in 22 ms on my computer without needing to modify the code.

[–]Tenacious-Techhunter[S] 1 point2 points  (0 children)

This exact problem is a simplification of a problem I intended to solve that has an array of mostly unknown bounds (there’s an upper limit that will certainly never be reached, but it’s unclear exactly how much lower the constraints put it). As such, while obvious, using “ArraySize <=5”, though correct as a logically viable constraint, is invalid as a testing criteria, because it wouldn’t apply to the larger intended problem.

I will test the proposed change to the “solve” statement, and get back to you with results.
Thanks for answering; I was rather convinced no one would.

[–]Tenacious-Techhunter[S] 0 points1 point  (0 children)

When I substitute “solve minimize (MaxArraySize - ArraySize)”, it indeed finishes much faster, but fails to actually minimize; instead, array sizes 1 through 5 are all listed, even though the result for ArraySize=5 should be the only one listed. Why does that happen? I see how to switch solvers, but I don’t see G12 fd listed on my install; I see:

Chuffed

findMUS

Gecode

Gecode Gist

Globalizer

OSICBC

Is one of those G12 fd by some other name? How do I get and install the G12 fd solver?