choco-solver icon indicating copy to clipboard operation
choco-solver copied to clipboard

"regular" constraint doesn't accept empty array

Open aengelberg opened this issue 10 years ago • 1 comments

ICF.regular() throws when I pass it an empty IntVar array:

ArrayIndexOutOfBoundsException 0  org.chocosolver.solver.constraints.Propagator.<init> (Propagator.java:140)

I assumed that if I passed in an empty array, the constraint would succeed if and only if the automaton accepts the empty string. Is that not a desired feature in Choco or is this a bug?

aengelberg avatar Oct 10 '15 19:10 aengelberg

First, posting a constraint without variable is either always true (and does not help the resolution) or false (and there is trivially no solution). So, we consider that posting a constraint without variable is not an expected behavior since the goal is to find a solution, that is, a state wherein all variables are instantiated and all constraints are satisfied.

Technically, the main reason is that every propagator needs to know the Solver and most of the time, it is reached through on of its variables. There is a check in the Propagator's constructor , based on assertion:

assert vars != null && vars.length > 0 && vars[0] != null : "wrong variable set in propagator constructor";

Note that TRUE and FALSE also require a variable (solver.ONE or solver.ZERO. So, all APIs in IntConstraintFactory always require at least one variable.

I can consider either promoting the assertion to SolverException (which would be the easy solution) or creating a kind of boolean constraint which would be lazily created on posting (a priori, a better solution, but instrumenting the library could be a tough task to do).

cprudhom avatar Oct 14 '15 08:10 cprudhom