Skip to content

Commit

Permalink
chore: update to MATSim 15 (#29)
Browse files Browse the repository at this point in the history
* chore: update to MATSim 15

* update github workflow
  • Loading branch information
sebhoerl authored Nov 27, 2023
1 parent 238cf5e commit d354656
Show file tree
Hide file tree
Showing 26 changed files with 154 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 17
- name: Install GLPK and CBC
run: sudo apt install glpk-utils coinor-cbc libglpk-java
- name: Run tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.matsim.contrib.drt.run.DrtConfigGroup;
import org.matsim.contrib.drt.schedule.DrtStayTaskEndTimeCalculator;
import org.matsim.contrib.drt.schedule.DrtTaskFactory;
import org.matsim.contrib.drt.schedule.StopDurationEstimator;
import org.matsim.contrib.drt.scheduler.DrtScheduleInquiry;
import org.matsim.contrib.drt.scheduler.EmptyVehicleRelocator;
import org.matsim.contrib.dvrp.fleet.Fleet;
Expand Down Expand Up @@ -219,7 +220,7 @@ protected void configureQSim() {
Network network = getter.getModal(Network.class);
TravelTime travelTime = getter.getModal(TravelTime.class);

return new ParallelLeastCostPathCalculator(drtConfig.getNumberOfThreads(), factory, network,
return new ParallelLeastCostPathCalculator(drtConfig.numberOfThreads, factory, network,
new OnlyTimeDependentTravelDisutility(travelTime), travelTime);
}));

Expand Down Expand Up @@ -322,7 +323,7 @@ protected void configureQSim() {
CongestionMitigationParameters congestionParameters = amConfig.getCongestionMitigationParameters();

return new DefaultAlonsoMoraFunction(travelTimeEstimator, sequenceGeneratorFactory,
drtConfig.getStopDuration(), congestionParameters.getAllowPickupViolations(),
drtConfig.stopDuration, congestionParameters.getAllowPickupViolations(),
congestionParameters.getAllowPickupsWithDropoffViolations(),
amConfig.getCheckDeterminsticTravelTimes(), objective, constraint, amConfig.getViolationFactor(),
amConfig.getViolationOffset(), amConfig.getPreferNonViolation());
Expand All @@ -332,7 +333,7 @@ protected void configureQSim() {
bindModal(Constraint.class).toInstance(new NoopConstraint());

bindModal(StayTaskEndTimeCalculator.class).toProvider(modalProvider(getter -> {
return new DrtStayTaskEndTimeCalculator(drtConfig);
return new DrtStayTaskEndTimeCalculator(getter.getModal(StopDurationEstimator.class));
}));

bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> {
Expand All @@ -345,7 +346,7 @@ protected void configureQSim() {

OperationalVoter operationalVoter = getter.getModal(OperationalVoter.class);

return new DefaultAlonsoMoraScheduler(taskFactory, drtConfig.getStopDuration(),
return new DefaultAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration,
amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime,
network, endTimeCalculator, router, operationalVoter);
}));
Expand All @@ -356,7 +357,7 @@ protected void configureQSim() {
Double rebalancingInterval = null;

if (drtConfig.getRebalancingParams().isPresent()) {
rebalancingInterval = (double) drtConfig.getRebalancingParams().get().getInterval();
rebalancingInterval = (double) drtConfig.getRebalancingParams().get().interval;
}

return new StandardRebalancer( //
Expand Down Expand Up @@ -388,7 +389,7 @@ protected void configureQSim() {
getter.getModal(AlonsoMoraVehicleFactory.class), //
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), //
getter.getModal(TravelTimeEstimator.class), //
drtConfig.getStopDuration(), //
drtConfig.stopDuration, //
new AlgorithmSettings(amConfig));
}));

Expand All @@ -408,7 +409,7 @@ protected void configureQSim() {
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), //
getter.getModal(LeastCostPathCalculator.class), //
getter.getModal(TravelTime.class), //
drtConfig.getAdvanceRequestPlanningHorizon(), //
drtConfig.advanceRequestPlanningHorizon, //
getter.getModal(InformationCollector.class) //
);
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import java.util.stream.Stream;

import org.apache.commons.lang3.tuple.Pair;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.alonso_mora.AlonsoMoraConfigGroup;
import org.matsim.alonso_mora.AlonsoMoraSubmissionEvent;
import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType;
Expand All @@ -36,6 +37,7 @@
import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler;
import org.matsim.alonso_mora.travel_time.TravelTimeEstimator;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.passenger.AcceptedDrtRequest;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.schedule.DefaultDrtStopTask;
import org.matsim.contrib.drt.scheduler.EmptyVehicleRelocator;
Expand Down Expand Up @@ -65,7 +67,7 @@
*
*/
public class AlonsoMoraAlgorithm {
private final Logger logger = Logger.getLogger(AlonsoMoraAlgorithm.class);
private final Logger logger = LogManager.getLogger(AlonsoMoraAlgorithm.class);

private RequestGraph requestGraph;
private final AssignmentSolver assignmentSolver;
Expand Down Expand Up @@ -474,9 +476,9 @@ private void processAssignedRequests(Solution solution, double now, Information
}
}
}

