Ejemplo n.º 1
0
void Simulation::oneStep() {
    //Search for possible transitions by source state
    vector<Transition*> filteredTransitions;
	//std::cout << curState << " ==> ";
    auto ret = transitions.equal_range(curState);
    for (auto it=ret.first;it!=ret.second;++it) {
        filteredTransitions.push_back((*it).second);
    }
    if (filteredTransitions.empty()) {
		curState = "reject";
		return;
    }
    
    //Search for possible transitions by read character
    vector<Transition*> possibleTransitions;
	char readValue = tape->getChar();
    for (Transition* tr : filteredTransitions ) {
        if (tr->getRead() == readValue) {
            possibleTransitions.push_back(tr);
        }
    }
    if (possibleTransitions.empty()) {
		curState = "reject";
		return;
    }
    
    // transition
	assert(possibleTransitions.size() == 1); // cannot copy with multi transitions
	Transition* select = possibleTransitions[0];
	char wt = select->getWrite();
	char mv = select->getMove();
	std::string nextState = select->getNextState();
	tape->setChar(wt);
	tape->move(mv);
	curState = nextState;

	//std::cout << nextState << std::endl;
}