public void changeLanes(StreetMobilityInfo smi, Integer id) { if (DEBUG) { System.out.println("Node " + id + ": Beginning to change lanes!"); } int nextLane = -1; LaneChangeInfo lci = new LaneChangeInfo(); LinkedList nextLaneList; // set state info lci.changeTime = smi.extraSpeed * speedFactor + LANE_CHANGE_TIME; if (lci.changeTime < MIN_CHANGE_TIME) lci.changeTime = MIN_CHANGE_TIME; if (lci.changeTime > MAX_CHANGE_TIME) lci.changeTime = MAX_CHANGE_TIME; lci.remainingTime = lci.changeTime; // pick lane (prefer left lane) if (safeLeft) { lci.toLeft = true; nextLane = smi.current.getLane(smi.currentLane) - 1; } else { lci.toLeft = false; nextLane = smi.current.getLane(smi.currentLane) + 1; } // store state laneChangers.put(id, lci); // add car to new lane, but don't remove from old while changing smi.current.addToLane(smi, nextLane); nextLaneList = smi.current.getLanes(smi)[nextLane]; lci.nextLane = nextLane; lci.nextCar = getNextCar(nextLaneList, smi); updateLaneChangeInfo(smi, lci); }
public StreetMobilityInfo getClosestCarInfo(StreetMobilityInfo smi, Integer id) { StreetMobilityInfo returnValue = null; LaneChangeInfo lci = (LaneChangeInfo) laneChangers.get(id); if (lci == null) return null; // this is wrong "currentlane" lci.nextCar = getNextCar(smi.current.getLanes(smi)[lci.nextLane], smi); if (lci.nextCar == null) return null; // float spacing = (float)smi.getCarSpacing()-1; // floating point imprecision here... if (lci.nextCar.getRemainingDist() + RoadSegment.CAR_LENGTH + RoadSegment.SPACE > smi.getRemainingDist()) throw new RuntimeException("Wrong next car!"); if (smi.nextCar == null || smi.nextCar.getRemainingDist() < lci.nextCar.getRemainingDist()) returnValue = lci.nextCar; else returnValue = smi.nextCar; if (smi.getRemainingDist() <= returnValue.getRemainingDist()) throw new RuntimeException("Wrong car picked!"); return returnValue; }