TEST(wali$wfa$$WFA$$semideterminize, weightGenAcceptingStates) { sem_elem_t reach_one = Reach(true).one(); sem_elem_t reach_zero = Reach(true).zero(); Letters letters; Key start = getKey("start"), acc1 = getKey("acc1"), acc2 = getKey("acc2"), rej = getKey("rej"); // --> start -----> ((acc1)) // | | // | +------> ((acc2)) // | // +---------> rej WFA nondet; nondet.addState(start, reach_zero); nondet.addState(acc1, reach_zero); nondet.addState(acc2, reach_zero); nondet.addState(rej, reach_zero); nondet.setInitialState(start); nondet.addFinalState(acc1); nondet.addFinalState(acc2); nondet.addTrans(start, letters.a, acc1, reach_one); nondet.addTrans(start, letters.a, acc2, reach_one); nondet.addTrans(start, letters.a, rej, reach_one); WFA det = nondet.semideterminize(TestLifter()); // Sanity checks std::set<Key> start_set, fin_set; start_set.insert(start); fin_set.insert(acc1); fin_set.insert(acc2); fin_set.insert(rej); Key start_set_key = getKey(start_set), fin_set_key = getKey(fin_set); ASSERT_EQ(2u, det.getStates().size()); ASSERT_CONTAINS(det.getStates(), start_set_key); ASSERT_CONTAINS(det.getStates(), fin_set_key); // Extract the transition, then the weight StringWeight * w = dynamic_cast<StringWeight*>(det.getState(fin_set_key)->acceptWeight().get_ptr()); ASSERT_TRUE(w != NULL); // Test. This is maybe a fragile (though not as much as before)... EXPECT_EQ(" | acc1 | acc2", w->str); }
TEST(wali$wfa$$isIsomorphicTo, isomorphismChecksStateWeights) { sem_elem_t one = Reach(true).one(); sem_elem_t zero = Reach(true).zero(); Letters l; WFA w0, w1; w0.addState(l.a, zero); w1.addState(l.a, one); EXPECT_FALSE(w0.isIsomorphicTo(w1)); }
TEST(wali$wfa$$isIsomorphicTo, isomorphismIgnoresStateWeightsWhenCheckWeghtsIsFalse) { sem_elem_t one = Reach(true).one(); sem_elem_t zero = Reach(true).zero(); Letters l; WFA w0, w1; w0.addState(l.a, zero); w1.addState(l.a, one); EXPECT_TRUE(w0.isIsomorphicTo(w1, false)); }
TEST(wali$wfa$$semideterminize, initialStateGetsLabeledWithTheCorrectKindOfWeight) { // zero // -> A ---> (B) Key A = getKey("A"); Key B = getKey("B"); sem_elem_t zero = Reach(true).zero(); WFA wfa; wfa.addState(A, zero); wfa.addState(B, zero); wfa.addTrans(A, A, B, zero); wfa.setInitialState(A); wfa.addFinalState(B); WFA det = wfa.semideterminize(TestLifter()); sem_elem_t initial_weight = det.getState(det.getInitialState())->weight(); Reach * reach = dynamic_cast<Reach*>(initial_weight.get_ptr()); StringWeight * str = dynamic_cast<StringWeight*>(initial_weight.get_ptr()); EXPECT_EQ(NULL, reach); EXPECT_TRUE(str != NULL); }
// FIXME: this isn't a test! TEST(wali$wfa$$semideterminize, zeroWeightPathDoesNotAccept) { // zero // -> A ---> (B) Key A = getKey("A"); Key B = getKey("B"); sem_elem_t zero = Reach(true).zero(); WFA wfa; wfa.addState(A, zero); wfa.addState(B, zero); wfa.addTrans(A, A, B, zero); wfa.setInitialState(A); wfa.addFinalState(B); WFA det = wfa.semideterminize(); wfa.print(std::cerr); det.print(std::cerr); WFA::Word w; w.push_back(A); std::cerr << "wfa accepts: " << wfa.isAcceptedWithNonzeroWeight(w) << "\n"; std::cerr << "det accepts: " << det.isAcceptedWithNonzeroWeight(w) << "\n"; }
int Reaching::StartRecordTraj(joint_vec_t& initpos){ if(SetActualRobPosition(initpos)){ return Reach(); } else{ return -1; //unvalid init position } }
TEST(wali$wfa$$isIsomorphicTo, loopRejectAndSimilar) { LoopReject f; WFA wfa; sem_elem_t one = Reach(true).one(); sem_elem_t zero = Reach(true).zero(); Letters l; Key state = getKey("different state"); ASSERT_NE(state, f.state); wfa.addState(state, zero); wfa.setInitialState(state); wfa.addTrans(state, l.a, state, one); wfa.addTrans(state, l.b, state, one); wfa.addTrans(state, l.c, state, one); EXPECT_TRUE(f.wfa.isIsomorphicTo(wfa)); }
void GlideComputerRoute::ProcessRoute(const MoreData &basic, DerivedInfo &calculated, const DerivedInfo &last_calculated, const RoutePlannerConfig &config, const GlidePolar &glide_polar, const GlidePolar &safety_polar) { protected_route_planner.SetPolars(glide_polar, safety_polar, calculated.wind); Reach(basic, calculated, config); TerrainWarning(basic, calculated, last_calculated, config); }
void RouteComputer::ProcessRoute(const MoreData &basic, DerivedInfo &calculated, const GlideSettings &settings, const RoutePlannerConfig &config, const GlidePolar &glide_polar, const GlidePolar &safety_polar) { if (!basic.location_available || !basic.NavAltitudeAvailable()) return; protected_route_planner.SetPolars(settings, glide_polar, safety_polar, calculated.GetWindOrZero()); Reach(basic, calculated, config); TerrainWarning(basic, calculated, config); }
void Climber_Class::AutoClimb(int state) { bool climb; bool reach; bool pushOut; bool safety; bool release; switch(state) { case AUTO_CLIMB_STATE_1: //brings the towers stationary hooks all the way up //The towers need to be reset, but only once /*if(firstReach) { ResetTowers(); firstReach = false; }*/ if(startCC) { ResetTowers(); startCC = false; } inState = ReachDistance(LEVEL_1A_REACH_POS); break; case AUTO_CLIMB_STATE_2: //pushes the candy cane out inState = (bool)candyCane->PushOut(); //The startCC boolean only allows the CC functions to be called once per state startCC = true; break; case AUTO_CLIMB_STATE_3: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Grab the pole if(startCC) { candyCane->StartGrab(LEVEL_1_GRAB_POS); //This line makes the CC only grab once startCC = false; } //If we're done grabbing, inState will be false and we can go to the next state otherwise it will be true inState = (bool)candyCane->Grab(); break; case AUTO_CLIMB_STATE_4: //climb until arms grab the horizontal bar //If we're still climbing inState is set to true, otherwise it is set to false inState = (bool)ClimbDistance(LEVEL_1A_CLIMB_POS); //Tell the CC it can move in the next state startCC = true; break; case AUTO_CLIMB_STATE_5: //Release the CC if(startCC) { //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); candyCane->StartRelease(); startCC = false; release = true; climb = true; } //If we're done releasing, inState will be set to false so we can go to the next state, otherwise it will be true release = (bool)candyCane->Release(); climb = (bool)Climb(); if(!climb && !release) { inState = false; } break; /*case AUTO_CLIMB_STATE_6: //Climb until the hooks transition //Check to see if we're still climbing inState = (bool)Climb(); break;*/ case AUTO_CLIMB_STATE_6: //Reach until the CC is clear if(startCC) { reach = true; pushOut = true; startCC = false; bringOutCC = true; } //Check to see if we're still reaching reach = (bool)ReachDistance(LEVEL_2A_REACH_POS); //Once the towers reached a certain distance, push out the CC if((leftTower->GetDistance() >= DISTANCE_FOR_EXTENDEING_CC) && bringOutCC) { candyCane->StartSafety(LEVEL_2A_SAFETY_POS); bringOutCC = false; } pushOut = candyCane->Safety(); //If we're not reaching or pushing out, we're not in the state anymore if(!reach && !pushOut) { inState = false; } /*//Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_2A_REACH_POS); //Tell the CC it can move in the next state startCC = true;*/ break; //Level 2 /*case AUTO_CLIMB_STATE_7: //CC safety position if(startCC) { candyCane->StartSafety(LEVEL_2A_SAFETY_POS); //This line makes the CC go into the safety position only once startCC = false; } inState = (bool)candyCane->Safety(); break;*/ case AUTO_CLIMB_STATE_7: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Bring in the CC so the servo turns if(startCC) { candyCane->StartLeanIn(LEVEL_2A_SAFETY_LEAN_POS); startCC = false; } inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_8: //Reach until the CC grabs the vertical bar //Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_2B_REACH_POS); //Tell the CC it can move in the next state startCC = true; break; case AUTO_CLIMB_STATE_9: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean a little bit if(startCC) { candyCane->StartLeanIn(LEVEL_2A_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_10: //Reach all the way //Check to see if we're still reaching inState = (bool)Reach(); startCC = true; break; case AUTO_CLIMB_STATE_11: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean in until the arms touch the horizontal bars if(startCC) { candyCane->StartLeanIn(LEVEL_2B_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_12: //climb until the arms grab the horizontal bars //Check to see if we're still climbing inState = (bool)ClimbDistance(LEVEL_2A_CLIMB_POS); startCC = true; break; /*case AUTO_CLIMB_STATE_14: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //CC safety if(startCC) { candyCane->StartSafety(LEVEL_2B_SAFETY); startCC = false; } //Check to see if we're still safetying inState = (bool)candyCane->Safety(); break;*/ case AUTO_CLIMB_STATE_13: //Release the CC if(startCC) { //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); candyCane->StartRelease(); startCC = false; climb = true; release = true; } //Climb until the hooks transition //Check to see if we're still climbing climb = (bool)Climb(); release = (bool)candyCane->Release(); if(!climb && !release) { inState = false; } break; /*case AUTO_CLIMB_STATE_16: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Release the CC if(startCC) { candyCane->StartRelease(); startCC = false; } //Check to see if we're still releasing inState = (bool)candyCane->Release(); break;*/ //Level 3 case AUTO_CLIMB_STATE_14: //Reach until the CC is clear if(startCC) { reach = true; pushOut = true; bringOutCC = true; startCC = false; } //Check to see if we're still reaching reach = (bool)ReachDistance(LEVEL_3A_REACH_POS); //Once the towers reached a certain distance, push out the CC if((leftTower->GetDistance() >= DISTANCE_FOR_EXTENDEING_CC) && bringOutCC) { candyCane->StartSafety(LEVEL_3A_SAFETY_POS); bringOutCC = false; } pushOut = candyCane->Safety(); //If we're not reaching or pushing out, we're not in the state anymore if(!reach && !pushOut) { inState = false; } /*//Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_3A_REACH_POS); startCC = true;*/ break; /*case AUTO_CLIMB_STATE_16: //CC safety if(startCC) { candyCane->StartSafety(LEVEL_3A_SAFETY_POS); startCC = false; } //Check to see if we're still safetying inState = (bool)candyCane->Safety(); break;*/ case AUTO_CLIMB_STATE_15: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Bring in the CC so the servo turns if(startCC) { candyCane->StartLeanIn(LEVEL_3A_SAFETY_LEAN_POS); startCC = false; } inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_16: //Reach until the CC grabs the verticle bar //Check to see if we're still reaching inState = (bool)ReachDistance(LEVEL_3B_REACH_POS); startCC = true; break; case AUTO_CLIMB_STATE_17: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean in if(startCC) { candyCane->StartLeanIn(LEVEL_3A_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_18: //Reach all the way //Check to see if we're still reaching inState = (bool)Reach(); startCC = true; break; case AUTO_CLIMB_STATE_19: //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); //Lean in until the arms hit the horizontal bar if(startCC) { candyCane->StartLeanIn(LEVEL_3B_LEAN_POS); startCC = false; } //Check to see if we're still leaning in inState = (bool)candyCane->LeanIn(); break; case AUTO_CLIMB_STATE_20: //climb until the arms grab the horizontal bars //Check to see if we're still climbing inState = (bool)ClimbDistance(LEVEL_3A_CLIMB_POS); startCC = true; break; case AUTO_CLIMB_STATE_21: //CC safety if(startCC) { //Reset the towers so we know we can move them in the next state ResetTowers(); TowersStop(); candyCane->StartSafety(LEVEL_3B_SAFETY_POS); startCC = false; safety = true; climb = true; } //Check to see if we're still safetying safety = (bool)candyCane->Safety(); climb = (bool)ClimbDistance(LEVEL_3B_CLIMB_POS); if(!safety && !climb) { inState = false; } break; /*case AUTO_CLIMB_STATE_27: //Climb until we want to stop and win ////Check to see if we're still climbing inState = (bool)ClimbDistance(LEVEL_3B_CLIMB_POS); break;*/ } /*grabbing = (bool)candyCane->Grab(); safetying = (bool)candyCane->Safety(); releasing = (bool)candyCane->Release(); leaningIn = (bool)candyCane->LeanIn();*/ }