java - 如何将事件从一个链表移动到另一个链表
问题描述
我正在为我的模拟课程做一个围绕机场模拟的项目。目标是事件到达不同的车站或终点站,我需要公共汽车将事件带到正确的目的地。我可以创建事件并将它们放置在正确的终端中。我遇到问题的地方是将事件从一个链接列表移动到另一个链接列表。
例如,如果一个事件出现在 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--;
}
}
}
}
如果我一个人做第一部分,它会起作用,当我尝试移动它时,它不会。任何帮助将不胜感激。如果您希望我从我的链表类中添加代码,请告诉我。谢谢。
解决方案
推荐阅读
- swift - 如何在 swift setMethodCallHandler 中使用传递的参数 - self?.methodName(result: result)
- qmail - 一个帐户正在迁移。如何停止该单个域的本地传递并使用不同的邮件服务器?
- php - 如何将 PDO 转换为 MYSQLi
- java - 如何解决spring-boot的冲突实体
- unity3d - Unity:尝试复制“网格”时构建崩溃
- javascript - “如何在我的着陆页属性中获取 URL 参数”
- gnuplot - 普通PDF的对数函数评估与Python不同
- javascript - 有没有办法否定 message.content?
- mysql - 是否可以在 SQL 中左连接 @variable 表
- javascript - 使用 rootReducer 调用 createStore 时遇到参数 TypeError