Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add late diversion constraint for drt detours #2455

Merged
merged 20 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public EmptyVehicleChargingScheduler get() {
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool()))).asEagerSingleton();

bindModal(InsertionCostCalculator.class).toProvider(modalProvider(
getter -> new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class))));
getter -> new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class), drtCfg)));

install(DrtModeOptimizerQSimModule.getInsertionSearchQSimModule(drtCfg));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ shiftsParams, new DefaultShiftStartLogic(), new DefaultAssignShiftToVehicleLogic

bindModal(InsertionCostCalculator.class).toProvider(modalProvider(
getter -> new ShiftInsertionCostCalculator(getter.get(MobsimTimer.class),
new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class)))));
new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class), drtCfg))));

bindModal(VehicleEntry.EntryFactory.class).toInstance(new ShiftVehicleDataEntryFactory(new VehicleDataEntryFactoryImpl(drtCfg)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void configureQSim() {
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool()))).asEagerSingleton();

bindModal(InsertionCostCalculator.class).toProvider(modalProvider(
getter -> new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class))));
getter -> new DefaultInsertionCostCalculator(getter.getModal(CostCalculationStrategy.class), drtCfg)));

install(getInsertionSearchQSimModule(drtCfg));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@

import static org.matsim.contrib.drt.optimizer.insertion.InsertionGenerator.Insertion;

import org.matsim.contrib.drt.optimizer.Waypoint;
import org.matsim.contrib.drt.optimizer.insertion.InsertionDetourTimeCalculator.DetourTimeInfo;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.run.DrtConfigGroup;

/**
* @author michalm
*/
public class DefaultInsertionCostCalculator implements InsertionCostCalculator {
private final CostCalculationStrategy costCalculationStrategy;
private final DrtConfigGroup drtConfigGroup;

public DefaultInsertionCostCalculator(CostCalculationStrategy costCalculationStrategy) {
public DefaultInsertionCostCalculator(CostCalculationStrategy costCalculationStrategy,
DrtConfigGroup drtConfigGroup) {
this.costCalculationStrategy = costCalculationStrategy;
this.drtConfigGroup = drtConfigGroup;
}

/**
Expand All @@ -55,6 +60,23 @@ public double calculate(DrtRequest drtRequest, Insertion insertion, DetourTimeIn
return INFEASIBLE_SOLUTION_COST;
}

// divert right now
if(insertion.pickup.index == 0) {
Waypoint nextWaypoint = insertion.pickup.nextWaypoint;
// there is an existing stop following the new insertion
if(nextWaypoint instanceof Waypoint.Stop && nextWaypoint != insertion.pickup.newWaypoint) {
// passengers are being dropped off == may be close to arrival
nkuehnel marked this conversation as resolved.
Show resolved Hide resolved
if(!((Waypoint.Stop) nextWaypoint).task.getDropoffRequests().isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the second next waypoint is dropping off and is within the defined time limit?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. This means we need to iterate over all scheduled stops!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... all scheduled stops within the fixedApproachTime horizon

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @michalmac
I updated the code to check for all scheduled stops and check whether the actual detour caused is >0 (in some configurations it could also be that the new insertion is after the next stop and only adds an additional passenger to an existing stop without increasing stop duration, in which case there wouldn't be any additional detour)

double nextArrival = nextWaypoint.getArrivalTime();
double departureTime = insertion.vehicleEntry.start.getDepartureTime();
//arrival is very soon
if (nextArrival - departureTime < drtConfigGroup.fixedApproachTime) {
return INFEASIBLE_SOLUTION_COST;
}
}
}
}

nkuehnel marked this conversation as resolved.
Show resolved Hide resolved
return costCalculationStrategy.calcCost(drtRequest, insertion, detourTimeInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ public enum OperationalScheme {
@PositiveOrZero
public double advanceRequestPlanningHorizon = 0; // beta-feature; planning horizon for advance (prebooked) requests

@Parameter
@Comment(
"Time before reaching a planned dropoff from which it is not allowed to insert new detours for new requests. I.e.," +
" if set to 180, then a vehicle will not divert to pickup a new passenger once a boarded passenger is only " +
nkuehnel marked this conversation as resolved.
Show resolved Hide resolved
"3 minutes away from her destination, even though her time window would allow it." +
" Delayed detour just before arrival are usually perceived very negatively.")
nkuehnel marked this conversation as resolved.
Show resolved Hide resolved
@PositiveOrZero // used only for stopbased DRT scheme
public double fixedApproachTime = 0;// [m];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixedApproachTime is too general. It will be very hard to memorise what it means. I think we need a name that would be more expressive.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "allowDetourBeforeArrivalThreshold"?


@NotNull
private DrtInsertionSearchParams drtInsertionSearchParams;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.matsim.contrib.drt.optimizer.VehicleEntry;
import org.matsim.contrib.drt.optimizer.insertion.InsertionGenerator.Insertion;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.testcases.fakes.FakeLink;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ public void testCalculate() {

private void assertCalculate(Insertion insertion, DetourTimeInfo detourTimeInfo, double expectedCost) {
var insertionCostCalculator = new DefaultInsertionCostCalculator(
new CostCalculationStrategy.RejectSoftConstraintViolations());
new CostCalculationStrategy.RejectSoftConstraintViolations(), new DrtConfigGroup());
var insertionWithDetourData = new InsertionWithDetourData(insertion, null, detourTimeInfo);
assertThat(insertionCostCalculator.calculate(drtRequest, insertionWithDetourData.insertion,
insertionWithDetourData.detourTimeInfo)).isEqualTo(expectedCost);
Expand Down