Search code examples
c++randompoissonnetwork-traffic

Generating random arrivals via Poisson process c++


There is something I didn't understand. I use the sample given from the cpp reference to generate numbers:

const int nrolls = 10; // number of experiments

std::default_random_engine generator;
std::poisson_distribution<int> distribution(4.1);

for (int i=0; i<nrolls; ++i){
int number = distribution(generator);
cout<<number<<" "<<endl;
}

(original code: http://www.cplusplus.com/reference/random/poisson_distribution/ )

This outputs: 2 3 1 4 3 4 4 3 2 3 and so on... First of all what those numbers mean? I mean do I have to sum them to create timing? For example: 2, (2+3)=5, (5+1)=6, (6+4)=10,..., and so on..

Secondly, my real question is, I need to produce both random arrivals for network packets and the size of packets. I mean, when the packets come and if packets come, what are the size of packets? How can I do that? I need something like that: http://i.hizliresim.com/dWmaGX.png


Solution

  • [Explanation about Poisson distribution which may help you for better understanding]

    The meaning of "Poisson distribution" and the function of "std::poisson_distribution()" are tightly related but not same.

    The Poisson distribution is a discrete probability distribution. You can calculate probabilities like probability of no packet comes in next period (one second for example) is 0.002, that of one packets is 0.075, that of two packets is 0.15, that of three packets is 0.20, and so on when average arrival is 4. (values of possibility I used are samples(not real value)) Total of probabilities that for 0 packets to infinite packets becomes 1.0 always.

    std::poisson_distribution() returns numbers of packets for each period which the average of those in long periods equals to average (4.1 in your code) and their distribution is the Poisson distribution.

    You can calclate that by following steps.

    1. Make table of number_of_packet and probability.

    2. Make a random number between 0 to 1.

    3. Sum up probabilitys in the table until the sum becomes larger than the random number.

    4. (number of probabilitiys used to sum up)-2 is the value.

    Example: If you get 0.3 as random number.

    The sum of probabilitys of no packet to two packets are 0.002+0.075+0.15= 0.227 is smaller than 0.3.

    The sum of probabilitys of no packet to three packets are 0.002+0.075+0.15+0.20= 0.427 is larger than 0.3.

    Then 'two packets' is used for next value.

    This is an illustration what happened in std::poisson_distribution().

    [Direct answer for your question:How to make packets arrivals in Poisson distribution]

    I assume a period is one second for easy understanding.

    outputs: 2 3 1 4 3 4 4 3 2 3 you got are number of packets of each seconds, two packets in first second, three packets in 2nd second, one packet in 3rd seconds, and so on.

    You can make arrivals by placing packets evenly in that second.

    [Example for outputs: 2 3 1]

    Time 0s - 1s

    Two packets arrives. Divide 1 second by 2 (two 0.5s period), and place packets in middle of them. => 1st packet is placed at 0.25s, and 2nd is at 0.75s.

    Time 1s - 2s

    Therre packets arrives. Divide 1 second by 3, and place packets in middle of them. => 1st packet is placed at 1.166s, 2nd is at 1.5s, 3rd is at 1.833.

    ...and so on.

    0.25, 0.75, 1.166, 1.5, 1.833 are arrival time of first five packets which comes from the 'outputs: 2 3' you got.

    ===== Size of packet is another issue.

    You should determine what distribution is used for packet size.

    I don't think Poisson distribution is suitable for packet size.