Skip to content

Commit

Permalink
ndfa to text
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacioDias committed Apr 8, 2024
1 parent 4966a2f commit 9f274eb
Show file tree
Hide file tree
Showing 38 changed files with 1,112 additions and 6,934 deletions.
8 changes: 8 additions & 0 deletions TP/automata/dfa/DeterministicFiniteAutomata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ DeterministicFiniteAutomata::DeterministicFiniteAutomata() : K(), E(), d(), q0()
void DeterministicFiniteAutomata::setE(set<int> alphabet) {
this->E = alphabet;
}
set<int> DeterministicFiniteAutomata::getE() {
return this->E;
}

void DeterministicFiniteAutomata :: setK(set<set<int>> states) {
this->K = states;
}
set<set<int>> DeterministicFiniteAutomata :: getK() {
return this->K;
}
void DeterministicFiniteAutomata :: setInitialState(set<int> q) {
this->q0 = q;
}
Expand Down Expand Up @@ -68,3 +74,5 @@ bool DeterministicFiniteAutomata :: isFinalNode(const set<int>& node) {
return false;
}



2 changes: 2 additions & 0 deletions TP/automata/dfa/DeterministicFiniteAutomata.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class DeterministicFiniteAutomata {
DeterministicFiniteAutomata();
void setE(set<int> alphabet);
void setK(set<set<int>> states);
set<set<int>> getK();
set<int> getE();
void setInitialState(set<int> q);
void setF(set<set<int>> final);
set<int> calculateDelta(const pair<set<int>,int>& key);
Expand Down
11 changes: 11 additions & 0 deletions TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ void NotDeterministicFiniteAutomata :: calculateNewK(set<set<int>> newK, Determi
unvisitedNodes.erase(currentNode);
}
}
set<int> NotDeterministicFiniteAutomata :: calculateWaysToGo(int from, int destination) {
set<int> ret;
for(int letter : this->E) {
pair<int,int> pair;
pair.first = from;
pair.second = letter;
if(!calculateDelta(pair).empty())
ret.insert(letter);
}
return ret;
}

set<set<int>> NotDeterministicFiniteAutomata :: calculateFinal(set<set<int>> k) {
set<set<int>> newF;
Expand Down
2 changes: 2 additions & 0 deletions TP/automata/ndfa/NotDeterministicFiniteAutomata.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class NotDeterministicFiniteAutomata : public AutomataInterface {
set<int> calculateDelta(pair<int,int> key);
bool repOk();
DeterministicFiniteAutomata nfaToDfa();
set<int> calculateWaysToGo(int from, int destination);

private:
set<int> getSymbolClosure(const set<int> Q, int symbol);
set<int> move(const set<int>& Q, int a);
Expand Down
26 changes: 25 additions & 1 deletion TP/parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,33 @@ void Parser::fileManagement(const string& line) {
} else if(!isRankdirLine(line) || line == "}" && readLastLine)
throw runtime_error("Formato invalido del archivo.");
}
string Parser::dnaToFile(DeterministicFiniteAutomata dfa) {
string Parser::ndnaToFile(NotDeterministicFiniteAutomata ndfa) {
string ret = "digraph{"
"inic[shape=point];"
"inic->";
ret += to_string(ndfa.getInitialState()) + ";\n";
toStringSates(ndfa, ret);
toStringFinalState(ndfa, ret);
ret += "}";
return ret;
}
void Parser::toStringSates(NotDeterministicFiniteAutomata ndfa, string ret) {
for(int number : ndfa.getK()) {
for(int number2 : ndfa.getK()) {
set<int> label = ndfa.calculateWaysToGo(number,number2);q3->q3 [label="a,b"];
if(!label.empty()) {
ret += to_string(number) + "->" + to_string(number2) + "label[=\"";
for(auto elem : label) {
ret += to_string(elem) + ",";
}
ret.pop_back();
ret += "\"];";
}
}
}
}
void Parser :: toStringFinalState(NotDeterministicFiniteAutomata ndfa, string ret) {
for(int finalState : ndfa.getF())
ret += to_string(finalState) + "[shape=doublecircle];\n";
ret.pop_back();
}
4 changes: 3 additions & 1 deletion TP/parser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ class Parser {
static bool validateTransitionLine(const string& line);
static bool validateFinalStateLine(const string& line);
bool isRankdirLine(const string& line);
string dnaToFile(DeterministicFiniteAutomata dfa);
string ndnaToFile(NotDeterministicFiniteAutomata ndfa);

private:
static bool checkDelta(const string& line);
NotDeterministicFiniteAutomata nda;
bool readLastLine;
void toStringSates(NotDeterministicFiniteAutomata ndfa, string ret);
void toStringFinalState(NotDeterministicFiniteAutomata ndfa, string ret);

};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}
],
"type" : "INTERNAL",
"value" : "/home/ignaciodias/Desktop/Uni/Automatas/automataTPO1/cmake-build-debug"
"value" : "/home/ignaciodias/Desktop/uni/automatas/automataTPO1/cmake-build-debug"
},
{
"name" : "CMAKE_CACHE_MAJOR_VERSION",
Expand Down Expand Up @@ -627,7 +627,7 @@
}
],
"type" : "STATIC",
"value" : "/home/ignaciodias/Desktop/Uni/Automatas/automataTPO1/cmake-build-debug/CMakeFiles/pkgRedirects"
"value" : "/home/ignaciodias/Desktop/uni/automatas/automataTPO1/cmake-build-debug/CMakeFiles/pkgRedirects"
},
{
"name" : "CMAKE_GENERATOR",
Expand Down Expand Up @@ -687,7 +687,7 @@
}
],
"type" : "INTERNAL",
"value" : "/home/ignaciodias/Desktop/Uni/Automatas/automataTPO1"
"value" : "/home/ignaciodias/Desktop/uni/automatas/automataTPO1"
},
{
"name" : "CMAKE_INSTALL_PREFIX",
Expand Down Expand Up @@ -1283,7 +1283,7 @@
}
],
"type" : "STATIC",
"value" : "/home/ignaciodias/Desktop/Uni/Automatas/automataTPO1/cmake-build-debug"
"value" : "/home/ignaciodias/Desktop/uni/automatas/automataTPO1/cmake-build-debug"
},
{
"name" : "tpOb1_IS_TOP_LEVEL",
Expand All @@ -1307,7 +1307,7 @@
}
],
"type" : "STATIC",
"value" : "/home/ignaciodias/Desktop/Uni/Automatas/automataTPO1"
"value" : "/home/ignaciodias/Desktop/uni/automatas/automataTPO1"
}
],
"kind" : "cache",
Expand Down

This file was deleted.

Loading

0 comments on commit 9f274eb

Please sign in to comment.