5.多客户的并联系统

AB两城市间有n条电话线路,由A发出的通话请求到达间隔服从均值10s的指数分布,由B发出的12s。通话时间长度均值4分的指数分布。模拟12小时,统计平均忙线的数目,被拒的通号请求数目。
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--;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值