Skip to content

Commit

Permalink
Fix simulation reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
Adda0 committed Sep 11, 2023
1 parent f5fbdb0 commit d85d445
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
1 change: 1 addition & 0 deletions 3rdparty/simlib/include/mata/simlib/explicit_lts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace Simlib { class ExplicitLTS; }

class Simlib::ExplicitLTS {

std::unordered_map<size_t, size_t> symbol_map{};
size_t states_{};
size_t transitions_;
std::vector<
Expand Down
8 changes: 3 additions & 5 deletions 3rdparty/simlib/src/explicit_lts_sim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -903,11 +903,9 @@ BinaryRelation Simlib::ExplicitLTS::compute_simulation()
}


void Simlib::ExplicitLTS::add_transition(
size_t q,
size_t a,
size_t r)
{
void Simlib::ExplicitLTS::add_transition(size_t q, size_t a, size_t r) {
if (!symbol_map.contains(a)) { symbol_map[a] = symbol_map.size(); };
a = symbol_map[a];
if (a >= this->data_.size())
{
this->data_.resize(a + 1);
Expand Down
5 changes: 1 addition & 4 deletions src/nfa/operations.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,12 @@ 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 = 0;
Symbol maxSymbol{ aut.get_max_symbol() };
const size_t state_num = aut.size();
Simlib::ExplicitLTS LTSforSimulation(state_num);

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

// final states cannot be simulated by nonfinal -> we add new selfloops over final states with new symbol in LTS
Expand Down
39 changes: 39 additions & 0 deletions tests-integration/src/reduce_epsilon.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "utils/utils.hh"

#include "mata/nfa/nfa.hh"

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <chrono>
#include <string>
#include <cstring>

using namespace mata::nfa;

int main() {
Nfa b{10};
b.initial.insert(0);
b.final.insert({2, 4, 8, 7});
b.delta.add(0, 'b', 1);
b.delta.add(0, 'a', 2);
b.delta.add(2, 'a', 4);
b.delta.add(2, EPSILON, 3);
b.delta.add(3, 'b', 4);
b.delta.add(0, 'c', 5);
b.delta.add(5, 'a', 8);
b.delta.add(5, EPSILON, 6);
b.delta.add(6, 'a', 9);
b.delta.add(6, 'b', 7);

Nfa c;
TIME_BLOCK(reduce,
for (size_t i{ 0 }; i < 1'000; ++i) {
c = reduce(b);
}
);
if (!are_equivalent(b, c)) { // Check correctness.
return EXIT_FAILURE;
}
}

0 comments on commit d85d445

Please sign in to comment.