Skip to content

Commit

Permalink
remove prebooking
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Jan 4, 2024
1 parent cbfbb68 commit 0ea60d5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.common.base.Verify;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;
import jakarta.validation.constraints.PositiveOrZero;

/**
Expand Down Expand Up @@ -210,22 +209,6 @@ public int getCandidateVehiclesPerRequest() {
public void setCandidateVehiclesPerRequest(int value) {
this.candidateVehiclesPerRequest = value;
}

private final static String PLANNING_HORIZON = "planningHorizon";
private final static String PLANNING_HORIZON_COMMENT = "Defines how much in advance requests are considered for scheduling";

@PositiveOrZero
private double planningHorizon = 0.0;

@StringGetter(PLANNING_HORIZON)
public double getPlanningHorizon() {
return planningHorizon;
}

@StringSetter(PLANNING_HORIZON)
public void setPlanningHorizon(double value) {
this.planningHorizon = value;
}

@Override
public Map<String, String> getComments() {
Expand All @@ -251,7 +234,6 @@ public Map<String, String> getComments() {
comments.put(VIOLATION_OFFSET, VIOLATION_OFFSET_COMMENT);
comments.put(PREFER_NON_VIOLATION, PREFER_NON_VIOLATION_COMMENT);
comments.put(CANDIDATE_VEHICLES_PER_REQUEST, CANDIDATE_VEHICLES_PER_REQUEST_COMMENT);
comments.put(PLANNING_HORIZON, PLANNING_HORIZON_COMMENT);
return comments;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ protected void configureQSim() {
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), //
getter.getModal(LeastCostPathCalculator.class), //
getter.getModal(TravelTime.class), //
amConfig.getPlanningHorizon(), //
getter.getModal(InformationCollector.class) //
);
}));
Expand Down
30 changes: 5 additions & 25 deletions core/src/main/java/org/matsim/alonso_mora/AlonsoMoraOptimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.ForkJoinPool;
import java.util.stream.IntStream;

Expand Down Expand Up @@ -45,15 +43,9 @@ public class AlonsoMoraOptimizer implements DrtOptimizer {

private final InformationCollector collector;

private final Queue<AlonsoMoraRequest> prebookingQueue = new PriorityQueue<>((a, b) -> {
return Double.compare(a.getEarliestPickupTime(), b.getEarliestPickupTime());
});

private final double prebookingHorizon;

public AlonsoMoraOptimizer(AlonsoMoraAlgorithm algorithm, AlonsoMoraRequestFactory requestFactory,
ScheduleTimingUpdater scheduleTimingUpdater, Fleet fleet, double assignmentInterval,
ForkJoinPool forkJoinPool, LeastCostPathCalculator router, TravelTime travelTime, double prebookingHorizon,
ForkJoinPool forkJoinPool, LeastCostPathCalculator router, TravelTime travelTime,
InformationCollector collector) {
this.algorithm = algorithm;
this.requestFactory = requestFactory;
Expand All @@ -63,7 +55,6 @@ public AlonsoMoraOptimizer(AlonsoMoraAlgorithm algorithm, AlonsoMoraRequestFacto
this.forkJoinPool = forkJoinPool;
this.router = router;
this.travelTime = travelTime;
this.prebookingHorizon = prebookingHorizon;
this.collector = collector;
}

Expand All @@ -77,7 +68,7 @@ public void notifyMobsimBeforeSimStep(@SuppressWarnings("rawtypes") MobsimBefore
double now = e.getSimulationTime();

if (now % assignmentInterval == 0) {
List<AlonsoMoraRequest> newRequests = new LinkedList<>();
List<AlonsoMoraRequest> processedRequests = new LinkedList<>();

List<DrtRequest> submittedRequests = new ArrayList<>(this.submittedRequests);
this.submittedRequests.clear();
Expand All @@ -93,7 +84,6 @@ public void notifyMobsimBeforeSimStep(@SuppressWarnings("rawtypes") MobsimBefore
});
}).join();

// Grouped requests
for (int i = 0; i < submittedRequests.size(); i++) {
DrtRequest drtRequest = submittedRequests.get(i);

Expand All @@ -104,25 +94,15 @@ public void notifyMobsimBeforeSimStep(@SuppressWarnings("rawtypes") MobsimBefore
AlonsoMoraRequest request = requestFactory.createRequest(drtRequest, directArrivalTime,
earliestDepartureTime, directRideDistance);

if (now >= request.getEarliestPickupTime() - prebookingHorizon) {
newRequests.add(request);
} else {
prebookingQueue.add(request);
}
processedRequests.add(request);
}

while (prebookingQueue.size() > 0
&& now >= prebookingQueue.peek().getEarliestPickupTime() - prebookingHorizon) {
newRequests.add(prebookingQueue.poll());
}

submittedRequests.clear();

for (DvrpVehicle v : fleet.getVehicles().values()) {
scheduleTimingUpdater.updateTimings(v);
}

Optional<AlonsoMoraAlgorithm.Information> information = algorithm.run(newRequests, e.getSimulationTime());
Optional<AlonsoMoraAlgorithm.Information> information = algorithm.run(processedRequests,
e.getSimulationTime());

if (information.isPresent()) {
collector.addInformation(e.getSimulationTime(), information.get());
Expand Down

0 comments on commit 0ea60d5

Please sign in to comment.