日期:2014-05-20 浏览次数:20894 次
for (int startTime = 1; startTime < lastTime; startTime++) {
System.err.println("-----------------------------------Time "
+ startTime);
if (inWorkSet.size() == 0 && state) {
System.err.println("All is done.");
break;
}
// 下面的for循环用于检查是否有船可靠泊
for (Vessel vessel : list) {
if (startTime == vessel.getArriveTime()) {
int a;
if ((a = findEnoughBerth(vessel.getLength())) >= 0) {
vessel.setStartLocation(a);
System.out.println("Vessel " + vessel.getIndex()
+ " is berthed started in " + a);
System.out.println("Vessel " + vessel.getIndex()
+ " length is " + vessel.getLength());
inWorkSet.add(vessel);
state = true;
currentVessel = vessel;
berthAlloacte(vessel);
} else {
vessel.setArriveTime(vessel.getArriveTime() + 1);
}
} else {
break;
}
}
list.remove(currentVessel);
// 下面的if是在此刻有船靠泊后为其执行。无新船靠泊就跳过
if (currentVessel != null) {
while (QCS_left > 0) {
if (currentVessel.getQCs_allocated() < currentVessel
.getMaxQCs()) {
currentVessel.setQCs_allocated(currentVessel
.getQCs_allocated() + 1);
QCS_left--;
} else {
break;
}
}
}
// 给泊位中的每艘船作业
Vessel doneVessel = null;
for (Vessel vessel : inWorkSet) {
System.out.println("Vessel " + vessel.getIndex() + " has QCs "
+ vessel.getQCs_allocated());
vessel.setWorkAmount(vessel.getWorkAmount()
- vessel.getQCs_allocated());
System.out.println("Vessel " + vessel.getIndex()
+ " left work is " + vessel.getWorkAmount());
if (vessel.getWorkAmount() <= 0) {
System.err.println("Vessel " + vessel.getIndex()
+ " is done.");
doneVessel = vessel;