Skip to content

Commit

Permalink
remove group requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Jan 4, 2024
1 parent 165bec0 commit cbfbb68
Show file tree
Hide file tree
Showing 38 changed files with 996 additions and 1,169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,6 @@ public void setMaximumQueueTime(double value) {
this.maximumQueueTime = value;
}

private final static String MAXIMUM_GROUP_REQUEST_SIZE = "maximumGroupRequestSize";
private final static String MAXIMUM_GROUP_REQUEST_SIZE_COMMENT = "For computational reasons, the implementation can group multiple individual requests with the same departure time and OD requirements into one aggregate request. This value defines the size limit for aggregation as large group requests may not fit in some vehicles (based on their capacity).";

@Positive
private int maximumGroupRequestSize = 6;

@StringGetter(MAXIMUM_GROUP_REQUEST_SIZE)
public int getMaximumGroupRequestSize() {
return maximumGroupRequestSize;
}

@StringSetter(MAXIMUM_GROUP_REQUEST_SIZE)
public void setMaximumGroupRequestSize(int value) {
this.maximumGroupRequestSize = value;
}

private final static String USE_PLANNED_PICKUP_TIME = "usePlannedPickupTime";
private final static String USE_PLANNED_PICKUP_TIME_COMMENT = "By default, the algorithm updates the latest pickup time for a request to the planned pickup time that has been calculated at the first assignment. Subsequent dispatching steps must adhere to that value. Using this flag, this functionality may be turned off.";

Expand Down Expand Up @@ -249,7 +233,6 @@ public Map<String, String> getComments() {
comments.put(MODE, MODE_COMMENT);
comments.put(LOGGING_INTERVAL, LOGGING_INTERVAL_COMMENT);
comments.put(MAXIMUM_QUEUE_TIME, MAXIMUM_QUEUE_TIME_COMMENT);
comments.put(MAXIMUM_GROUP_REQUEST_SIZE, MAXIMUM_GROUP_REQUEST_SIZE_COMMENT);
comments.put(USE_PLANNED_PICKUP_TIME, USE_PLANNED_PICKUP_TIME_COMMENT);
comments.put(PLANNED_PICKUP_TIME_SLACK, PLANNED_PICKUP_TIME_SLACK_COMMENT);
comments.put(CHECK_DETERMINISTIC_TRAVEL_TIMES, CHECK_DETERMINISTIC_TRAVEL_TIMES_COMMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ public void install() {
return new InformationCollector();
})).asEagerSingleton();

bindModal(RequestAggregationHandler.class).to(RequestAggregationHandler.class).asEagerSingleton();
addEventHandlerBinding().to(modalKey(RequestAggregationHandler.class));

