示例#1
0
文件: DFA.cpp 项目: aliench0/DFA
void DFA::changeAllStatesName(int start) {
	int newStates[countOfStates];
	int k = 0, oldState, index;
	for (int i = 0; i < countOfStates; i++) {
		newStates[i] = start;
		if (isFinalState(states[i]))
			finalStates[k++] = start;
		start++;
	}

	for (int i = 0; i < countOfStates; i++) { // Презаписваме таблицата с новите състояния
		for (int j = 0; j < countOfAlphabet; j++) {
			if (transitionFunction(states[i], alphabet[j]) != -2
					&& transitionFunction(states[i], alphabet[j]) != -1) {
				oldState = table[states[i]][alphabet[j]]; //трябва да вземем индекса на oldState и да вземем новото име така newStates[индекс на oldState]

				for (int z = 0; z < countOfStates; z++)
					if (states[z] == oldState)
						index = z;

				table[newStates[i]][alphabet[j]] = newStates[index];
				table[states[i]].erase(alphabet[j]); // Изтриваме старите състояния
			}
		}
	}

	for (int i = 0; i < countOfStates; i++) {
		if (startState == states[i])
			startState = newStates[i];
		states[i] = newStates[i];
	}
}
示例#2
0
文件: utils.c 项目: Toussaic/main
/**
 * Locate string in string.
 *   regexp: ^[ \t\r\n]*([^,]*)[ \t\r\n]*,?
 * @param str1 string to be searched
 * @param len1 length of string
 * @param str2 result
 * @param len2 length of result
 * @return string str1 contains text and str2 was set
 */
bool_t locateStr(const char * str1, size_t len1, const char ** str2, size_t * len2) {
    locate_text_nfa nfa;
    nfa.state = STATE_FIRST_WHITESPACE;
    nfa.startIdx = 0;
    nfa.stopIdx = 0;


    for (nfa.i = 0; nfa.i < len1; nfa.i++) {
        if(FALSE == locateStrAutomaton(&nfa, str1[nfa.i])) {
            break;
        }
    }

    if (isFinalState(nfa.state)) {

        if (str2) {
            *str2 = &str1[nfa.startIdx];
        }

        if (len2) {
            *len2 = nfa.stopIdx - nfa.startIdx;
        }
        return TRUE;
    }
    return FALSE;
}
示例#3
0
    void StateStorage::dupState( State orig, State dup )
    {
      if( isInitialState(orig) )
        addInitialState(dup);

      if( isFinalState(orig) )
        addFinalState(dup);
    }
