From 250438ffc12d9e8113464fc066ac56779e8c46a0 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Thu, 29 May 2014 20:17:28 +0200 Subject: [PATCH] fix:set difference instead of symmetric difference --- alib2/src/automaton/FSM/CompactNFA.cpp | 2 +- alib2/src/automaton/FSM/ExtendedNFA.cpp | 2 +- alib2/src/automaton/PDA/PDA.cpp | 6 +++--- .../automaton/common/BlankSymbolInputTapeAlphabet.cpp | 8 ++++---- alib2/src/automaton/common/InputAlphabet.cpp | 4 ++-- alib2/src/automaton/common/MultiInitialStates.cpp | 4 ++-- alib2/src/automaton/common/States.cpp | 8 ++++---- alib2/src/regexp/RegExp.cpp | 11 ++++++----- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/alib2/src/automaton/FSM/CompactNFA.cpp b/alib2/src/automaton/FSM/CompactNFA.cpp index f3eac6a63a..f9fe803140 100644 --- a/alib2/src/automaton/FSM/CompactNFA.cpp +++ b/alib2/src/automaton/FSM/CompactNFA.cpp @@ -53,7 +53,7 @@ bool CompactNFA::addTransition(const State& from, const string::String& input, c throw AutomatonException("State \"" + from.getName() + "\" doesn't exist."); std::set<alphabet::Symbol> inputStringAlphabet; - std::set_symmetric_difference(inputAlphabet.begin(), inputAlphabet.end(), input.getAlphabet().begin(), input.getAlphabet().end(), std::inserter(inputStringAlphabet, inputStringAlphabet.end())); + std::set_difference(inputAlphabet.begin(), inputAlphabet.end(), input.getAlphabet().begin(), input.getAlphabet().end(), std::inserter(inputStringAlphabet, inputStringAlphabet.end())); if (inputStringAlphabet.size() != 0) throw AutomatonException("Input string is over different alphabet than automaton"); diff --git a/alib2/src/automaton/FSM/ExtendedNFA.cpp b/alib2/src/automaton/FSM/ExtendedNFA.cpp index d788fe1b97..315a312c12 100644 --- a/alib2/src/automaton/FSM/ExtendedNFA.cpp +++ b/alib2/src/automaton/FSM/ExtendedNFA.cpp @@ -53,7 +53,7 @@ bool ExtendedNFA::addTransition(const State& from, const regexp::RegExp& input, throw AutomatonException("State \"" + from.getName() + "\" doesn't exist."); std::set<alphabet::Symbol> inputRegExpAlphabet; - std::set_symmetric_difference(inputAlphabet.begin(), inputAlphabet.end(), input.getAlphabet().begin(), input.getAlphabet().end(), std::inserter(inputRegExpAlphabet, inputRegExpAlphabet.end())); + std::set_difference(inputAlphabet.begin(), inputAlphabet.end(), input.getAlphabet().begin(), input.getAlphabet().end(), std::inserter(inputRegExpAlphabet, inputRegExpAlphabet.end())); if (inputRegExpAlphabet.size() != 0) throw AutomatonException("Input string is over different alphabet than automaton"); diff --git a/alib2/src/automaton/PDA/PDA.cpp b/alib2/src/automaton/PDA/PDA.cpp index ec6ce1b45d..f7973688ee 100644 --- a/alib2/src/automaton/PDA/PDA.cpp +++ b/alib2/src/automaton/PDA/PDA.cpp @@ -56,10 +56,10 @@ bool PDA::addStackSymbol(const alphabet::Symbol& symbol) { void PDA::setStackSymbols(const std::set<alphabet::Symbol>& newSymbols) { std::set<alphabet::Symbol> removed; - std::set_symmetric_difference(stackAlphabet.begin(), stackAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); + std::set_difference(stackAlphabet.begin(), stackAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); std::set<alphabet::Symbol> added; - std::set_symmetric_difference(newSymbols.begin(), newSymbols.end(), stackAlphabet.begin(), stackAlphabet.end(), std::inserter(added, added.end())); + std::set_difference(newSymbols.begin(), newSymbols.end(), stackAlphabet.begin(), stackAlphabet.end(), std::inserter(added, added.end())); for(const alphabet::Symbol& removedSymbol : removed) { removeStackSymbol(removedSymbol); @@ -156,7 +156,7 @@ bool PDA::removeInitialSymbol(const alphabet::Symbol& start) { void PDA::setInitialSymbols(const std::set<alphabet::Symbol>& symbols) { std::set<alphabet::Symbol> tmp; - std::set_symmetric_difference(symbols.begin(), symbols.end(), this->stackAlphabet.begin(), this->stackAlphabet.end(), std::inserter(tmp, tmp.end())); + std::set_difference(symbols.begin(), symbols.end(), this->stackAlphabet.begin(), this->stackAlphabet.end(), std::inserter(tmp, tmp.end())); if(tmp.size() != 0) throw AutomatonException("Initial symbols not in stack alphabet"); diff --git a/alib2/src/automaton/common/BlankSymbolInputTapeAlphabet.cpp b/alib2/src/automaton/common/BlankSymbolInputTapeAlphabet.cpp index fc3aa67646..1a0028f2cb 100644 --- a/alib2/src/automaton/common/BlankSymbolInputTapeAlphabet.cpp +++ b/alib2/src/automaton/common/BlankSymbolInputTapeAlphabet.cpp @@ -34,10 +34,10 @@ bool BlankSymbolInputTapeAlphabet::addInputSymbol(const alphabet::Symbol& symbol void BlankSymbolInputTapeAlphabet::setInputSymbols(const std::set<alphabet::Symbol>& newSymbols) { std::set<alphabet::Symbol> removed; - std::set_symmetric_difference(inputAlphabet.begin(), inputAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); + std::set_difference(inputAlphabet.begin(), inputAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); std::set<alphabet::Symbol> added; - std::set_symmetric_difference(newSymbols.begin(), newSymbols.end(), inputAlphabet.begin(), inputAlphabet.end(), std::inserter(added, added.end())); + std::set_difference(newSymbols.begin(), newSymbols.end(), inputAlphabet.begin(), inputAlphabet.end(), std::inserter(added, added.end())); for(const alphabet::Symbol& removedSymbol : removed) { removeInputSymbol(removedSymbol); @@ -54,10 +54,10 @@ bool BlankSymbolInputTapeAlphabet::addTapeSymbol(const alphabet::Symbol& symbol) void BlankSymbolInputTapeAlphabet::setTapeSymbols(const std::set<alphabet::Symbol>& newSymbols) { std::set<alphabet::Symbol> removed; - std::set_symmetric_difference(tapeAlphabet.begin(), tapeAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); + std::set_difference(tapeAlphabet.begin(), tapeAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); std::set<alphabet::Symbol> added; - std::set_symmetric_difference(newSymbols.begin(), newSymbols.end(), tapeAlphabet.begin(), tapeAlphabet.end(), std::inserter(added, added.end())); + std::set_difference(newSymbols.begin(), newSymbols.end(), tapeAlphabet.begin(), tapeAlphabet.end(), std::inserter(added, added.end())); for(const alphabet::Symbol& removedSymbol : removed) { removeTapeSymbol(removedSymbol); diff --git a/alib2/src/automaton/common/InputAlphabet.cpp b/alib2/src/automaton/common/InputAlphabet.cpp index 34039f62cc..41f4f8fb0e 100644 --- a/alib2/src/automaton/common/InputAlphabet.cpp +++ b/alib2/src/automaton/common/InputAlphabet.cpp @@ -22,10 +22,10 @@ bool InputAlphabet::addInputSymbol(const alphabet::Symbol& symbol) { void InputAlphabet::setInputSymbols(const std::set<alphabet::Symbol>& newSymbols) { std::set<alphabet::Symbol> removed; - std::set_symmetric_difference(inputAlphabet.begin(), inputAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); + std::set_difference(inputAlphabet.begin(), inputAlphabet.end(), newSymbols.begin(), newSymbols.end(), std::inserter(removed, removed.end())); std::set<alphabet::Symbol> added; - std::set_symmetric_difference(newSymbols.begin(), newSymbols.end(), inputAlphabet.begin(), inputAlphabet.end(), std::inserter(added, added.end())); + std::set_difference(newSymbols.begin(), newSymbols.end(), inputAlphabet.begin(), inputAlphabet.end(), std::inserter(added, added.end())); for(const alphabet::Symbol& removedSymbol : removed) { removeInputSymbol(removedSymbol); diff --git a/alib2/src/automaton/common/MultiInitialStates.cpp b/alib2/src/automaton/common/MultiInitialStates.cpp index aa8aa2287f..53a6f2a366 100644 --- a/alib2/src/automaton/common/MultiInitialStates.cpp +++ b/alib2/src/automaton/common/MultiInitialStates.cpp @@ -23,10 +23,10 @@ bool MultiInitialStates::addInitialState(const State& state) { void MultiInitialStates::setInitialStates(const std::set<State>& newStates) { std::set<State> removed; - std::set_symmetric_difference(initialStates.begin(), initialStates.end(), newStates.begin(), newStates.end(), std::inserter(removed, removed.end())); + std::set_difference(initialStates.begin(), initialStates.end(), newStates.begin(), newStates.end(), std::inserter(removed, removed.end())); std::set<State> added; - std::set_symmetric_difference(newStates.begin(), newStates.end(), initialStates.begin(), initialStates.end(), std::inserter(added, added.end())); + std::set_difference(newStates.begin(), newStates.end(), initialStates.begin(), initialStates.end(), std::inserter(added, added.end())); for(const State& removedState : removed) { removeInitialState(removedState); diff --git a/alib2/src/automaton/common/States.cpp b/alib2/src/automaton/common/States.cpp index e5b2fcdbfe..2e007bbc4c 100644 --- a/alib2/src/automaton/common/States.cpp +++ b/alib2/src/automaton/common/States.cpp @@ -23,10 +23,10 @@ bool States::addState(const State& state) { void States::setStates(const std::set<State>& newStates) { std::set<State> removed; - std::set_symmetric_difference(states.begin(), states.end(), newStates.begin(), newStates.end(), std::inserter(removed, removed.end())); + std::set_difference(states.begin(), states.end(), newStates.begin(), newStates.end(), std::inserter(removed, removed.end())); std::set<State> added; - std::set_symmetric_difference(newStates.begin(), newStates.end(), states.begin(), states.end(), std::inserter(added, added.end())); + std::set_difference(newStates.begin(), newStates.end(), states.begin(), states.end(), std::inserter(added, added.end())); for(const State& removedState : removed) { removeState(removedState); @@ -51,10 +51,10 @@ bool States::addFinalState(const State& state) { void States::setFinalStates(const std::set<State>& newFinalStates) { std::set<State> removed; - std::set_symmetric_difference(finalStates.begin(), finalStates.end(), newFinalStates.begin(), newFinalStates.end(), std::inserter(removed, removed.end())); + std::set_difference(finalStates.begin(), finalStates.end(), newFinalStates.begin(), newFinalStates.end(), std::inserter(removed, removed.end())); std::set<State> added; - std::set_symmetric_difference(newFinalStates.begin(), newFinalStates.end(), finalStates.begin(), finalStates.end(), std::inserter(added, added.end())); + std::set_difference(newFinalStates.begin(), newFinalStates.end(), finalStates.begin(), finalStates.end(), std::inserter(added, added.end())); for(const State& removedState : removed) { removeFinalState(removedState); diff --git a/alib2/src/regexp/RegExp.cpp b/alib2/src/regexp/RegExp.cpp index 076fb86b4e..7f10b79b73 100644 --- a/alib2/src/regexp/RegExp.cpp +++ b/alib2/src/regexp/RegExp.cpp @@ -105,13 +105,14 @@ void RegExp::addSymbolToAlphabet(const alphabet::Symbol & symbol) { } void RegExp::setAlphabet(const std::set<alphabet::Symbol> & symbols) { + std::set<alphabet::Symbol> minimalAlphabet; + this->regExp->computeMinimalAlphabet(minimalAlphabet); std::set<alphabet::Symbol> removedSymbols; - std::set_symmetric_difference(this->alphabet.begin(), this->alphabet.end(), symbols.begin(), symbols.end(), std::inserter(removedSymbols, removedSymbols.end())); + std::set_difference(minimalAlphabet.begin(), minimalAlphabet.end(), symbols.begin(), symbols.end(), std::inserter(removedSymbols, removedSymbols.end())); + + if(removedSymbols.size() > 0) + throw alib::AlibException("Input symbols are used."); - for(const alphabet::Symbol& symbol : removedSymbols) { - if(this->regExp->testSymbol(symbol)) - throw alib::AlibException("Input symbol \"" + (std::string) symbol + "\" is used."); - } this->alphabet = symbols; } -- GitLab