void nest::ppd_sup_generator::update( Time const& T, const long_t from, const long_t to ) { assert( to >= 0 && ( delay ) from < Scheduler::get_min_delay() ); assert( from < to ); if ( P_.rate_ <= 0 || P_.num_targets_ == 0 ) return; for ( long_t lag = from; lag < to; ++lag ) { Time t = T + Time::step( lag ); if ( !device_.is_active( t ) ) continue; // no spike at this lag // get current (time-dependent) hazard rate and store it. if ( P_.amplitude_ > 0.0 && ( P_.frequency_ > 0.0 || P_.frequency_ < 0.0 ) ) { double_t t_ms = t.get_ms(); V_.hazard_step_t_ = V_.hazard_step_ * ( 1.0 + P_.amplitude_ * std::sin( V_.omega_ * t_ms ) ); } else V_.hazard_step_t_ = V_.hazard_step_; DSSpikeEvent se; network()->send( *this, se, lag ); } }
void ProjectionModifierTriesch::Clear() { // 1. Clear weight values vector<float> postValues = m_projectionFixed->GetPostValues(); vector<vector<long> >* preIds;// = m_projectionFixed->PreIds(); // move to initializer (until Invalidate().. called) long preId, postId; // need max post id for N-function for(int j=0;j<postValues.size();j++) { vector<float> preValues = m_projectionFixed->GetPreValues(m_idsPost[j]); postId = m_idsPost[j]; for(int i=0;i<preValues.size();i++) { preId = (*preIds)[j][i]; network()->SetWeight(0.0,preId,postId); } } // 2. Clear transfer function values ((TransferTriesch*)m_transferFunction)->Clear(); }
void place_cell_generator::update(Time const & T, const long_t from, const long_t to) { assert(to >= 0 && (delay) from < Scheduler::get_min_delay()); assert(from < to); for (long_t lag = from; lag < to; ++lag) { long_t now = T.get_steps() + lag; if (device_.is_active(T + Time::step(lag))) { librandom::RngPtr rng = net_->get_rng(get_thread()); ulong_t n_spikes = poisson_dev_.uldev(rng); if (n_spikes > 0) // we must not send events with multiplicity 0 { nest::SpikeEvent se; se.set_multiplicity(n_spikes); network()->send(*this, se, lag); } // Advance the positional information if there is space in the // positional vector if (now >= next_pos_step) { next_pos_step = now + sim_dt_per_pos_dt; if (pos_it < P_.rat_pos_x.size() - 1) pos_it++; setFiringRate(); } } } }
QList<QByteArray> CoreBasicHandler::channelEncode(const QString& bufferName, const QStringList& stringlist) { QList<QByteArray> list; foreach (QString s, stringlist) list << network()->channelEncode(bufferName, s); return list; }
void CControlWidget::slot_openTrace() { if (static_cast<CAbstractItem *>(ui->treeView->currentIndex().internalPointer()) ->itemType() == CAbstractItem::Trace) { if (m_reply) { m_reply->abort(); } m_lastTraceItem = static_cast<CTraceItem *>(ui->treeView->currentIndex().internalPointer()); // create new query QUrl queryUrl("http://service.iris.edu/irisws/timeseries/1/query"); queryUrl.addQueryItem("output", "miniseed"); queryUrl.addQueryItem("net", m_lastTraceItem->fdsn()); queryUrl.addQueryItem("sta", m_lastTraceItem->station()); queryUrl.addQueryItem("loc", m_lastTraceItem->location()); queryUrl.addQueryItem("cha", m_lastTraceItem->channel()); queryUrl.addQueryItem("start", m_lastTraceItem->phaseDateTime() .addSecs(-ui->spinBox_secondBefore->value()).toString("yyyy-MM-ddTHH:mm:ss")); queryUrl.addQueryItem("end", m_lastTraceItem->phaseDateTime() .addSecs(ui->spinBox_secondAfter->value()).toString("yyyy-MM-ddTHH:mm:ss")); // threre should be log output qDebug() << queryUrl.toString(); // show progress bar m_reply = network()->get(QNetworkRequest(queryUrl)); connect(m_reply, SIGNAL(finished()), this, SLOT(slot_reply_Finished())); connect(m_reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slot_reply_downloadProgress(qint64,qint64))); emit aboutSoundToBeCreated(); } }
QList<QByteArray> CoreBasicHandler::serverEncode(const QStringList& stringlist) { QList<QByteArray> list; foreach (QString s, stringlist) list << network()->serverEncode(s); return list; }
QStringList CoreBasicHandler::userDecode(const QString& userNick, const QList<QByteArray>& stringlist) { QStringList list; foreach (QByteArray s, stringlist) list << network()->userDecode(userNick, s); return list; }
QStringList CoreBasicHandler::serverDecode(const QList<QByteArray>& stringlist) { QStringList list; foreach (QByteArray s, stringlist) list << network()->serverDecode(s); return list; }
int main(int argc, char *argv[]) { if (argc != 2) //Test for correct number of arguments { cerr << "Usage: " << argv[0] << " <Server Port>" << endl; exit(1); } unsigned short servPort = atoi(argv[1]); //First arg: local port /* Make the Threaded Network */ ThreaddedNetwork network(servPort); while(true) { /* get any new messages from the network */ std::vector<std::string> data = network.getNewMessages(); if(!data.empty()) { std::cout << "Received new data:\n"; for(int i=0; i<data.size(); i++) { std::cout << data.at(i) << "\n"; } std::cout <<"End new data\n"; } } return 0; }
void IrcChannel::joinIrcUsers(const QStringList &nicks, const QStringList &modes) { QList<IrcUser *> users; foreach(QString nick, nicks) users << network()->newIrcUser(nick); joinIrcUsers(users, modes); }
TEST (peer_container, empty_peers) { nano::system system (24000, 1); nano::network & network (system.nodes[0]->network); system.nodes[0]->network.cleanup (std::chrono::steady_clock::now ()); ASSERT_EQ (0, network.size ()); }
int main(){ s/*FILE *stdin=fopen("teste.txt","r");*/ int n,m; fscanf(stdin,"%d",&n); fscanf(stdin,"%d",&m); int i,j; int a,b; for(i=0;i<n;i++){ arrayTemp[i]=0; for(j=0;j<n;j++){ array[i][j]=0; } } for(i=0;i<m;i++){ fscanf(stdin,"%d %d",&a,&b); array[a][b]=1; array[b][a]=1; } if(m>0){ network(n,0,0); printf("%d\n",levelMax); } else{ printf("%d\n",n); } return 0; }
QList<QByteArray> CoreBasicHandler::userEncode(const QString& userNick, const QStringList& stringlist) { QList<QByteArray> list; foreach (QString s, stringlist) list << network()->userEncode(userNick, s); return list; }
// ---- Function verify_town_before_merge ---- // Adds some robustness for errors by checking a town and fixing errors // in the town network structure. Used only by town_create. // // - nationRecno: the nation recno of the town that is created // - townRecno: the recno of the town to check. This should be a town linked to the newly created town. // void TownNetworkArray::verify_town_network_before_merge(int nationRecno, int townRecno) { Town *pTown = town_array[townRecno]; int tnRecno = pTown->town_network_recno; bool shouldFix = false; if (tnRecno < 1 || tnRecno > size()) { if (DEBUG_CHECK) throw "town_created: one of the same-nation linked towns has an invalid town network recno"; else shouldFix = true; } else if (network(tnRecno) == NULL) { if (DEBUG_CHECK) throw "Town Network has been deleted, but towns still point to its recno"; else shouldFix = true; } // Fixing errors in the town-network structure, by creating a new town network for the town if (shouldFix) { TownNetwork *pTN = add_network(nationRecno); pTN->add_town(townRecno); } }
TransportationNetwork BipartiteGraph::createTransportationNetwork() { std::vector< std::vector<int> > capacity_adjacency_matrix; int vertex_number = 1 + this->left_vertex_number + this->rigth_vertex_number + 1; capacity_adjacency_matrix.resize(vertex_number); for (int vertex_count=0; vertex_count < vertex_number; vertex_count++) capacity_adjacency_matrix[vertex_count].resize(vertex_number, 0); for (int left_vertex_count=0; left_vertex_count < this->left_vertex_number; left_vertex_count++) { capacity_adjacency_matrix[0][1+left_vertex_count] = 1; capacity_adjacency_matrix[1+left_vertex_count][0] = -1; for (int rigth_vertex_count=0; rigth_vertex_count < this->rigth_vertex_number; rigth_vertex_count++) if (this->link_list[left_vertex_count][rigth_vertex_count]) { capacity_adjacency_matrix[1+left_vertex_count][1+this->left_vertex_number+rigth_vertex_count] = 1; capacity_adjacency_matrix[1+this->left_vertex_number+rigth_vertex_count][1+left_vertex_count] = -1; } } for (int rigth_vertex_count=0; rigth_vertex_count < this->rigth_vertex_number; rigth_vertex_count++) { capacity_adjacency_matrix[1+this->left_vertex_number+rigth_vertex_count][vertex_number-1] = 1; capacity_adjacency_matrix[vertex_number-1][1+this->left_vertex_number+rigth_vertex_count] = -1; } TransportationNetwork network(capacity_adjacency_matrix); network.setSource(0); network.setSink(vertex_number-1); return network; }
QByteArray IrcChannel::encodeString(const QString &string) const { if (codecForEncoding()) { return _codecForEncoding->fromUnicode(string); } return network()->encodeString(string); }
int main() { unsigned char no[4] = { 0 }; unsigned int a = 0x0123; host(no, a); network(no, a); }
void ProjectionModifierBCM::Initialize(Projection* Projection) { network(Projection->network()); m_projectionFixed = Projection; m_firstRun = true; m_idsPost = m_projectionFixed->GetPostIds(); }
void nest::hh_cond_exp_traub::handle(SpikeEvent & e) { assert(e.get_delay() > 0); if(e.get_weight() > 0.0) { B_.spike_exc_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()), e.get_weight() * e.get_multiplicity()); } else { // add with negative weight, ie positive value, since we are changing a // conductance B_.spike_inh_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()), -e.get_weight() * e.get_multiplicity()); } }
void nest::iaf_neuron_dif_alpha::handle(SpikeEvent & e) { assert(e.get_delay() > 0); B_.spikes_.add_value(e.get_rel_delivery_steps(network()->get_slice_origin()), e.get_weight() * e.get_multiplicity() ); //std::cout<<"spike handle "<<e.get_stamp().get_ms()<<"\n"; }
void nest::iaf_neuron::handle( SpikeEvent& e ) { assert( e.get_delay() > 0 ); B_.spikes_.add_value( e.get_rel_delivery_steps( network()->get_slice_origin() ), e.get_weight() * e.get_multiplicity() ); }
void Enemy::logic(int stage_velocity, string stage_name, int global_iteration, string username) { animationControl(); spellControl(stage_velocity); for (std::list<Pattern*>::iterator pattern = active_patterns->begin(); pattern != active_patterns->end(); pattern++) { Pattern* p = (Pattern*)*pattern; double distance_x= player->getHitbox().getX() - p->getX(); double distance_y= player->getHitbox().getY() - p->getY(); if (p->getHoming() != 0) { p->setAngle(-atan2(distance_y,distance_x)*180/PI); } else if(p->getAimPlayer()) { p->setAngle(p->getAngle()-atan2(distance_y,distance_x)*180/PI); } } if(this->hp>0) modifiersControl(); else { if(orientation!="destroyed" && flag_begin_upload) { orientation="destroyed"; if(this->sonido->soundExists(name+".destroyed")) this->sonido->playSound(name+".destroyed"); this->hitbox.setValues(0,0,0,0,0); //Delete bullets std::list<Pattern*>* active_patterns=getActivePatterns(); std::list<Pattern*>::iterator i = active_patterns->begin(); while (i != active_patterns->end()) { Pattern*p=(Pattern*)*i; active_patterns->erase(i++); delete p; } RosalilaNetwork network(painter); //score_upload_message = network.runTcpClientSendScore(31716, "108.59.1.187",stage_name, username, global_iteration); score_upload_message = network.runTcpClientSendScore(31716, "localhost",stage_name, username, global_iteration); } } this->angle+=this->angle_change / getSlowdown(); this->x += cos (angle*PI/180) * velocity / getSlowdown() + stage_velocity; this->y -= sin (angle*PI/180) * velocity / getSlowdown(); getIterateSlowdownFlag(); }
/* ---------------------------------------------------------------- * Update and spike handling functions * ---------------------------------------------------------------- */ void nest::hh_cond_exp_traub::update(Time const & origin, const long_t from, const long_t to) { assert(to >= 0 && (delay) from < Scheduler::get_min_delay()); assert(from < to); for ( long_t lag = from ; lag < to ; ++lag ) { double tt = 0.0 ; //it's all relative! V_.U_old_ = S_.y_[State_::V_M]; // adaptive step integration while (tt < B_.step_) { const int status = gsl_odeiv_evolve_apply(B_.e_, B_.c_, B_.s_, &B_.sys_, // system of ODE &tt, // from t... B_.step_, // ...to t=t+h &B_.IntegrationStep_ , // integration window (written on!) S_.y_); // neuron state if ( status != GSL_SUCCESS ) throw GSLSolverFailure(get_name(), status); } S_.y_[State_::G_EXC] += B_.spike_exc_.get_value(lag); S_.y_[State_::G_INH] += B_.spike_inh_.get_value(lag); // sending spikes: crossing 0 mV, pseudo-refractoriness and local maximum... // refractory? if (S_.r_) { --S_.r_; } else { // (threshold && maximum ) if (S_.y_[State_::V_M] >= P_.V_T + 30. && V_.U_old_ > S_.y_[State_::V_M]) { S_.r_ = V_.RefractoryCounts_; set_spiketime(Time::step(origin.get_steps()+lag+1)); SpikeEvent se; network()->send(*this, se, lag); } } // set new input current B_.I_stim_ = B_.currents_.get_value(lag); // log state data B_.logger_.record_data(origin.get_steps() + lag); } }
// ==================== // protected: // ==================== BufferInfo::Type BasicHandler::typeByTarget(const QString &target) const { if(target.isEmpty()) return BufferInfo::StatusBuffer; if(network()->isChannelName(target)) return BufferInfo::ChannelBuffer; return BufferInfo::QueryBuffer; }
void nest::ac_poisson_generator::update(Time const& origin, const long_t from, const long_t to) { assert(to >= 0 && (delay) from < Scheduler::get_min_delay()); assert(from < to); const long_t start = origin.get_steps(); // time resolution const double h = Time::get_resolution().get_ms(); // random number generator librandom::RngPtr rng = net_->get_rng(get_thread()); // We iterate the dynamics even when the device is turned off, // but do not issue spikes while it is off. In this way, the // oscillators always have the right phase. This is quite // time-consuming, so it should be done only if the device is // on most of the time. for ( long_t lag = from ; lag < to ; ++lag ) { // update oscillator blocks, accumulate rate as sum of DC and N_osc_ AC elements // rate is instantaneous sum of state double r = P_.dc_; for ( unsigned int n = 0 ; n < B_.N_osc_ ; ++n ) { const unsigned int offs = 2 * n; // index of first block elem const double_t new1 = V_.coss_[n] * B_.state_oscillators_[offs] - V_.sins_[n] * B_.state_oscillators_[offs+1]; B_.state_oscillators_[offs+1] = V_.sins_[n] * B_.state_oscillators_[offs] + V_.coss_[n] * B_.state_oscillators_[offs+1]; B_.state_oscillators_[offs] = new1; r += B_.state_oscillators_[offs+1]; } // store rate in Hz B_.rates_.record_data(origin.get_steps()+lag, r * 1000); // create spikes if ( r > 0 && device_.is_active(Time::step(start+lag)) ) { V_.poisson_dev_.set_lambda(r * h); ulong_t n_spikes = V_.poisson_dev_.uldev(rng); while ( n_spikes-- ) { SpikeEvent se; network()->send(*this, se, lag); S_.last_spike_ = Time::step(origin.get_steps()+lag+1); } } } }
int network(int n,int level,int aux){ int i, j; int nUnsocials=0; /*actualiza o maximo*/ if(level+1>levelMax){ levelMax=level+1; } /*fazer a contagem das pessoas que nao se conhece. Faz-se a contagem fora do for para evitar repetição de calculos, guarda-se o valor em nUnsocials*/ for(i=aux;i<n;i++){ if(arrayTemp[i]==0){ nUnsocials++; } } /*pessoa i selecionada*/ for(i=aux;i<n;i++) { /*verifica se vale a pena ir expandir as conexões dessa pessoa, ou seja, se se irá atingir um novo maximo*/ if(level+nUnsocials>levelMax){ /*verificar se essa mesma pessoa é conhecida por elementos anteriores*/ if(arrayTemp[i]==0){ /*soma-se à matriz temporaria os valores das suas conexoes*/ for(j=i+1;j<n;j++){ if(array[i][j]==1){ arrayTemp[j]+=array[i][j]; } } /*verificar as conexoes que esta pessoa i conhece*/ for(j=i+1;j<n;j++){ /*verificar se vale a pena passar à recursao seguinte de uma pessoa j que a pessoa i está conectada*/ //if(level+nUnsocials>levelMax){ /*se a pessoa j não é conhecida de i*/ if(arrayTemp[j]==0){ network(n,level+1,j); break; } //} } /*subtrair à matriz auxiliar as conexoes*/ for(j=i+1;j<n;j++){ if(array[i][j]==1){ arrayTemp[j]-=array[i][j]; } } /*se nao conheceu entao vamos decrementar o numero de pessoas que nao se conhecem*/ nUnsocials--; } } else{ return 0; } } return 0; }
void nest::iaf_psc_delta::update( Time const& origin, const long_t from, const long_t to ) { assert( to >= 0 && ( delay ) from < Scheduler::get_min_delay() ); assert( from < to ); const double_t h = Time::get_resolution().get_ms(); for ( long_t lag = from; lag < to; ++lag ) { if ( S_.r_ == 0 ) { // neuron not refractory S_.y3_ = V_.P30_ * ( S_.y0_ + P_.I_e_ ) + V_.P33_ * S_.y3_ + B_.spikes_.get_value( lag ); // if we have accumulated spikes from refractory period, // add and reset accumulator if ( P_.with_refr_input_ && S_.refr_spikes_buffer_ != 0.0 ) { S_.y3_ += S_.refr_spikes_buffer_; S_.refr_spikes_buffer_ = 0.0; } // lower bound of membrane potential S_.y3_ = ( S_.y3_ < P_.V_min_ ? P_.V_min_ : S_.y3_ ); } else // neuron is absolute refractory { // read spikes from buffer and accumulate them, discounting // for decay until end of refractory period if ( P_.with_refr_input_ ) S_.refr_spikes_buffer_ += B_.spikes_.get_value( lag ) * std::exp( -S_.r_ * h / P_.tau_m_ ); else B_.spikes_.get_value( lag ); // clear buffer entry, ignore spike --S_.r_; } // threshold crossing if ( S_.y3_ >= P_.V_th_ ) { S_.r_ = V_.RefractoryCounts_; S_.y3_ = P_.V_reset_; // EX: must compute spike time set_spiketime( Time::step( origin.get_steps() + lag + 1 ) ); SpikeEvent se; network()->send( *this, se, lag ); } // set new input current S_.y0_ = B_.currents_.get_value( lag ); // voltage logging B_.logger_.record_data( origin.get_steps() + lag ); } }
void ProjectionModifierTriesch::Initialize(Projection* Projection) { network(Projection->network()); vector<float> postValues = m_projectionFixed->GetPostValues(); m_projectionFixed = Projection; m_firstRun = true; m_idsPost = m_projectionFixed->GetPostIds(); }
void nest::izhikevich::handle( CurrentEvent& e ) { assert( e.get_delay() > 0 ); const double_t c = e.get_current(); const double_t w = e.get_weight(); B_.currents_.add_value( e.get_rel_delivery_steps( network()->get_slice_origin() ), w * c ); }
unsigned int Multicaster::gather(const Address &queryingPeer,uint64_t nwid,const MulticastGroup &mg,Buffer<ZT_PROTO_MAX_PACKET_LENGTH> &appendTo,unsigned int limit) const { unsigned char *p; unsigned int added = 0,i,k,rptr,totalKnown = 0; uint64_t a,picked[(ZT_PROTO_MAX_PACKET_LENGTH / 5) + 2]; if (!limit) return 0; else if (limit > 0xffff) limit = 0xffff; const unsigned int totalAt = appendTo.size(); appendTo.addSize(4); // sizeof(uint32_t) const unsigned int addedAt = appendTo.size(); appendTo.addSize(2); // sizeof(uint16_t) { // Return myself if I am a member of this group SharedPtr<Network> network(RR->node->network(nwid)); if ((network)&&(network->subscribedToMulticastGroup(mg,true))) { RR->identity.address().appendTo(appendTo); ++totalKnown; ++added; } } Mutex::Lock _l(_groups_m); const MulticastGroupStatus *s = _groups.get(Multicaster::Key(nwid,mg)); if ((s)&&(!s->members.empty())) { totalKnown += (unsigned int)s->members.size(); // Members are returned in random order so that repeated gather queries // will return different subsets of a large multicast group. k = 0; while ((added < limit)&&(k < s->members.size())&&((appendTo.size() + ZT_ADDRESS_LENGTH) <= ZT_UDP_DEFAULT_PAYLOAD_MTU)) { rptr = (unsigned int)RR->node->prng(); restart_member_scan: a = s->members[rptr % (unsigned int)s->members.size()].address.toInt(); for(i=0;i<k;++i) { if (picked[i] == a) { ++rptr; goto restart_member_scan; } } picked[k++] = a; if (queryingPeer.toInt() != a) { // do not return the peer that is making the request as a result p = (unsigned char *)appendTo.appendField(ZT_ADDRESS_LENGTH); *(p++) = (unsigned char)((a >> 32) & 0xff); *(p++) = (unsigned char)((a >> 24) & 0xff); *(p++) = (unsigned char)((a >> 16) & 0xff); *(p++) = (unsigned char)((a >> 8) & 0xff); *p = (unsigned char)(a & 0xff); ++added; } }