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); } }
public EndLegMessage(final Scheduler scheduler, final Vehicle vehicle) { // need the time interpretation info here. Attaching it to the message feels weird. The scheduler seems a pure simulation object. // Consequence: attach it to Vehicle super(scheduler, vehicle); this.priority = JDEQSimConfigGroup.PRIORITY_ARRIVAL_MESSAGE; if ( vehicle == null ) { this.activityDurationInterpretation = PlansConfigGroup.ActivityDurationInterpretation.minOfDurationAndEndTime ; // need this for some test cases. kai, nov'13 } else { this.activityDurationInterpretation = vehicle.getActivityEndTimeInterpretation() ; } }
private void scheduleEndLegMessage(double time) { // move to first link in next leg and schedule an end leg message vehicle.moveToFirstLinkInNextLeg(); Road road = Road.getRoad(vehicle.getCurrentLinkId()); vehicle.scheduleEndLegMessage(time, road); }
/** * 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()]); }
/** * 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()); }
this.vehicle.setLegIndex(this.vehicle.getLegIndex() + 2); this.vehicle.setLinkIndex(-1); Plan plan = this.vehicle.getOwnerPerson().getSelectedPlan(); List<? extends PlanElement> actsLegs = plan.getPlanElements(); if ((actsLegs.size() > this.vehicle.getLegIndex())) { this.vehicle.setCurrentLeg((Leg) actsLegs.get(this.vehicle.getLegIndex())); Activity currentAct = (Activity) actsLegs.get(this.vehicle.getLegIndex() - 1); this.vehicle.setCurrentLinkId(currentAct.getLinkId()); Road road = Road.getRoad(this.vehicle.getCurrentLinkId()); this.vehicle.scheduleStartingLegMessage(departureTime, road);
@Override public void handleMessage() { if (vehicle.isCurrentLegFinished()) { /* * the leg is completed, try to enter the last link but do not enter * it (just wait, until you have clearance for enter and then leave * the road) */ vehicle.initiateEndingLegMode(); vehicle.moveToFirstLinkInNextLeg(); Road road = Road.getRoad(vehicle.getCurrentLinkId()); road.enterRequest(vehicle, getMessageArrivalTime()); } else if (!vehicle.isCurrentLegFinished()) { // if leg is not finished yet vehicle.moveToNextLinkInLeg(); Road nextRoad = Road.getRoad(vehicle.getCurrentLinkId()); nextRoad.enterRequest(vehicle, getMessageArrivalTime()); } }
@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); }
@Override public void processEvent() { Event event; // schedule ActEndEvent event = new ActivityEndEvent(this.getMessageArrivalTime(), vehicle.getOwnerPerson().getId(), vehicle.getCurrentLinkId(), vehicle .getPreviousActivity().getFacilityId(), vehicle.getPreviousActivity().getType()); eventsManager.processEvent(event); // schedule AgentDepartureEvent event = new PersonDepartureEvent(this.getMessageArrivalTime(), vehicle.getOwnerPerson().getId(), vehicle.getCurrentLinkId(), vehicle.getCurrentLeg().getMode()); eventsManager.processEvent(event); }
setCurrentLeg((Leg) actsLegs.get(legIndex)); Activity firstAct = (Activity) actsLegs.get(0); setCurrentLinkId(firstAct.getLinkId()); Road road = Road.getRoad(getCurrentLinkId()); scheduleStartingLegMessage(departureTime, road);
@Override public boolean handleActivity(MobsimAgent agent) { // We expect all the agents to appear here at the beginning of the simulation (starting their // overnight activity.) That's when we enter them into JDEQSim and never let them out. new Vehicle(scheduler, ((HasPerson) agent).getPerson(), scenario.getConfig().plans().getActivityDurationInterpretation()); numberOfAgents++; return true; }
public void moveToFirstLinkInNextLeg() { Plan plan = getOwnerPerson().getSelectedPlan(); List<? extends PlanElement> actsLegs = plan.getPlanElements(); setCurrentLinkId(((Activity) actsLegs.get(getLegIndex() + 1)).getLinkId()); }
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 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); }
@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()); } }
public void initiateEndingLegMode() { linkIndex = getCurrentLinkRoute().length; }
@Override public void handleMessage() { // enter the next road Road road = Road.getRoad(vehicle.getCurrentLinkId()); road.enterRoad(vehicle, getMessageArrivalTime()); }
@Override public void processEvent() { Road road = (Road) this.getReceivingUnit(); Event event = null; event = new LinkLeaveEvent(this.getMessageArrivalTime(), Id.create(vehicle.getOwnerPerson().getId(), org.matsim.vehicles.Vehicle.class), road.getLink().getId()); eventsManager.processEvent(event); }
@Override public void run() { events.initProcessing(); Timer t = new Timer(); t.startTimer(); Scheduler scheduler = new Scheduler(new MessageQueue(), config.getSimulationEndTime()); Road.setAllRoads(new HashMap<Id<Link>, Road>()); // initialize network Road road; for (Link link : this.scenario.getNetwork().getLinks().values()) { road = new Road(scheduler, link); Road.getAllRoads().put(link.getId(), road); } for (Person person : this.scenario.getPopulation().getPersons().values()) { new Vehicle(scheduler, person, activityDurationInterpretation); // the vehicle registers itself to the scheduler } scheduler.startSimulation(); t.endTimer(); log.info("Time needed for one iteration (only JDEQSimulation part): " + t.getMeasuredTime() + "[ms]"); events.finishProcessing(); } }
public boolean isCurrentLegFinished() { return getCurrentLinkRoute().length == getLinkIndex() + 1; }