-
Notifications
You must be signed in to change notification settings - Fork 456
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: flexibly configure the drt insertion process (#2947)
* 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
Showing
17 changed files
with
1,671 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
...n/java/org/matsim/contrib/drt/extension/insertion/ConfigurableCostCalculatorStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ions/src/main/java/org/matsim/contrib/drt/extension/insertion/DrtInsertionConstraint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.