当前位置: 首页>>代码示例>>C++>>正文


C++ Transition::getBeginningState方法代码示例

本文整理汇总了C++中Transition::getBeginningState方法的典型用法代码示例。如果您正苦于以下问题:C++ Transition::getBeginningState方法的具体用法?C++ Transition::getBeginningState怎么用?C++ Transition::getBeginningState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transition的用法示例。


在下文中一共展示了Transition::getBeginningState方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RegularExpression

/**
 * @brief Converts a FSA to a regular expression using Brzozowski's algebraic method.
 * The method was implemented according to information found at 
 * <a href="http://cs.stackexchange.com/questions/2016/how-to-convert-finite-automata-to-regular-expressions">Stack Exchange</a>.
 * This algorithm was then adapted to the existing data structures and improved.
 * @param fsa The FSA to convert.
 * @return A regular expression equivalent to the given automaton.
 * @author Daniel Dreibrodt
 */
RegularExpression *FSAtoREConverter::toRE(FiniteStateAutomaton *fsa) {
    fsa = fsa->fsaConvertNEAtoDEA();
    fsa = fsa->minimize();
    
	vector<State*> *states = fsa->getStateList();
	vector<Transition*> *transitions = fsa->getTransitions();

	//create hash-maps to easily find transitions to/from states
	map<string, vector<Transition*> > transitionsFromState;
	map<string, vector<Transition*> > transitionsToState;    
    
	for(vector<Transition*>::iterator it = transitions->begin(); it != transitions->end(); ++it) {
        Transition *currentTrans = *it;
		//Add transition to transitionsFromState map
        //transitionsFromState.insert(make_pair(currentTrans->getBeginningState(), currentTrans);
		transitionsFromState[currentTrans->getBeginningState()->getName()].push_back(currentTrans);
		//Add transition to transitionsToState map
		transitionsToState[currentTrans->getFinishState()->getName()].push_back(currentTrans);
	}

	///// BRZOZOWSKI ALGORITHM /////
    
    int m,n,i,j;
    
    //m is the number of states
	m = (int)states->size();
    
    //b[n] holds the regular expression that describes how a final state can be reached from state n
	RETreeNode* b[m];
    //a is a matrix that holds all transitions
    //If there is a transition from state 0 to state 1 with the symbol x
    //then a[0][1]=x

	RETreeNode* a[m][m];
    
	//Make sure that start state comes first in state vector
	if(!(states->at(0)->isStartState())) {
		State *firstState = states->at(0);
		for(i=1;i<m;i++) {
			State *currentState = states->at(i);
			if(currentState->isStartState()) {
				(*states)[0] = currentState;
				(*states)[i] = firstState;
				break;
			}
		}
	}

	for(i=0;i<m;i++) {
		//Build b
		State *currentState = states->at(i);
		if(currentState->isFinalState()) {
			b[i] = new RETreeNode("");
		} else {
			b[i] = NULL;
		}
        
		//Build a 
		vector<Transition*> *transFromCurrentState = &(transitionsFromState[currentState->getName()]);
		for(j=0;j<m;j++) {
			a[i][j] = NULL;
            State *targetState = states->at(j);
            
			for(vector<Transition*>::iterator it = transFromCurrentState->begin(); it != transFromCurrentState->end(); ++it) {
				Transition *currentTransition = *it;                
                
				if(currentTransition->getFinishState()->getName() == targetState->getName()) {
					//If several transitions from currentState to targetState exist
					//create a boolean "or" regular expression tree node
					if(a[i][j] == NULL) {
						a[i][j] = new RETreeNode(currentTransition->getEdgeName());
					}
					else {
						RETreeNode *orNode = new RETreeNode(RegularExpression::re_orOp);
						orNode->setRight(a[i][j]->clone());
						orNode->setLeft(new RETreeNode(currentTransition->getEdgeName()));
						a[i][j] = orNode;
                        
					}
				}
			}
		}
	}
    
	for(n=m-1;n>=0;n--) {
		//B[n] := star(A[n,n]) . B[n]
        bool foundNNLoop = false; //Addition to original algorithm
        if(a[n][n]!=NULL) {
            foundNNLoop = true;
            //Loops mean repetition -> star operator
            RETreeNode* bnStarNode = new RETreeNode(RegularExpression::re_starOp);        
//.........这里部分代码省略.........
开发者ID:3breadt,项目名称:UPB-ADT-Automata-Tools,代码行数:101,代码来源:FSA_FSAtoREConverter.cpp


注:本文中的Transition::getBeginningState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。