ztellman / automat

better automata through combinators
588 stars 50 forks source link

infinite loop with "or" #40

Closed huahaiy closed 7 years ago

huahaiy commented 8 years ago

The or function in core may run into infinite loop at the minimization step. In particular, when it happens, the infinite loop will appear in the root function in the merge-pairs function. The occurrence of the infinite loop seems to be random, however, it will always appear if one runs or enough times.

To reproduce, run the following code:

(dotimes [i 100]
   (println (str "No." i))
   (a/or 1 2 3 4))

It may take a couple of runs of the above to generate an infinite loop. The process will have to be killed to stop it.

If we only or two states together, this bug doesn't appear.

huahaiy commented 8 years ago

Apparently, calling (fsm/reset-generation) between calls solve the problem.

huahaiy commented 8 years ago

There are still infinite loop issues with certain construction. For example, the following still leads to infinite loop:

(dotimes [i 10]
  (println i)
  (apply a/or [[1 2 4 (a/or 5 6 7 8)] [1 (a/or 5 6 7 8) 10]])
  (fsm/reset-generations))

Namely, if we or together automatons containing identical nested or of more than 3 items, an infinite loop appears.

huahaiy commented 7 years ago

This is now fixed. Thanks.