Skip to content

Commit

Permalink
Now DFA accepts sets of numbers as nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacioDias committed Apr 1, 2024
1 parent 43f5a60 commit ddf989b
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 33 deletions.
26 changes: 15 additions & 11 deletions TP/automata/dfa/DeterministicFiniteAutomata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
#include "../../auxiliarmethods/CollectionsOperators.h"
using namespace std;

DeterministicFiniteAutomata::DeterministicFiniteAutomata() : K(), E(), d(), q0(0), F() {
DeterministicFiniteAutomata::DeterministicFiniteAutomata() : K(), E(), d(), q0(), F() {
}
void DeterministicFiniteAutomata::setE(set<int> alphabet) {
this->E = alphabet;
}
void DeterministicFiniteAutomata :: setK(set<int> states) {
void DeterministicFiniteAutomata :: setK(set<set<int>> states) {
this->K = states;
}
void DeterministicFiniteAutomata :: setInitialState(int q) {
void DeterministicFiniteAutomata :: setInitialState(set<int> q) {
this->q0 = q;
}
void DeterministicFiniteAutomata :: setF(set<int> final) {
void DeterministicFiniteAutomata :: setF(set<set<int>> final) {
this->F = final;
}
int DeterministicFiniteAutomata :: calculateDelta(pair<int,int> key) {
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.");

}
void DeterministicFiniteAutomata :: addPath(int node, int arc, int destination) {
pair<int,int> path;
path.first = node;
void DeterministicFiniteAutomata :: addPath(set<int> node, int arc, int destination) {
pair<set<int>,int> path;
path.first = std::move(node);
path.second = arc;
auto it = d.find(path);
if (it == d.end())
Expand All @@ -35,8 +35,12 @@ void DeterministicFiniteAutomata :: addPath(int node, int arc, int destination)
throw runtime_error("El nodo ya tiene asignado un destino con dicho arco");
}
bool DeterministicFiniteAutomata :: repOk() {
bool invariant = CollectionsOperators::contained(this->K, this->E);
invariant &= CollectionsOperators::contained(this->F, this->K);
invariant &= CollectionsOperators::belongs(this->q0, this->K);
bool invariant = CollectionsOperators::setContained(this->K, this->E);
for(auto currentSet : K) {
invariant &= CollectionsOperators::setContained(this->F, currentSet);
}
for(auto currentSet : K) {
invariant &= CollectionsOperators::contained(this->q0, currentSet);
}
return invariant;
}
18 changes: 9 additions & 9 deletions TP/automata/dfa/DeterministicFiniteAutomata.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ using namespace std;

class DeterministicFiniteAutomata {
private:
set<int> K;
set<set<int>> K;
set<int> E;
map<pair<int,int>, int> d;
int q0;
set<int> F;
map<pair<set<int>,int>, int> d;
set<int> q0;
set<set<int>> F;

public:
DeterministicFiniteAutomata();
void setE(set<int> alphabet);
void setK(set<int> states);
void setInitialState(int q);
void setF(set<int> final);
int calculateDelta(pair<int,int> key);
void addPath(int node, int arc, int destination);
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);
bool repOk();
};
#endif // DETERMINISTICFINITEAUTOMATA_H
23 changes: 16 additions & 7 deletions TP/auxiliarmethods/CollectionsOperators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@

using namespace std;

bool CollectionsOperators :: contained(const set<int>& firstVector, const set<int>& biggerVector) {
if(biggerVector.size() < firstVector.size())
bool CollectionsOperators :: contained(const set<int>& firstSet, const set<int>& biggerSet) {
if(biggerSet.size() < firstSet.size())
return false;
for(int elem : firstVector) {
if (!belongs(elem, biggerVector))
for(int elem : firstSet) {
if (!belongs(elem, biggerSet))
return false;
}
return true;
}
bool CollectionsOperators :: belongs(int elem, const set<int>& vector) {
for(int vCurrentElem : vector) {
if (elem == vCurrentElem)
bool CollectionsOperators :: belongs(int elem, const set<int>& set) {
for(int sCurrentElem : set) {
if (elem == sCurrentElem)
return true;
}
return false;
}
bool CollectionsOperators :: setContained(set<set<int>> firstSet, set<int> biggerSet) {
bool ret = true;
for(auto currentSet : firstSet) {
if(!contained(currentSet,biggerSet))
return false;
}
return true;
}

5 changes: 3 additions & 2 deletions TP/auxiliarmethods/CollectionsOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ using namespace std;

class __attribute__((unused)) CollectionsOperators {
public:
static bool contained(const set<int>& firstVector, const set<int>& biggerVector);
static bool belongs(int elem, const set<int>& vector);
static bool contained(const set<int>& firstSet, const set<int>& biggerSet);
static bool belongs(int elem, const set<int>& set);
static bool setContained(set<set<int>> firstSet, set<int> biggerSet);

};

Expand Down
1 change: 0 additions & 1 deletion cmake-build-debug/CMakeFiles/Progress/5

This file was deleted.

1 change: 0 additions & 1 deletion cmake-build-debug/CMakeFiles/Progress/count.txt

This file was deleted.

Binary file modified cmake-build-debug/CMakeFiles/tpOb1.dir/TP/Main.cpp.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified cmake-build-debug/CMakeFiles/tpOb1.dir/TP/parser/Parser.cpp.o
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: Mar 31 21:36 -03
Start testing: Apr 01 17:49 -03
----------------------------------------------------------
End testing: Mar 31 21:36 -03
End testing: Apr 01 17:49 -03
Binary file modified cmake-build-debug/tpOb1
Binary file not shown.

0 comments on commit ddf989b

Please sign in to comment.