Particle Sensor::getMeasurement(const Particles &input_measurement) { // auto __input = input_measurement.getParticles(); // float len = __input.size(); // auto it = __input.begin(); // Particle vals = Particle(_size); // std::vector<float> __vals(_size); // for(;it<__input.end();it++) { // auto in = it->getStates().begin(); // auto vl = __vals.begin(); // for(;in<it->getStates().end();in++,vl++) { // *vl+=(*in)*(it->getWeight()); } } // vals.setStates(__vals); // return vals; }
const RegionState* RegionAutomaton::findState(const Region& region) const { RegionState query(region); StateSet::const_iterator it = getStates().find(&query); if (it == getStates().end()) return NULL; return *it; }
Particle ExampleSystem::getState(const Particles &input_state) { // auto __input = input_state.getParticles(); // auto it = __input.begin(); // Particle vals = Particle(_size); //std::cout<<"size:"<<_size<<std::endl; // std::vector<float> __vals(_size); // float len = __input.size(); // for(;it<__input.end();it++) { // auto in = it->getStates().begin(); // auto vl = __vals.begin(); // for(;in<it->getStates().end();in++,vl++) { // //std::cout<<*vl<<std::endl; *vl+=*in*(it->getWeight()); } } // vals.setStates(__vals); // return vals; }
TreeOutput DecisionTree::decide(std::vector<std::pair<States, bool>> states){ //Check if current node is not a leaf if (!m_currentNode->getIsLeaf()){ bool stateCondition = NULL; if (m_currentNode->getStateID() != States::DEFAULTSTATE){ stateCondition = getStates(states, m_currentNode->getStateID()); } bool leftCondition = NULL; if (m_currentNode->getLeftNode()->getCondition() != NULL){ leftCondition = m_currentNode->getLeftNode()->getCondition(); } bool rightCondition = NULL; if (m_currentNode->getRightNode()->getCondition() != NULL){ rightCondition = m_currentNode->getRightNode()->getCondition(); } if (stateCondition == leftCondition){ m_currentNode = m_currentNode->getLeftNode(); return decide(states); } else if (stateCondition == rightCondition){ m_currentNode = m_currentNode->getRightNode(); return decide(states); } else { } } TreeOutput target = m_currentNode->getTarget(); m_currentNode = m_rootNode; return target; }
void TuringMachine::operator()(char a){ int transitionsSize = strlen(getCurrent().getTransitions()); char temp; bool done = false; for (int i = 0; i < transitionsSize && !done; i += 4){ temp = getCurrent().getTransitions()[i]; done = false; if (getCurrent().getTransitions()[i] == a){ write(head, getCurrent().getTransitions()[i + 3]); move(getCurrent().getTransitions()[i + 2]); for (int j = 0; j < getSize() && !done; j++) if (getStates()[j].getName() == getCurrent().getTransitions()[i + 1]){ setCurrent(getStates()[j]); done = true; } } } }
void Player::moveBackward(){ if (getStates(States::HEALTH)){ m_position.x -= m_speed* m_deltaTime *m_viewDirection.x; m_position.y -= m_speed* m_deltaTime *m_viewDirection.y; m_position.z -= m_speed* m_deltaTime *m_viewDirection.z; //std::cout << "Player moveBwd" << std::endl; notify(*this, Object_Event::OBJECT_MOVED); } }
void Player::moveForward(){ if (getStates(States::HEALTH)){ m_position.x += m_speed* m_deltaTime *m_viewDirection.x; m_position.y += m_speed* m_deltaTime *m_viewDirection.y; m_position.z += m_speed* m_deltaTime *m_viewDirection.z; //std::cout << "Player moveFwd to: x:" << m_position.x << "; z: " << m_position.z << std::endl; notify(*this, Object_Event::OBJECT_MOVED); } }
void Player::turnRight(){ if (getStates(States::HEALTH)){ m_phi += m_speedTurn* m_deltaTime; if (m_phi < 0) m_phi += 360.0; else if (m_phi > 360) m_phi -= 360; rotateView(m_phi, m_theta); notify(*this, Object_Event::OBJECT_ROTATED); } }
void Player::moveRight(){ if (getStates(States::HEALTH)){ glm::vec3 directionOrtho = glm::cross(glm::vec3(m_viewDirection), glm::vec3(0, 1, 0)); m_position.x += m_speed* m_deltaTime*directionOrtho.x; m_position.y += m_speed* m_deltaTime*directionOrtho.y; m_position.z += m_speed* m_deltaTime*directionOrtho.z; //std::cout << "Player moveRight" << std::endl; notify(*this, Object_Event::OBJECT_MOVED); } }
void Player::update(){ if (m_health == 0){ //std::cout << "Player: Died" << std::endl; //TODO OBJECT_DIED, Weil "stopped" den Observervorgang bescheibt , wenn sich das Object nicht mehr bewegt notify(*this, Object_Event::PLAYER_DIED); notify(*this, Object_Event::OBJECT_STOPPED); setStates(States::HEALTH, false); } if (getStates(States::HEALTH)){ //std::cout << "<<<<<<<< UpdateMethod <<<<<<<<" << std::endl; updateStates(); //std::cout << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl; } if (m_i > 20){ m_i = 0; notify(*this, Object_Event::OBJECT_STOPPED); } m_i++; }
DFA::DFA(int _startState, int* _finalStates, int _countOfFinalStates, std::map<int, std::map<char, int> > _table) { int k = 0; for (int i = 97; i <= 122; i++) alphabet[k++] = (char) i; for (int i = 48; i <= 57; i++) alphabet[k++] = (char) i; alphabet[k] = '\0'; countOfAlphabet = k; table = _table; countOfFinalStates = _countOfFinalStates; countOfStates = getCountOfStates(); states = new int[countOfStates]; states = getStates(); finalStates = new int[countOfFinalStates]; std::sort(_finalStates, _finalStates + countOfFinalStates); for (int i = 0; i < countOfFinalStates; i++) finalStates[i] = _finalStates[i]; if (isValidState(_startState)) startState = _startState; else throw "Error: start state is not valid."; }
QJsonObject copySelected(const Scenario_T& sm, QObject* parent) { auto selectedConstraints = selectedElements(getConstraints(sm)); auto selectedEvents = selectedElements(getEvents(sm)); auto selectedTimeNodes = selectedElements(getTimeNodes(sm)); auto selectedStates = selectedElements(getStates(sm)); for(const ConstraintModel* constraint : selectedConstraints) { auto start_it = find_if(selectedStates, [&] (const StateModel* state) { return state->id() == constraint->startState();}); if(start_it == selectedStates.end()) { selectedStates.push_back(&sm.state(constraint->startState())); } auto end_it = find_if(selectedStates, [&] (const StateModel* state) { return state->id() == constraint->endState();}); if(end_it == selectedStates.end()) { selectedStates.push_back(&sm.state(constraint->endState())); } } for(const StateModel* state : selectedStates) { auto ev_it = find_if(selectedEvents, [&] (const EventModel* event) { return state->eventId() == event->id(); }); if(ev_it == selectedEvents.end()) { selectedEvents.push_back(&sm.event(state->eventId())); } // If the previous or next constraint is not here, we set it to null in a copy. } for(const EventModel* event : selectedEvents) { auto tn_it = find_if(selectedTimeNodes, [&] (const TimeNodeModel* tn) { return tn->id() == event->timeNode(); }); if(tn_it == selectedTimeNodes.end()) { selectedTimeNodes.push_back(&sm.timeNode(event->timeNode())); } // If some events aren't there, we set them to null in a copy. } std::vector<TimeNodeModel*> copiedTimeNodes; copiedTimeNodes.reserve(selectedTimeNodes.size()); for(const auto& tn : selectedTimeNodes) { auto clone_tn = new TimeNodeModel(*tn, tn->id(), parent); auto events = clone_tn->events(); for(const auto& event : events) { auto absent = none_of(selectedEvents, [&] (const EventModel* ev) { return ev->id() == event; }); if(absent) clone_tn->removeEvent(event); } copiedTimeNodes.push_back(clone_tn); } std::vector<EventModel*> copiedEvents; copiedEvents.reserve(selectedEvents.size()); for(const auto& ev : selectedEvents) { auto clone_ev = new EventModel(*ev, ev->id(), parent); auto states = clone_ev->states(); for(const auto& state : states) { auto absent = none_of(selectedStates, [&] (const StateModel* st) { return st->id() == state; }); if(absent) clone_ev->removeState(state); } copiedEvents.push_back(clone_ev); } std::vector<StateModel*> copiedStates; copiedStates.reserve(selectedStates.size()); auto& stack = iscore::IDocument::documentContext(*parent).commandStack; for(const StateModel* st : selectedStates) { auto clone_st = new StateModel(*st, st->id(), stack, parent); // NOTE : we must not serialize the state with their previous / next constraint // since they will change once pasted and cause crash at the end of the ctor // of StateModel. They are saved in the previous / next state of constraint anyway. SetNoPreviousConstraint(*clone_st); SetNoNextConstraint(*clone_st); copiedStates.push_back(clone_st); } QJsonObject base; base["Constraints"] = arrayToJson(selectedConstraints); base["Events"] = arrayToJson(copiedEvents); base["TimeNodes"] = arrayToJson(copiedTimeNodes); base["States"] = arrayToJson(copiedStates); for(auto elt : copiedTimeNodes) delete elt; for(auto elt : copiedEvents) delete elt; for(auto elt : copiedStates) delete elt; return base; }
int main(void) { //Initialization routines initIO(); setPort(&PORTB); sendColor(LEDCLK,LEDDAT,colors[0]); sei(); initAD(); initTimer(); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_enable(); //Set up timing ring buffers for(uint8_t i = 0; i<6; i++){ timeBuf[i]=0; } mode = running; while(1) { if(mode==sleep){ disAD(); // DDRB &= ~IR;//Set direction in PORTB &= ~IR;//Set pin tristated sendColor(LEDCLK, LEDDAT, dark); PORTA |= POWER;//Set LED and Mic power pin high (off) wake = 0; while(!wake){ cli(); uint32_t diff = timer-powerDownTimer; sei(); if(diff>500){ sleep_cpu(); wake = 1; } } holdoff=500; PORTA &= ~POWER; uint8_t done = 0; cli(); uint32_t startTime = timer; sei(); while(!done){ cli(); uint32_t time = timer; sei(); if(time-startTime>250){ done=1; } } done = 0; cli(); startTime = timer; sei(); DDRB |= IR;//Set direction out PORTB |= IR;//Set pin on sendColor(LEDCLK, LEDDAT, transmitColor); while(!done){ cli(); uint32_t time = timer; sei(); if(time-startTime>500){ done=1; } } enAD(); powerDownTimer = timer; sleepTimer = timer; mode = running; }else if(mode==running){ if(click){ uint8_t neighborStates[6]; getStates(neighborStates); uint8_t clickColor[] = {bright(colors[state][0]),bright(colors[state][1]),bright(colors[state][2])}; sendColor(LEDCLK, LEDDAT, clickColor); uint8_t numOn = 0; sync = 3;//request sync pulse be sent at next possible opportunity (set to 4 for logistical reasons) for (uint8_t i = 0; i< 6; i++) { //at the moments specific state detection is a bit iffy, //so mapping any received state>1 to a state of 1 works for now if(neighborStates[i]>0){ numOn++; } } //Logic for what to do to the state based on number of on neighbors if(state == 0) { if(birthRules[numOn]) { state=1; } } else { if(deathRules[numOn]) { state = (state + 1) % numStates; } } //End logic //prevent another click from being detected for a bit holdoff = 100; click = 0; } //periodically update LED once every 0x3F = 64 ms (fast enough to feel responsive) cli(); if(!(timer & 0x3F)){ if(timer!=lastTime){ lastTime=timer; cycleTimer++; cycleTimer %= CYCLE_TIME; uint8_t outColor[3] = {(colors[state][0]*breatheCycle[cycleTimer])/255, (colors[state][1]*breatheCycle[cycleTimer])/255, (colors[state][2]*breatheCycle[cycleTimer])/255}; sendColor(LEDCLK, LEDDAT, outColor); } } sei(); //check if we enter sleep mode cli();//temporarilly prevent interrupts to protect timer if(timer-sleepTimer>1000*TIMEOUT){ mode = sleep; } sei(); }else if(mode==recieving){ //disable A/D disAD(); //set photo transistor interrupt to only trigger on specific direction setDir(progDir); //set recieving color sendColor(LEDCLK, LEDDAT, recieveColor); //record time entering the mode for timeout cli(); uint32_t modeStart = timer; sei(); while(mode==recieving){//stay in this mode until instructed to leave or timeout cli(); uint32_t diff = timer-modeStart; sei(); if(diff>3000){//been in mode 1 for more than 5 seconds mode = transmitting; } } }else if(mode==transmitting){ //disable Phototransistor Interrupt setDirNone(); //set LED to output DDRB |= IR;//Set direction out //send 5 pulses uint32_t startTime = timer; if(bitsRcvd>=8 && comBuf[0]!=seqNum){ for(int i=0; i<5; i++){ while(timer==startTime){ PORTB &= ~IR; } startTime = timer; while(timer==startTime){ PORTB |= IR; } startTime = timer; } parseBuffer(); }else{ bitsRcvd = 0; } startTime = timer; sendColor(LEDCLK, LEDDAT, transmitColor);//update color while waiting while(timer<startTime+20);//pause for mode change startTime = timer; uint16_t timeDiff; uint16_t bitNum; while(bitsRcvd>0){ timeDiff = (timer-startTime)/PULSE_WIDTH; bitNum = timeDiff/2; if(timeDiff%2==0){//first half if(comBuf[bitNum/8]&(1<<bitNum%8)){//bit high PORTB &= ~IR; }else{//bit low PORTB |= IR; } }else{//second half if(comBuf[bitNum/8]&(1<<bitNum%8)){//bit high PORTB |= IR; }else{//bit low PORTB &= ~IR; } } if(bitNum>=bitsRcvd){ bitsRcvd = 0; } } //while(timer<startTime+2000);//pause for effect //done transmitting //re-enable A/D enAD(); //re-enable all phototransistors setDirAll(); state = 0; mode = running; } } }