AB两城市间有n条电话线路,由A发出的通话请求到达间隔服从均值10s的指数分布,由B发出的12s。通话时间长度均值4分的指数分布。模拟12小时,统计平均忙线的数目,被拒的通号请求数目。
1 用事件链表时,写出事件结构体组成
的最小集合、系统状态变量。
2 写出到达和离开事件的算法。
思路:
1.链表结构:事件类型,时间,下一个
2.事件:到达(A-->B,B-->A),离开
3.到达事件:
安排下一个到达的时间,若n条线已经被占满,则被拒绝的客户数+1;若没被占满,占用一条电话线,占用数+1,计算忙线时间,安排他的离开时间。
离开事件:
占用数-1,计算忙线时间。
java程序:
事件类型:
到达:
离开:
1 用事件链表时,写出事件结构体组成
的最小集合、系统状态变量。
2 写出到达和离开事件的算法。
思路:
1.链表结构:事件类型,时间,下一个
2.事件:到达(A-->B,B-->A),离开
3.到达事件:
安排下一个到达的时间,若n条线已经被占满,则被拒绝的客户数+1;若没被占满,占用一条电话线,占用数+1,计算忙线时间,安排他的离开时间。
离开事件:
占用数-1,计算忙线时间。
java程序:
事件类型:
public class Event implements Comparable<Event> {
private double time;
private int eventType;
private double theta=0.0;
static int AToBType=1;
static int BToAType=2;
static int DepartType=3;
public double getTime() {
return time;
}
public void setTime(double time) {
this.time = time;
}
public int getEventType() {
return eventType;
}
public void setEventType(int eventType) {
this.eventType = eventType;
}
public double getTheta() {
return theta;
}
public void setTheta(double theta) {
this.theta = theta;
}
@Override
public int compareTo(Event e) {
if(this.time<e.time)
return -1;
else
return 1;
}
}
到达:
private void arrive(Event e) {
this.totalCome++;
this.currentTime=e.getTime();
Event next=new Event();
next.setEventType(e.getEventType());
next.setTheta(e.getTheta());
next.setTime(this.currentTime+this.GenerateExpRandom(e.getTheta()));
eventList.add(next);
String type="";
if(e.getEventType()==Event.AToBType){
type="A TO B";
}else{
type="B TO A";
}
System.out.println("at "+this.currentTime+" a task came: from "+type);
if(this.onLineNum<n){
//没被占用完
this.onLineNum++;
Event e1=new Event();
e1.setEventType(Event.DepartType);
e1.setTheta(this.thetaStay);
e1.setTime(this.currentTime+this.GenerateExpRandom(this.thetaStay));
eventList.add(e1);
this.busyCount++;
this.totalBusyNum+=this.busyQueue*(this.currentTime-this.lastBusyTime);
this.busyQueue++;
this.lastBusyTime=this.currentTime;
}else{
balked++;
}
}
离开:
private void depart(Event e) {
this.currentTime=e.getTime();
System.out.println("at "+this.currentTime+" a task depart.");
this.totalBusyNum+=this.busyQueue*(this.currentTime-this.lastBusyTime);
this.busyQueue--;
if(this.busyQueue<0) this.busyQueue=0;
this.lastBusyTime=this.currentTime;
this.onLineNum--;
}