user1352843
user1352843

Reputation: 11

Conversion OF FIFO code from Java to c#

couple of days ago i posted a topic about fifo programming and how to do it because the topic was a bit broad and vague and lacks coding example, so i followed experts advice and searched for codes and tried a bit of coding. and i knew exactly what i wanted to do

i want to create a DES (Discrete event simulation) for the FIFO (first in first out) scheduling algorithm using the C# as my programming language.

so i searched the net and i couldn't find something really helpful in c# for guidance but i found exactly what i wanted to in java codes. which i will post now

The process of Initialization

    Queue q = new Queue();
    EventQueue eventq = new EventQueue();
    Random rand = new Random();
    Distribution interarrivalTimeDist =
    new ExponentialDistribution(lambda, rand);
    Distribution serviceTimeDist =
    new ExponentialDistribution(mu, rand);
    double t = 0;
    // generate first arrival
    eventq.addEvent(new Event(Event.ARRIVAL,
    interarrivalTimeDist.nextRandom()));

Main program

while (t < simLength) {
Event e = eventq.nextEvent();
t = e.getTime();
switch (e.getType()) {
case Event.ARRIVAL : {
// handle arrival
}
case Event.DEPARTURE : {
// handle departure
}
}
}

Case of Arrival

case Event.ARRIVAL : {
// schedule next arrival
eventq.addEvent(new Event(Event.ARRIVAL,
t + interarrivalTimeDist.nextRandom()));
double serviceTime =
serviceTimeDist.nextRandom();
q.addCustomer(new Customer(t, serviceTime));
if (q.getSize() == 1) {
eventq.addEvent(new Event(Event.DEPARTURE,
t + serviceTime));
}
break;
}

Case of departure

case Event.DEPARTURE : {
q.removeCustomer(t);
if (q.getSize() > 0) {
double serviceTime =
q.getCustomerAt(0).getServiceTime();
eventq.addEvent(new Event(Event.DEPARTURE,
t + serviceTime));
}
break;
}

any clues or guidance how to convert this code to c#?? and help will help highly appreciated it PS:- for the experts please show some tolerance if my topic wasn't as professional as you guys thought it will be thanks

Upvotes: 0

Views: 835

Answers (1)

payo
payo

Reputation: 4561

Your question sounds a lot like "how do I program this idea", and isn't a good SO question. You should design a lot about what you want to do, build it in steps, and come here with specific questions you have, not broad ideas or lots of code.

To answer just FIFO, that is a queue. Read about queues and practice with them.

Upvotes: 1

Related Questions