diff --git a/CMakeLists.txt b/CMakeLists.txt index 21991db..6ebfd89 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,14 +18,12 @@ set(CMAKE_CXX_STANDARD 17) set(SOURCE_FILES src/regular/RegularTree.cpp src/regular/RegularTreeNode.cpp - src/NFA/NFATree.cpp + src/NFA/NFAGraph.cpp src/NFA/NFATreeVertex.cpp src/converters/RegularToNFA.cpp src/converters/NFAToDFA.cpp src/DFA/DFAGraph.cpp src/DFA/DFAGraphVertex.cpp - # src/FDFA/FDFAGraph.cpp - # src/FDFA/FDFAGraphVertex.cpp src/converters/DFAToFDFA.cpp src/converters/DFAToMinDFA.cpp src/converters/DFAToRegular.cpp diff --git a/include/FDFA/FDFAGraph.hpp b/include/FDFA/FDFAGraph.hpp deleted file mode 100644 index 591a50f..0000000 --- a/include/FDFA/FDFAGraph.hpp +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once -#include -#include -#include -#include - -namespace FDFA { -class FDFAGraph { - public: - class Vertex { - public: - Vertex(FDFAGraph* owner); - - bool IsFinal() const; - bool IsStart() const; - size_t GetNumber() const; - - const std::map& GetTransitions() const; - const std::map& GetBackTransitions() const; - - void AddEdge(char, size_t); - void RemoveEdge(char); - void SetOwner(FDFAGraph* owner); - void SetFinal(bool status); - void SetStart(bool status); - private: - FDFAGraph* owner_; - std::map transitions_; - std::map back_transitions_; - - size_t number_; - bool is_final_ = false; - bool is_start_ = false; - - friend class FDFAGraph; - }; - - FDFAGraph() = default; - FDFAGraph(const FDFAGraph&) = delete; - FDFAGraph(FDFAGraph&&) = default; - - FDFAGraph& operator=(const FDFAGraph&) = delete; - FDFAGraph& operator=(FDFAGraph&&) = default; - - size_t AddNewVertex(); - void AddFinalVertex(size_t number); - void AddStartVertex(size_t number); - - void RemoveVertex(size_t number); - void RemoveFinalVertex(size_t number); - void RemoveStartVertex(size_t number); - - std::shared_ptr GetVertex(size_t number); - - size_t GetCountVertexes() const; - const std::vector& GetFinalVertexes() const; - const std::vector& GetStartVertexes() const; - - void Print() const; - bool Accepted(const std::string&) const; - private: - size_t count_vertexes_ = 0; - std::map> vertexes_; - std::vector final_vertexes_; - std::vector start_vertexes_; -}; -} diff --git a/include/NFA/NFATree.hpp b/include/NFA/NFAGraph.hpp similarity index 81% rename from include/NFA/NFATree.hpp rename to include/NFA/NFAGraph.hpp index 02e0d56..abbabaf 100644 --- a/include/NFA/NFATree.hpp +++ b/include/NFA/NFAGraph.hpp @@ -6,11 +6,11 @@ #include namespace NFA { -class NFATree { +class NFAGraph { public: class Vertex { public: - Vertex(NFATree* owner); + Vertex(NFAGraph* owner); bool IsFinal() const; bool IsStart() const; @@ -21,11 +21,11 @@ class NFATree { void AddEdge(char, size_t); void RemoveEdge(char, size_t); - void SetOwner(NFATree* owner); + void SetOwner(NFAGraph* owner); void SetFinal(bool status); void SetStart(bool status); private: - NFATree* owner_; + NFAGraph* owner_; std::map> transitions_; std::map> back_transitions_; @@ -33,15 +33,15 @@ class NFATree { bool is_final_ = false; bool is_start_ = false; - friend class NFATree; + friend class NFAGraph; }; - NFATree() = default; - NFATree(const NFATree&) = delete; - NFATree(NFATree&&); + NFAGraph() = default; + NFAGraph(const NFAGraph&) = delete; + NFAGraph(NFAGraph&&); - NFATree& operator=(const NFATree&) = delete; - NFATree& operator=(NFATree&&); + NFAGraph& operator=(const NFAGraph&) = delete; + NFAGraph& operator=(NFAGraph&&); size_t AddNewVertex(); void AddFinalVertex(size_t number); @@ -51,7 +51,7 @@ class NFATree { void RemoveFinalVertex(size_t number); void RemoveStartVertex(size_t number); - void Composition(NFATree&&, + void Composition(NFAGraph&&, std::vector start_vertexes, std::vector final_vertexes); diff --git a/include/converters/DFAToFDFA.hpp b/include/converters/DFAToFDFA.hpp index bdf1eda..915d51c 100644 --- a/include/converters/DFAToFDFA.hpp +++ b/include/converters/DFAToFDFA.hpp @@ -1,10 +1,7 @@ #pragma once #include "DFA/DFAGraph.hpp" -#include "FDFA/FDFAGraph.hpp" namespace converters { using namespace DFA; -using namespace FDFA; DFAGraph DFAGraphToFDFAGraph(DFAGraph&&, const std::vector& alphabet); -// FDFAGraph DFAGraphToFDFAGraph(DFAGraph&&, const std::vector& alphabet); } diff --git a/include/converters/DFAToMinDFA.hpp b/include/converters/DFAToMinDFA.hpp index dd25402..9791c83 100644 --- a/include/converters/DFAToMinDFA.hpp +++ b/include/converters/DFAToMinDFA.hpp @@ -3,5 +3,5 @@ namespace converters { using namespace DFA; -DFAGraph DFAToMinDFA(DFAGraph&&); +DFAGraph DFAGraphToMinDFAGraph(DFAGraph&&); } diff --git a/include/converters/NFAToDFA.hpp b/include/converters/NFAToDFA.hpp index ecb0669..4dd51eb 100644 --- a/include/converters/NFAToDFA.hpp +++ b/include/converters/NFAToDFA.hpp @@ -1,13 +1,13 @@ #pragma once -#include "NFA/NFATree.hpp" +#include "NFA/NFAGraph.hpp" #include "DFA/DFAGraph.hpp" namespace converters { using namespace NFA; using namespace DFA; -NFATree AddAllEpsilonTransitions(NFATree&&); -NFATree AddAllPossibleStartFilnal(NFATree&&); -NFATree DeleteEpsilonTransitions(NFATree&&); -NFATree DeleteTransitionsByOneLetter(NFATree&&); -DFAGraph NFATreeToDFAGraph(NFATree&&); +NFAGraph AddAllEpsilonTransitions(NFAGraph&&); +NFAGraph AddAllPossibleStartFinal(NFAGraph&&); +NFAGraph DeleteEpsilonTransitions(NFAGraph&&); +NFAGraph DeleteTransitionsByOneLetter(NFAGraph&&); +DFAGraph NFAGraphToDFAGraph(NFAGraph&&); } diff --git a/include/converters/RegularToNFA.hpp b/include/converters/RegularToNFA.hpp index d4dd5f9..dce3ef0 100644 --- a/include/converters/RegularToNFA.hpp +++ b/include/converters/RegularToNFA.hpp @@ -1,10 +1,10 @@ #pragma once #include "regular/RegularTree.hpp" -#include "NFA/NFATree.hpp" +#include "NFA/NFAGraph.hpp" namespace converters { using namespace NFA; using namespace regular; -NFATree RegularToNFA(RegularTree&&); +NFAGraph RegularToNFAGraph(RegularTree&&); } diff --git a/include/regular/RegularTree.hpp b/include/regular/RegularTree.hpp index d6c031e..a564142 100644 --- a/include/regular/RegularTree.hpp +++ b/include/regular/RegularTree.hpp @@ -1,5 +1,4 @@ #pragma once -#include #include #include #include diff --git a/src/DFA/DFAGraphVertex.cpp b/src/DFA/DFAGraphVertex.cpp index a5d0f78..015ba92 100644 --- a/src/DFA/DFAGraphVertex.cpp +++ b/src/DFA/DFAGraphVertex.cpp @@ -1,5 +1,4 @@ #include "DFA/DFAGraph.hpp" -#include using Vertex = DFA::DFAGraph::Vertex; diff --git a/src/FDFA/FDFAGraph.cpp b/src/FDFA/FDFAGraph.cpp deleted file mode 100644 index 310bfec..0000000 --- a/src/FDFA/FDFAGraph.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include "FDFA/FDFAGraph.hpp" -#include -#include - -namespace FDFA { -size_t FDFAGraph::AddNewVertex() { - vertexes_[count_vertexes_] = std::make_shared(this); - vertexes_[count_vertexes_]->number_ = count_vertexes_; - return count_vertexes_++; -} - -void FDFAGraph::AddFinalVertex(size_t number) { - if (!vertexes_[number]->is_final_) { - vertexes_[number]->is_final_ = true; - final_vertexes_.push_back(number); - } -} - -void FDFAGraph::AddStartVertex(size_t number) { - if (!vertexes_[number]->is_start_) { - vertexes_[number]->is_start_ = true; - start_vertexes_.push_back(number); - } -} - -void FDFAGraph::RemoveVertex(size_t number) { - RemoveFinalVertex(number); - RemoveStartVertex(number); - vertexes_.erase(number); -} - -void FDFAGraph::RemoveFinalVertex(size_t number) { - for (size_t i = 0; i < final_vertexes_.size(); ++i) { - if (final_vertexes_[i] == number) { - vertexes_[number]->is_final_ = false; - std::swap(final_vertexes_[i], final_vertexes_.back()); - final_vertexes_.pop_back(); - break; - } - } -} - -void FDFAGraph::RemoveStartVertex(size_t number) { - for (size_t i = 0; i < start_vertexes_.size(); ++i) { - if (start_vertexes_[i] == number) { - vertexes_[number]->is_start_ = false; - std::swap(start_vertexes_[i], start_vertexes_.back()); - start_vertexes_.pop_back(); - break; - } - } -} - -std::shared_ptr FDFAGraph::GetVertex(size_t number) { - if (vertexes_.count(number)) - return vertexes_[number]; - return nullptr; -} - -size_t FDFAGraph::GetCountVertexes() const { - return count_vertexes_; -} - -const std::vector& FDFAGraph::GetFinalVertexes() const { - return final_vertexes_; -} - -const std::vector& FDFAGraph::GetStartVertexes() const { - return start_vertexes_; -} - -void FDFAGraph::Print() const { - for (auto i: vertexes_) { - std::cout << i.second->number_ << " " << "f-" << i.second->is_final_ << " s-" << - i.second->is_start_ << std::endl; - } - for (auto& i: vertexes_) { - for (auto& j: i.second->transitions_) { - std::cout << i.second->number_ << "->" << j.second << " <" << j.first << ">" << - std::endl; - } - } - std::cout << std::endl; -} - -bool FDFAGraph::Accepted(const std::string& str) const { - std::shared_ptr current = vertexes_.at(start_vertexes_[0]); - for (auto i: str) { - if (current->GetTransitions().count(i)) { - current = vertexes_.at(current->GetTransitions().at(i)); - } else { - return false; - } - } - return current->IsFinal(); -} -} - diff --git a/src/FDFA/FDFAGraphVertex.cpp b/src/FDFA/FDFAGraphVertex.cpp deleted file mode 100644 index 8304387..0000000 --- a/src/FDFA/FDFAGraphVertex.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "FDFA/FDFAGraph.hpp" -#include - -using Vertex = FDFA::FDFAGraph::Vertex; - -Vertex::Vertex(FDFAGraph* owner) : owner_(owner) {} - -bool Vertex::IsFinal() const { - return is_final_; -} - -bool Vertex::IsStart() const { - return is_start_; -} - -size_t Vertex::GetNumber() const { - return number_; -} - -const std::map& Vertex::GetTransitions() const { - return transitions_; -} - -const std::map& Vertex::GetBackTransitions() const { - return back_transitions_; -} - -void Vertex::AddEdge(char symbol, size_t number) { - transitions_[symbol] = number; - owner_->GetVertex(number)->back_transitions_[symbol] = number_; -} - -void Vertex::RemoveEdge(char symbol) { - owner_->GetVertex(transitions_[symbol])->back_transitions_.erase(symbol); - transitions_.erase(symbol); -} - -void Vertex::SetOwner(FDFAGraph* owner) { - owner_ = owner; -} - -void Vertex::SetFinal(bool status) { - if (status != is_final_) { - if (status) - owner_->AddFinalVertex(number_); - else - owner_->RemoveFinalVertex(number_); - } -} - -void Vertex::SetStart(bool status) { - if (status != is_start_) { - if (status) - owner_->AddStartVertex(number_); - else - owner_->RemoveStartVertex(number_); - } -} diff --git a/src/NFA/NFATree.cpp b/src/NFA/NFAGraph.cpp similarity index 82% rename from src/NFA/NFATree.cpp rename to src/NFA/NFAGraph.cpp index aa57d47..aefe35a 100644 --- a/src/NFA/NFATree.cpp +++ b/src/NFA/NFAGraph.cpp @@ -1,9 +1,9 @@ -#include "NFA/NFATree.hpp" +#include "NFA/NFAGraph.hpp" #include #include namespace NFA { -NFATree::NFATree(NFATree&& another) { +NFAGraph::NFAGraph(NFAGraph&& another) { std::swap(count_vertexes_, another.count_vertexes_); std::swap(vertexes_, another.vertexes_); std::swap(final_vertexes_, another.final_vertexes_); @@ -15,7 +15,7 @@ NFATree::NFATree(NFATree&& another) { i.second->owner_ = &another; } -NFATree& NFATree::operator=(NFATree&& another) { +NFAGraph& NFAGraph::operator=(NFAGraph&& another) { std::swap(count_vertexes_, another.count_vertexes_); std::swap(vertexes_, another.vertexes_); std::swap(final_vertexes_, another.final_vertexes_); @@ -28,33 +28,33 @@ NFATree& NFATree::operator=(NFATree&& another) { return *this; } -size_t NFATree::AddNewVertex() { +size_t NFAGraph::AddNewVertex() { vertexes_[count_vertexes_] = std::make_shared(this); vertexes_[count_vertexes_]->number_ = count_vertexes_; return count_vertexes_++; } -void NFATree::AddFinalVertex(size_t number) { +void NFAGraph::AddFinalVertex(size_t number) { if (!vertexes_[number]->is_final_) { vertexes_[number]->is_final_ = true; final_vertexes_.push_back(number); } } -void NFATree::AddStartVertex(size_t number) { +void NFAGraph::AddStartVertex(size_t number) { if (!vertexes_[number]->is_start_) { vertexes_[number]->is_start_ = true; start_vertexes_.push_back(number); } } -void NFATree::RemoveVertex(size_t number) { +void NFAGraph::RemoveVertex(size_t number) { RemoveFinalVertex(number); RemoveStartVertex(number); vertexes_.erase(number); } -void NFATree::RemoveFinalVertex(size_t number) { +void NFAGraph::RemoveFinalVertex(size_t number) { for (size_t i = 0; i < final_vertexes_.size(); ++i) { if (final_vertexes_[i] == number) { vertexes_[number]->is_final_ = false; @@ -65,7 +65,7 @@ void NFATree::RemoveFinalVertex(size_t number) { } } -void NFATree::RemoveStartVertex(size_t number) { +void NFAGraph::RemoveStartVertex(size_t number) { for (size_t i = 0; i < start_vertexes_.size(); ++i) { if (start_vertexes_[i] == number) { vertexes_[number]->is_start_ = false; @@ -76,15 +76,15 @@ void NFATree::RemoveStartVertex(size_t number) { } } -void NFATree::Composition(NFATree&& tree, +void NFAGraph::Composition(NFAGraph&& nfa_graph, std::vector start_vertexes, std::vector final_vertexes) { - auto add_final_vertexes = tree.final_vertexes_; - auto add_start_vertexes = tree.start_vertexes_; + auto add_final_vertexes = nfa_graph.final_vertexes_; + auto add_start_vertexes = nfa_graph.start_vertexes_; size_t new_count_vertexes = count_vertexes_; - for (auto& i: tree.vertexes_) { + for (auto& i: nfa_graph.vertexes_) { new_count_vertexes = std::max(new_count_vertexes, i.first + count_vertexes_ + 1); i.second->number_ += count_vertexes_; std::map> new_transitions; @@ -135,25 +135,25 @@ void NFATree::Composition(NFATree&& tree, } } -std::shared_ptr NFATree::GetVertex(size_t number) { +std::shared_ptr NFAGraph::GetVertex(size_t number) { if (vertexes_.count(number)) return vertexes_[number]; return nullptr; } -size_t NFATree::GetCountVertexes() const { +size_t NFAGraph::GetCountVertexes() const { return count_vertexes_; } -const std::vector& NFATree::GetFinalVertexes() const { +const std::vector& NFAGraph::GetFinalVertexes() const { return final_vertexes_; } -const std::vector& NFATree::GetStartVertexes() const { +const std::vector& NFAGraph::GetStartVertexes() const { return start_vertexes_; } -void NFATree::Print() const { +void NFAGraph::Print() const { for (auto i: vertexes_) { std::cout << i.second->number_ << " " << "f-" << i.second->is_final_ << " s-" << i.second->is_start_ << std::endl; diff --git a/src/NFA/NFATreeVertex.cpp b/src/NFA/NFATreeVertex.cpp index 4060d82..a887fae 100644 --- a/src/NFA/NFATreeVertex.cpp +++ b/src/NFA/NFATreeVertex.cpp @@ -1,9 +1,8 @@ -#include "NFA/NFATree.hpp" -#include +#include "NFA/NFAGraph.hpp" -using Vertex = NFA::NFATree::Vertex; +using Vertex = NFA::NFAGraph::Vertex; -Vertex::Vertex(NFATree* owner) : owner_(owner) {} +Vertex::Vertex(NFAGraph* owner) : owner_(owner) {} bool Vertex::IsFinal() const { return is_final_; @@ -40,7 +39,7 @@ void Vertex::RemoveEdge(char symbol, size_t number) { owner_->GetVertex(number)->back_transitions_.erase(symbol); } -void Vertex::SetOwner(NFATree* owner) { +void Vertex::SetOwner(NFAGraph* owner) { owner_ = owner; } diff --git a/src/converters/DFAToFDFA.cpp b/src/converters/DFAToFDFA.cpp index 9d6ec37..8120746 100644 --- a/src/converters/DFAToFDFA.cpp +++ b/src/converters/DFAToFDFA.cpp @@ -43,48 +43,4 @@ DFAGraph DFAGraphToFDFAGraph(DFAGraph&& graph, const std::vector& alphabet return result; } -/* -FDFAGraph DFAGraphToFDFAGraph(DFAGraph&& graph, const std::vector& alphabet) { - FDFAGraph result; - const int n = graph.GetCountVertexes(); - std::map number_vertex_in_DFA; - for (int i = 0; i < n; ++i) { - if (!graph.GetVertex(i)) continue; - number_vertex_in_DFA[i] = result.AddNewVertex(); - } - for (int i = 0; i < n; ++i) { - if (!graph.GetVertex(i)) continue; - if (graph.GetVertex(i)->IsFinal()) - result.GetVertex(number_vertex_in_DFA[i])->SetFinal(true); - if (graph.GetVertex(i)->IsStart()) - result.GetVertex(number_vertex_in_DFA[i])->SetStart(true); - - const auto& transitions = graph.GetVertex(i)->GetTransitions(); - for (const auto& t: transitions) { - result.GetVertex(number_vertex_in_DFA[i])->AddEdge(t.first, t.second); - } - } - - size_t drain = result.AddNewVertex(); - - for (int i = 0; i < n; ++i) { - const auto& transitions = graph.GetVertex(i)->GetTransitions(); - for (char j: alphabet) { - if (!transitions.count(j)) { - result.GetVertex(i)->AddEdge(j, drain); - } - } - } - - if (result.GetVertex(drain)->GetBackTransitions().size() == 0) { - result.RemoveVertex(drain); - } else { - for (char j: alphabet) { - result.GetVertex(drain)->AddEdge(j, drain); - } - } - - return result; -} -*/ } diff --git a/src/converters/DFAToMinDFA.cpp b/src/converters/DFAToMinDFA.cpp index 2cc349c..5912b6d 100644 --- a/src/converters/DFAToMinDFA.cpp +++ b/src/converters/DFAToMinDFA.cpp @@ -1,22 +1,20 @@ #include "converters/DFAToMinDFA.hpp" -#include -#include namespace converters { -DFAGraph DFAToMinDFA(DFAGraph&& graph) { +DFAGraph DFAGraphToMinDFAGraph(DFAGraph&& graph) { const int n = graph.GetCountVertexes(); DFAGraph result; std::vector alphabet; { - std::set salphabet; + std::set set_alphabet; for (int i = 0; i < n; ++i) { for (auto i: graph.GetVertex(i)->GetTransitions()) { - salphabet.insert(i.first); + set_alphabet.insert(i.first); } } - alphabet = std::vector(salphabet.begin(), salphabet.end()); + alphabet = std::vector(set_alphabet.begin(), set_alphabet.end()); } std::vector>> table(n, diff --git a/src/converters/DFAToRegular.cpp b/src/converters/DFAToRegular.cpp index c19834c..4a59507 100644 --- a/src/converters/DFAToRegular.cpp +++ b/src/converters/DFAToRegular.cpp @@ -1,6 +1,4 @@ #include "converters/DFAToRegular.hpp" -#include -#include namespace converters { std::string DFAGraphToRegular(DFAGraph&& graph) { diff --git a/src/converters/NFAToDFA.cpp b/src/converters/NFAToDFA.cpp index c2ac47c..29e2df6 100644 --- a/src/converters/NFAToDFA.cpp +++ b/src/converters/NFAToDFA.cpp @@ -1,135 +1,22 @@ #include "converters/NFAToDFA.hpp" #include -#include #include +#include namespace converters { -/* -OLD version - - -NFATree AddAllEpsilonTransitions(NFATree&& tree) { - // Algorithm from 2-sat - const int n = tree.GetCountVertexes(); - std::vector used(n, false); - std::vector component(n, -1); - std::vector order; - - std::function dfs_order = [&tree, &used, &order, &dfs_order](int v) -> void { - used[v] = true; - const auto& transitions = tree.GetVertex(v)->GetTransitions(); - if (transitions.count(' ')) { - const auto& s = transitions.at(' '); - for (auto i: s) { - if (!used[i]) { - dfs_order(i); - } - } - } - order.push_back(v); - }; - - std::function dfs_component = [&tree, &component, - &dfs_component](int v, int c) -> void { - component[v] = c; - const auto& transitions = tree.GetVertex(v)->GetBackTransitions(); - if (transitions.count(' ')) { - const auto& s = transitions.at(' '); - for (auto i: s) { - if (component[i] == -1) { - dfs_component(i, c); - } - } - } - }; - - for (int i = 0; i < n; ++i) { - if (!used[i] && tree.GetVertex(i)) { - dfs_order(i); - } - } - - int current_component = 0; - for (int i = 0; i < n; ++i) { - int v = order[n - i - 1]; - if (component[v] == -1 && tree.GetVertex(i)) { - dfs_component(v, current_component++); - } - } - - std::set> connectivity_components; - - used.assign(n, false); - std::vector> connectivity_from(current_component); - - std::function dfs_connectivity = [&tree, &component, - &used, &dfs_connectivity, &connectivity_from](int v) -> void { - used[v] = true; - const auto& transitions = tree.GetVertex(v)->GetTransitions(); - if (transitions.count(' ')) { - const auto& s = transitions.at(' '); - for (auto i: s) { - if (!used[i]) { - dfs_connectivity(i); - } - if (component[v] != component[i]) { - connectivity_from[component[v]].insert(connectivity_from[component[i]].begin(), - connectivity_from[component[i]].end()); - connectivity_from[component[v]].insert(component[i]); - } - } - } - }; - - for (int i = 0; i < n; ++i) { - if (!tree.GetVertex(i)) continue; - connectivity_components.emplace(component[i], component[i]); - if (!used[i]) { - dfs_connectivity(i); - } - for (int j: connectivity_from[component[i]]) { - std::cout << i << " " << j << std::endl; - connectivity_components.emplace(component[i], j); - } - } - - for (int i = 0; i < n; ++i) { - std::cout << component[i] << " "; - } - std::cout << std::endl; - for (int i: connectivity_from[1]) { - std::cout << i << " "; - } - std::cout << std::endl; - - - - for (int i = 0; i < n; ++i) { - for (int j = 0; j < n; ++j) { - if (i == j) continue; - if (connectivity_components.count(std::make_pair(component[i], component[j]))) { - tree.GetVertex(i)->AddEdge(' ', j); - } - } - } - - return std::move(tree); -} -*/ - -NFATree AddAllEpsilonTransitions(NFATree&& tree) { - const int n = tree.GetCountVertexes(); +NFAGraph AddAllEpsilonTransitions(NFAGraph&& nfa_graph) { + const int n = nfa_graph.GetCountVertexes(); std::vector used(n, false); - std::function dfs = [&tree, &used, &dfs](int u, int v) -> void { + std::function dfs = [&nfa_graph, &used, &dfs](int u, int v) -> void { used[v] = true; - const auto& transitions = tree.GetVertex(v)->GetTransitions(); + const auto& transitions = nfa_graph.GetVertex(v)->GetTransitions(); if (transitions.count(' ')) { const auto& s = transitions.at(' '); for (auto i: s) { if (!used[i]) { if (u != i) - tree.GetVertex(u)->AddEdge(' ', i); + nfa_graph.GetVertex(u)->AddEdge(' ', i); dfs(u, i); } } @@ -137,62 +24,62 @@ NFATree AddAllEpsilonTransitions(NFATree&& tree) { }; for (int i = 0; i < n; ++i) { - if (!tree.GetVertex(i)) continue; + if (!nfa_graph.GetVertex(i)) continue; used.assign(n, false); dfs(i, i); } - return std::move(tree); + return std::move(nfa_graph); } -NFATree AddAllPossibleStartFilnal(NFATree&& tree) { - if (tree.GetStartVertexes().size() != 1) { - size_t start_vertex = tree.AddNewVertex(); - for (auto v: tree.GetStartVertexes()) { - tree.GetVertex(start_vertex)->AddEdge(' ', v); +NFAGraph AddAllPossibleStartFinal(NFAGraph&& nfa_graph) { + if (nfa_graph.GetStartVertexes().size() != 1) { + size_t start_vertex = nfa_graph.AddNewVertex(); + for (auto v: nfa_graph.GetStartVertexes()) { + nfa_graph.GetVertex(start_vertex)->AddEdge(' ', v); } } - for (const auto& v: tree.GetFinalVertexes()) { - const auto& transitions = tree.GetVertex(v)->GetBackTransitions(); + for (const auto& v: nfa_graph.GetFinalVertexes()) { + const auto& transitions = nfa_graph.GetVertex(v)->GetBackTransitions(); if (transitions.count(' ')) { const auto& s = transitions.at(' '); for (auto i: s) { - tree.GetVertex(i)->SetFinal(true); + nfa_graph.GetVertex(i)->SetFinal(true); } } } - return std::move(tree); + return std::move(nfa_graph); } -NFATree DeleteEpsilonTransitions(NFATree&& tree) { - const int n = tree.GetCountVertexes(); +NFAGraph DeleteEpsilonTransitions(NFAGraph&& nfa_graph) { + const int n = nfa_graph.GetCountVertexes(); for (int v = 0; v < n; ++v) { - if (!tree.GetVertex(v)) continue; + if (!nfa_graph.GetVertex(v)) continue; - const auto& transitions = tree.GetVertex(v)->GetTransitions(); + const auto& transitions = nfa_graph.GetVertex(v)->GetTransitions(); if (transitions.count(' ')) { auto s = transitions.at(' '); for (auto u: s) { - for (auto& i: tree.GetVertex(u)->GetTransitions()) { + for (auto& i: nfa_graph.GetVertex(u)->GetTransitions()) { if (i.first == ' ') continue; for (auto t: i.second) { - tree.GetVertex(v)->AddEdge(i.first, t); + nfa_graph.GetVertex(v)->AddEdge(i.first, t); } } } for (auto u: s) { - tree.GetVertex(v)->RemoveEdge(' ', u); + nfa_graph.GetVertex(v)->RemoveEdge(' ', u); } } } - return std::move(tree); + return std::move(nfa_graph); } -NFATree DeleteTransitionsByOneLetter(NFATree&& tree) { - const int n = tree.GetCountVertexes(); +NFAGraph DeleteTransitionsByOneLetter(NFAGraph&& nfa_graph) { + const int n = nfa_graph.GetCountVertexes(); - NFATree result_tree; + NFAGraph result_tree; std::map, char>, std::set> transitions; std::map, size_t> number_vertex_in_result_tree; @@ -200,14 +87,14 @@ NFATree DeleteTransitionsByOneLetter(NFATree&& tree) { std::set alphabet; for (int i = 0; i < n; ++i) { - if (!tree.GetVertex(i)) continue; - for (const auto& j: tree.GetVertex(i)->GetTransitions()) { + if (!nfa_graph.GetVertex(i)) continue; + for (const auto& j: nfa_graph.GetVertex(i)->GetTransitions()) { if (j.second.size() > 0) alphabet.insert(j.first); } } - for (auto i: tree.GetStartVertexes()) { + for (auto i: nfa_graph.GetStartVertexes()) { queue.push({i}); number_vertex_in_result_tree[{i}] = result_tree.AddNewVertex(); } @@ -219,7 +106,7 @@ NFATree DeleteTransitionsByOneLetter(NFATree&& tree) { for (auto symbol: alphabet) { std::set result; for (auto v: current) { - const auto& transitions = tree.GetVertex(v)->GetTransitions(); + const auto& transitions = nfa_graph.GetVertex(v)->GetTransitions(); if (transitions.count(symbol)) { const auto& s = transitions.at(symbol); result.insert(s.begin(), s.end()); @@ -248,9 +135,9 @@ NFATree DeleteTransitionsByOneLetter(NFATree&& tree) { auto v = i.second; for (auto i: s) { - if (tree.GetVertex(i)->IsFinal()) + if (nfa_graph.GetVertex(i)->IsFinal()) result_tree.GetVertex(v)->SetFinal(true); - if (tree.GetVertex(i)->IsStart()) + if (nfa_graph.GetVertex(i)->IsStart()) result_tree.GetVertex(v)->SetStart(true); } } @@ -258,31 +145,25 @@ NFATree DeleteTransitionsByOneLetter(NFATree&& tree) { return result_tree; } -DFAGraph NFATreeToDFAGraph(NFATree&& tree) { - /* - tree = AddAllEpsilonTransitions(std::move(tree)); - tree = AddAllPossibleStartFilnal(std::move(tree)); - tree = DeleteEpsilonTransitions(std::move(tree)); - tree = DeleteTransitionsByOneLetter(std::move(tree)); - */ - tree = DeleteTransitionsByOneLetter(DeleteEpsilonTransitions(AddAllPossibleStartFilnal( - AddAllEpsilonTransitions(std::move(tree))))); +DFAGraph NFAGraphToDFAGraph(NFAGraph&& nfa_graph) { + nfa_graph = DeleteTransitionsByOneLetter(DeleteEpsilonTransitions(AddAllPossibleStartFinal( + AddAllEpsilonTransitions(std::move(nfa_graph))))); - const int n = tree.GetCountVertexes(); + const int n = nfa_graph.GetCountVertexes(); DFAGraph result; std::map number_vertex_in_DFA; for (int i = 0; i < n; ++i) { - if (!tree.GetVertex(i)) continue; + if (!nfa_graph.GetVertex(i)) continue; number_vertex_in_DFA[i] = result.AddNewVertex(); } for (int i = 0; i < n; ++i) { - if (!tree.GetVertex(i)) continue; - if (tree.GetVertex(i)->IsFinal()) + if (!nfa_graph.GetVertex(i)) continue; + if (nfa_graph.GetVertex(i)->IsFinal()) result.GetVertex(number_vertex_in_DFA[i])->SetFinal(true); - if (tree.GetVertex(i)->IsStart()) + if (nfa_graph.GetVertex(i)->IsStart()) result.GetVertex(number_vertex_in_DFA[i])->SetStart(true); - const auto& transitions = tree.GetVertex(i)->GetTransitions(); + const auto& transitions = nfa_graph.GetVertex(i)->GetTransitions(); for (const auto& t: transitions) { if (t.second.size() != 1) throw std::logic_error(""); result.GetVertex(number_vertex_in_DFA[i])->AddEdge(t.first, *t.second.begin()); diff --git a/src/converters/RegularToNFA.cpp b/src/converters/RegularToNFA.cpp index 54c59b2..c08b686 100644 --- a/src/converters/RegularToNFA.cpp +++ b/src/converters/RegularToNFA.cpp @@ -1,7 +1,6 @@ #include "converters/RegularToNFA.hpp" #include "regular/RegularTree.hpp" -#include "NFA/NFATree.hpp" -#include +#include "NFA/NFAGraph.hpp" using namespace NFA; using namespace regular; @@ -13,8 +12,8 @@ struct do_nothing_deleter{ }; template -NFATree RegularToNFA(std::unique_ptr node) { - NFATree result; +NFAGraph RegularToNFA(std::unique_ptr node) { + NFAGraph result; if (node->type == Node::Type::Word) { auto end = result.AddNewVertex(); auto start = end; @@ -80,7 +79,7 @@ NFATree RegularToNFA(std::unique_ptr node) { } namespace converters { -NFATree RegularToNFA(RegularTree&& tree) { +NFAGraph RegularToNFAGraph(RegularTree&& tree) { const Node& root = tree.GetNode(); return RegularToNFA(std::unique_ptr(&const_cast(tree.GetNode()))); diff --git a/src/main.cpp b/src/main.cpp index 0f1f819..1b71cd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,17 +16,17 @@ using namespace converters; int main() { { RegularTree r("a*"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); DFA_graph.Print(); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); DFA_graph.Print(); } @@ -36,16 +36,16 @@ int main() { { RegularTree r("a+"); r.Print(); - NFA::NFATree NFA_tree = converters::RegularToNFA(std::move(r)); + NFA::NFAGraph NFA_tree = converters::RegularToNFAGraph(std::move(r)); NFA_tree.Print(); - DFA::DFAGraph DFA_graph = converters::NFATreeToDFAGraph(std::move(NFA_tree)); + DFA::DFAGraph DFA_graph = converters::NFAGraphToDFAGraph(std::move(NFA_tree)); DFA_graph.Print(); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); DFA_graph.Print(); } return 0; - NFA::NFATree tree; + NFA::NFAGraph tree; const int N = 10; int a[N]; @@ -110,7 +110,7 @@ int main() { tree.GetVertex(a[3])->SetFinal(true); tree.GetVertex(a[4])->SetFinal(true); - DFA::DFAGraph res = converters::NFATreeToDFAGraph(std::move(tree)); + DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree)); // FDFA::FDFAGraph res2 = converters::DFAGraphToFDFAGraph(std::move(res), {'a', 'b'}); // res2.Print(); @@ -119,7 +119,7 @@ int main() { // res = converters::DFAGraphToFDFAGraph(std::move(res), {'a', 'b'}); - res = converters::DFAToMinDFA(std::move(res)); + res = converters::DFAGraphToMinDFAGraph(std::move(res)); res.Print(); @@ -163,7 +163,7 @@ int main() { RegularTree reg_tree(str); reg_tree.Print(); - auto NFA_tree = converters::RegularToNFA(std::move(reg_tree)); + auto NFA_tree = converters::RegularToNFAGraph(std::move(reg_tree)); std::cout << std::endl; diff --git a/tests/DFAToRegular/DFAToRegular.cpp b/tests/DFAToRegular/DFAToRegular.cpp index 01c465e..e46e99f 100644 --- a/tests/DFAToRegular/DFAToRegular.cpp +++ b/tests/DFAToRegular/DFAToRegular.cpp @@ -17,16 +17,16 @@ extern std::string GenerateRandomString(std::vector alphabet, size_t len); TEST(DFA_to_regular, a_star) { RegularTree r("a*"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string s = ""; @@ -40,16 +40,16 @@ TEST(DFA_to_regular, a_plus) { std::string regulars[] = {"a+", "(a)+", "(a+)"}; for (const auto& regular: regulars) { RegularTree r(regular); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string s = ""; ASSERT_EQ(DFA_graph.Accepted(s), false); @@ -65,16 +65,16 @@ TEST(DFA_to_regular, abc) { std::string regulars[] = {"abc"}; for (const auto& regular: regulars) { RegularTree r(regular); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); ASSERT_EQ(DFA_graph.Accepted("abc"), true); for (int i = 0; i < 1000; ++i) { @@ -89,16 +89,16 @@ TEST(DFA_to_regular, a_or_b_or_c) { std::string regulars[] = {}; for (const auto& regular: regulars) { RegularTree r("a|b|c"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); ASSERT_EQ(DFA_graph.Accepted("a"), true); ASSERT_EQ(DFA_graph.Accepted("b"), true); @@ -117,16 +117,16 @@ TEST(DFA_to_regular, a_star_or_b_star_or_c_star) { std::string regulars[] = {"a*|b*|c*", "(a*)|(b*|c*)", "(a*|b*|c*)", "((a*)|(b*)|(c*))"}; for (const auto& regular: regulars) { RegularTree r(regular); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); auto check = [](const std::string str) { std::set s(str.begin(), str.end()); @@ -151,16 +151,16 @@ TEST(DFA_to_regular, a_star_or_b_star_or_c_star) { TEST(DFA_to_regular, _a_star_or_b_star_or_c_star_plus) { RegularTree r("(a*|b*|c*)+"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); auto check = [](const std::string str) { std::set s(str.begin(), str.end()); @@ -177,16 +177,16 @@ TEST(DFA_to_regular, _a_star_or_b_star_or_c_star_plus) { TEST(DFA_to_regular, _a_or_b_or_c_star_plus) { RegularTree r("(a|b|c*)+"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string reg = DFAGraphToRegular(std::move(DFA_graph)); r = RegularTree(reg); - NFA_tree = RegularToNFA(std::move(r)); - DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFA_tree = RegularToNFAGraph(std::move(r)); + DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); auto check = [](const std::string str) { std::set s(str.begin(), str.end()); diff --git a/tests/NFAToDFA/check_equivalence.cpp b/tests/NFAToDFA/check_equivalence.cpp index 579632c..2594763 100644 --- a/tests/NFAToDFA/check_equivalence.cpp +++ b/tests/NFAToDFA/check_equivalence.cpp @@ -1,7 +1,7 @@ #include #include #include "DFA/DFAGraph.hpp" -#include "NFA/NFATree.hpp" +#include "NFA/NFAGraph.hpp" #include "converters/NFAToDFA.hpp" using namespace NFA; @@ -19,7 +19,7 @@ std::string GenerateRandomString(std::vector alphabet, size_t len) { } TEST(check_equivalence_NFA_to_DFA, 1) { - NFA::NFATree tree; + NFA::NFAGraph tree; const int N = 10; int a[N]; @@ -34,7 +34,7 @@ TEST(check_equivalence_NFA_to_DFA, 1) { tree.GetVertex(a[2])->SetFinal(true); tree.GetVertex(a[3])->SetFinal(true); - DFA::DFAGraph res = converters::NFATreeToDFAGraph(std::move(tree)); + DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree)); EXPECT_FALSE(res.Accepted("")); EXPECT_TRUE(res.Accepted("a")); @@ -46,7 +46,7 @@ TEST(check_equivalence_NFA_to_DFA, 1) { } TEST(check_equivalence_NFA_to_DFA, 2) { - NFA::NFATree tree; + NFA::NFAGraph tree; const int N = 10; int a[N]; @@ -62,7 +62,7 @@ TEST(check_equivalence_NFA_to_DFA, 2) { tree.GetVertex(a[1])->SetFinal(true); tree.GetVertex(a[2])->SetFinal(true); - DFA::DFAGraph res = converters::NFATreeToDFAGraph(std::move(tree)); + DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree)); auto check = [](const std::string& str) { if (str.size() > 0) { diff --git a/tests/regularToDFA/regularToDFA.cpp b/tests/regularToDFA/regularToDFA.cpp index 3d157a1..6087923 100644 --- a/tests/regularToDFA/regularToDFA.cpp +++ b/tests/regularToDFA/regularToDFA.cpp @@ -16,9 +16,9 @@ extern std::string GenerateRandomString(std::vector alphabet, size_t len); TEST(regular_to_DFA, a_star) { RegularTree r("a*"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string s = ""; for (int i = 0; i < 100; ++i) { @@ -31,9 +31,9 @@ TEST(regular_to_DFA, a_plus) { std::string regulars[] = {"a+", "(a)+", "(a+)"}; for (const auto& regular: regulars) { RegularTree r(regular); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); std::string s = ""; ASSERT_EQ(DFA_graph.Accepted(s), false); @@ -49,9 +49,9 @@ TEST(regular_to_DFA, abc) { std::string regulars[] = {"abc"}; for (const auto& regular: regulars) { RegularTree r(regular); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); ASSERT_EQ(DFA_graph.Accepted("abc"), true); for (int i = 0; i < 1000; ++i) { @@ -66,9 +66,9 @@ TEST(regular_to_DFA, a_or_b_or_c) { std::string regulars[] = {}; for (const auto& regular: regulars) { RegularTree r("a|b|c"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); ASSERT_EQ(DFA_graph.Accepted("a"), true); ASSERT_EQ(DFA_graph.Accepted("b"), true); @@ -87,9 +87,9 @@ TEST(regular_to_DFA, a_star_or_b_star_or_c_star) { std::string regulars[] = {"a*|b*|c*", "(a*)|(b*|c*)", "(a*|b*|c*)", "((a*)|(b*)|(c*))"}; for (const auto& regular: regulars) { RegularTree r(regular); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); auto check = [](const std::string str) { std::set s(str.begin(), str.end()); @@ -114,9 +114,9 @@ TEST(regular_to_DFA, a_star_or_b_star_or_c_star) { TEST(regular_to_DFA, _a_star_or_b_star_or_c_star_plus) { RegularTree r("(a*|b*|c*)+"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); auto check = [](const std::string str) { std::set s(str.begin(), str.end()); @@ -133,9 +133,9 @@ TEST(regular_to_DFA, _a_star_or_b_star_or_c_star_plus) { TEST(regular_to_DFA, _a_or_b_or_c_star_plus) { RegularTree r("(a|b|c*)+"); - NFATree NFA_tree = RegularToNFA(std::move(r)); - DFAGraph DFA_graph = NFATreeToDFAGraph(std::move(NFA_tree)); - DFA_graph = DFAToMinDFA(std::move(DFA_graph)); + NFAGraph NFA_tree = RegularToNFAGraph(std::move(r)); + DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_tree)); + DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph)); auto check = [](const std::string str) { std::set s(str.begin(), str.end());