几天前,我发布了一个关于 fifo 编程以及如何进行编程的主题,因为该主题有点广泛和模糊,并且缺乏编码示例,所以我听从了专家的建议,搜索了代码并尝试了一些编码。我清楚地知道我想做什么
我想使用 C# 作为我的编程语言,为 FIFO(先进先出)调度算法创建 DES(离散事件模拟)。
所以我在网上搜索,在 C# 中找不到真正有用的指导,但我在 Java 代码中找到了我想要的东西。我现在就发布
初始化过程
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()));
主程序
while (t < simLength) {
Event e = eventq.nextEvent();
t = e.getTime();
switch (e.getType()) {
case Event.ARRIVAL : {
// handle arrival
}
case Event.DEPARTURE : {
// handle departure
}
}
}
到达情况
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 Event.DEPARTURE : {
q.removeCustomer(t);
if (q.getSize() > 0) {
double serviceTime =
q.getCustomerAt(0).getServiceTime();
eventq.addEvent(new Event(Event.DEPARTURE,
t + serviceTime));
}
break;
}
有任何线索或指导如何将此代码转换为 C# 吗? 和帮助将帮助高度赞赏它 PS:-对于专家来说,如果我的主题没有你们想象的那么专业,请表现出一些宽容 谢谢
最佳答案
你的问题听起来很像“我如何编写这个想法”,这不是一个好的问题。您应该设计很多关于您想要做的事情,分步骤构建它,然后带着您遇到的具体问题来到这里,而不是宽泛的想法或大量代码。
如果只回答 FIFO,那就是一个队列
。了解 queues并与他们一起练习。
关于c# - 将 FIFO 代码从 Java 转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308862/