本文整理汇总了C++中Automaton::getNSymbols方法的典型用法代码示例。如果您正苦于以下问题:C++ Automaton::getNSymbols方法的具体用法?C++ Automaton::getNSymbols怎么用?C++ Automaton::getNSymbols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Automaton
的用法示例。
在下文中一共展示了Automaton::getNSymbols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: findSymbolId
Automaton * Automaton::getDeterministic() {
Automaton * b = new Automaton;
std::vector< std::vector< int > > mEmptyTransitions;
std::vector< int > vEmptyIn;
std::vector< int > vEmptyOut;
int i, j, removed;
b->vStates = vStates;
b->vFinal = vFinal;
b->vSymbols = vSymbols;
b->mTransitions = mTransitions;
//creates the mEmptyTransitions table
vEmptyIn.resize(getNStates());
vEmptyOut.resize(getNStates());
mEmptyTransitions.resize(getNStates());
for(i = 0; i < getNStates(); i++)
mEmptyTransitions[i].resize(getNStates());
//initialize mEmptyTransitions
for(i = 0; i < mEmptyTransitions.size(); i++){
vEmptyIn[i] = 0;
vEmptyOut[i] = 0;
for(j = 0; j < mEmptyTransitions[i].size(); j++)
mEmptyTransitions[i][j] = 0;
}
//fills mEmptyTransitons
j = findSymbolId("");
if(j != -1) {
for(int i = 0; i < getNStates(); i++) {
for(std::list<int>::iterator it = mTransitions[i][j].begin(); it != mTransitions[i][j].end(); it++) {
vEmptyIn[*it]++;
vEmptyOut[i]++;
mEmptyTransitions[i][*it]++;
}
}
}
//finds a state 'i' with incoming empty transitions, but no outgoing empty transitions,
//copy its transtions to states 'j' able to reach 'i' and removes these empty transitions
do {
removed = 0;
for(i = 0; i < getNStates(); i++) {
if((vEmptyIn[i] > 0) && (vEmptyOut[i] == 0)) {
for(j = 0; j < getNStates(); j++) {
if(i == j)
continue;
if(mEmptyTransitions[j][i] > 0) {
b->copyOutgoingTransitions(i, j);
b->removeIncomingEmptyTransitions(i);
if(b->vFinal[i] == true)
b->vFinal[j] = true;
mEmptyTransitions[j][i]--;
vEmptyIn[i]--;
vEmptyOut[j]--;
removed++;
}
}
}
}
} while(removed > 0);
//finds a state 'i' that has a non-determinism (two or more outputs for the same symbol),
//creates a state representing all those symbols and change the transition to this one
do {
removed = 0;
for(i = 0; i < b->getNStates(); i++) {
for(j = 0; j < b->getNSymbols(); j++) {
if(b->mTransitions[i][j].size() > 1) {
int newStateId;
std::string newStateName;
bool isFinal;
//fills newStateName and isFinal
newStateName = b->vStates[mTransitions[i][j].front()];
std::list<int>::iterator it = b->mTransitions[i][j].begin();
isFinal = vFinal[*it];
++it;
for(; it != b->mTransitions[i][j].end(); it++) {
newStateName += "_" + b->vStates[*it];
isFinal = isFinal || vFinal[*it];
}
//guarantees the newStateName is unique
while(b->findStateId(newStateName) != -1)
newStateName += '_';
//adds newStateName to b
b->addState(newStateName, isFinal);
newStateId = b->findStateId(newStateName);
//.........这里部分代码省略.........