-
Notifications
You must be signed in to change notification settings - Fork 21
Minimization #476
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
base: devel
Are you sure you want to change the base?
Minimization #476
Changes from all commits
341f0d6
0c35b01
52222c3
fa8f618
8f8b3cf
f84c984
714ab67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -927,27 +927,54 @@ Nfa mata::nfa::algorithms::minimize_brzozowski(const Nfa& aut) { | |
| return determinize(revert(determinize(revert(aut)))); | ||
| } | ||
|
|
||
| Nfa mata::nfa::minimize( | ||
| const Nfa& aut, | ||
| const ParameterMap& params) | ||
| { | ||
| Nfa result; | ||
| // setting the default algorithm | ||
| decltype(algorithms::minimize_brzozowski)* algo = algorithms::minimize_brzozowski; | ||
| Nfa mata::nfa::make_minimal_dfa(const Nfa& nfa, const ParameterMap& params) { | ||
| if (!haskey(params, "algorithm")) { | ||
| throw std::runtime_error(std::to_string(__func__) + | ||
| " requires setting the \"algorithm\" key in the \"params\" argument; " | ||
| "received: " + std::to_string(params)); | ||
| } | ||
|
|
||
| // Setting the algorithm. Default is Brzozowski. | ||
| const std::string& str_algo = params.at("algorithm"); | ||
| if ("brzozowski" == str_algo) { /* default */ } | ||
| decltype(algorithms::minimize_brzozowski)* algo = algorithms::minimize_brzozowski; | ||
| if (str_algo == "brzozowski") { /* default */ } | ||
| else { | ||
| throw std::runtime_error(std::string(__func__) + | ||
| " received an unknown value for the \"algorithm\" key: " + str_algo); | ||
| } | ||
|
|
||
| return algo(nfa); | ||
| } | ||
|
|
||
| Nfa mata::nfa::minimize(const Nfa &dfa, const ParameterMap& params) | ||
| { | ||
| if (!haskey(params, "algorithm")) { | ||
| throw std::runtime_error(std::to_string(__func__) + | ||
| " received an unknown value of the \"algorithm\" key: " + str_algo); | ||
| " requires setting the \"algorithm\" key in the \"params\" argument; " | ||
| "received: " + std::to_string(params)); | ||
| } | ||
|
|
||
| return algo(aut); | ||
| // Setting the algorithm. Default is Hopcroft. | ||
| const std::string& str_algo = params.at("algorithm"); | ||
| decltype(algorithms::minimize_hopcroft)* algo = algorithms::minimize_hopcroft; | ||
| if (str_algo == "hopcroft") { | ||
| /* default */; | ||
| } else if (str_algo == "brzozowski") { | ||
| algo = algorithms::minimize_brzozowski; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this should be named
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But this will break the naming convention for minimizazion algorithms.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but Brzozowski does not perform minimization as per the definition given by Lukáš. But this is debatable. What does @jurajsic think?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know, but I realized that this change, that minimize now HAVE to take DFA, might break noodler (and anyone using mata, if such people exists), because before it was assumed it takes nfa and calls brzozowski. |
||
| } else { | ||
| throw std::runtime_error(std::string(__func__) + | ||
| " received an unknown value for the \"algorithm\" key: " + str_algo); | ||
| } | ||
|
|
||
| // Hopcroft algorithm does not work with non-trimmed automata. | ||
| if (str_algo == "hopcroft") { | ||
| const BoolVector is_used = dfa.get_useful_states(); | ||
| bool is_trimmed = std::all_of(is_used.begin(), is_used.end(), [](bool b) { return b; }); | ||
| if (!is_trimmed) { | ||
| return algo(Nfa(dfa).trim()); | ||
| } | ||
| } | ||
| return algo(dfa); | ||
| } | ||
|
|
||
| // Anonymous namespace for the Hopcroft minimization algorithm. | ||
|
|
@@ -1295,7 +1322,7 @@ Nfa mata::nfa::algorithms::minimize_hopcroft(const Nfa& dfa_trimmed) { | |
| for (const SymbolPost &symbol_post : dfa_trimmed.delta[q]) { | ||
| assert(symbol_post.targets.size() == 1); | ||
| const State target = brp.set_idx[*symbol_post.targets.begin()]; | ||
| mut_state_post.push_back(SymbolPost{ symbol_post.symbol, StateSet{ target } }); | ||
| mut_state_post.emplace_back(SymbolPost{ symbol_post.symbol, StateSet{ target } }); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.