-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get arbitrary word using DFS #413
Conversation
src/nfa/operations.cc
Outdated
result.insert(new_word); | ||
} | ||
} | ||
if (move.symbol < first_epsilon) { new_word.push_back(move.symbol); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curr_length
is not correctly updated with epsilon transitions. So it should be updated here I think.
But then, you cannot have epsilon loops, otherwise this procedure will never finish.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current length (and the maximal length) here was (and still is) implemented as the number of transitions made, not the length of the words (which it should be, as per the function description). That is OK until you start working with epsilons.
We could, for example, remove epsilon transitions to solve this issue (or simply start the removal by checking that the computation of epsilon closure for a given state does not try to add the same state twice, otherwise perform the actual removal).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will require a larger refactorization of the epsilon removal function and the function to get words of a specific length. Therefore, I will remove these changes from this PR and rework this in another PR. The only changes kept in this PR are the changes introducing get_word()
which works correctly even with epsilons.
src/nfa/operations.cc
Outdated
result.insert(mata::Word()); | ||
} | ||
worklist.emplace_back(init_state, Word{}); | ||
if (final.contains(init_state)) { result.insert(Word{}); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for putting this on one line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is not. Just that it is shorter. A matter of taste change (caused by the fact that I earlier modified the body of the condition and later removed the added code again).
Since the addition of the new method was approved, I will merge the trimmed PR. |
This PR adds a method to get an arbitrary word accepted by an NFA using DFS. Since we are using a bit vector of searched states, the NFA does not need to be trimmed to prevent cycling in DFS.
This PR resolves #411.