choco-solver
choco-solver copied to clipboard
FiniteAutomaton from regex can't use "."
FiniteAutomaton(".")
hangs indefinitely. Probably because .
means any character, and a FiniteAutomaton's alphabet is finite. Though I'd at least assume something like this would be returned:
#<FiniteAutomaton initial state: 0
state 0 [reject]:
\u0000-\u9999 -> 1
state 1 [accept]:
>
Yes, that's a known problem.
The .
expresses that all letters from the alphabet are acceptable; in our case, all values from Character.MIN_VALUE
to Character.MAX_VALUE
.
Then, the automaton is populated and all valid transitions from all known states are built; in our case, there are 65536 states and all possible transitions are valid, that is, 4294967296 iterations to add (or not) a digit to the alphabet...
To avoid (temporarily) this, we added the following constructor:
/**
* ..
* @param min an overall minimum value for transitions
* @param max an overall maximum value for transitions
*/
public FiniteAutomaton(String regexp, int min, int max) {...}
A realistic patch would be to reimplement the REGULAR constraint on the basis of a more accurate library (we already have one in the pipes, but it is based on Java8 only).