📄 simulation.cs
字号:
namespace Opus6
{
using System;
[Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng."), Version("$Id: Simulation.cs,v 1.4 2001/10/28 19:50:09 brpreiss Exp $")]
public class Simulation
{
public Simulation()
{
this.eventList = new LeftistHeap();
}
public void Run(double timeLimit)
{
bool flag1 = false;
int num1 = 0;
RandomVariable variable1 = new ExponentialRV(100);
RandomVariable variable2 = new ExponentialRV(100);
this.eventList.Enqueue(new Event(EventType.ARRIVAL, 0));
while (!this.eventList.IsEmpty)
{
Event event1 = (Event) this.eventList.DequeueMin();
double num2 = event1.Time;
if (num2 > timeLimit)
{
this.eventList.Purge();
return;
}
Opus6.Console.WriteLine(event1);
switch (event1.Type)
{
case EventType.ARRIVAL:
if (flag1)
{
break;
}
flag1 = true;
this.eventList.Enqueue(new Event(EventType.DEPARTURE, num2 + variable1.Next));
goto Label_00B7;
case EventType.DEPARTURE:
if (num1 != 0)
{
goto Label_00DA;
}
flag1 = false;
goto Label_00F8;
default:
{
continue;
}
}
num1++;
Label_00B7:
this.eventList.Enqueue(new Event(EventType.ARRIVAL, num2 + variable2.Next));
continue;
Label_00DA:
num1--;
this.eventList.Enqueue(new Event(EventType.DEPARTURE, num2 + variable1.Next));
Label_00F8:;
}
}
private PriorityQueue eventList;
private class Event : Association
{
internal Event(Simulation.EventType type, double time) : base(time, (int) type)
{
}
public override string ToString()
{
switch (this.Type)
{
case Simulation.EventType.ARRIVAL:
return ("Event {" + this.Time + ", arrival}");
case Simulation.EventType.DEPARTURE:
return ("Event {" + this.Time + ", departure}");
}
return null;
}
internal double Time
{
get
{
return (double) base.Key;
}
}
internal Simulation.EventType Type
{
get
{
return (Simulation.EventType) ((int) base.Value);
}
}
}
private enum EventType
{
ARRIVAL,
DEPARTURE
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -