/** * find out, if the vehicle is in endingLegMode this means, that the vehicle * is just waiting until it can enter the last link (without entering it) * and then ends the leg * * @return */ public boolean isEndingLegMode() { return (getCurrentLinkRoute().length == getLinkIndex()); }
public boolean isCurrentLegFinished() { return getCurrentLinkRoute().length == getLinkIndex() + 1; }
/** * updates both the currentLink and link index variables with the next link * in the link route of the current leg attention: only applicable, if * isCurrentLegFinished==false */ public void moveToNextLinkInLeg() { setLinkIndex(getLinkIndex() + 1); setCurrentLinkId(getCurrentLinkRoute()[getLinkIndex()]); }
public void scheduleLeavePreviousRoadMessage(double scheduleTime) { Road previousRoad = null; Id<Link> previousLinkId = null; /* * we need to handle the first road in a leg specially, because the load * to be left is accessed over the last act performed instead of the leg */ if (this.getLinkIndex() == 0) { Plan plan = ownerPerson.getSelectedPlan(); List<? extends PlanElement> actsLegs = plan.getPlanElements(); previousLinkId = ((Activity) actsLegs.get(legIndex - 1)).getLinkId(); previousRoad = Road.getRoad(previousLinkId); } else if (this.getLinkIndex() >= 1) { previousLinkId = this.getCurrentLinkRoute()[this.getLinkIndex() - 1]; previousRoad = Road.getRoad(previousLinkId); } else { log.error("Some thing is wrong with the simulation: Why is this.getLinkIndex() negative"); } scheduleLeaveRoadMessage(scheduleTime, previousRoad); }
public void scheduleEnterRoadMessage(double scheduleTime, Road road) { /* * before entering the new road, we must leave the previous road (if * there is a previous road) the first link does not need to be left * (which has index -1) */ if (this.getLinkIndex() >= 0) { scheduleLeavePreviousRoadMessage(scheduleTime); } if (isEndingLegMode()) { /* * attention: as we are not actually entering the road, we need to * give back the promised space to the road else a precondition of * the enterRequest would not be correct any more (which involves * the noOfCarsPromisedToEnterRoad variable) */ road.giveBackPromisedSpaceToRoad(); // next road scheduleEndLegMessage(scheduleTime, road); } else { _scheduleEnterRoadMessage(scheduleTime, road); } }
@Override public void processEvent() { Event event = null; // the first EnterLink in a leg is a Wait2LinkEvent if (vehicle.getLinkIndex() == -1) { event = new VehicleEntersTrafficEvent(this.getMessageArrivalTime(), vehicle.getOwnerPerson().getId(), vehicle.getCurrentLinkId(), Id.create(vehicle.getOwnerPerson().getId(), org.matsim.vehicles.Vehicle.class), null, 1.0); } else { event = new LinkEnterEvent(this.getMessageArrivalTime(), Id.create(vehicle.getOwnerPerson().getId(), org.matsim.vehicles.Vehicle.class), vehicle.getCurrentLinkId()); } eventsManager.processEvent(event); }