private VrpPathWithTravelData calculateFromPickupToPickup( VrpPathWithTravelData previous, TaxibusRequest current, double time) { return VrpPaths.calcAndCreatePath( previous.getToLink(), current.getFromLink(), time, routerWithCache, optimContext.travelTime); }
@Override protected void scheduleUnplannedRequests() { Set<TaxibusRequest> handledRequests = new HashSet<>(); for (TaxibusRequest req : unplannedRequests) { TaxibusLine line = dispatcher.findLineForRequest(req); if (line == null) { log.error("rejecting reqeuest" + req.getId() + " f " + req.getPassenger()); req.setRejected(true); handledRequests.add(req); continue; } if (this.optimContext.timer.getTimeOfDay() > req.getT0() - 3600) { TaxibusDispatch requestPath = this.currentRequestPathForLine.get(line.getId()); if (requestPath == null) { Vehicle veh = line.getNextEmptyVehicle(); if (veh == null) break; VrpPathWithTravelData path = calculateVrpPath(veh, req); requestPath = new TaxibusDispatch(veh, req, path); this.currentRequestPathForLine.put(line.getId(), requestPath); double twmax = Math.max(req.getT0(), path.getArrivalTime()) + line.getCurrentTwMax(); this.currentTwMax.put(line.getId(), twmax); } else { double departureTime = requestPath.getEarliestNextDeparture(); VrpPathWithTravelData path = calculateFromPickupToPickup(requestPath.getLastPathAdded(), req, departureTime); requestPath.addRequestAndPath(req, path); } handledRequests.add(req); if (line.getCurrentOccupationRate() == requestPath.requests.size()) { fillPathWithDropOffsAndSchedule(requestPath, line.getId()); this.currentRequestPathForLine.put(line.getId(), null); this.currentTwMax.put(line.getId(), null); } } } unplannedRequests.removeAll(handledRequests); }
private Tuple<VrpPathWithTravelData, TaxibusRequest> getNextDropoffSegment( Set<TaxibusRequest> allRequests, double departureTime, Link departureLink) { double bestTime = Double.MAX_VALUE; Tuple<VrpPathWithTravelData, TaxibusRequest> bestSegment = null; for (TaxibusRequest request : allRequests) { VrpPathWithTravelData segment = VrpPaths.calcAndCreatePath( departureLink, request.getToLink(), departureTime, routerWithCache, optimContext.travelTime); if (segment.getTravelTime() < bestTime) { bestTime = segment.getTravelTime(); bestSegment = new Tuple<>(segment, request); } } return bestSegment; }
protected void scheduleRankReturn(Vehicle veh, double time, boolean charge, boolean home) { @SuppressWarnings("unchecked") Schedule<Task> sched = (Schedule<Task>) veh.getSchedule(); TaxiStayTask last = (TaxiStayTask) Schedules.getLastTask(veh.getSchedule()); if (last.getStatus() != TaskStatus.STARTED) throw new IllegalStateException(); last.setEndTime(time); Link currentLink = last.getLink(); Link nearestRank; if (charge) { nearestRank = optimizer.getNearestFreeCharger(currentLink.getId()); log.info("veh" + veh.getId() + " to charge"); } else if (home) { nearestRank = veh.getStartLink(); // log.info("start" + veh.getId()+ " at " + time + " t1 " + veh.getT1()); optimizer.homebound++; } else nearestRank = optimizer.getNearestFreeRank(currentLink.getId()); VrpPathWithTravelData path = calcPath(currentLink, nearestRank, time); if (path.getArrivalTime() > veh.getT1()) return; // no rank return if vehicle is going out of service anyway sched.addTask(new TaxiDriveTask(path)); sched.addTask(new TaxiStayTask(path.getArrivalTime(), veh.getT1(), nearestRank)); }