示例#4
0
GenParticle* getChargedHiggs(TClonesArray* particles) {
    for (int ip = 0; ip < particles->GetEntries(); ++ip) {
        GenParticle* part = (GenParticle*)particles->At(ip);
        if (isFinalState(part, particles) && abs(part->PID) == 37 ) {
            return part;
        }
    }
    return 0;
}
示例#5
0
void LinearStateSystem::updateState(double value) {
	//cout << "update state: " << value << endl;
	_duration++;
	if (_currentState > 0 && ((_duration < _states[_currentState].minDuration && !_states[_currentState].isSatisfied(value)) || _duration > _states[_currentState].maxDuration)) {
		setState(0);
	}

	if (!isFinalState() && _states[_currentState + 1].isSatisfied(value)) {
		setState(_currentState + 1);
	}
}
示例#6
0
文件: DFA.cpp 项目: jpsember/mcheck
void DFA::setStartState(int s) {
	if (s < 0 || s >= MAX_STATES)
		throw Exception("Invalid state");

	// If this state is a final state, that's a problem!
	// We don't want to recognize zero-length tokens.
	if (isFinalState(s))
		throw Exception("Start state cannot be a final state");

	startState_ = s;
	setState(s);
}
示例#7
0
//Returns the final state in with maximum prefix match
//i.e which has maximum forward pointer. 
STATE_AND_FORWARD simulateNFA(char input[], STATE STARTSTATE, int forward)
{
	char currentChar = input[forward];
	
	if(isFinalState(STARTSTATE))//Final state has no output transition
	{
		STATE_AND_FORWARD t = {STARTSTATE, forward-1};
		return t;
	}
	
	/*flag checks if there is any transition available for this state,
	otherwise returns -1*/
	int i, flag = 0;
	STATE_AND_FORWARD max = {-1, -1}, temp = {-1, -1};
	for(i=1;i<nextAvailableState;++i)
	{
		if(STT[STARTSTATE][i][currentChar])//Move forward ahead
		{
			flag = 1;
			temp = simulateNFA(input, i, forward+1);
		}
		else if(STT[STARTSTATE][i]['$'])//EPSILON transition.Dont move forward ahead
		{
			flag = 1;
			temp = simulateNFA(input, i, forward);
		}
		
		if(temp.forward>max.forward)
			max = temp;	
	}
	if(flag == 0)//No transition found
	{
		STATE_AND_FORWARD t = {-1, -1};
		return t;
	}
	return max;
}
示例#8
0
文件: DFA.cpp 项目: aliench0/DFA
bool DFA::checkWord(char* word) {
	if (isFinalState(extendedTransitionFunction(startState, word)))
		return true;
	return false;
}
示例#9
0
int aStar(tNodeQueue *root, int heuristica, int *answer) {
    tQueue *a = malloc(sizeof(tQueue));
    tQueue *f = malloc(sizeof(tQueue));
    *answer = -1;
    printf("%d\n",a);
    initialize(a);
    initialize(f);


    insertAtEnd(a, root);

    while (!isEmpty(a)) {
        tNodeQueue *v = removeMin(a);
        insertAtEnd(f, v);

        if (isFinalState(v->elem->matrix)) {
            *answer = v->elem->f;
            return 1;
        } else {
            tNodeQueue *top = malloc(sizeof (tNodeQueue));
            tNodeBoard *topBoard = malloc(sizeof (tNodeBoard));
            top->elem = topBoard;
            tNodeQueue *right = malloc(sizeof (tNodeQueue));
            tNodeBoard *rightBoard = malloc(sizeof (tNodeBoard));
            right->elem = rightBoard;
            tNodeQueue *bottom = malloc(sizeof (tNodeQueue));
            tNodeBoard *bottomBoard = malloc(sizeof (tNodeBoard));
            bottom->elem = bottomBoard;
            tNodeQueue *left = malloc(sizeof (tNodeQueue));
            tNodeBoard *leftBoard = malloc(sizeof (tNodeBoard));
            left->elem = leftBoard;

            int i;
            int j;
            findZeroPosition(v->elem->matrix, &i, &j);
            if (moveTop(v->elem->matrix, top->elem->matrix, i, j)) {
                validSuccessor(a, f, v, top, heuristica);
            } else {
                free(topBoard);
                free(top);
            }
            if (moveRight(v->elem->matrix, right->elem->matrix, i, j)) {
                validSuccessor(a, f, v, right, heuristica);
            } else {
                free(rightBoard);
                free(right);
            }
            if (moveBottom(v->elem->matrix, bottom->elem->matrix, i, j)) {
                validSuccessor(a, f, v, bottom, heuristica);
            } else {
                free(bottomBoard);
                free(bottom);
            }
            if (moveLeft(v->elem->matrix, left->elem->matrix, i, j)) {
                validSuccessor(a, f, v, left, heuristica);
            } else {
                free(leftBoard);
                free(left);
            }

        }
    }
    if (isEmpty(a)) {
        return 0;
    }

}
示例#10
0
文件: DFA.cpp 项目: jpsember/mcheck
int DFA::recognize(const String &str, int startPos, int &length) {

	ASSERT(startPos <= str.length());

	// keep track of the length of the longest token found, and
	// the final state it's associated with
	int maxLengthFound = 0;
	int bestFinalState = -1;
	int bestFinalCode = -1;

	setState(startState_);
	int i = startPos;

	while (i < str.length()) {

		char c = str.charAt(i);

		// if this is not a legal character for a token, no match.
		if (!isValid(c))
			break;

		int newState = getTransitionState(state(), c);
		// if there's no transition on this symbol from the state, no match.
		if (newState < 0)
			break;

		setState(newState);
		i++;

#if AUGMENT
		// if the current state has a <token id> transition, 
		// then we've reached a final state; choose the
		// first such number in the list, since we want the productions
		// that were listed first to have higher priority.

		int token = findTokenID();
		if (token >= 0) {
			maxLengthFound = i - startPos;
			bestFinalCode = token;
			bestFinalState = newState;
		}
#endif

		// With the augmented <token id>s, we will never
		// actually get to the (distinct) final state; so this is not
		// necessary.  We'll leave it in for compatibility with HW #1.

		// if this is a final state, update the longest token length.
		if (isFinalState(newState)) {
			maxLengthFound = i - startPos;
			bestFinalState = newState;
#if !AUGMENT
			bestFinalCode = getState(newState).finalCode();
#endif
		}
	}
	// don't know why this is here.
	setState(bestFinalState);
	length = maxLengthFound;
	return bestFinalCode;
}
bool OlmoAutomata::isSequenceValid(vector<int> *sequence){
   startAutomata();
   calcSequenceRating(*sequence); 
   
    return isFinalState();
}