我正在为我的模拟课程开发一个项目,该项目围绕机场模拟进行。目的是事件到达不同的站点或终端,并且我需要公共汽车将事件带到正确的目的地。我可以创建事件并将其放置在正确的终端中。我遇到问题的地方是将事件从一个链表移动到另一个链表。
例如,如果某个事件在车站A上出现,我需要它上公共汽车,然后在航站楼下车。
while(passengers < 200){
/*
* This first section is where I create my events and place
* them in their appropriate places.
*/
Random ran = new Random();
int x = ran.nextInt(4) + 1;
for(int i = 1; i <= x; i++){
//passengers arrival time
double U = random.nextFloat();
double nextArrival = -(Math.log(U))/lambda;
//double nextDeparture = -(Math.log(U))/mu;
//determines place of origin and destination
Random r = new Random();
int randnum = r.nextInt(places.length);
int randnum1 = r.nextInt(places.length - 1);
String o = places[randnum];
String d;
if(o.equalsIgnoreCase("Terminal") ) d = places[randnum1];
else d = places[3];
//creates new event
Event a = new Event(nextArrival, o, d);
//place event at origin
if(o.equalsIgnoreCase("StationA")){
StationA.insert(a);
StationA.curSize++;
}
else if(o.equalsIgnoreCase("StationB")){
StationB.insert(a);
StationB.curSize++;
}
else if(o.equalsIgnoreCase("StationC")){
StationC.insert(a);
StationC.curSize++;
}
else {
Terminal.insert(a);
Terminal.curSize++;
}
passengers++;
}
/*
* Now bus has to go to all stations and terminal
*/
//BUS GOES TO STATION A
//people have to get off bus first
if(Bus.isEmpty()) break;
else {
while(StationA.curSize != StationA.limit){
boolean w = Bus.findEventTF("StationA");
if(w = true){
//find an event that needs to get off bus
Event a = Bus.findEvent("StationA");
//place event stationa completed list
CompletedA.addLast(a);
//increase current size of stationa completed list
CompletedA.curSize++;
//remove event from bus
Bus.delete(a);
//decrease current size of bus list
Bus.curSize--;
}
}
}
//people have to get on bus from station a
if(StationA.isEmpty()) break;
else {
while(Bus.curSize != Bus.limit){
boolean w = Bus.findEventTF("Terminal");
if(w = true){
//find an event that needs to get on bus
Event a = StationA.findEvent("Terminal");
//place event on bus
Bus.addLast(a);
//increase current size of bus
Bus.curSize++;
//remove event from StationA
StationA.delete(a);
//decrease current size of stationa
StationA.curSize--;
}
}
}
/*
*
* Right now im trying to work on Station A and Terminal
* before i add Station B & C
*
*/
//BUS GOES TO TERMINAL
//people have to get off bus first
if(Bus.isEmpty()) break;
else {
while(Terminal.curSize != Terminal.limit){
boolean w = Bus.findEventTF("Terminal");
if(w = true){
//find an event that needs to get off bus
Event a = Bus.findEvent("Terminal");
//place event terminal completed list
CompletedT.addLast(a);
//increase current size of terminal completed list
CompletedT.curSize++;
//remove event from bus
Bus.delete(a);
//decrease current size of bus list
Bus.curSize--;
}
}
}
//people have to get on bus from terminal
if(Terminal.isEmpty()) break;
else {
while(Bus.curSize != Bus.limit){
//boolean w = Bus.findEventTFTerm('S');
if(Bus.findEventTFTerm('S') = true){
//find an event that needs to get on bus
Event a = StationA.findEventTerm('S');
//place event on bus
Bus.addLast(a);
//increase current size of bus
Bus.curSize++;
//remove event from StationA
Terminal.delete(a);
//decrease current size of terminal
Terminal.curSize--;
}
}
}
}
如果我只做第一部分,它会起作用,而当我尝试移动它时,它不会起作用。任何帮助将不胜感激。如果您希望我从链接列表类中添加代码,请告诉我。谢谢。