bindModal(AnalysisListener.class).toProvider(modalProvider(getter -> {
return new AnalysisListener( //
getter.getModal(InformationCollector.class), //
getter.get(OutputDirectoryHierarchy.class), //
getter.getModal(RequestAggregationHandler.class) //
getter.get(OutputDirectoryHierarchy.class) //
);
})).asEagerSingleton();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ protected void configureQSim() {
getter.getModal(ScheduleTimingUpdater.class), //
getter.getModal(Fleet.class), //
amConfig.getAssignmentInterval(), //
amConfig.getMaximumGroupRequestSize(), //
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), //
getter.getModal(LeastCostPathCalculator.class), //
getter.getModal(TravelTime.class), //
Expand Down
71 changes: 17 additions & 54 deletions core/src/main/java/org/matsim/alonso_mora/AlonsoMoraOptimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
Expand All @@ -15,7 +14,6 @@
import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest;
import org.matsim.alonso_mora.algorithm.AlonsoMoraRequestFactory;
import org.matsim.contrib.drt.optimizer.DrtOptimizer;
import org.matsim.contrib.drt.passenger.AcceptedDrtRequest;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.fleet.Fleet;
Expand All @@ -41,8 +39,6 @@ public class AlonsoMoraOptimizer implements DrtOptimizer {
private final List<DrtRequest> submittedRequests = new LinkedList<>();
private final double assignmentInterval;

private final int maximumGroupRequestSize;

private final ForkJoinPool forkJoinPool;
private final LeastCostPathCalculator router;
private final TravelTime travelTime;
Expand All @@ -57,14 +53,13 @@ public class AlonsoMoraOptimizer implements DrtOptimizer {

public AlonsoMoraOptimizer(AlonsoMoraAlgorithm algorithm, AlonsoMoraRequestFactory requestFactory,
ScheduleTimingUpdater scheduleTimingUpdater, Fleet fleet, double assignmentInterval,
int maximumGroupRequestSize, ForkJoinPool forkJoinPool, LeastCostPathCalculator router,
TravelTime travelTime, double prebookingHorizon, InformationCollector collector) {
ForkJoinPool forkJoinPool, LeastCostPathCalculator router, TravelTime travelTime, double prebookingHorizon,
InformationCollector collector) {
this.algorithm = algorithm;
this.requestFactory = requestFactory;
this.assignmentInterval = assignmentInterval;
this.scheduleTimingUpdater = scheduleTimingUpdater;
this.fleet = fleet;
this.maximumGroupRequestSize = maximumGroupRequestSize;
this.forkJoinPool = forkJoinPool;
this.router = router;
this.travelTime = travelTime;
Expand All @@ -77,69 +72,37 @@ public void requestSubmitted(Request request) {
submittedRequests.add((DrtRequest) request);
}

/**
* Goes through the submitted individual requests and tries to find those that
* should be aggregated to a collective request.
*/
private List<List<DrtRequest>> poolRequests(List<DrtRequest> submittedRequests) {
submittedRequests = new LinkedList<>(submittedRequests);
List<List<DrtRequest>> allPooledRequests = new LinkedList<>();

while (submittedRequests.size() > 0) {
List<DrtRequest> pooledRequests = new LinkedList<>();
pooledRequests.add(submittedRequests.remove(0));
DrtRequest mainRequest = pooledRequests.get(0);

Iterator<DrtRequest> iterator = submittedRequests.iterator();

while (iterator.hasNext() && pooledRequests.size() < maximumGroupRequestSize) {
DrtRequest nextRequest = iterator.next();

if (nextRequest.getFromLink() == mainRequest.getFromLink()) {
if (nextRequest.getToLink() == mainRequest.getToLink()) {
if (nextRequest.getEarliestStartTime() == mainRequest.getEarliestStartTime()) {
pooledRequests.add(nextRequest);
iterator.remove();
}
}
}
}

allPooledRequests.add(pooledRequests);
}

return allPooledRequests;
}

@Override
public void notifyMobsimBeforeSimStep(@SuppressWarnings("rawtypes") MobsimBeforeSimStepEvent e) {
double now = e.getSimulationTime();

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

List<List<DrtRequest>> pooledRequests = poolRequests(submittedRequests);
List<VrpPathWithTravelData> paths = new ArrayList<>(Collections.nCopies(pooledRequests.size(), null));
List<DrtRequest> submittedRequests = new ArrayList<>(this.submittedRequests);
this.submittedRequests.clear();

List<VrpPathWithTravelData> paths = new ArrayList<>(Collections.nCopies(submittedRequests.size(), null));

// Here this direct routing is performed
forkJoinPool.submit(() -> {
IntStream.range(0, pooledRequests.size()).parallel().forEach(i -> {
DrtRequest request = pooledRequests.get(i).get(0);
paths.set(i, VrpPaths.calcAndCreatePath(request.getFromLink(), request.getToLink(), request.getEarliestStartTime(), router,
travelTime));
IntStream.range(0, submittedRequests.size()).parallel().forEach(i -> {
DrtRequest request = submittedRequests.get(i);
paths.set(i, VrpPaths.calcAndCreatePath(request.getFromLink(), request.getToLink(),
request.getEarliestStartTime(), router, travelTime));
});
}).join();

// Grouped requests
for (int i = 0; i < pooledRequests.size(); i++) {
List<DrtRequest> pool = pooledRequests.get(i);
double earliestDepartureTime = pool.get(0).getEarliestStartTime();
for (int i = 0; i < submittedRequests.size(); i++) {
DrtRequest drtRequest = submittedRequests.get(i);

double earliestDepartureTime = drtRequest.getEarliestStartTime();
double directArrivalTime = paths.get(i).getTravelTime() + earliestDepartureTime;
double directRideDistance = VrpPaths.calcDistance(paths.get(i));

AlonsoMoraRequest request = requestFactory.createRequest(pool, directArrivalTime, earliestDepartureTime,
directRideDistance);
AlonsoMoraRequest request = requestFactory.createRequest(drtRequest, directArrivalTime,
earliestDepartureTime, directRideDistance);

if (now >= request.getEarliestPickupTime() - prebookingHorizon) {
newRequests.add(request);
Expand Down

This file was deleted.

This file was deleted.

26 changes: 1 addition & 25 deletions core/src/main/java/org/matsim/alonso_mora/AnalysisListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

Expand All @@ -32,11 +31,9 @@
import org.matsim.alonso_mora.InformationCollector.RebalancingInformation;
import org.matsim.alonso_mora.InformationCollector.SolverInformation;
import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver.Solution.Status;
import org.matsim.api.core.v01.Id;
import org.matsim.contrib.common.timeprofile.TimeProfileCharts;
import org.matsim.contrib.common.timeprofile.TimeProfileCharts.ChartType;
import org.matsim.contrib.common.util.ChartSaveUtils;
import org.matsim.contrib.dvrp.optimizer.Request;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.controler.events.IterationEndsEvent;
import org.matsim.core.controler.listener.IterationEndsListener;
Expand All @@ -50,19 +47,16 @@
*/
class AnalysisListener implements IterationEndsListener {
private final InformationCollector information;
private final RequestAggregationHandler requestHandler;
private final OutputDirectoryHierarchy outputHierarchy;

private final List<Long> numberOfInvalidSolutions = new LinkedList<>();
private final List<Long> numberOfNonOptimalSolutions = new LinkedList<>();
private final List<Long> numberOfOptimalSolutions = new LinkedList<>();
private final List<Long> numberOfReassignments = new LinkedList<>();

public AnalysisListener(InformationCollector information, OutputDirectoryHierarchy outputHierarchy,
RequestAggregationHandler requestHandler) {
public AnalysisListener(InformationCollector information, OutputDirectoryHierarchy outputHierarchy) {
this.information = information;
this.outputHierarchy = outputHierarchy;
this.requestHandler = requestHandler;
}

@Override
Expand Down Expand Up @@ -364,23 +358,5 @@ public void notifyIterationEnds(IterationEndsEvent event) {
ChartSaveUtils.saveAsPNG(stackedChart,
outputHierarchy.getIterationFilename(event.getIteration(), "am_occupancy_requests"), 1500, 1000);
}

{
List<Set<Id<Request>>> requests = requestHandler.consolidate();

try {
File path = new File(
outputHierarchy.getIterationFilename(event.getIteration(), "am_group_requests.txt"));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path)));

for (Set<Id<Request>> set : requests) {
writer.write(set.stream().map(String::valueOf).collect(Collectors.joining(",")) + "\n");
}

writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

This file was deleted.

Loading

0 comments on commit cbfbb68

Please sign in to comment.