Closed ekg closed 2 years ago
Would it make sense for only the order of application the production rules to be randomized? As in, at each rewrite step we sample a production rule and apply it to a random instance in the string.
Yes, that does make more sense, good call. If you want you can make the necessary changes and open a PR, otherwise I will implement this once I get the time.
Should be fixed by ee51519
Now we randomize the order of application by generating a random sequence of indices into the production vector at each iteration of the while loop in apply_productions
and also restart the process as soon as a match is found. That guarantees that 1) The productions are not applied in a "uniquely" random fashion; there is a chance that the same production is applied twice in a row and 2) That the program will eventually terminate once it fails to find a matching production. I'm not completely happy with this solution but it works.
There are still one potential issue with the approach used however, which is that the matching algorithm doesn't really select a random match, it just randomizes the direction of the search. It might be better to collect all matches into a vector and then select a match randomly from that.
EDIT: As of 433c81c2194f3c5a48992fddd24802529610ea35, the above is now implemented.
Would it make sense for only the order of application the production rules to be randomized? As in, at each rewrite step we sample a production rule and apply it to a random instance in the string.