Question

write a program in matlab to produce a discrete event simulation of a switching element with...

write a program in matlab to produce a discrete event simulation of a switching element with 10 inputs and 3 outputs. Time is slotted on all inputs and outputs. Each input packet follows a Bernoulli process. In a given slot, the independent probability that a packet arrives in a slot is p and the probability that a slot is empty is (1– p). One packet fills one slot. For a switching element if 3 or less packets arrives to some inputs, they are forwarded to the switching element outputs without a loss. If more than 3 packets arrive to the inputs of the switching element, only 3 packets are randomly chosen to be forwarded to the switching element outputs and the remaining ones are discarded. In your simulation the program will mimic the operation of the switch and collect statistics. That is, in each time slot the program randomly generates packets for all inputs of the switching element and counts how many packets can be passed to the output of the switching element (causing throughput) and, alternatively counts how many packets are dropped (when the switching element has more than 3 input packets at a given time slot) . Your task is to collect throughput statistics for different values of p (p = 0.05, 0.1 up to 1.0 in steps of 0.05), by running the procedure described above for each value of p and for many slots (at least a thousand slots per value of p). The more simulated slots, the more accurate the results will be. Based on this statistics, plot two graphs: 1) the average number of busy outputs versus p, and 2) the average number of dropped packets versus p.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ANSWER

Screenshot of the code:

/Include the required header files #include iostream» #include <random> #include <ioma nip> #include«time.h> using namespace std; //Define the array and variables float p1[10]- float d1[10]- int 1-0; //Define the function BernoulliProcess() int BernoulliProcess (float p, int packetGen) //Define the variables int passed 0; int count-0, drop 0; //Use the bernoullis distribution default random engine generator bernoulli_distribution distribution(p); /Iterate and generate the distribution //Increase the count. for (int i-0; i<packetGen; ++i) if (distribution (generator)) ++count //Evaluate the passed packets from the count. if (count 3) passed-3; else passed-count //Evaluate the dropped packets from the passed packets. drop - packetGen-passed;

//Display the Probability, passed cout<< Probability: <<p<<endl; cout<<passed:<<passed<<endl; cout << Drop: <<dropくくendl<<endl; and dropped packets //Return the passed packets. return passed; //Define the main function. int main() //Generate the numbewr of packets in range 1 to 10. srand(time (NULL)); int packetGen rand() % (10-1 + 1) + 1; //Dispaly the packet generated cout<<Packet generated: <<packetGen<<endl<<endl; //Define the variables and array. float p -0.02 , d=0.8; int p2[5e]-,d2[50]-0: //collect throughput statistics for different values //of p (p 0.02, 0.04 up to 1.0 in steps of θ.02), for(int j-e j<5e;j++) //Evaluate the passed and dropped packets. //and Probabilities p2[j]-BernoulliProcess (P, packetGen); d2[j]- 10-p2l: P- p+0.02 int k-0; //Display the average number of busy outputs versus p. cout<<The average number of busy outputs versus p:<<endl; for (float i-0.02; ie.98; i-i+0.02)

cout <<set precision(2)くくfixed<< for( int j-e;j<p2[k];j++) cout<<*; ǐ << - << (i+9 .82) << : ; cout<<endl; coutくくendl; k-0; //Display the average number of dropped packets versus p cout<<The average number of dropped packets versus p: <<endl; for (float i-0.02; i<e.98; i-i+0.02) for(int j=0;jcd2[k];j++) cout<<*; cout<<endl; / /Return the value e. return e;

Sample output:

Packet generated:7 Probability:0.02 passed: 0 Drop:7 Probability:0.04 passed:1 Drop: 6 Probability:0.06 passed:1 Drop: 6 Probability:0.08 passed:1 Drop: 6 Probability:0.1 passed:1 Drop: 6 Probability:0.12 passed:1 Drop: 6 Probability:0.14 passed: 2 Drop:5 Probability:0.16 passed: 2 Drop:5 Probability:0.18 passed: 2 Drop:5 Probability:0.2 passed: 2 Drop:5 Probability:0.22 passed: 3 Drop: 4 Probability:0.24 passed: 3 Drop: 4 Probability:0.26 passed: 3 Drop: 4 Probability:0.28 passed: 3 Drop: 4

Probability:0.3 passed:3 Drop: 4 Probability:0.32 passed:3 Drop: 4 Probability:0.34 passed:3 Drop: 4 Probability:0.36 passed:3 Drop: 4 Probability:0.38 passed:3 Drop: 4 Probability:0.4 passed:3 Drop: 4 Probability:0.42 passed:3 Drop: 4 Probability:0.44 passed:3 Drop: 4 Probability:0.46 passed:3 Drop: 4 Probability:0.48 passed:3 Drop: 4 Probability:0.5 passed:3 Drop: 4 Probability:0.52 passed:3 Drop: 4 Probability:0.54 passed:3 Drop: 4 Probability:0.56 passed:3 Drop: 4

Probability:0.58 passed:3 Drop: 4 Probability:0.6 passed:3 Drop: 4 Probability:0.62 passed: 3 Drop: 4 Probability:0.64 passed:3 Drop: 4 Probability:0.66 passed:3 Drop: 4 Probability:0.68 passed:3 Drop: 4 Probability:0.7 passed: 3 Drop: 4 Probability:0.72 passed: 3 Drop: 4 Probability:0.74 passed:3 Drop: 4 Probability:0.76 passed:3 Drop: 4 Probability:0.78 passed:3 Drop: 4 Probability:0.8 passed: 3 Drop: 4 Probability:0.82 passed:3 Drop: 4 Probability:0.84 passed:3 Drop:

