public void initiateEndingLegMode() { linkIndex = getCurrentLinkRoute().length; }
/** * 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); }
@Override public void handleMessage() { // if current leg is in car mode, then enter request in first road if (vehicle.getCurrentLeg().getMode().equals(TransportMode.car)) { // if empty leg, then end leg, else simulate leg if (vehicle.getCurrentLinkRoute().length == 0) { // move to first link in next leg and schedule an end leg // message // duration of leg = 0 (departure and arrival time is the same) scheduleEndLegMessage(getMessageArrivalTime()); } else { // start the new leg Road road = Road.getRoad(vehicle.getCurrentLinkId()); road.enterRequest(vehicle, getMessageArrivalTime()); } } else { scheduleEndLegMessage(getMessageArrivalTime() + vehicle.getCurrentLeg().getTravelTime()); } }
@Override public void processEvent() { Event event = null; // schedule enter link event // only, if car leg and is not empty if (vehicle.getCurrentLeg().getMode().equals(TransportMode.car) && (vehicle.getCurrentLinkRoute()!=null && vehicle.getCurrentLinkRoute().length!=0)){ event = new LinkEnterEvent(this.getMessageArrivalTime(), Id.create(vehicle.getOwnerPerson().getId().toString(), org.matsim.vehicles.Vehicle.class), vehicle.getCurrentLinkId()); eventsManager.processEvent(event); } // schedule VehicleLeavesTrafficEvent Id<org.matsim.vehicles.Vehicle> vehicleId = Id.create( this.vehicle.getOwnerPerson().getId() , org.matsim.vehicles.Vehicle.class ) ; event = new VehicleLeavesTrafficEvent(this.getMessageArrivalTime(), this.vehicle.getOwnerPerson().getId(), this.vehicle.getCurrentLinkId(), vehicleId, this.vehicle.getCurrentLeg().getMode(), 1.0 ); eventsManager.processEvent(event); // schedule AgentArrivalEvent event = new PersonArrivalEvent(this.getMessageArrivalTime(), this.vehicle.getOwnerPerson().getId(), this.vehicle.getCurrentLinkId(), this.vehicle.getCurrentLeg().getMode()); eventsManager.processEvent(event); // schedule ActStartEvent Activity nextAct = this.vehicle.getNextActivity(); double actStartEventTime = nextAct.getStartTime(); if (this.getMessageArrivalTime() > actStartEventTime) { actStartEventTime = this.getMessageArrivalTime(); } event = new ActivityStartEvent(actStartEventTime, this.vehicle.getOwnerPerson().getId(), this.vehicle.getCurrentLinkId(), nextAct.getFacilityId(), nextAct.getType()); eventsManager.processEvent(event); }