Skip to content

Commit

Permalink
compute unused symbol better for simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
jurajsic committed Jul 19, 2024
1 parent ea68dc0 commit 43b109b
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/nfa/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,36 @@ using StateBoolArray = std::vector<bool>; ///< Bool array for states in the auto

namespace {
Simlib::Util::BinaryRelation compute_fw_direct_simulation(const Nfa& aut) {
Symbol maxSymbol{ aut.delta.get_max_symbol() };
OrdVector<mata::Symbol> used_symbols = aut.delta.get_used_symbols();
mata::Symbol unused_symbol = 0;
if (!used_symbols.empty() && *used_symbols.begin() == 0) {
auto it = used_symbols.begin();
unused_symbol = *it + 1;
++it;
const auto used_symbols_end = used_symbols.end();
while (it != used_symbols_end && unused_symbol == *it) {
unused_symbol = *it + 1;
++it;
}
if (unused_symbol == 0) { // sanity check to see if we did not use the full range of mata::Symbol
throw std::runtime_error("all symbols are used, we cannot compute simluation reduction");
}
}

const size_t state_num{ aut.num_of_states() };
Simlib::ExplicitLTS LTSforSimulation(state_num);
Simlib::ExplicitLTS lts_for_simulation(state_num);

for (const Transition& transition : aut.delta.transitions()) {
LTSforSimulation.add_transition(transition.source, transition.symbol, transition.target);
lts_for_simulation.add_transition(transition.source, transition.symbol, transition.target);
}

// final states cannot be simulated by nonfinal -> we add new selfloops over final states with new symbol in LTS
for (State finalState : aut.final) {
LTSforSimulation.add_transition(finalState, maxSymbol + 1, finalState);
for (State final_state : aut.final) {
lts_for_simulation.add_transition(final_state, unused_symbol, final_state);
}

LTSforSimulation.init();
return LTSforSimulation.compute_simulation();
lts_for_simulation.init();
return lts_for_simulation.compute_simulation();
}

Nfa reduce_size_by_simulation(const Nfa& aut, StateRenaming &state_renaming) {
Expand Down

0 comments on commit 43b109b

Please sign in to comment.