Skip to content

Commit

Permalink
feat: flexibly configure the drt insertion process (#2947)
Browse files Browse the repository at this point in the history
* drt insertion extension

* some last updates

* add warning about distance calculations

* switch Pair in InsertionDistanceCalculator to record

* integrate latest changes about group bookings

* take into account multi-person requests when calculating occupancy
  • Loading branch information
sebhoerl authored Nov 25, 2023
1 parent 269511e commit e2a10c2
Show file tree
Hide file tree
Showing 17 changed files with 1,671 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.matsim.contrib.drt.extension.insertion;

import java.util.List;

import javax.annotation.Nullable;

import org.matsim.contrib.drt.optimizer.insertion.CostCalculationStrategy;
import org.matsim.contrib.drt.optimizer.insertion.InsertionCostCalculator;
import org.matsim.contrib.drt.optimizer.insertion.InsertionDetourTimeCalculator.DetourTimeInfo;
import org.matsim.contrib.drt.optimizer.insertion.InsertionGenerator.Insertion;
import org.matsim.contrib.drt.passenger.DrtRequest;

public class ConfigurableCostCalculatorStrategy implements CostCalculationStrategy {
private final List<DrtInsertionConstraint> constraints;
private final DrtInsertionObjective objective;

private final SoftInsertionParams softInsertionParams;

public ConfigurableCostCalculatorStrategy(DrtInsertionObjective objective, List<DrtInsertionConstraint> constraints,
@Nullable SoftInsertionParams softInsertionParams) {
this.objective = objective;
this.constraints = constraints;
this.softInsertionParams = softInsertionParams;
}

private boolean checkHardInsertion(DrtRequest request, DetourTimeInfo detourTimeInfo) {
return detourTimeInfo.pickupDetourInfo.departureTime <= request.getLatestStartTime()
&& detourTimeInfo.dropoffDetourInfo.arrivalTime <= request.getLatestArrivalTime();
}

private double calculateSoftInsertionPenalty(DrtRequest request, DetourTimeInfo detourTimeInfo) {
if (softInsertionParams == null) {
return 0.0;
} else {
double pickupDelay = Math.max(0,
detourTimeInfo.pickupDetourInfo.departureTime - request.getLatestStartTime());

double dropoffDelay = Math.max(0,
detourTimeInfo.dropoffDetourInfo.arrivalTime - request.getLatestArrivalTime());

return softInsertionParams.pickupWeight * pickupDelay + softInsertionParams.dropoffWeight * dropoffDelay;
}
}

@Override
public double calcCost(DrtRequest request, Insertion insertion, DetourTimeInfo detourTimeInfo) {
if (softInsertionParams == null && !checkHardInsertion(request, detourTimeInfo)) {
return InsertionCostCalculator.INFEASIBLE_SOLUTION_COST;
}

for (DrtInsertionConstraint constraint : constraints) {
if (!constraint.checkInsertion(request, insertion, detourTimeInfo)) {
return InsertionCostCalculator.INFEASIBLE_SOLUTION_COST;
}
}

return objective.calculateObjective(request, insertion, detourTimeInfo)
+ calculateSoftInsertionPenalty(request, detourTimeInfo);
}

static record SoftInsertionParams(double pickupWeight, double dropoffWeight) {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.matsim.contrib.drt.extension.insertion;

import org.matsim.contrib.drt.optimizer.insertion.InsertionDetourTimeCalculator.DetourTimeInfo;
import org.matsim.contrib.drt.optimizer.insertion.InsertionGenerator.Insertion;
import org.matsim.contrib.drt.passenger.DrtRequest;

public interface DrtInsertionConstraint {
boolean checkInsertion(DrtRequest drtRequest, Insertion insertion, DetourTimeInfo detourTimeInfo);
}
Loading

0 comments on commit e2a10c2

Please sign in to comment.