/* For each DRT request, we create a scheduling event */
for (DrtRequest drtRequest : request.getDrtRequests()) {
for (AcceptedDrtRequest drtRequest : request.getAcceptedDrtRequests()) {
eventsManager.processEvent(new PassengerRequestScheduledEvent(now, mode, drtRequest.getId(),
drtRequest.getPassengerId(), trip.getVehicle().getVehicle().getId(), expectedPickupTime,
expectedDropoffTime));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;

import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.passenger.AcceptedDrtRequest;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.schedule.DrtStopTask;

Expand Down Expand Up @@ -34,6 +35,8 @@ public interface AlonsoMoraRequest extends Comparable<AlonsoMoraRequest> {
double getLatestAssignmentTime();

Collection<DrtRequest> getDrtRequests();

Collection<AcceptedDrtRequest> getAcceptedDrtRequests();

public int getSize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.stream.Collectors;

import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.passenger.AcceptedDrtRequest;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.schedule.DrtStopTask;
import org.matsim.contrib.dvrp.schedule.Task.TaskStatus;
Expand All @@ -26,6 +27,7 @@
*/
public class DefaultAlonsoMoraRequest implements AlonsoMoraRequest {
private final List<DrtRequest> drtRequests;
private List<AcceptedDrtRequest> acceptedDrtRequests;

private DrtStopTask pickupTask;
private DrtStopTask dropoffTask;
Expand Down Expand Up @@ -169,7 +171,16 @@ public double getLatestAssignmentTime() {
public Collection<DrtRequest> getDrtRequests() {
return drtRequests;
}


public Collection<AcceptedDrtRequest> getAcceptedDrtRequests() {
if (acceptedDrtRequests == null) {
acceptedDrtRequests = drtRequests.stream().map(AcceptedDrtRequest::createFromOriginalRequest)
.collect(Collectors.toList());
}

return acceptedDrtRequests;
}

@Override
public void setVehicle(AlonsoMoraVehicle vehicle) {
this.vehicle = vehicle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip;
import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver.Solution.Status;

Expand All @@ -27,7 +28,7 @@
public class CbcMpsAssignmentSolver implements AssignmentSolver {
static public final String TYPE = "CbcMps";

private final static Logger logger = Logger.getLogger(CbcMpsAssignmentSolver.class);
private final static Logger logger = LogManager.getLogger(CbcMpsAssignmentSolver.class);

private final double rejectionPenalty;
private final double unassignmentPenalty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip;
import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver.Solution.Status;

Expand All @@ -27,7 +28,7 @@
public class GlpkMpsAssignmentSolver implements AssignmentSolver {
static public final String TYPE = "GlpkMps";

private static final Logger logger = Logger.getLogger(GlpkMpsAssignmentSolver.class);
private static final Logger logger = LogManager.getLogger(GlpkMpsAssignmentSolver.class);

private final double unassignmentPenalty;
private final double rejectionPenalty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
* Solves the relocation problem as described by Alonso-Mora et al. using the
Expand All @@ -24,7 +25,7 @@
public class CbcMpsRelocationSolver implements RelocationSolver {
static public final String TYPE = "CbcMps";

private final static Logger logger = Logger.getLogger(CbcMpsRelocationSolver.class);
private final static Logger logger = LogManager.getLogger(CbcMpsRelocationSolver.class);

private final File problemPath;
private final File solutionPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.alonso_mora.algorithm.assignment.GlpkMpsAssignmentSolver;

/**
Expand All @@ -25,7 +26,7 @@
public class GlpkMpsRelocationSolver implements RelocationSolver {
static public final String TYPE = "GlpkMps";

private static final Logger logger = Logger.getLogger(GlpkMpsRelocationSolver.class);
private static final Logger logger = LogManager.getLogger(GlpkMpsRelocationSolver.class);

private final File problemPath;
private final File solutionPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;

import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
Expand All @@ -41,7 +42,7 @@
import org.matsim.core.trafficmonitoring.FreeSpeedTravelTime;

public class CalculateTravelTimes {
private final static Logger logger = Logger.getLogger(CalculateTravelTimes.class);
private final static Logger logger = LogManager.getLogger(CalculateTravelTimes.class);

static public void main(String[] args) throws ConfigurationException {
CommandLine cmd = new CommandLine.Builder(args) //
Expand Down
27 changes: 13 additions & 14 deletions core/src/main/java/org/matsim/alonso_mora/example/RunNewYork.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,19 @@ static public void main(String[] args) throws CommandLine.ConfigurationException

MultiModeDrtConfigGroup drtConfig = new MultiModeDrtConfigGroup();
config.addModule(drtConfig);

DrtConfigGroup modeConfig = new DrtConfigGroup() //
.setMode(TransportMode.drt) //
.setMaxTravelTimeAlpha(detourFactor) //
.setMaxTravelTimeBeta(stopDuration) //
.setMaxWaitTime(maximumWaitingTime + stopDuration) //
.setStopDuration(stopDuration) //
.setRejectRequestIfMaxWaitOrTravelTimeViolated(true) //
.setUseModeFilteredSubnetwork(false) //
.setIdleVehiclesReturnToDepots(false) //
.setOperationalScheme(DrtConfigGroup.OperationalScheme.door2door) //
.setPlotDetailedCustomerStats(true) //
.setMaxWalkDistance(1000.) //
.setNumberOfThreads(threads);

DrtConfigGroup modeConfig = new DrtConfigGroup();
modeConfig.mode = TransportMode.drt;
modeConfig.maxTravelTimeAlpha = detourFactor;
modeConfig.maxTravelTimeBeta = stopDuration;
modeConfig.maxWaitTime = maximumWaitingTime + stopDuration;
modeConfig.rejectRequestIfMaxWaitOrTravelTimeViolated = true;
modeConfig.useModeFilteredSubnetwork = false;
modeConfig.idleVehiclesReturnToDepots = false;
modeConfig.operationalScheme = DrtConfigGroup.OperationalScheme.door2door;
modeConfig.plotDetailedCustomerStats = true;
modeConfig.maxWalkDistance = 1000.0;
modeConfig.numberOfThreads = threads;

modeConfig.addParameterSet(new ExtensiveInsertionSearchParams());
drtConfig.addParameterSet(modeConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.extension.shifts.schedule.WaitForShiftStayTask;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftStayTask;
import org.matsim.contrib.drt.passenger.AcceptedDrtRequest;
import org.matsim.contrib.drt.schedule.DrtDriveTask;
import org.matsim.contrib.drt.schedule.DrtStayTask;
import org.matsim.contrib.drt.schedule.DrtStopTask;
Expand Down Expand Up @@ -121,13 +121,13 @@ private void verifyActivePickupAndDropoff(AlonsoMoraVehicle vehicle, List<Alonso
// another task with this request to the vehicle's schedule, this should not be
// here. Most likely, this is an error in the TravelFunction.

for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) {
for (AcceptedDrtRequest drtRequest : stop.getRequest().getAcceptedDrtRequests()) {
Verify.verify(!stopTask.getDropoffRequests().containsKey(drtRequest.getId()));
}

break;
case Pickup:
for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) {
for (AcceptedDrtRequest drtRequest : stop.getRequest().getAcceptedDrtRequests()) {
Verify.verify(!stopTask.getPickupRequests().containsKey(drtRequest.getId()));
}

Expand Down Expand Up @@ -288,7 +288,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
// Add requests to the stop task

if (stop.getType().equals(StopType.Pickup)) {
stop.getRequest().getDrtRequests().forEach(stopTask::addPickupRequest);
stop.getRequest().getAcceptedDrtRequests().forEach(stopTask::addPickupRequest);
stop.getRequest().setPickupTask(vehicle, stopTask);

if (checkDeterminsticTravelTimes) {
Expand All @@ -298,7 +298,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
"Checking for determinstic travel times and found mismatch between expected stop time and planned stop time.");
}
} else if (stop.getType().equals(StopType.Dropoff)) {
stop.getRequest().getDrtRequests().forEach(stopTask::addDropoffRequest);
stop.getRequest().getAcceptedDrtRequests().forEach(stopTask::addDropoffRequest);
stop.getRequest().setDropoffTask(vehicle, stopTask);

if (checkDeterminsticTravelTimes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import org.matsim.alonso_mora.algorithm.function.RouteTracker;
import org.matsim.alonso_mora.travel_time.TravelTimeEstimator;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.extension.shifts.schedule.OperationalStop;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.OperationalStop;
import org.matsim.contrib.dvrp.schedule.Schedule;
import org.matsim.contrib.dvrp.schedule.StayTask;
import org.matsim.contrib.dvrp.schedule.Task;
Expand Down
Loading

0 comments on commit d354656

Please sign in to comment.