Fix some bugs
This commit is contained in:
parent
1aed271643
commit
40b634b722
|
@ -131,7 +131,7 @@ void DFAGraph::CreateDotFile(const std::string& filename) const {
|
||||||
|
|
||||||
for (auto& i: vertexes_) {
|
for (auto& i: vertexes_) {
|
||||||
for (auto& j: i.second.transitions_) {
|
for (auto& j: i.second.transitions_) {
|
||||||
out << i.first << "." << j.second << "[label=" << j.first << "]\n";
|
out << i.first << "->" << j.second << "[label=" << j.first << "]\n";
|
||||||
}
|
}
|
||||||
if (i.second.IsStart() && i.second.IsFinal()) {
|
if (i.second.IsStart() && i.second.IsFinal()) {
|
||||||
out << " " << i.first << " [shape=star];\n";
|
out << " " << i.first << " [shape=star];\n";
|
||||||
|
|
|
@ -66,6 +66,7 @@ DFAGraph DFAGraphToMinDFAGraph(DFAGraph&& graph) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
for (int k = 0; k < n; ++k) {
|
for (int k = 0; k < n; ++k) {
|
||||||
for (int j = 0; j < alphabet.size() + 1; ++j) {
|
for (int j = 0; j < alphabet.size() + 1; ++j) {
|
||||||
|
@ -75,6 +76,7 @@ DFAGraph DFAGraphToMinDFAGraph(DFAGraph&& graph) {
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
std::vector<std::vector<size_t>>& last_layer(table.back());
|
std::vector<std::vector<size_t>>& last_layer(table.back());
|
||||||
size_t count_vertex = 0;
|
size_t count_vertex = 0;
|
||||||
|
|
|
@ -5,7 +5,7 @@ DFAGraph InvertFDFAGraph(DFAGraph&& fdfa_graph) {
|
||||||
const size_t n = fdfa_graph.GetCountVertexes();
|
const size_t n = fdfa_graph.GetCountVertexes();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
if (fdfa_graph.NotExistVertex(i)) continue;
|
if (fdfa_graph.NotExistVertex(i)) continue;
|
||||||
fdfa_graph.GetVertex(i).SetFinal(fdfa_graph.GetVertex(i).IsFinal());
|
fdfa_graph.GetVertex(i).SetFinal(!fdfa_graph.GetVertex(i).IsFinal());
|
||||||
}
|
}
|
||||||
return std::move(fdfa_graph);
|
return std::move(fdfa_graph);
|
||||||
}
|
}
|
||||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -50,7 +50,20 @@ void example2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
{
|
||||||
|
RegularTree r("a*");
|
||||||
|
NFAGraph NFA_graph = RegularToNFAGraph(std::move(r));
|
||||||
|
DFAGraph DFA_graph = NFAGraphToDFAGraph(std::move(NFA_graph));
|
||||||
|
DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph));
|
||||||
|
DFA_graph = DFAGraphToFDFAGraph(std::move(DFA_graph), {'a', 'b'});
|
||||||
|
DFA_graph.Print();
|
||||||
|
DFA_graph.CreateDotFile("1.dot");
|
||||||
|
DFA_graph = InvertFDFAGraph(std::move(DFA_graph));
|
||||||
|
DFA_graph.CreateDotFile("2.dot");
|
||||||
|
DFA_graph = DFAGraphToMinDFAGraph(std::move(DFA_graph));
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
{
|
{
|
||||||
RegularTree r("((ab|ba)*( |a|ba))");
|
RegularTree r("((ab|ba)*( |a|ba))");
|
||||||
NFAGraph NFA_tree = RegularToNFAGraph(std::move(r));
|
NFAGraph NFA_tree = RegularToNFAGraph(std::move(r));
|
||||||
|
|
|
@ -26,13 +26,13 @@ TEST(check_equivalence_NFA_to_DFA, 1) {
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
a[i] = tree.AddNewVertex();
|
a[i] = tree.AddNewVertex();
|
||||||
|
|
||||||
tree.GetVertex(a[0])->AddEdge('a', a[1]);
|
tree.GetVertex(a[0]).AddEdge('a', a[1]);
|
||||||
tree.GetVertex(a[1])->AddEdge('a', a[2]);
|
tree.GetVertex(a[1]).AddEdge('a', a[2]);
|
||||||
tree.GetVertex(a[0])->AddEdge('a', a[3]);
|
tree.GetVertex(a[0]).AddEdge('a', a[3]);
|
||||||
|
|
||||||
tree.GetVertex(a[0])->SetStart(true);
|
tree.GetVertex(a[0]).SetStart(true);
|
||||||
tree.GetVertex(a[2])->SetFinal(true);
|
tree.GetVertex(a[2]).SetFinal(true);
|
||||||
tree.GetVertex(a[3])->SetFinal(true);
|
tree.GetVertex(a[3]).SetFinal(true);
|
||||||
|
|
||||||
DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree));
|
DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree));
|
||||||
|
|
||||||
|
@ -53,14 +53,14 @@ TEST(check_equivalence_NFA_to_DFA, 2) {
|
||||||
for (int i = 0; i < N; ++i)
|
for (int i = 0; i < N; ++i)
|
||||||
a[i] = tree.AddNewVertex();
|
a[i] = tree.AddNewVertex();
|
||||||
|
|
||||||
tree.GetVertex(a[0])->AddEdge('a', a[1]);
|
tree.GetVertex(a[0]).AddEdge('a', a[1]);
|
||||||
tree.GetVertex(a[0])->AddEdge('a', a[2]);
|
tree.GetVertex(a[0]).AddEdge('a', a[2]);
|
||||||
tree.GetVertex(a[1])->AddEdge('b', a[1]);
|
tree.GetVertex(a[1]).AddEdge('b', a[1]);
|
||||||
tree.GetVertex(a[2])->AddEdge('c', a[2]);
|
tree.GetVertex(a[2]).AddEdge('c', a[2]);
|
||||||
|
|
||||||
tree.GetVertex(a[0])->SetStart(true);
|
tree.GetVertex(a[0]).SetStart(true);
|
||||||
tree.GetVertex(a[1])->SetFinal(true);
|
tree.GetVertex(a[1]).SetFinal(true);
|
||||||
tree.GetVertex(a[2])->SetFinal(true);
|
tree.GetVertex(a[2]).SetFinal(true);
|
||||||
|
|
||||||
DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree));
|
DFA::DFAGraph res = converters::NFAGraphToDFAGraph(std::move(tree));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue