Skip to content

Commit

Permalink
consigna 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacioDias committed Apr 1, 2024
1 parent 1fba1ec commit 6beca7b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
31 changes: 25 additions & 6 deletions TP/automata/dfa/DeterministicFiniteAutomata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ void DeterministicFiniteAutomata :: setInitialState(set<int> q) {
void DeterministicFiniteAutomata :: setF(set<set<int>> final) {
this->F = final;
}
int DeterministicFiniteAutomata :: calculateDelta(pair<set<int>,int> key) {
if (d.count(key))
return d[key];
throw std::out_of_range("La clave no tiene un valor asociado.");

set<set<int>> DeterministicFiniteAutomata :: getF() {
return this->F;
}
set<int> DeterministicFiniteAutomata :: calculateDelta(const pair<set<int>,int>& key) {
return d[key];
}
void DeterministicFiniteAutomata :: addPath(set<int> node, int arc, int destination) {
void DeterministicFiniteAutomata :: addPath(set<int> node, int arc, set<int> destination) {
pair<set<int>,int> path;
path.first = std::move(node);
path.second = arc;
Expand All @@ -48,4 +48,23 @@ bool DeterministicFiniteAutomata :: repOk() {
}
return invariant;
}
bool DeterministicFiniteAutomata :: belongs(string numbers) {
set<int> currentNode = q0;
for(char ch : numbers) {
pair<set<int>, int> key;
key.first = currentNode;
key.second = stoi(string(1, ch));
if(d.count(key) == 0)
return false;
currentNode = calculateDelta(key);
}
return isFinalNode(currentNode);
}
bool DeterministicFiniteAutomata :: isFinalNode(set<int> node) {
for(auto currentNode : getF()) {
if(currentNode == node)
return true;
}
return false;
}

10 changes: 7 additions & 3 deletions TP/automata/dfa/DeterministicFiniteAutomata.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DeterministicFiniteAutomata {
private:
set<set<int>> K;
set<int> E;
map<pair<set<int>,int>, int> d;
map<pair<set<int>,int>, set<int>> d;
set<int> q0;
set<set<int>> F;

Expand All @@ -20,9 +20,13 @@ class DeterministicFiniteAutomata {
void setK(set<set<int>> states);
void setInitialState(set<int> q);
void setF(set<set<int>> final);
int calculateDelta(pair<set<int>,int> key);
void addPath(set<int> node, int arc, int destination);
set<int> calculateDelta(const pair<set<int>,int>& key);
void addPath(set<int> node, int arc, set<int> destination);
bool repOk();
void setQ0(set<int> q0);
bool belongs(string numbers);
set<set<int>> getF();
private:
bool isFinalNode(set<int> node);
};
#endif // DETERMINISTICFINITEAUTOMATA_H
2 changes: 1 addition & 1 deletion TP/automata/ndfa/NotDeterministicFiniteAutomata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ bool NotDeterministicFiniteAutomata :: repOk() {
invariant &= CollectionsOperators::belongs(this->q0, this->K);
return invariant;
}
DeterministicFiniteAutomata NotDeterministicFiniteAutomata :: nfaToDfa() {
DeterministicFiniteAutomata NotDeterministicFiniteAutomata :: nfaToDfa() { //TODO: FLATA ADD PATH, LOS NODOS NO ESTÁN REALMENTE VINCULADOS
DeterministicFiniteAutomata convertedAutomata = *new DeterministicFiniteAutomata();

set<int> q0AsSet;
Expand Down
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 01 18:38 -03
Start testing: Apr 01 18:58 -03
----------------------------------------------------------
End testing: Apr 01 18:38 -03
End testing: Apr 01 18:58 -03

0 comments on commit 6beca7b

Please sign in to comment.