I am trying to write an event-driven simulation in C to simply use a Poisson dis
ID: 3670202 • Letter: I
Question
I am trying to write an event-driven simulation in C to simply use a Poisson distribution (a random function I have already written), to simulate 'customers' arriving and 'departing.' The average interval for arrivals in a time period as well as the number serviced in a time period, the number to simulate, and the number of service channels are inputs to the program. Given the inputs, I want to just use my random Poisson distribution function to give me approximately the results that the formulas give (avg time waiting, avg time in system total, avg people in system, percent time idle). I have the formulas and functions for the calculations already written. I need to know how to use a single customer struct (that includes a customer next pointer for the FIFO queue once the queue is filled at 100) to accomplish this simulation and get approximately the same numbers from the sim. as the calculations. Any help would be much appreciated!
Explanation / Answer
Answer
// IF have 100 number of Customers is there , so you need to follow
// the FIFO Order , you can use the following enqueue method of logic
public void enqueue(Object ob) {
// check for full array and expand if necessary
// consider items means number of customers
if (items.length == numItems) {
// dynamic memory allocation here for your customers
Object[] tmp = new Object[items.length*2];
//array copy happend here
System.arraycopy(items, frontIndex, tmp, frontIndex,
items.length-frontIndex);
if (frontIndex != 0) {
System.arraycopy(items, 0, tmp, items.length, frontIndex);
}
items = tmp;
rearIndex = frontIndex + numItems - 1;
}
// use auxiliary method to increment rear index with wraparound
rearIndex = incrementIndex(rearIndex);
// insert new item at rear of queue
// insert new customer if you have through queue
items[rearIndex] = ob;
numItems++;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.