diff --git a/alib2/src/automaton/FSM/CompactNFA.cpp b/alib2/src/automaton/FSM/CompactNFA.cpp index f3eac6a63a58032f93761610a4d99c3760a4fa1a..f9fe803140a222fc2a3aebd90be274497890a8dc 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 d788fe1b97a68c7584c86ca37bb923e9ce98e483..315a312c1229f5fe14e018e4b8671fe060ad2446 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 ec6ce1b45dacd0c1124a4d5057f43491c477a18c..f7973688ee247c5c277326ad79dd3a6b8a35821f 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 fc3aa67646713bf206d6218e8fc9b5a6b763da31..1a0028f2cb01300882368306ad950caface82688 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 34039f62cce5056e307deb0e3b72a11bc802f9f7..41f4f8fb0e2a48079d9132de70fd1067fe0ee8bf 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 aa8aa2287f428cb3cd4547858440a34dda6ee8c1..53a6f2a3667c57b4d07f986b625bb6d5763551a3 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 e5b2fcdbfe3798621670c8ad941b597123368dea..2e007bbc4c4daa7ee8b4088d33c05163385095c2 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 076fb86b4e4c8024d9ae6b9b306d4fa1d87c80a6..7f10b79b735cfd7e68644e798a2a77614235aa29 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; }