Probability:0.86 passed: 3 Drop: 4 Probability:0.88 passed: 3 Drop: 4 Probability:0.9 passed: 3 Drop: 4 Probability:0.92 passed: 3 rop:4 Probability:0.94 passed: 3 Drop: 4 Probability:0.96 passed: 3 Drop: 4 Probability:0.98 passed: 3 Drop: 4 Probability:1 passed: 3 Drop: 4The average number of busy outputs versus p: 0.02-0.04: * 0.04-0.06:* 0.06-0.88: * 0.08-0.10: * 0.10-0.12:* 0.12-0.14: ** 0.14-0.16: ** 0.16-0.18: ** 0.18-0.20: ** θ.29-0.22: 0.22-0.24: 8.24-9.26 : 0.26-0.28: 8.28-9.30 : θ.38-0.32: 8.32-9.34: 8.34-9.36: 0.36-0.38:*** 0.38-0.40: 8.40-9.42 : 8.42-9.44 : 0.44-0.46: 0.46-0.48: 8.48-9.50: 0.52-0.54: .54-9.56: 0.56-0.58: .58-9.60 : 0.60-0.62: 0.62-0.64: 0.64-0.66: 0.66-0.68: 8.68-9.70 : .70-9.72: .72-9.74: .74-9.76: .76-9.78: θ.78-9.30: 0.80-0.82: 0.82-0.84: 0.84-0.86: 0.86-0.88: 0.88-0.90: .90-9.92: 8.92-9.94: 8.94-9.96: .96-9.98: 8.98-1.00:

The average number of dropped packets versus p: 0.04-0.06: ** 0.44-0.46:** 0.46-0.48:*

Code to copy:

//Include the required header files.

#include <iostream>

#include <random>

#include <iomanip>

#include<time.h>

using namespace std;

//Define the array and variables

float p1[10]={};

float d1[10]={};

int l=0;

//Define the function BernoulliProcess()

int BernoulliProcess(float p, int packetGen)

{

//Define the variables

int passed =0;

int count=0, drop =0;

//Use the bernoulli's distribution.

default_random_engine generator;

bernoulli_distribution distribution(p);

//Iterate and generate the distribution.

//Increase the count.

for (int i=0; i<packetGen; ++i)

{

if (distribution(generator))

{

++count;

}

}

//Evaluate the passed packets from the count.

if(count >3)

passed = 3;

else

passed =count;

//Evaluate the dropped packets from the passed packets.

drop = packetGen-passed;

//Display the Probability, passed and dropped packets.

cout<<"Probability:"<<p<<endl;

cout<<"passed:"<<passed<<endl;

cout<<"Drop:"<<drop<<endl<<endl;

//Return the passed packets.

return passed;

}

//Define the main function.

int main()

{

//Generate the numbewr of packets in range 1 to 10.

srand(time(NULL));

int packetGen = rand() % (10 - 1 + 1) + 1;

//Dispaly the packet generated.

cout<<"Packet generated:"<<packetGen<<endl<<endl;

//Define the variables and array.

float p =0.02,d=0.8;

int p2[50]={},d2[50]={};

//collect throughput statistics for different values

//of p (p = 0.02, 0.04 up to 1.0 in steps of 0.02),

for(int j=0; j<50;j++)

{

//Evaluate the passed and dropped packets.

//and Probabilities.

p2[j]=BernoulliProcess(p, packetGen);

d2[j]= 10-p2[j];

p= p+0.02;

d =1-p;

}

int k=0;

//Display the average number of busy outputs versus p.

cout<<"The average number of busy outputs versus p:"<<endl;

for (float i=0.02; i<0.98; i=i+0.02)

{

k++;

cout <<setprecision(2)<<fixed<< i << "-" << (i+0.02) << ": ";

for(int j=0;j<p2[k];j++)

cout<<"*";

cout<<endl;

}

cout<<endl;

k=0;

//Display the average number of dropped packets versus p.

cout<<"The average number of dropped packets versus p:"<<endl;

for (float i=0.02; i<0.98; i=i+0.02 )

{

k++;

cout <<setprecision(2)<<fixed<< i << "-" << (i+0.02) << ": ";

for(int j=0;j<d2[k];j++)

cout<<"*";

cout<<endl;

}

//Return the value 0.

return 0;

}

Add a comment
Know the answer?
Add Answer to:
write a program in matlab to produce a discrete event simulation of a switching element with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Have to show work for every problem 4. A company uses three plants to produce a...

    Have to show work for every problem 4. A company uses three plants to produce a new computer chip. Plant A produces 30% of the chips. Plant B produces 45% of the chips. The rest of the chips are produced by plant C. Each plant has its own defectiv rate. These are: plant A produces 3% defective chips, plant B produces 1% defective chips, plant C produces 5% defective chips. Hint: draw a tree diagram. (a) Construct a tree diagram...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • Q1 Error detection/correction Can these schemes correct bit errors: Internet checksums, two-dimendional parity, cyclic...

    Q1 Error detection/correction Can these schemes correct bit errors: Internet checksums, two-dimendional parity, cyclic redundancy check (CRC) A. Yes, No, No B. No, Yes, Yes c. No, Yes, No D. No, No, Yes E. Ho, hum, ha Q2 CRC vs Internet checksums Which of these is not true? A. CRC's are commonly used at the link layer B. CRC's can detect any bit error of up to r bits with an r-bit EDC. c. CRC's are more resilient to bursty...

  • summatize the following info and break them into differeng key points. write them in yojr own...

    summatize the following info and break them into differeng key points. write them in yojr own words   apartus 6.1 Introduction—The design of a successful hot box appa- ratus is influenced by many factors. Before beginning the design of an apparatus meeting this standard, the designer shall review the discussion on the limitations and accuracy, Section 13, discussions of the energy flows in a hot box, Annex A2, the metering box wall loss flow, Annex A3, and flanking loss, Annex...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT