Skip to content

Commit

Permalink
intento de conversión de estados
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacioDias committed Apr 12, 2024
1 parent d4841eb commit a4cb9d6
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 24 deletions.
21 changes: 12 additions & 9 deletions TP/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ int main() {

NotDeterministicFiniteAutomata ndfa;
ndfa.setInitialState(10);
ndfa.setAlphabet({-1, 1, 2}); //a, b
ndfa.setStates({10, 11, 12, 13});
ndfa.setStates({10,11,12,13,14,15});
ndfa.setAlphabet({-1,1,2,3});
ndfa.addPath(10,1,11);
ndfa.addPath(11,2,11);
ndfa.addPath(11,2,12);
ndfa.addPath(11,1,13);
ndfa.addPath(13,1,13);
ndfa.addPath(13,2,13);
ndfa.addFinalState(12);
// cout << Parser::ndfaToString(ndfa);
ndfa.addPath(11,3,12);
ndfa.addPath(12,-1,15);
ndfa.addPath(15,-1,10);
ndfa.addPath(10,-1,13);
ndfa.addPath(13,2,14);
ndfa.addPath(13,2,15);
ndfa.addPath(14,2,14);
ndfa.addPath(14,2,15);
ndfa.setFinalState({4,5});
// cout << Parser::ndfaToString(ndfa);
ConvertionOfAutomatas convertor;
convertor.setNDFA(ndfa);
convertor.convertFromNDFA();
Expand Down
37 changes: 24 additions & 13 deletions TP/automata/convertion/ConvertionOfAutomatas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,41 @@ void ConvertionOfAutomatas :: convertFromNDFA() {
q0AsSet.insert(ndfa.getInitialState());
set<int> Q0 = getSymbolClosure(q0AsSet);
dfa.setInitialState(Q0);
set<set<int>> newK;
newK.insert(Q0);

dfa.setAlphabet(ndfa.getAlphabet());

dfa.setStates(newK);
dfa.setStates({Q0});
calculateNewK();
dfa.setFinalStates(calculateFinal(dfa.getStates()));
}
void ConvertionOfAutomatas::calculateNewK() {
set<set<int>> unvisitedNodes = dfa.getStates();
set<set<int>> unvisitedNodes;
unvisitedNodes.insert(dfa.getInitialState());
while(!unvisitedNodes.empty()) {
auto currentNode = *unvisitedNodes.begin();
for (auto currentNumber : ndfa.getAlphabet()) {
set<int> currentSet = move(currentNode, currentNumber);
currentSet = getSymbolClosure(currentSet);
if (dfa.getStates().count(currentSet) <= 0) {
dfa.insertSate(currentSet);
unvisitedNodes.insert(currentSet);
dfa.addPath(currentNode, currentNumber, currentSet);
set<int> currentNode = *unvisitedNodes.begin();
unvisitedNodes.erase(currentNode);
for(auto letter : ndfa.getAlphabet()) {
set<int> destination = getSymbolClosure(move(currentNode, letter));
if(unvisitedNodes.count(destination) <= 0) {
unvisitedNodes.insert(destination);
}
dfa.insertSate(currentNode);
dfa.addPath(currentNode, letter, destination);
}
unvisitedNodes.erase(currentNode);
}
// while(!unvisitedNodes.empty()) {
// auto currentNode = *unvisitedNodes.begin();
// for (auto currentNumber : ndfa.getAlphabet()) {
// set<int> currentSet = move(currentNode, currentNumber);
// currentSet = getSymbolClosure(currentSet);
// if (dfa.getStates().count(currentSet) <= 0) {
// dfa.insertSate(currentSet);
// unvisitedNodes.insert(currentSet);
// dfa.addPath(currentNode, currentNumber, currentSet);
// }
// }
// unvisitedNodes.erase(currentNode);
// }
}
set<int> ConvertionOfAutomatas::getSymbolClosure(const set<int>& Q) {
set<int> result;
Expand Down
1 change: 1 addition & 0 deletions TP/automata/convertion/ConvertionOfAutomatas.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ConvertionOfAutomatas {
void convertFromNDFA();
DeterministicFiniteAutomata getDFA();
private:
set<int> calculateDelta(const set<int>& state, int symbol);
set<int> getSymbolClosure(const set<int>& Q);
set<int> move(const set<int>& Q, int a);
set<set<int>> calculateFinal(const set<set<int>>& k);
Expand Down
Binary file modified cmake-build-debug/CMakeFiles/tpOb1.dir/TP/Main.cpp.o
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions cmake-build-debug/Testing/Temporary/LastTest.log
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Start testing: Apr 12 13:37 -03
Start testing: Apr 12 19:07 -03
----------------------------------------------------------
End testing: Apr 12 13:37 -03
End testing: Apr 12 19:07 -03
Binary file modified cmake-build-debug/tpOb1
Binary file not shown.

0 comments on commit a4cb9d6

Please sign in to comment.