本文整理汇总了C++中FSM::addTransition方法的典型用法代码示例。如果您正苦于以下问题:C++ FSM::addTransition方法的具体用法?C++ FSM::addTransition怎么用?C++ FSM::addTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FSM
的用法示例。
在下文中一共展示了FSM::addTransition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: fsm_simple
FSM fsm_simple() {
FSM fsm;
int even = fsm.addState("Even", true);
int odd = fsm.addState("Odd");
fsm.addTransition(even, even, 1, "1");
fsm.addTransition(even, odd, 0, "0");
fsm.addTransition(odd, odd, 1, "1");
fsm.addTransition(odd, even, 0, "0");
return fsm;
}
示例2: fsm_moonman
FSM fsm_moonman() {
FSM fsm;
int start = fsm.addState("No Input");
int bogus = fsm.addState("Not MOONMAN");
int m1 = fsm.addState("M");
int o1 = fsm.addState("O");
int o2 = fsm.addState("O");
int n1 = fsm.addState("N");
int m2 = fsm.addState("M");
int a1 = fsm.addState("A");
int n2 = fsm.addState("N", true);
fsm.addTransition(start, m1, (int) 'M', "M"); // 1
fsm.addTransition(m1, o1, (int) 'O', "O"); // 2
fsm.addTransition(o1, o2, (int) 'O', "O"); // 3
fsm.addTransition(o2, n1, (int) 'N', "N"); // 4
fsm.addTransition(n1, m2, (int) 'M', "M"); // 5
fsm.addTransition(m2, a1, (int) 'A', "A"); // 6
fsm.addTransition(a1, n2, (int) 'N', "N"); // 7
fsm.addTransition(start, bogus, (int) 'X', "X"); // 8
fsm.addTransition(m1, bogus, (int) 'X', "X"); // 9
fsm.addTransition(o1, bogus, (int) 'X', "X"); // 10
fsm.addTransition(o2, bogus, (int) 'X', "X"); // 11
fsm.addTransition(n1, bogus, (int) 'X', "X"); // 12
fsm.addTransition(m2, bogus, (int) 'X', "X"); // 13
fsm.addTransition(a1, bogus, (int) 'X', "X"); // 14
fsm.addTransition(n2, bogus, (int) 'X', "X"); // 15
return fsm;
}
示例3: parseFSM
FSM* IRParser::parseFSM(llvm::MDNode* node){
FSM* fsm = new FSM();
//Parse initial state
MDString* initialState = cast<MDString>(node->getOperand(0));
//Parse all fsm state
MDNode* stateArray = cast<MDNode>(node->getOperand(1));
for (unsigned i = 0, e = stateArray->getNumOperands(); i != e; ++i){
MDString* stateMD = cast<MDString>(stateArray->getOperand(i));
fsm->addState(stateMD->getString());
}
// set the initial state after initializing the states
fsm->setInitialState(initialState->getString());
//Parse transition
MDNode* transitionsArray = cast<MDNode>(node->getOperand(2));
for (unsigned i = 0, e = transitionsArray->getNumOperands(); i != e; ++i){
MDNode* transitionArray = cast<MDNode>(transitionsArray->getOperand(i));
MDString* source = cast<MDString>(transitionArray->getOperand(0));
Value* targetValue = transitionArray->getOperand(1);
//In case of "undefined" state, no target are given
if (targetValue != NULL){
MDNode* targetsArray = cast<MDNode>(targetValue);
for (unsigned j = 0, f = targetsArray->getNumOperands() ; j != f; ++j){
MDNode* targetArray = cast<MDNode>(targetsArray->getOperand(j));
Action* action = getAction(cast<MDNode>(targetArray->getOperand(0)));
MDString* target = cast<MDString>(targetArray->getOperand(1));
fsm->addTransition(source->getString(), target->getString(), action);
}
}
}
return fsm;
}
示例4: writeFSM
FSM* IRWriter::writeFSM(FSM* fsm){
list<llvm::Function*>::iterator it;
FSM* newFSM = new FSM();
//Copy states of the source fsm
std::map<std::string, FSM::State*>::iterator itState;
std::map<std::string, FSM::State*>* states = fsm->getStates();
for (itState = states->begin(); itState != states->end(); itState++){
newFSM->addState(itState->first);
}
//Copy transitions of the source fsm
map<string, Action*>::iterator itActionsMap;
std::map<std::string, FSM::Transition*>::iterator itTransition;
std::map<std::string, FSM::Transition*>* transitions = fsm->getTransitions();
for (itTransition = transitions->begin(); itTransition != transitions->end(); itTransition++){
FSM::Transition* transition = itTransition->second;
FSM::State* sourceState = transition->getSourceState();
list<FSM::NextStateInfo*>::iterator itNextStateInfo;
list<FSM::NextStateInfo*>* nextStateInfos = transition->getNextStateInfo();
for (itNextStateInfo = nextStateInfos->begin(); itNextStateInfo != nextStateInfos->end(); itNextStateInfo++){
FSM::State* targetState = (*itNextStateInfo)->getTargetState();
Action* targetAction = (*itNextStateInfo)->getAction();
newFSM->addTransition(sourceState->getName(), targetState->getName(), getAction(targetAction));
}
}
//Set initiale state of the FSM
newFSM->setInitialState(fsm->getInitialState()->getName());
return newFSM;
}
示例5: buildFSM
//.........这里部分代码省略.........
delete fsm;
return 0x0;
}
state->clearGoalSelector();
GoalSelector * srcGS = src->getGoalSelector();
srcGS->setPersistence( true );
state->setGoalSelector( srcGS );
}
}
if ( VERBOSE ) logger << Logger::INFO_MSG << "There are " << fsmDescrip._transitions.size() << " transitions\n";
// 2. Create transitions
std::map< std::string, std::list< Transition * > >::iterator stItr = fsmDescrip._transitions.begin();
for ( ; stItr != fsmDescrip._transitions.end(); ++stItr ) {
const std::string fromName = stItr->first;
std::list< Transition * > & tList = stItr->second;
// Determine if the origin state is valid
if ( fsmDescrip._stateNameMap.find( fromName ) == fsmDescrip._stateNameMap.end() ) {
logger << Logger::ERR_MSG << "Transition with invalid from node name: " << fromName << ".";
delete fsm;
return 0x0;
}
// Try to connect the transitions to the destination(s)
std::list< Transition * >::iterator tItr = tList.begin();
for ( ; tItr != tList.end(); ++tItr ) {
Transition * t = *tItr;
if ( ! t->connectStates( fsmDescrip._stateNameMap ) ) {
delete fsm;
return 0x0;
}
fsm->addTransition( stateNameMap[ fromName ], t );
}
tList.clear();
}
fsmDescrip._transitions.clear();
//////////////
// copy over the velocity modifiers
vItr = fsmDescrip._velModifiers.begin();
for ( ; vItr != fsmDescrip._velModifiers.end(); ++vItr ) { //TODO: replace global vel mod initalizer
fsm->addVelModifier( *vItr );
}
fsmDescrip._velModifiers.clear();
// 3. Query simulator and fsm for possible reasons to have a task
fsm->collectTasks();
for ( std::list< Task * >::iterator itr = fsmDescrip._tasks.begin();
itr != fsmDescrip._tasks.end();
++itr ) {
fsm->addTask( (*itr) );
}
fsmDescrip._tasks.clear();
// spatial query and elevation tasks
fsm->addTask( SPATIAL_QUERY->getTask() );
if ( sim->getElevationInstance() ) {
// NOTE: The elevation instance is null because none were specified.
// Eventually, the default elevation will be set.
// HOWEVER, if the default ever changes such that it requires a task,
// this won't catch it!!! So, make sure the default never requires
// a task.
示例6: fsm_brain_bag
FSM fsm_brain_bag() {
FSM fsm;
int S = fsm.addState("Start State");
int Z = fsm.addState("Bogus State");
int b = fsm.addState("B");
int i = fsm.addState("I");
int r = fsm.addState("R");
int a = fsm.addState("A");
int n = fsm.addState("N", true);
int g = fsm.addState("G", true);
int a2 = fsm.addState("A", true);
int s = fsm.addState("S", true);
int i2 = fsm.addState("I");
int n2 = fsm.addState("N", true);
fsm.addTransition(S, b, (int) 'B', "B");
fsm.addTransition(b, i, (int) 'I', "I");
fsm.addTransition(b, r, (int) 'R', "R");
fsm.addTransition(b, a, (int) 'A', "A");
fsm.addTransition(i, n, (int) 'N', "N");
fsm.addTransition(i, g, (int) 'G', "G");
fsm.addTransition(r, a2, (int) 'A', "A");
fsm.addTransition(a, g, (int) 'G', "G");
fsm.addTransition(n, s, (int) 'S', "S");
fsm.addTransition(a2, s, (int) 'S', "S");
fsm.addTransition(a2, i2, (int) 'I', "I");
fsm.addTransition(i2, n2, (int) 'N', "N");
fsm.addTransition(n2, s, (int) 'S', "S");
fsm.addTransition(S, Z, -1, "Bogus");
fsm.addTransition(b, Z, -1, "Bogus");
fsm.addTransition(i, Z, -1, "Bogus");
fsm.addTransition(r, Z, -1, "Bogus");
fsm.addTransition(a, Z, -1, "Bogus");
fsm.addTransition(n, Z, -1, "Bogus");
fsm.addTransition(g, Z, -1, "Bogus");
fsm.addTransition(a2, Z, -1, "Bogus");
fsm.addTransition(s, Z, -1, "Bogus");
fsm.addTransition(i2, Z, -1, "Bogus");
fsm.addTransition(n2, Z, -1, "Bogus");
return fsm;
}