系统中有两个以上的队列。
指数分布后的数据包(lamda,mu)继续进入每个队列(queue1,queue2)
但是,服务率mu针对queue1处理一次,针对queue2处理一次,针对queue2处理一次,针对queue2处理一次。
即,在queue1中处理数据包时,queue2的等待时间增加。处理队列2时队列1的等待时间增加。
此时,如何计算queue1和queue2中的等待时间?
我使用的是java语言。
lamda是到达率,mu是服务率,我如何获得等待时间?
因此,我漏了几个晚上,请帮助我......
package scheduling;
import java.util.LinkedList;
import java.util.Random;
public class q_learning_final2 {
private final double alpha = 0.1;
private final double gamma = 0.9;
private static final double rqstate = 0.2;
private static final double rqstate2 = 0.0;
private static final double rqstate3 = -0.2;
private final double rwtime = 0;
private final double rwtime2 = 0;
private final double rwtime3 = 0;
private static double num = 5.0;
private static double num1 = 5.0;
static int cnt=0;
public static class State {
public double lambda;
public double ts;
public double simulationTime;
public State(double lam, double ts, double simTime) {
this.lambda = lam;
this.ts = ts;
this.simulationTime = simTime;
}
}
public static class State2 {
public double lambda;
public double ts;
public double simulationTime;
public State2(double lam, double ts, double simTime) {
this.lambda = lam;
this.ts = ts;
this.simulationTime = simTime;
}
}
public static class State3 {
public double lambda;
public double ts;
public double simulationTime;
public State3(double lam, double ts, double simTime) {
this.lambda = lam;
this.ts = ts;
this.simulationTime = simTime;
}
}
public static class Event {
public int id;
public double interarrival;
public double arrival;
public double service;
public double serviceStart;
public double serviceEnd;
public double tw;
public double tq;
public void function(LinkedList<Event> schedule, State state, double time) {
Event next = schedule.removeLast();
if (this.serviceEnd < next.arrival) {
next.serviceStart = next.arrival;
}
if (this.serviceEnd >= next.arrival) {
next.serviceStart = this.serviceEnd;
}
next.serviceEnd = next.serviceStart + next.service;
if(cnt==0) {
next.tw = next.serviceStart ;//is this correct?
System.out.println(next.tw);
cnt=1;
}else if(cnt==1) {
next.tw = next.serviceStart-next.arrival ;//is this correct?
cnt=0;
}
next.tq = next.serviceEnd - next.arrival;
schedule.addLast(next);
}
}
public static class Event2 {
public int id;
public double interarrival;
public double arrival;
public double service;
public double serviceStart;
public double serviceEnd;
public double tw;
public double tq;
public void function(LinkedList<Event2> schedule2, State state2, double time2) {
Event2 next = schedule2.removeLast();
if (this.serviceEnd < next.arrival) {
next.serviceStart = next.arrival;
}
if (this.serviceEnd >= next.arrival) {
next.serviceStart = this.serviceEnd;
}
next.serviceEnd = next.serviceStart + next.service;
if(cnt==0) {
next.tw = next.serviceStart - next.arrival;//여기 건드려야해
cnt=1;
}else if(cnt==1) {
next.tw = next.serviceStart;//여기 건드려야해
cnt=0;
}
next.tq = next.serviceEnd - next.arrival;
schedule2.addLast(next);
}
}
public static double exponential(double lambda) {
Random R = new Random();
return -(Math.log(1 - R.nextDouble()) / lambda);
}
public static State initializeState(double lambda, double ts, double simTime) {
System.out.println("Lambda\tTs\tSimulationTime");
System.out.println(lambda + "\t" + ts + "\t" + simTime);
State state = new State(lambda, ts, simTime);
return state;
}
public static State initializeState2(double lambda, double ts, double simTime) {
System.out.println("Lambda\tTs\tSimulationTime");
System.out.println(lambda + "\t" + ts + "\t" + simTime);
State state2 = new State(lambda, ts, simTime);
return state2;
}
public static LinkedList<Event> initializeSchedule(State state) {
LinkedList<Event> schedule = new LinkedList<Event>();
double time = 0.0;
for (int i = 1; i < 5000; i++) {
Event event = new Event();
event.id = i;
event.interarrival = exponential(state.lambda);
event.service = exponential(state.ts);
time += event.interarrival;
event.arrival = time;
schedule.push(event);
}
return schedule;
}
public static LinkedList<Event2> initializeSchedule2(State state2) {
LinkedList<Event2> schedule2 = new LinkedList<Event2>();
double time = 0.0;
for (int i = 1; i < 10000; i++) {
Event2 event2 = new Event2();
event2.id = i;
event2.interarrival = exponential(state2.lambda);
event2.service = exponential(state2.ts);
time += event2.interarrival;
event2.arrival = time;
schedule2.push(event2);
}
return schedule2;
}
public static void printResults(double wait, double turnaround, int count, State state, double time) {
double tw = wait / count;
double tq = turnaround / count;
System.out.println("\nResults of Queue 1");
System.out.println("Number of Events Processed:\t" + count);
System.out.println("Average Wait Time in Queue 1:\t" + tw);
System.out.println("Average Time in System 1:\t" + tq);
}
public static void printResults2(double wait2, double turnaround2, int count2, State state2, double time2) {
double tw2 = wait2 / count2;
double tq2 = turnaround2 / count2;
System.out.println("\nResults of Queue 2");
System.out.println("Number of Events Processed:\t" + count2);
System.out.println("Average Wait Time in Queue 2:\t" + tw2);
System.out.println("Average Time in System 2:\t" + tq2);
}
public static void main(String[] args) {
State state = initializeState(4.0, 10.0, 100);
State state2 = initializeState2(3.0, 10.0, 100);
LinkedList<Event> schedule = initializeSchedule(state);
LinkedList<Event2> schedule2 = initializeSchedule2(state2);
int count = 0;
int count2 = 0;
int count3 = 0;
double time = 0.0;
double time2 = 0.0;
double time3 = 0.0;
double wait = 0.0;
double wait2 = 0.0;
double wait3 = 0.0;
double turnaround = 0.0;
double turnaround2 = 0.0;
double turnaround3 = 0.0;
while (time < state.simulationTime) {
Event event = schedule.removeLast();
if (time == 0.0) {
event.serviceStart = event.interarrival;
event.serviceEnd = event.serviceStart + event.service;
event.tw = event.serviceStart - event.arrival;
event.tq = event.serviceEnd - event.arrival;
}
event.function(schedule, state, time);
count++;
time = event.arrival;
wait += event.tw;
turnaround += event.tq;
}
while (time2 < state2.simulationTime) {
Event2 event2 = schedule2.removeLast();
if (time2 == 0.0) {
event2.serviceStart = event2.interarrival;
event2.serviceEnd = event2.serviceStart + event2.service;
event2.tw = event2.serviceStart - event2.arrival;
event2.tq = event2.serviceEnd - event2.arrival;
}
event2.function(schedule2, state2, time2);
count2++;
time2 = event2.arrival;
wait2 += event2.tw;
turnaround2 += event2.tq;
}
printResults(wait, turnaround, count, state, time);
printResults2(wait2, turnaround2, count2, state2, time2);
}
}
我在源代码中写的这是正确的吗?这是正确的吗?..