// ---------------------------------------------------------------------- void LocalizationMinMaxModule:: work( void ) throw() { if ( owner().is_anchor() ) state_ = minmax_finished; if ( state_ == minmax_finished ) return; if ( state_ == minmax_wait ) state_ = minmax_work; shawn::Vec est_pos; NeighborInfoList neighbors; collect_neighbors( neighborhood(), lat_anchors, neighbors ); if ( est_pos_min_max( neighbors, est_pos ) ) { if ( !observer().check_residue() || check_residue( neighbors, est_pos, lat_anchors, observer().comm_range() ) ) node_w().set_est_position( est_pos ); } state_ = minmax_finished; }
// ---------------------------------------------------------------------- void NodeMovement:: movement_update_boxes() throw() { MovementObservable::movement_update_boxes(node_w(), position(), velocity()); }
// ---------------------------------------------------------------------- void LocalizationDLSModule:: estimate_position( void ) throw(){ shawn::Vec* est_pos; double distance_r1,distance_r2; int count =0; distance_r1 = owner().estimate_distance(node(), *linearization_tool_); distance_r1 *=distance_r1; NeighborInfoList neighbors; collect_neighbors( neighborhood(), lat_anchors, neighbors ); for( std::vector<shawn::Node*>::iterator iter = beacons_->begin(); iter!=beacons_->end();iter++,count++){ for( ConstNeighborInfoListIterator iter1 = neighbors.begin(); iter1!=neighbors.end(); iter1++){ if((*iter)->id() == (*iter1)->node().id() ){ distance_r2 = (*iter1)->distance(); //distance_r2 = owner().estimate_distance(node(), **iter); if(distance_r2 == std::numeric_limits<double>::max() ||distance_r2 == std::numeric_limits<double>::min()) vector_r_->at(count,0) = 0; else vector_r_->at(count,0) = 0.5*( distance_r1 - (distance_r2*distance_r2) + (vector_r_->at(count,0))); break; } } } SimpleMatrix<double>* temp = new SimpleMatrix<double>(3,1); *temp= *matrix_a_ * *vector_r_; est_pos = new shawn::Vec(temp->at(0,0),temp->at(1,0),temp->at(2,0)); *est_pos += (linearization_tool_->has_est_position())? (linearization_tool_->est_position()):(linearization_tool_->real_position()); node_w().set_est_position( *est_pos ); delete temp; }
void nano::rep_crawler::query (std::vector<std::shared_ptr<nano::transport::channel>> const & channels_a) { auto transaction (node.store.tx_begin_read ()); std::shared_ptr<nano::block> block (node.store.block_random (transaction)); auto hash (block->hash ()); // Don't send same block multiple times in tests if (node.network_params.network.is_test_network ()) { for (auto i (0); exists (hash) && i < 4; ++i) { block = node.store.block_random (transaction); hash = block->hash (); } } add (hash); for (auto i (channels_a.begin ()), n (channels_a.end ()); i != n; ++i) { on_rep_request (*i); nano::confirm_req message (block); (*i)->send (message); } // A representative must respond with a vote within the deadline std::weak_ptr<nano::node> node_w (node.shared ()); node.alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (5), [node_w, hash]() { if (auto node_l = node_w.lock ()) { node_l->rep_crawler.remove (hash); } }); }
// ---------------------------------------------------------------------- void NodeMovement:: observers_added(MovementObserver& obs) throw() { obs.observer_initial_zone(node_w(), position(), velocity() ); movement_update_boxes(); boxes_changed(); }
// ---------------------------------------------------------------------- void LocalizationIterLaterationModule:: work( void ) throw() { if ( state_ == il_finished ) return; // do initial stuff; // if anchor, send 'init-message' and set state to 'finished'; // if unknown, check whether the node is sound or not. if sound, // send messages, if not, clear estimated position. if ( state_ == il_init ) { if ( owner().is_anchor() ) { send( new LocalizationIterLaterationMessage( observer().confidence() ) ); state_ = il_finished; } else { sound_ = neighborhood().is_sound(); if ( sound_ && node().has_est_position() ) { send( new LocalizationIterLaterationMessage( observer().confidence() ) ); send( new LocalizationIterLaterationSoundMessage() ); } else { set_confidence( 0 ); node_w().clear_est_position(); } state_ = il_work; } } if ( state_ == il_work ) iter_lateration_step(); }
void nano::rep_crawler::ongoing_crawl () { auto now (std::chrono::steady_clock::now ()); auto total_weight_l (total_weight ()); query (get_crawl_targets (total_weight_l)); auto sufficient_weight (total_weight_l > node.config.online_weight_minimum.number ()); // If online weight drops below minimum, reach out to preconfigured peers if (!sufficient_weight) { node.keepalive_preconfigured (node.config.preconfigured_peers); } // Reduce crawl frequency when there's enough total peer weight unsigned next_run_seconds = sufficient_weight ? 7 : 3; std::weak_ptr<nano::node> node_w (node.shared ()); node.alarm.add (now + std::chrono::seconds (next_run_seconds), [node_w, this]() { if (auto node_l = node_w.lock ()) { this->ongoing_crawl (); } }); }
// ---------------------------------------------------------------------- void LocalizationIterLaterationModule:: iter_lateration_step( void ) throw() { if ( state_ == il_finished || !sound_ ) return; if ( iteration_cnt_ >= iteration_limit_ ) state_ = il_finished; ++iteration_cnt_; neighborhood_w().reassign_twins( twin_measure_ * observer().comm_range() ); if ( neighborhood().confident_neighbor_cnt() < min_confident_nbrs_ ) return; Vec est_pos; NeighborInfoList neighbors; collect_neighbors( neighborhood(), lat_confident, neighbors ); // try to update position. if lateration fails, confidence is set to 0, // else position is updated and confidence is set to average of all // neighbor confidences if ( est_pos_lateration( neighbors, est_pos, lat_confident, false ) && est_pos_lateration( neighbors, est_pos, lat_confident, true ) ) { set_confidence( neighborhood().avg_neighbor_confidence() ); // check validity of new position. if check fails, there is a chance // of 'res_acceptance_', which is normally set to 0.1, to accept // the position anyway. this is done to avoid being trapped in a // local minimum. moreover, if the bad position is accepted, the // confidence is reduced by 50%. if ( !check_residue( neighbors, est_pos, lat_confident, observer().comm_range() ) ) { if ( res_acceptance_ > uniform_random_0i_1i() ) set_confidence( observer().confidence() / 2 ); else { if ( observer().confidence() == 0 ) return; set_confidence( 0 ); node_w().clear_est_position(); send( new LocalizationIterLaterationMessage( observer().confidence() ) ); return; } } // check, whether the new position is very close to the old one or // not. if so, refinement is finished. if ( node().has_est_position() ) { double pos_diff = euclidean_distance( est_pos, node().est_position() ); if ( pos_diff < abort_pos_update_ * observer().comm_range() ) state_ = il_finished; } node_w().set_est_position( est_pos ); } else { if ( observer().confidence() == 0 ) return; set_confidence( 0 ); node_w().clear_est_position(); } send( new LocalizationIterLaterationMessage( observer().confidence() ) ); }