/** * @brief generate */ sPointer generate() const { assert(lhs && rhs); sPointer lcs = std::make_shared<Range>(); //! lambda to do the real work using Lambda = std::function<void(SizeType, SizeType)>; Lambda build_lcs = [&lcs, &build_lcs, this](SizeType l, SizeType r) { //! stop condition if(l == 0 || r == 0) return; //! recur if((*lhs)[l - 1] == (*rhs)[r - 1]) { build_lcs(l - 1, r - 1); lcs->push_back((*lhs)[l - 1]); } else if (maze(l - 1, r) >= maze(l, r - 1)) build_lcs(l - 1, r); else build_lcs(l, r - 1); }; //! call the lambda build_lcs(lhs->size(),rhs->size()); return lcs; }
// ---------------------------------------------------------------------- void LocalizationGPSfreeLCSModule:: work( void ) throw() { // send initial messages if ( state_ == gflcs_init ) { send( new LocalizationGPSfreeLCSInitMessage() ); state_ = gflcs_wait_bc; } // after idle-time passed, initial messages of neighbors had already been // received and state is set to 'broadcast'. if ( state_ == gflcs_wait_bc && simulation_round() - last_useful_msg_ > observer().idle_time() ) { state_ = gflcs_broadcast; last_useful_msg_ = simulation_round(); } // broadcast collected information if ( state_ == gflcs_broadcast ) { broadcast_neighborhood(); state_ = gflcs_wait_w; } // after idle-time passed, neighborhood messages of neighbors had already been // received and state is set to 'work'. if ( state_ == gflcs_wait_w && simulation_round() - last_useful_msg_ > observer().idle_time() ) state_ = gflcs_work; if ( state_ == gflcs_work ) { build_lcs(); state_ = gflcs_finished; } // maybe shutdown processor if ( simulation_round() - last_useful_msg_ > observer().idle_shutdown_time() ) { state_ = gflcs_finished; } }