Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tuple<float, float> aloha (
- int M = 2, // количество абонентов
- int N = 4, // размер потока (количество событий)
- int W = 20, // количество окон для моделирования
- float h = 0.6f, // плотность потока (общая)
- float p = 0.5f, // вероятность, с которой абонент
- // отправляет при наличии сообщения
- type t = probabilistic, // вариант разрешения конфликта
- bool debug = false ) // выводить само моделирование (номер окна и содержания буферов)
- {
- auto subscribers = subscriber::several ( M, N, h, bernoulli );
- auto windows = range ( 1, W+1 );
- float delay = 0, load = 0;
- int sended = 0;
- for ( auto& w : windows ) {
- if(debug) cout << w << "\t";
- vector<subscriber*> senders;
- for ( auto& sub : subscribers ) {
- auto &flow = sub.flow, &arr = sub.arrived;
- copy_if ( flow.begin (), flow.end (), back_inserter ( arr ), [ = ] ( float& x ) { return x < w; } );
- flow.erase ( remove_if ( flow.begin (), flow.end (), [ = ] ( float& x ) { return x < w; } ), flow.end () );
- if ( rnd () < p && sub.arrived.size () > 0 ) {
- senders.push_back ( &sub );
- }
- load += sub.arrived.size ();
- if(debug) cout << sub << " ";
- }
- if(debug) cout << endl;
- if ( senders.size () == 1 ) {
- auto& mess = senders[ 0 ]->arrived.begin ();
- delay += w - *mess;
- sended += 1;
- senders[ 0 ]->arrived.erase (mess);
- } else {
- for ( auto& s : senders ) {
- s->resolve_collision ( t, 2 * M );
- }
- }
- }
- return make_tuple ( delay / sended, load / W );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement