reg automata fixes
This commit is contained in:
parent
41aa8daeb2
commit
dd6b63acb1
2 changed files with 31 additions and 22 deletions
|
|
@ -38,6 +38,9 @@ namespace tp {
|
||||||
|
|
||||||
[[nodiscard]] bool isEpsilon() const { return mType == EPSILON; }
|
[[nodiscard]] bool isEpsilon() const { return mType == EPSILON; }
|
||||||
|
|
||||||
|
const State* getState() const { return mState; }
|
||||||
|
const tAlphabetType& getSymbol() const { return mSymbol; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
State* mState = nullptr;
|
State* mState = nullptr;
|
||||||
Type mType;
|
Type mType;
|
||||||
|
|
@ -53,6 +56,9 @@ namespace tp {
|
||||||
public:
|
public:
|
||||||
void setValue(const tStateType& stateValue) { mStateVal = stateValue; }
|
void setValue(const tStateType& stateValue) { mStateVal = stateValue; }
|
||||||
void setAcceptance(bool isAccepting) { mIsAccepting = isAccepting; }
|
void setAcceptance(bool isAccepting) { mIsAccepting = isAccepting; }
|
||||||
|
bool isAccepting() const { return mIsAccepting; }
|
||||||
|
const tStateType& getStateVal() const { return mStateVal; }
|
||||||
|
const Buffer<Transition>* getTransitions() const { return &mTransitions; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Buffer<Transition> mTransitions;
|
Buffer<Transition> mTransitions;
|
||||||
|
|
@ -94,6 +100,11 @@ namespace tp {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] ualni numStates() const { return mStates.length(); }
|
||||||
|
|
||||||
|
[[nodiscard]] const List<State>* getStates() const { return &mStates; }
|
||||||
|
|
||||||
|
private:
|
||||||
typedef AvlTree<AvlNumericKey<State*>, bool> StatesSet;
|
typedef AvlTree<AvlNumericKey<State*>, bool> StatesSet;
|
||||||
|
|
||||||
// Expands initial set with states that are reachable from initial set with no input consumption (E-transitions)
|
// Expands initial set with states that are reachable from initial set with no input consumption (E-transitions)
|
||||||
|
|
@ -128,6 +139,7 @@ namespace tp {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
template <typename tAlphabetIterator>
|
template <typename tAlphabetIterator>
|
||||||
bool makeDeterministic(const tAlphabetIterator& allSymbols) {
|
bool makeDeterministic(const tAlphabetIterator& allSymbols) {
|
||||||
if (!isValid()) return false;
|
if (!isValid()) return false;
|
||||||
|
|
|
||||||
|
|
@ -27,51 +27,48 @@ namespace tp {
|
||||||
auto getTransitions() const { return &mTransitions; }
|
auto getTransitions() const { return &mTransitions; }
|
||||||
auto getStart() const { return mStart; }
|
auto getStart() const { return mStart; }
|
||||||
|
|
||||||
void construct(const FiniteStateAutomation<tAlphabetType, tStateType>& dfa) {
|
void construct(const FiniteStateAutomation<tAlphabetType, tStateType>& automata) {
|
||||||
// mSymbolRange = { dfa.getRange().first(), dfa.getRange().last() };
|
// mSymbolRange = { dfa.getRange().first(), dfa.getRange().last() };
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
||||||
/*
|
|
||||||
auto range_len = ualni(mSymbolRange.mEnd - mSymbolRange.mBegin);
|
auto range_len = ualni(mSymbolRange.mEnd - mSymbolRange.mBegin);
|
||||||
auto sizeX = range_len ? range_len : 1;
|
auto sizeX = range_len ? range_len : 1;
|
||||||
auto sizeY = (ualni) (dfa.nVertices() + 1);
|
auto sizeY = (ualni) (automata.numStates() + 1);
|
||||||
|
|
||||||
mTransitions.reserve({ sizeX, sizeY });
|
mTransitions.reserve({ sizeX, sizeY });
|
||||||
mTransitions.assign(dfa.nVertices());
|
mTransitions.assign(automata.numStates());
|
||||||
mStates.reserve(sizeY);
|
mStates.reserve(sizeY);
|
||||||
|
|
||||||
ualni idx = 0;
|
ualni idx = 0;
|
||||||
for (auto vertex : dfa.mVertices) {
|
for (auto state : *automata.getStates()) {
|
||||||
auto state = vertex.data().termination ? vertex.data().state : tNoStateVal;
|
auto stateVal = state->isAccepting() ? state->getStateVal() : tNoStateVal;
|
||||||
mStates[idx] = state;
|
mStates[idx] = stateVal;
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mStates[dfa.nVertices()] = tFailedStateVal;
|
mStates[automata.numStates()] = tFailedStateVal;
|
||||||
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
for (auto vertex : dfa.mVertices) {
|
for (auto state : *automata.getStates()) {
|
||||||
if (&vertex.data() == dfa.mStart) {
|
if (&state.data() == automata.getStartState()) {
|
||||||
mStart = mIter = mIterPrev = idx;
|
mStart = mIter = mIterPrev = idx;
|
||||||
}
|
}
|
||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ualni vertexIdx = 0;
|
ualni stateIdx = 0;
|
||||||
for (auto vertex : dfa.mVertices) {
|
for (auto state : *automata.getStates()) {
|
||||||
for (auto edge : vertex.data().edges) {
|
for (auto transition : *state->getTransitions()) {
|
||||||
ualni vertex2Idx = 0;
|
ualni stateIdx2 = 0;
|
||||||
for (auto vertex2 : dfa.mVertices) {
|
for (auto state2 : *automata.getStates()) {
|
||||||
if (edge.data().vertex == &vertex2.data()) break;
|
if (transition->getState() == &state2.data()) break;
|
||||||
vertex2Idx++;
|
stateIdx2++;
|
||||||
}
|
}
|
||||||
auto const code = edge.data().transition_code;
|
auto const code = transition->getSymbol();
|
||||||
mTransitions.set({ (ualni) (code - mSymbolRange.mBegin), (ualni) vertexIdx }, vertex2Idx);
|
mTransitions.set({ (ualni) (code - mSymbolRange.mBegin), (ualni) stateIdx }, stateIdx2);
|
||||||
}
|
}
|
||||||
vertexIdx++;
|
stateIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isTrapped() { return mStates[mIter] == tFailedStateVal; }
|
bool isTrapped() { return mStates[mIter] == tFailedStateVal; }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue