From cbfbb68b7aa1968834e4193ae2f93ed413baa80c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20H=C3=B6rl?= Date: Thu, 4 Jan 2024 11:29:54 +0100 Subject: [PATCH] remove group requests --- .../alonso_mora/AlonsoMoraConfigGroup.java | 17 - .../alonso_mora/AlonsoMoraModeModule.java | 6 +- .../alonso_mora/AlonsoMoraModeQSimModule.java | 1 - .../alonso_mora/AlonsoMoraOptimizer.java | 71 +- .../AlonsoMoraSubmissionEvent.java | 53 -- .../AlonsoMoraSubmissionEventHandler.java | 12 - .../matsim/alonso_mora/AnalysisListener.java | 26 +- .../RequestAggregationHandler.java | 28 - .../algorithm/AlonsoMoraAlgorithm.java | 33 +- .../algorithm/AlonsoMoraRequest.java | 6 +- .../algorithm/AlonsoMoraRequestFactory.java | 4 +- .../alonso_mora/algorithm/AlonsoMoraStop.java | 5 +- .../algorithm/DefaultAlonsoMoraRequest.java | 87 +- .../DefaultAlonsoMoraRequestFactory.java | 9 +- .../DefaultAlonsoMoraScheduler.java | 26 +- .../shifts/ShiftAlonsoMoraScheduler.java | 860 +++++++++--------- .../org/matsim/alonso_mora/DiversionTest.java | 17 +- .../CbcMpsAssignmentSolverTest.java | 72 +- .../GlpkMpsAssignmentSolverTest.java | 68 +- .../GreedyTripFirstAssignmentSolverTest.java | 38 +- ...reedyVehicleFirstAssignmentSolverTest.java | 38 +- .../algorithm/function/RouteTrackerTest.java | 183 ++-- .../graphs/DefaultRequestGraphTest.java | 46 +- .../graphs/DefaultVehicleGraphTest.java | 49 +- .../EuclideanSequenceGeneratorTest.java | 19 +- .../ExtensiveSequenceGeneratorTest.java | 47 +- .../InsertiveSequenceGeneratorTest.java | 29 +- .../CbcMpsRelocationSolverTest.java | 57 +- .../GlpkMpsRelocationSolverTest.java | 65 +- .../relocation/MpsRelocationWriterTest.java | 13 +- .../alonso_mora/run/AlonsoMoraExamplesIT.java | 38 +- .../gurobi/CplexAssignmentSolverTest.java | 33 +- .../gurobi/CplexRelocationSolverTest.java | 4 +- .../glpk/GlpkJniAssignmentSolverTest.java | 33 +- .../glpk/GlpkJniRelocationSolverTest.java | 4 +- .../gurobi/GurobiAssignmentSolverTest.java | 33 +- .../gurobi/GurobiRelocationSolverTest.java | 4 +- pom.xml | 31 +- 38 files changed, 996 insertions(+), 1169 deletions(-) delete mode 100644 core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEvent.java delete mode 100644 core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEventHandler.java delete mode 100644 core/src/main/java/org/matsim/alonso_mora/RequestAggregationHandler.java diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraConfigGroup.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraConfigGroup.java index 66499cd..044161a 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraConfigGroup.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraConfigGroup.java @@ -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."; @@ -249,7 +233,6 @@ public Map 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); diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeModule.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeModule.java index 30d4539..4b66d43 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeModule.java @@ -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(); diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java index e009c0b..76cca39 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraModeQSimModule.java @@ -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), // diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraOptimizer.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraOptimizer.java index 1f7de50..4fb83a3 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraOptimizer.java +++ b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraOptimizer.java @@ -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; @@ -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; @@ -41,8 +39,6 @@ public class AlonsoMoraOptimizer implements DrtOptimizer { private final List submittedRequests = new LinkedList<>(); private final double assignmentInterval; - private final int maximumGroupRequestSize; - private final ForkJoinPool forkJoinPool; private final LeastCostPathCalculator router; private final TravelTime travelTime; @@ -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; @@ -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> poolRequests(List submittedRequests) { - submittedRequests = new LinkedList<>(submittedRequests); - List> allPooledRequests = new LinkedList<>(); - - while (submittedRequests.size() > 0) { - List pooledRequests = new LinkedList<>(); - pooledRequests.add(submittedRequests.remove(0)); - DrtRequest mainRequest = pooledRequests.get(0); - - Iterator 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 newRequests = new LinkedList<>(); - List> pooledRequests = poolRequests(submittedRequests); - List paths = new ArrayList<>(Collections.nCopies(pooledRequests.size(), null)); + List submittedRequests = new ArrayList<>(this.submittedRequests); + this.submittedRequests.clear(); + + List 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 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); diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEvent.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEvent.java deleted file mode 100644 index 1ae3683..0000000 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEvent.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.matsim.alonso_mora; - -import java.util.Arrays; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -import org.matsim.api.core.v01.Id; -import org.matsim.api.core.v01.events.Event; -import org.matsim.contrib.dvrp.optimizer.Request; - -/** - * For computational performance, this implementation of the algorithm by - * Alonso-Mora et al. aggregates requests with the same origin and destination - * into group requests. This event is published whenever an aggregated request - * arrives at the dispatcher to allow for a post-processing analysis of - * aggregated requests. - * - * @author sebhoerl - */ -public class AlonsoMoraSubmissionEvent extends Event { - static public final String EVENT_TYPE = "alonso mora submission"; - - static public final String REQUEST_IDS = "requestIds"; - - private final Set> requestIds; - - public AlonsoMoraSubmissionEvent(double time, Set> requestIds) { - super(time); - this.requestIds = requestIds; - } - - @Override - public String getEventType() { - return EVENT_TYPE; - } - - public Set> getRequestIds() { - return requestIds; - } - - public Map getAttributes() { - Map attributes = super.getAttributes(); - attributes.put(REQUEST_IDS, requestIds.stream().map(id -> id.toString()).collect(Collectors.joining(","))); - return attributes; - } - - static public AlonsoMoraSubmissionEvent convert(Event event) { - return new AlonsoMoraSubmissionEvent(event.getTime(), - Arrays.asList(((String) event.getAttributes().get(REQUEST_IDS)).split(",")).stream() - .map(id -> Id.create(id, Request.class)).collect(Collectors.toSet())); - } -} diff --git a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEventHandler.java b/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEventHandler.java deleted file mode 100644 index ca2e818..0000000 --- a/core/src/main/java/org/matsim/alonso_mora/AlonsoMoraSubmissionEventHandler.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.matsim.alonso_mora; - -import org.matsim.core.events.handler.EventHandler; - -/** - * Handles a submission event for the dispatcher by Alonso-Mora et al. - * - * @author sebhoerl - */ -public interface AlonsoMoraSubmissionEventHandler extends EventHandler { - public void handleEvent(AlonsoMoraSubmissionEvent event); -} diff --git a/core/src/main/java/org/matsim/alonso_mora/AnalysisListener.java b/core/src/main/java/org/matsim/alonso_mora/AnalysisListener.java index b589ae6..5ddbaa0 100644 --- a/core/src/main/java/org/matsim/alonso_mora/AnalysisListener.java +++ b/core/src/main/java/org/matsim/alonso_mora/AnalysisListener.java @@ -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; @@ -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; @@ -50,7 +47,6 @@ */ class AnalysisListener implements IterationEndsListener { private final InformationCollector information; - private final RequestAggregationHandler requestHandler; private final OutputDirectoryHierarchy outputHierarchy; private final List numberOfInvalidSolutions = new LinkedList<>(); @@ -58,11 +54,9 @@ class AnalysisListener implements IterationEndsListener { private final List numberOfOptimalSolutions = new LinkedList<>(); private final List 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 @@ -364,23 +358,5 @@ public void notifyIterationEnds(IterationEndsEvent event) { ChartSaveUtils.saveAsPNG(stackedChart, outputHierarchy.getIterationFilename(event.getIteration(), "am_occupancy_requests"), 1500, 1000); } - - { - List>> 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> set : requests) { - writer.write(set.stream().map(String::valueOf).collect(Collectors.joining(",")) + "\n"); - } - - writer.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } } } diff --git a/core/src/main/java/org/matsim/alonso_mora/RequestAggregationHandler.java b/core/src/main/java/org/matsim/alonso_mora/RequestAggregationHandler.java deleted file mode 100644 index 8038293..0000000 --- a/core/src/main/java/org/matsim/alonso_mora/RequestAggregationHandler.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.matsim.alonso_mora; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import org.matsim.api.core.v01.Id; -import org.matsim.contrib.dvrp.optimizer.Request; - -/** - * Simple event handler used to track the requests that are aggregated for the - * dispatcher. - */ -class RequestAggregationHandler implements AlonsoMoraSubmissionEventHandler { - private final List>> requests = new LinkedList<>(); - - @Override - public void handleEvent(AlonsoMoraSubmissionEvent event) { - requests.add(event.getRequestIds()); - } - - public List>> consolidate() { - List>> returnValue = new ArrayList<>(requests); - requests.clear(); - return returnValue; - } -} diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java index 3baec13..b8dbbba 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraAlgorithm.java @@ -21,7 +21,6 @@ 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; import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver; import org.matsim.alonso_mora.algorithm.assignment.AssignmentSolver.Solution; @@ -225,10 +224,10 @@ private void updateRequestsBeforeAssignment(Collection newReq if (now > request.getLatestAssignmentTime()) { iterator.remove(); - for (DrtRequest drtRequest : request.getDrtRequests()) { - eventsManager.processEvent(new PassengerRequestRejectedEvent(now, mode, drtRequest.getId(), - drtRequest.getPassengerIds(), "queue time exeeded")); - } + DrtRequest drtRequest = request.getDrtRequest(); + + eventsManager.processEvent(new PassengerRequestRejectedEvent(now, mode, drtRequest.getId(), + drtRequest.getPassengerIds(), "queue time exeeded")); numberOfRejectedRequests++; } @@ -239,11 +238,6 @@ private void updateRequestsBeforeAssignment(Collection newReq * create events to notify submission.s */ queuedRequests.addAll(newRequests); - - for (AlonsoMoraRequest request : newRequests) { - eventsManager.processEvent(new AlonsoMoraSubmissionEvent(now, - request.getDrtRequests().stream().map(r -> r.getId()).collect(Collectors.toSet()))); - } } /** @@ -476,13 +470,12 @@ private void processAssignedRequests(Solution solution, double now, Information } } } - + /* For each DRT request, we create a scheduling event */ - for (AcceptedDrtRequest drtRequest : request.getAcceptedDrtRequests()) { - eventsManager.processEvent(new PassengerRequestScheduledEvent(now, mode, drtRequest.getId(), - drtRequest.getPassengerIds(), trip.getVehicle().getVehicle().getId(), expectedPickupTime, - expectedDropoffTime)); - } + AcceptedDrtRequest drtRequest = request.getAcceptedDrtRequest(); + eventsManager.processEvent( + new PassengerRequestScheduledEvent(now, mode, drtRequest.getId(), drtRequest.getPassengerIds(), + trip.getVehicle().getVehicle().getId(), expectedPickupTime, expectedDropoffTime)); } } @@ -628,14 +621,14 @@ private void performRelocation(Solution solution, double now, Information inform information.numberOfRelocations++; } - + if (settings.useStepwiseRelocation) { List stopVehicles = new ArrayList<>(relocatableVehicles); relocations.forEach(r -> stopVehicles.remove(r.vehicle)); - + for (AlonsoMoraVehicle vehicle : stopVehicles) { - vehicle.setRoute( - Collections.singletonList(new AlonsoMoraStop(StopType.Relocation, vehicle.getNextDiversion(now).link, null))); + vehicle.setRoute(Collections.singletonList( + new AlonsoMoraStop(StopType.Relocation, vehicle.getNextDiversion(now).link, null))); scheduler.schedule(vehicle, now); } } diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequest.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequest.java index 1652b4f..a4394b2 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequest.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequest.java @@ -1,7 +1,5 @@ package org.matsim.alonso_mora.algorithm; -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; @@ -34,9 +32,9 @@ public interface AlonsoMoraRequest extends Comparable { double getLatestAssignmentTime(); - Collection getDrtRequests(); + DrtRequest getDrtRequest(); - Collection getAcceptedDrtRequests(); + AcceptedDrtRequest getAcceptedDrtRequest(); public int getSize(); diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequestFactory.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequestFactory.java index e3e179e..6a00688 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequestFactory.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraRequestFactory.java @@ -1,7 +1,5 @@ package org.matsim.alonso_mora.algorithm; -import java.util.Collection; - import org.matsim.contrib.drt.passenger.DrtRequest; /** @@ -11,6 +9,6 @@ * @author sebhoerl */ public interface AlonsoMoraRequestFactory { - AlonsoMoraRequest createRequest(Collection requests, double directArrvialTime, double earliestDepartureTime, + AlonsoMoraRequest createRequest(DrtRequest request, double directArrvialTime, double earliestDepartureTime, double directRideDistance); } diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraStop.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraStop.java index f71559d..fc60d75 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraStop.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/AlonsoMoraStop.java @@ -1,7 +1,5 @@ package org.matsim.alonso_mora.algorithm; -import java.util.stream.Collectors; - import org.matsim.api.core.v01.network.Link; import org.matsim.core.utils.misc.Time; @@ -56,7 +54,6 @@ public void setTime(double time) { @Override public String toString() { return String.format("Stop[%s,%s@%s,(%s)]", stopType.toString(), Time.writeTime(time), link.getId().toString(), - request != null ? request.getDrtRequests().stream().map(r -> r.getId().toString()) - .collect(Collectors.joining(",")) : ""); + request != null ? request.getDrtRequest().getId().toString() : ""); } } diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequest.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequest.java index 6d58ee3..9ddbf09 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequest.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequest.java @@ -1,11 +1,5 @@ package org.matsim.alonso_mora.algorithm; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -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; @@ -26,8 +20,8 @@ * @author sebhoerl */ public class DefaultAlonsoMoraRequest implements AlonsoMoraRequest { - private final List drtRequests; - private List acceptedDrtRequests; + private final DrtRequest drtRequest; + private AcceptedDrtRequest acceptedDrtRequest; private DrtStopTask pickupTask; private DrtStopTask dropoffTask; @@ -49,41 +43,22 @@ public class DefaultAlonsoMoraRequest implements AlonsoMoraRequest { private final double directRideDistance; - public DefaultAlonsoMoraRequest(Collection drtRequests, double latestAssignmentTime, - double directArrivalTime, double directRideDistance) { + public DefaultAlonsoMoraRequest(DrtRequest drtRequest, double latestAssignmentTime, double directArrivalTime, + double directRideDistance) { this.directArrivalTime = directArrivalTime; this.directRideDistance = directRideDistance; + this.drtRequest = drtRequest; + this.cachedHashCode = drtRequest.getId().index(); - this.drtRequests = new ArrayList<>(drtRequests); - Collections.sort(this.drtRequests, (a, b) -> Integer.compare(a.getId().index(), b.getId().index())); - - { - /* - * We need a unique has code for the aggregated requests. - */ - int hashCode = 13; - - for (int i = 0; i < this.drtRequests.size(); i++) { - DrtRequest drtRquest = this.drtRequests.get(i); - hashCode += 27 * (i + 1) * drtRquest.getId().index(); - } - - this.cachedHashCode = hashCode; - } - - this.pickupLink = this.drtRequests.get(0).getFromLink(); - this.dropoffLink = this.drtRequests.get(0).getToLink(); + this.pickupLink = this.drtRequest.getFromLink(); + this.dropoffLink = this.drtRequest.getToLink(); - this.latestPickupTime = this.drtRequests.stream().mapToDouble(r -> r.getLatestStartTime()).min().getAsDouble(); - this.latestDropoffTime = this.drtRequests.stream().mapToDouble(r -> r.getLatestArrivalTime()).min() - .getAsDouble(); - this.earliestPickupTime = this.drtRequests.stream().mapToDouble(r -> r.getEarliestStartTime()).max() - .getAsDouble(); + this.latestPickupTime = this.drtRequest.getLatestStartTime(); + this.latestDropoffTime = this.drtRequest.getLatestArrivalTime(); + this.earliestPickupTime = this.drtRequest.getEarliestStartTime(); - for (DrtRequest request : this.drtRequests) { - Verify.verify(this.pickupLink.equals(request.getFromLink())); - Verify.verify(this.dropoffLink.equals(request.getToLink())); - } + Verify.verify(this.pickupLink.equals(drtRequest.getFromLink())); + Verify.verify(this.dropoffLink.equals(drtRequest.getToLink())); this.latestAssignmentTime = Math.min(getLatestPickupTime(), latestAssignmentTime); } @@ -97,18 +72,7 @@ public int compareTo(AlonsoMoraRequest otherRequest) { return sizeComparison; } - DefaultAlonsoMoraRequest otherDefaultRequest = (DefaultAlonsoMoraRequest) otherRequest; - - for (int i = 0; i < getSize(); i++) { - int indexComparison = Integer.compare(drtRequests.get(i).getId().index(), - otherDefaultRequest.drtRequests.get(i).getId().index()); - - if (indexComparison != 0) { - return indexComparison; - } - } - - return 0; + return Integer.compare(drtRequest.getId().index(), otherRequest.getDrtRequest().getId().index()); } throw new IllegalStateException(); @@ -168,19 +132,18 @@ public double getLatestAssignmentTime() { return latestAssignmentTime; } - public Collection getDrtRequests() { - return drtRequests; + public DrtRequest getDrtRequest() { + return drtRequest; } - - public Collection getAcceptedDrtRequests() { - if (acceptedDrtRequests == null) { - acceptedDrtRequests = drtRequests.stream().map(AcceptedDrtRequest::createFromOriginalRequest) - .collect(Collectors.toList()); + + public AcceptedDrtRequest getAcceptedDrtRequest() { + if (acceptedDrtRequest == null) { + acceptedDrtRequest = AcceptedDrtRequest.createFromOriginalRequest(drtRequest); } - - return acceptedDrtRequests; + + return acceptedDrtRequest; } - + @Override public void setVehicle(AlonsoMoraVehicle vehicle) { this.vehicle = vehicle; @@ -208,7 +171,7 @@ public boolean isAssigned() { @Override public int getSize() { - return drtRequests.size(); + return drtRequest.getPassengerCount(); } @Override @@ -268,6 +231,6 @@ public double getEarliestPickupTime() { @Override public String toString() { - return "{" + drtRequests.stream().map(r -> r.getId().toString()).collect(Collectors.joining(",")) + "}"; + return drtRequest.toString(); } } diff --git a/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequestFactory.java b/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequestFactory.java index ddf78cc..5b0127f 100644 --- a/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequestFactory.java +++ b/core/src/main/java/org/matsim/alonso_mora/algorithm/DefaultAlonsoMoraRequestFactory.java @@ -1,7 +1,5 @@ package org.matsim.alonso_mora.algorithm; -import java.util.Collection; - import org.matsim.contrib.drt.passenger.DrtRequest; /** @@ -19,13 +17,12 @@ public DefaultAlonsoMoraRequestFactory(double maximumQueueTime) { } @Override - public AlonsoMoraRequest createRequest(Collection requests, double directArrvialTime, double earliestDepartureTime, + public AlonsoMoraRequest createRequest(DrtRequest request, double directArrvialTime, double earliestDepartureTime, double directRideDistance) { double latestAssignmentTime = earliestDepartureTime + maximumQueueTime; - double latestPickupTime = requests.stream().mapToDouble(r -> r.getLatestStartTime()).min() - .orElse(Double.POSITIVE_INFINITY); + double latestPickupTime = request.getLatestStartTime(); latestAssignmentTime = Math.min(latestAssignmentTime, latestPickupTime); - return new DefaultAlonsoMoraRequest(requests, latestAssignmentTime, directArrvialTime, directRideDistance); + return new DefaultAlonsoMoraRequest(request, latestAssignmentTime, directArrvialTime, directRideDistance); } } diff --git a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java index f549541..ecc3b62 100644 --- a/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java +++ b/core/src/main/java/org/matsim/alonso_mora/scheduling/DefaultAlonsoMoraScheduler.java @@ -115,23 +115,23 @@ private void verifyActivePickupAndDropoff(AlonsoMoraVehicle vehicle, List stops) { - Set onboardRequests = new HashSet<>( - vehicle.getOnboardRequests().stream().filter(r -> !r.isDroppedOff()).collect(Collectors.toSet())); - - for (AlonsoMoraStop stop : stops) { - switch (stop.getType()) { - case Dropoff: - onboardRequests.remove(stop.getRequest()); - break; - case Pickup: - Verify.verify(!vehicle.getOnboardRequests().contains(stop.getRequest()), - "Cannot pick-up onboard request"); - break; - case Relocation: - break; - default: - throw new IllegalStateException(); - } - } - - Verify.verify(onboardRequests.size() == 0, "Some onboard requests are not dropped off"); - } - - /** - * This is an additional check that makes sure that pick-ups and drop-offs which - * are currently already in progress (task is started) are not added again as a - * stop. This can happen if the travel function is not implemented properly. - */ - private void verifyActivePickupAndDropoff(AlonsoMoraVehicle vehicle, List stops) { - Task currentTask = vehicle.getVehicle().getSchedule().getCurrentTask(); - - if (currentTask instanceof DrtStopTask) { - DrtStopTask stopTask = (DrtStopTask) currentTask; - - for (AlonsoMoraStop stop : stops) { - switch (stop.getType()) { - case Dropoff: - // This means that the stop list contains a stop with a request that is - // currently being dropped off in the current task. As we don't want to add - // 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()) { - Verify.verify(!stopTask.getDropoffRequests().containsKey(drtRequest.getId())); - } - - break; - case Pickup: - for (DrtRequest drtRequest : stop.getRequest().getDrtRequests()) { - Verify.verify(!stopTask.getPickupRequests().containsKey(drtRequest.getId())); - } - - break; - case Relocation: - break; - default: - throw new IllegalStateException(); - } - } - } - } - - private void verifyRelocationIsLast(List stops) { - for (AlonsoMoraStop stop : stops) { - if (stop.getType().equals(StopType.Relocation)) { - Verify.verify(stops.get(stops.size() - 1) == stop, "Relocation must be the last!"); - } - } - } - - public void schedule(AlonsoMoraVehicle vehicle, double now) { - List stops = vehicle.getRoute(); - - verifyOnboardRequestsAreDroppedOff(vehicle, stops); - verifyActivePickupAndDropoff(vehicle, stops); - verifyRelocationIsLast(stops); - - DvrpVehicle dvrpVehicle = vehicle.getVehicle(); - Schedule schedule = dvrpVehicle.getSchedule(); - - Task currentTask = schedule.getCurrentTask(); - - // Verify that we understand what is in the schedule - for (int index = currentTask.getTaskIdx(); index < schedule.getTaskCount(); index++) { - Task task = schedule.getTasks().get(index); - - boolean isStayTask = task instanceof DrtStayTask; - boolean isStopTask = task instanceof DrtStopTask; - boolean isDriveTask = task instanceof DrtDriveTask; - boolean isWaitForStopTask = task instanceof WaitForStopTask; - boolean isOperationalTask = operationalVoter.isOperationalTask(task); - - Verify.verify(isStayTask || isStopTask || isDriveTask || isWaitForStopTask || isOperationalTask, - "Don't know what to do with this task"); - } - - // Collect operational tasks that need to be re-added at the end - List operationalTasks = new LinkedList<>(); - - for (int i = schedule.getCurrentTask().getTaskIdx() + 1; i < schedule.getTaskCount(); i++) { - Task task = schedule.getTasks().get(i); - - if (operationalVoter.isOperationalTask(task)) { - operationalTasks.add(task); - } - } - - // Clean up the task chain to reconstruct it - while (schedule.getTasks().get(schedule.getTaskCount() - 1).getStatus().equals(TaskStatus.PLANNED)) { - schedule.removeLastTask(); - } - - // Start rebuilding the schedule - - Link currentLink = null; - - if (operationalVoter.isOperationalTask(currentTask)) { - currentLink = ((StayTask) currentTask).getLink(); - } else if (currentTask instanceof StayTask) { - currentLink = ((StayTask) currentTask).getLink(); - - if (currentTask instanceof DrtStayTask || currentTask instanceof WaitForStopTask) { - // If we are currently staying somewhere, end the stay task now - currentTask.setEndTime(now); - } - } else if (currentTask instanceof DriveTask) { - // Will be handled individually further below - } else { - throw new IllegalStateException(); - } - - for (int index = 0; index < stops.size(); index++) { - AlonsoMoraStop stop = stops.get(index); - - if (stop.getType().equals(StopType.Pickup) || stop.getType().equals(StopType.Dropoff)) { - // We want to add a pickup or dropoff - - if (index == 0 && currentTask instanceof DriveTask) { - // Vehicle is driving, so we may need to divert it - - DriveTask driveTask = (DriveTask) currentTask; - - if (!driveTask.getTaskType().equals(DrtDriveTask.TYPE)) { - // Not a standard drive task, so we have to abort it - - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); - tracker.divertPath(diversionPath); - - currentLink = diversionPoint.link; - } else { - // We have a standard drive task, so we can simply divert it - - if (driveTask.getPath().getToLink() != stop.getLink() || reroutingDuringScheduling) { - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.calcAndCreatePathForDiversion(diversionPoint, - stop.getLink(), router, travelTime); - tracker.divertPath(diversionPath); - } - - currentLink = stop.getLink(); - } - } - - if (currentLink != stop.getLink()) { - // Add a conventional drive (e.g. after a previous stop) - - VrpPathWithTravelData drivePath = VrpPaths.calcAndCreatePath(currentLink, stop.getLink(), - currentTask.getEndTime(), router, travelTime); - - currentTask = taskFactory.createDriveTask(dvrpVehicle, drivePath, DrtDriveTask.TYPE); - schedule.addTask(currentTask); - - currentLink = stop.getLink(); - } - - // For pre-booked requests, we may need to wait for the customer - if (stop.getType().equals(StopType.Pickup)) { - double expectedStartTime = stop.getRequest().getEarliestPickupTime() - stopDuration; - - if (expectedStartTime > currentTask.getEndTime()) { - currentTask = new WaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink); - schedule.addTask(currentTask); - } - } - - // Now, retrieve or create the stop task - - DrtStopTask stopTask = null; - - if (currentTask instanceof DrtStopTask && index > 0) { - // We're at a stop task and the stop task is not already started, so we can add - // the requests to this stop - - stopTask = (DrtStopTask) currentTask; - } else { - // Create a new stop task as we are not at a previously created stop - stopTask = taskFactory.createStopTask(dvrpVehicle, currentTask.getEndTime(), - currentTask.getEndTime() + stopDuration, stop.getLink()); - - schedule.addTask(stopTask); - currentTask = stopTask; - } - - // Add requests to the stop task - - if (stop.getType().equals(StopType.Pickup)) { - stop.getRequest().getAcceptedDrtRequests().forEach(stopTask::addPickupRequest); - stop.getRequest().setPickupTask(vehicle, stopTask); - - if (checkDeterminsticTravelTimes) { - Verify.verify(stop.getTime() == stopTask.getEndTime(), - "Checking for determinstic travel times and found mismatch between expected stop time and scheduled stop time."); - Verify.verify(stop.getTime() <= stop.getRequest().getPlannedPickupTime(), - "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().getAcceptedDrtRequests().forEach(stopTask::addDropoffRequest); - stop.getRequest().setDropoffTask(vehicle, stopTask); - - if (checkDeterminsticTravelTimes) { - Verify.verify(stop.getTime() == stopTask.getBeginTime(), - "Checking for determinstic travel times and found mismatch between expected stop time and scheduled stop time."); - } - } else { - throw new IllegalStateException(); - } - } else if (stop.getType().equals(StopType.Relocation)) { - // We want to add a relocation to the schedule - - if (index == 0 && currentTask instanceof DriveTask) { - // Vehicle is driving, so we may need to divert it - - DriveTask driveTask = (DriveTask) currentTask; - - if (!driveTask.getTaskType().equals(EmptyVehicleRelocator.RELOCATE_VEHICLE_TASK_TYPE)) { - // Not a relocation drive task, so we have to abort it - - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); - tracker.divertPath(diversionPath); - - currentLink = diversionPoint.link; - } else { - // We have a relocation drive task, so we can simply divert it - - if (driveTask.getPath().getToLink() != stop.getLink() || reroutingDuringScheduling) { - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.calcAndCreatePathForDiversion(diversionPoint, - stop.getLink(), router, travelTime); - tracker.divertPath(diversionPath); - } - - currentLink = stop.getLink(); - } - } - - if (currentLink != stop.getLink()) { - // Add a relocation drive (e.g. after a stop or aborting another drive) - - VrpPathWithTravelData drivePath = VrpPaths.calcAndCreatePath(currentLink, stop.getLink(), - currentTask.getEndTime(), router, travelTime); - currentTask = taskFactory.createDriveTask(dvrpVehicle, drivePath, - EmptyVehicleRelocator.RELOCATE_VEHICLE_TASK_TYPE); - schedule.addTask(currentTask); - - currentLink = stop.getLink(); - } - } else { - throw new IllegalStateException(); - } - } - - if (stops.size() == 0 && operationalTasks.size() == 0) { - if (currentTask instanceof DriveTask) { - // We have neither stops nor relocation -> stop the drive - - DriveTask driveTask = (DriveTask) currentTask; - - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); - tracker.divertPath(diversionPath); - - currentLink = diversionPoint.link; - } - } - - // Add operational tasks - - if (operationalTasks.size() > 0) { - for (int index = 0; index < operationalTasks.size(); index++) { - Task operationalTask = operationalTasks.get(index); - Link operationalLink = ((StayTask) operationalTask).getLink(); - - DrtTaskType driveTaskType = operationalVoter.getDriveTaskType(operationalTask); - - if (index == 0 && stops.size() == 0 && currentTask instanceof DriveTask) { - // Vehicle is driving, so we may need to divert it - - DriveTask driveTask = (DriveTask) currentTask; - - if (!driveTask.getTaskType().equals(driveTaskType)) { - // Not a standard drive task, so we have to abort it - - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); - tracker.divertPath(diversionPath); - - currentLink = diversionPoint.link; - } else { - // We have a fitting drive task, so we can simply divert it - - if (driveTask.getPath().getToLink() != operationalLink || reroutingDuringScheduling) { - OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); - LinkTimePair diversionPoint = tracker.getDiversionPoint(); - VrpPathWithTravelData diversionPath = VrpPaths.calcAndCreatePathForDiversion(diversionPoint, - operationalLink, router, travelTime); - tracker.divertPath(diversionPath); - } - - currentLink = operationalLink; - } - } - - if (currentLink != operationalLink) { - // Add a drive - - VrpPathWithTravelData drivePath = VrpPaths.calcAndCreatePath(currentLink, operationalLink, - currentTask.getEndTime(), router, travelTime); - - currentTask = taskFactory.createDriveTask(dvrpVehicle, drivePath, driveTaskType); - schedule.addTask(currentTask); - - currentLink = operationalLink; - } - - if (operationalTask.getBeginTime() > currentTask.getEndTime()) { - if(operationalTask instanceof ShiftBreakTask) { - // We need to fill the gap with a stay task if break is not planned to start yet - double earliestBreakStartTime = ((ShiftBreakTask) operationalTask).getShiftBreak().getEarliestBreakStartTime(); - if (earliestBreakStartTime > currentTask.getEndTime()) { - if(currentTask instanceof DrtStayTask) { - currentTask.setEndTime(earliestBreakStartTime); - } else { - currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), - earliestBreakStartTime, operationalLink); - schedule.addTask(currentTask); - } - } - } else if (operationalTask instanceof ShiftChangeOverTask) { - // We need to fill the gap with a stay task - double shiftEndTime = ((ShiftChangeOverTask) operationalTask).getShift().getEndTime(); - if(shiftEndTime > currentTask.getEndTime()) { - if(currentTask instanceof DrtStayTask) { - currentTask.setEndTime(shiftEndTime); - } else { - currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), - shiftEndTime, operationalLink); - schedule.addTask(currentTask); - } - } - } - } - - double endTime = endTimeCalculator.calcNewEndTime(dvrpVehicle, (StayTask) operationalTask, - currentTask.getEndTime()); - operationalTask.setBeginTime(currentTask.getEndTime()); - operationalTask.setEndTime(endTime); - - currentTask = operationalTask; - schedule.addTask(currentTask); - } - } - - // Finally, add stay task until the end of the schedule - - if (currentTask instanceof DrtStayTask) { - currentTask.setEndTime(Math.max(currentTask.getEndTime(), vehicle.getVehicle().getServiceEndTime())); - }else if(currentTask instanceof WaitForShiftStayTask) { - if(currentTask.getEndTime() == now) { - //if the shift just started, re-create the stay task - StayTask stayTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), - Math.max(currentTask.getEndTime(), vehicle.getVehicle().getServiceEndTime()), currentLink); - schedule.addTask(stayTask); - } - } else { - StayTask stayTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), - Math.max(currentTask.getEndTime(), vehicle.getVehicle().getServiceEndTime()), currentLink); - schedule.addTask(stayTask); - } - } + private final DrtTaskFactory taskFactory; + private final LeastCostPathCalculator router; + private final TravelTime travelTime; + + private final double stopDuration; + private final boolean checkDeterminsticTravelTimes; + private final boolean reroutingDuringScheduling; + + private final org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter; + + private final StayTaskEndTimeCalculator endTimeCalculator; + + public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration, + boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime, + Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router, + org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter) { + this.taskFactory = taskFactory; + this.stopDuration = stopDuration; + this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes; + this.reroutingDuringScheduling = reroutingDuringScheduling; + this.endTimeCalculator = endTimeCalculator; + this.travelTime = travelTime; + this.router = router; + this.operationalVoter = operationalVoter; + } + + /** + * This is an additional check that makes sure that the result of the travel + * function does include stops for requests that are currently on board of the + * vehicle but have not been dropped off yet. + */ + private void verifyOnboardRequestsAreDroppedOff(AlonsoMoraVehicle vehicle, List stops) { + Set onboardRequests = new HashSet<>( + vehicle.getOnboardRequests().stream().filter(r -> !r.isDroppedOff()).collect(Collectors.toSet())); + + for (AlonsoMoraStop stop : stops) { + switch (stop.getType()) { + case Dropoff: + onboardRequests.remove(stop.getRequest()); + break; + case Pickup: + Verify.verify(!vehicle.getOnboardRequests().contains(stop.getRequest()), + "Cannot pick-up onboard request"); + break; + case Relocation: + break; + default: + throw new IllegalStateException(); + } + } + + Verify.verify(onboardRequests.size() == 0, "Some onboard requests are not dropped off"); + } + + /** + * This is an additional check that makes sure that pick-ups and drop-offs which + * are currently already in progress (task is started) are not added again as a + * stop. This can happen if the travel function is not implemented properly. + */ + private void verifyActivePickupAndDropoff(AlonsoMoraVehicle vehicle, List stops) { + Task currentTask = vehicle.getVehicle().getSchedule().getCurrentTask(); + + if (currentTask instanceof DrtStopTask) { + DrtStopTask stopTask = (DrtStopTask) currentTask; + + for (AlonsoMoraStop stop : stops) { + switch (stop.getType()) { + case Dropoff: { + // This means that the stop list contains a stop with a request that is + // currently being dropped off in the current task. As we don't want to add + // another task with this request to the vehicle's schedule, this should not be + // here. Most likely, this is an error in the TravelFunction. + + AcceptedDrtRequest drtRequest = stop.getRequest().getAcceptedDrtRequest(); + Verify.verify(!stopTask.getDropoffRequests().containsKey(drtRequest.getId())); + + break; + } + case Pickup: { + AcceptedDrtRequest drtRequest = stop.getRequest().getAcceptedDrtRequest(); + Verify.verify(!stopTask.getPickupRequests().containsKey(drtRequest.getId())); + + break; + } + case Relocation: + break; + default: + throw new IllegalStateException(); + } + } + } + } + + private void verifyRelocationIsLast(List stops) { + for (AlonsoMoraStop stop : stops) { + if (stop.getType().equals(StopType.Relocation)) { + Verify.verify(stops.get(stops.size() - 1) == stop, "Relocation must be the last!"); + } + } + } + + public void schedule(AlonsoMoraVehicle vehicle, double now) { + List stops = vehicle.getRoute(); + + verifyOnboardRequestsAreDroppedOff(vehicle, stops); + verifyActivePickupAndDropoff(vehicle, stops); + verifyRelocationIsLast(stops); + + DvrpVehicle dvrpVehicle = vehicle.getVehicle(); + Schedule schedule = dvrpVehicle.getSchedule(); + + Task currentTask = schedule.getCurrentTask(); + + // Verify that we understand what is in the schedule + for (int index = currentTask.getTaskIdx(); index < schedule.getTaskCount(); index++) { + Task task = schedule.getTasks().get(index); + + boolean isStayTask = task instanceof DrtStayTask; + boolean isStopTask = task instanceof DrtStopTask; + boolean isDriveTask = task instanceof DrtDriveTask; + boolean isWaitForStopTask = task instanceof WaitForStopTask; + boolean isOperationalTask = operationalVoter.isOperationalTask(task); + + Verify.verify(isStayTask || isStopTask || isDriveTask || isWaitForStopTask || isOperationalTask, + "Don't know what to do with this task"); + } + + // Collect operational tasks that need to be re-added at the end + List operationalTasks = new LinkedList<>(); + + for (int i = schedule.getCurrentTask().getTaskIdx() + 1; i < schedule.getTaskCount(); i++) { + Task task = schedule.getTasks().get(i); + + if (operationalVoter.isOperationalTask(task)) { + operationalTasks.add(task); + } + } + + // Clean up the task chain to reconstruct it + while (schedule.getTasks().get(schedule.getTaskCount() - 1).getStatus().equals(TaskStatus.PLANNED)) { + schedule.removeLastTask(); + } + + // Start rebuilding the schedule + + Link currentLink = null; + + if (operationalVoter.isOperationalTask(currentTask)) { + currentLink = ((StayTask) currentTask).getLink(); + } else if (currentTask instanceof StayTask) { + currentLink = ((StayTask) currentTask).getLink(); + + if (currentTask instanceof DrtStayTask || currentTask instanceof WaitForStopTask) { + // If we are currently staying somewhere, end the stay task now + currentTask.setEndTime(now); + } + } else if (currentTask instanceof DriveTask) { + // Will be handled individually further below + } else { + throw new IllegalStateException(); + } + + for (int index = 0; index < stops.size(); index++) { + AlonsoMoraStop stop = stops.get(index); + + if (stop.getType().equals(StopType.Pickup) || stop.getType().equals(StopType.Dropoff)) { + // We want to add a pickup or dropoff + + if (index == 0 && currentTask instanceof DriveTask) { + // Vehicle is driving, so we may need to divert it + + DriveTask driveTask = (DriveTask) currentTask; + + if (!driveTask.getTaskType().equals(DrtDriveTask.TYPE)) { + // Not a standard drive task, so we have to abort it + + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); + tracker.divertPath(diversionPath); + + currentLink = diversionPoint.link; + } else { + // We have a standard drive task, so we can simply divert it + + if (driveTask.getPath().getToLink() != stop.getLink() || reroutingDuringScheduling) { + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.calcAndCreatePathForDiversion(diversionPoint, + stop.getLink(), router, travelTime); + tracker.divertPath(diversionPath); + } + + currentLink = stop.getLink(); + } + } + + if (currentLink != stop.getLink()) { + // Add a conventional drive (e.g. after a previous stop) + + VrpPathWithTravelData drivePath = VrpPaths.calcAndCreatePath(currentLink, stop.getLink(), + currentTask.getEndTime(), router, travelTime); + + currentTask = taskFactory.createDriveTask(dvrpVehicle, drivePath, DrtDriveTask.TYPE); + schedule.addTask(currentTask); + + currentLink = stop.getLink(); + } + + // For pre-booked requests, we may need to wait for the customer + if (stop.getType().equals(StopType.Pickup)) { + double expectedStartTime = stop.getRequest().getEarliestPickupTime() - stopDuration; + + if (expectedStartTime > currentTask.getEndTime()) { + currentTask = new WaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink); + schedule.addTask(currentTask); + } + } + + // Now, retrieve or create the stop task + + DrtStopTask stopTask = null; + + if (currentTask instanceof DrtStopTask && index > 0) { + // We're at a stop task and the stop task is not already started, so we can add + // the requests to this stop + + stopTask = (DrtStopTask) currentTask; + } else { + // Create a new stop task as we are not at a previously created stop + stopTask = taskFactory.createStopTask(dvrpVehicle, currentTask.getEndTime(), + currentTask.getEndTime() + stopDuration, stop.getLink()); + + schedule.addTask(stopTask); + currentTask = stopTask; + } + + // Add requests to the stop task + + if (stop.getType().equals(StopType.Pickup)) { + stopTask.addPickupRequest(stop.getRequest().getAcceptedDrtRequest()); + stop.getRequest().setPickupTask(vehicle, stopTask); + + if (checkDeterminsticTravelTimes) { + Verify.verify(stop.getTime() == stopTask.getEndTime(), + "Checking for determinstic travel times and found mismatch between expected stop time and scheduled stop time."); + Verify.verify(stop.getTime() <= stop.getRequest().getPlannedPickupTime(), + "Checking for determinstic travel times and found mismatch between expected stop time and planned stop time."); + } + } else if (stop.getType().equals(StopType.Dropoff)) { + stopTask.addDropoffRequest(stop.getRequest().getAcceptedDrtRequest()); + stop.getRequest().setDropoffTask(vehicle, stopTask); + + if (checkDeterminsticTravelTimes) { + Verify.verify(stop.getTime() == stopTask.getBeginTime(), + "Checking for determinstic travel times and found mismatch between expected stop time and scheduled stop time."); + } + } else { + throw new IllegalStateException(); + } + } else if (stop.getType().equals(StopType.Relocation)) { + // We want to add a relocation to the schedule + + if (index == 0 && currentTask instanceof DriveTask) { + // Vehicle is driving, so we may need to divert it + + DriveTask driveTask = (DriveTask) currentTask; + + if (!driveTask.getTaskType().equals(EmptyVehicleRelocator.RELOCATE_VEHICLE_TASK_TYPE)) { + // Not a relocation drive task, so we have to abort it + + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); + tracker.divertPath(diversionPath); + + currentLink = diversionPoint.link; + } else { + // We have a relocation drive task, so we can simply divert it + + if (driveTask.getPath().getToLink() != stop.getLink() || reroutingDuringScheduling) { + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.calcAndCreatePathForDiversion(diversionPoint, + stop.getLink(), router, travelTime); + tracker.divertPath(diversionPath); + } + + currentLink = stop.getLink(); + } + } + + if (currentLink != stop.getLink()) { + // Add a relocation drive (e.g. after a stop or aborting another drive) + + VrpPathWithTravelData drivePath = VrpPaths.calcAndCreatePath(currentLink, stop.getLink(), + currentTask.getEndTime(), router, travelTime); + currentTask = taskFactory.createDriveTask(dvrpVehicle, drivePath, + EmptyVehicleRelocator.RELOCATE_VEHICLE_TASK_TYPE); + schedule.addTask(currentTask); + + currentLink = stop.getLink(); + } + } else { + throw new IllegalStateException(); + } + } + + if (stops.size() == 0 && operationalTasks.size() == 0) { + if (currentTask instanceof DriveTask) { + // We have neither stops nor relocation -> stop the drive + + DriveTask driveTask = (DriveTask) currentTask; + + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); + tracker.divertPath(diversionPath); + + currentLink = diversionPoint.link; + } + } + + // Add operational tasks + + if (operationalTasks.size() > 0) { + for (int index = 0; index < operationalTasks.size(); index++) { + Task operationalTask = operationalTasks.get(index); + Link operationalLink = ((StayTask) operationalTask).getLink(); + + DrtTaskType driveTaskType = operationalVoter.getDriveTaskType(operationalTask); + + if (index == 0 && stops.size() == 0 && currentTask instanceof DriveTask) { + // Vehicle is driving, so we may need to divert it + + DriveTask driveTask = (DriveTask) currentTask; + + if (!driveTask.getTaskType().equals(driveTaskType)) { + // Not a standard drive task, so we have to abort it + + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.createZeroLengthPathForDiversion(diversionPoint); + tracker.divertPath(diversionPath); + + currentLink = diversionPoint.link; + } else { + // We have a fitting drive task, so we can simply divert it + + if (driveTask.getPath().getToLink() != operationalLink || reroutingDuringScheduling) { + OnlineDriveTaskTracker tracker = (OnlineDriveTaskTracker) driveTask.getTaskTracker(); + LinkTimePair diversionPoint = tracker.getDiversionPoint(); + VrpPathWithTravelData diversionPath = VrpPaths.calcAndCreatePathForDiversion(diversionPoint, + operationalLink, router, travelTime); + tracker.divertPath(diversionPath); + } + + currentLink = operationalLink; + } + } + + if (currentLink != operationalLink) { + // Add a drive + + VrpPathWithTravelData drivePath = VrpPaths.calcAndCreatePath(currentLink, operationalLink, + currentTask.getEndTime(), router, travelTime); + + currentTask = taskFactory.createDriveTask(dvrpVehicle, drivePath, driveTaskType); + schedule.addTask(currentTask); + + currentLink = operationalLink; + } + + if (operationalTask.getBeginTime() > currentTask.getEndTime()) { + if (operationalTask instanceof ShiftBreakTask) { + // We need to fill the gap with a stay task if break is not planned to start yet + double earliestBreakStartTime = ((ShiftBreakTask) operationalTask).getShiftBreak() + .getEarliestBreakStartTime(); + if (earliestBreakStartTime > currentTask.getEndTime()) { + if (currentTask instanceof DrtStayTask) { + currentTask.setEndTime(earliestBreakStartTime); + } else { + currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), + earliestBreakStartTime, operationalLink); + schedule.addTask(currentTask); + } + } + } else if (operationalTask instanceof ShiftChangeOverTask) { + // We need to fill the gap with a stay task + double shiftEndTime = ((ShiftChangeOverTask) operationalTask).getShift().getEndTime(); + if (shiftEndTime > currentTask.getEndTime()) { + if (currentTask instanceof DrtStayTask) { + currentTask.setEndTime(shiftEndTime); + } else { + currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), + shiftEndTime, operationalLink); + schedule.addTask(currentTask); + } + } + } + } + + double endTime = endTimeCalculator.calcNewEndTime(dvrpVehicle, (StayTask) operationalTask, + currentTask.getEndTime()); + operationalTask.setBeginTime(currentTask.getEndTime()); + operationalTask.setEndTime(endTime); + + currentTask = operationalTask; + schedule.addTask(currentTask); + } + } + + // Finally, add stay task until the end of the schedule + + if (currentTask instanceof DrtStayTask) { + currentTask.setEndTime(Math.max(currentTask.getEndTime(), vehicle.getVehicle().getServiceEndTime())); + } else if (currentTask instanceof WaitForShiftStayTask) { + if (currentTask.getEndTime() == now) { + // if the shift just started, re-create the stay task + StayTask stayTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), + Math.max(currentTask.getEndTime(), vehicle.getVehicle().getServiceEndTime()), currentLink); + schedule.addTask(stayTask); + } + } else { + StayTask stayTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(), + Math.max(currentTask.getEndTime(), vehicle.getVehicle().getServiceEndTime()), currentLink); + schedule.addTask(stayTask); + } + } } - diff --git a/core/src/test/java/org/matsim/alonso_mora/DiversionTest.java b/core/src/test/java/org/matsim/alonso_mora/DiversionTest.java index ed8e474..8bc2699 100644 --- a/core/src/test/java/org/matsim/alonso_mora/DiversionTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/DiversionTest.java @@ -1,12 +1,13 @@ package org.matsim.alonso_mora; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.LinkedList; import java.util.List; import java.util.Objects; import java.util.Set; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; @@ -223,16 +224,16 @@ protected void configureQSim() { // Took the fixed value from the simulation, to make sure this stays consistent // over refactorings - Assert.assertEquals(testTracker.eventBasedArrivalTime, 657.0, 1e-3); + assertEquals(testTracker.eventBasedArrivalTime, 657.0, 1e-3); // Initially calculated arrival time should predict correctly the final arrival // time - Assert.assertEquals(testTracker.initialArrivalTime, 657.0, 1e-3); + assertEquals(testTracker.initialArrivalTime, 657.0, 1e-3); // Along the route, when diverting to the same destination, arrival time should // stay constant testTracker.diversionArrivalTimes.forEach(t -> { - Assert.assertEquals(t, 657.0, 1e-3); + assertEquals(t, 657.0, 1e-3); }); } @@ -552,16 +553,16 @@ protected void configureQSim() { // Took the fixed value from the simulation, to make sure this stays consistent // over refactorings - same as previous unit test - Assert.assertEquals(testTracker.eventBasedArrivalTime, 657.0, 1e-3); + assertEquals(testTracker.eventBasedArrivalTime, 657.0, 1e-3); // Initially calculated arrival time should predict correctly the final arrival // time - as in the first unit test as we route to L8 - Assert.assertEquals(testTracker.initialArrivalTime, 657.0, 1e-3); + assertEquals(testTracker.initialArrivalTime, 657.0, 1e-3); // Along the route, when diverting to the same destination, arrival time should // stay constant testTracker.diversionArrivalTimes.forEach(t -> { - Assert.assertEquals(t, 739.0, 1e-3); + assertEquals(t, 739.0, 1e-3); }); // Without fix in OnlineDriveTaskTrackerImpl, the last test will lead to a diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolverTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolverTest.java index cbd0960..5634dbf 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolverTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/CbcMpsAssignmentSolverTest.java @@ -1,16 +1,17 @@ package org.matsim.alonso_mora.algorithm.assignment; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -18,12 +19,9 @@ import org.mockito.Mockito; public class CbcMpsAssignmentSolverTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of Cbc solver", CbcMpsAssignmentSolver.checkAvailability()); + @BeforeAll + static public void checkSolver() { + assertTrue(CbcMpsAssignmentSolver.checkAvailability(), "Checking for availability of Cbc solver"); } private AlonsoMoraRequest mockRequest() { @@ -48,9 +46,11 @@ private AlonsoMoraTrip mockTrip(AlonsoMoraVehicle vehicle, double cost, AlonsoMo } @Test - public void testOneVehicleOneRequestExample() throws IOException { - AssignmentSolver solver = new CbcMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution"), 0); + public void testOneVehicleOneRequestExample(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + + AssignmentSolver solver = new CbcMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, problemFile, solutionFile, 0); AlonsoMoraVehicle vehicle = mockVehicle(); AlonsoMoraRequest request = mockRequest(); @@ -59,14 +59,16 @@ public void testOneVehicleOneRequestExample() throws IOException { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test - public void testTwoIndependentRequests() throws IOException { - AssignmentSolver solver = new CbcMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution"), 0); + public void testTwoIndependentRequests(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + + AssignmentSolver solver = new CbcMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, problemFile, solutionFile, 0); AlonsoMoraVehicle vehicle1 = mockVehicle(); AlonsoMoraRequest request1 = mockRequest(); @@ -79,15 +81,17 @@ public void testTwoIndependentRequests() throws IOException { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test - public void testTwoRequestsWithOneVehicle() throws IOException { - AssignmentSolver solver = new CbcMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution"), 0); + public void testTwoRequestsWithOneVehicle(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + + AssignmentSolver solver = new CbcMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, problemFile, solutionFile, 0); AlonsoMoraVehicle vehicle = mockVehicle(); AlonsoMoraRequest request1 = mockRequest(); @@ -104,15 +108,17 @@ public void testTwoRequestsWithOneVehicle() throws IOException { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @Test - public void testTwoRequestsWithOneVehicleLowPenalty() throws IOException { - AssignmentSolver solver = new CbcMpsAssignmentSolver(250.0, 250.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution"), 0); + public void testTwoRequestsWithOneVehicleLowPenalty(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + + AssignmentSolver solver = new CbcMpsAssignmentSolver(250.0, 250.0, 1000, 0.1, problemFile, solutionFile, 0); AlonsoMoraVehicle vehicle = mockVehicle(); AlonsoMoraRequest request1 = mockRequest(); @@ -128,8 +134,8 @@ public void testTwoRequestsWithOneVehicleLowPenalty() throws IOException { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolverTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolverTest.java index 6eb3846..f0beff4 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolverTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GlpkMpsAssignmentSolverTest.java @@ -1,16 +1,17 @@ package org.matsim.alonso_mora.algorithm.assignment; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -18,12 +19,9 @@ import org.mockito.Mockito; public class GlpkMpsAssignmentSolverTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of GLPK solver", GlpkMpsAssignmentSolver.checkAvailability()); + @BeforeAll + static public void checkSolver() { + assertTrue(GlpkMpsAssignmentSolver.checkAvailability(), "Checking for availability of GLPK solver"); } private AlonsoMoraRequest mockRequest() { @@ -48,9 +46,12 @@ private AlonsoMoraTrip mockTrip(AlonsoMoraVehicle vehicle, double cost, AlonsoMo } @Test - public void testOneVehicleOneRequestExample() throws IOException { + public void testOneVehicleOneRequestExample(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + AssignmentSolver solver = new GlpkMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution")); + problemFile, solutionFile); AlonsoMoraVehicle vehicle = mockVehicle(); AlonsoMoraRequest request = mockRequest(); @@ -59,14 +60,17 @@ public void testOneVehicleOneRequestExample() throws IOException { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test - public void testTwoIndependentRequests() throws IOException { + public void testTwoIndependentRequests(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + AssignmentSolver solver = new GlpkMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution")); + problemFile, solutionFile); AlonsoMoraVehicle vehicle1 = mockVehicle(); AlonsoMoraRequest request1 = mockRequest(); @@ -79,15 +83,18 @@ public void testTwoIndependentRequests() throws IOException { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test - public void testTwoRequestsWithOneVehicle() throws IOException { + public void testTwoRequestsWithOneVehicle(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + AssignmentSolver solver = new GlpkMpsAssignmentSolver(9000.0, 9000.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution")); + problemFile, solutionFile); AlonsoMoraVehicle vehicle = mockVehicle(); AlonsoMoraRequest request1 = mockRequest(); @@ -104,15 +111,18 @@ public void testTwoRequestsWithOneVehicle() throws IOException { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @Test - public void testTwoRequestsWithOneVehicleLowPenalty() throws IOException { + public void testTwoRequestsWithOneVehicleLowPenalty(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + AssignmentSolver solver = new GlpkMpsAssignmentSolver(250.0, 250.0, 1000, 0.1, - temporaryFolder.newFile("problem"), temporaryFolder.newFile("solution")); + problemFile, solutionFile); AlonsoMoraVehicle vehicle = mockVehicle(); AlonsoMoraRequest request1 = mockRequest(); @@ -128,8 +138,8 @@ public void testTwoRequestsWithOneVehicleLowPenalty() throws IOException { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyTripFirstAssignmentSolverTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyTripFirstAssignmentSolverTest.java index c60e8d9..51d8914 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyTripFirstAssignmentSolverTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyTripFirstAssignmentSolverTest.java @@ -1,11 +1,13 @@ package org.matsim.alonso_mora.algorithm.assignment; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -45,8 +47,8 @@ public void testOneVehicleOneRequestExample() { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test @@ -64,9 +66,9 @@ public void testTwoIndependentRequests() { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test @@ -85,8 +87,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } { @@ -97,8 +99,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip2)); } { @@ -109,8 +111,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @@ -133,8 +135,8 @@ public void testTwoRequestsWithTwoVehicles() { List candidates = Arrays.asList(trip1, trip2, trip3, trip4); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } { @@ -146,9 +148,9 @@ public void testTwoRequestsWithTwoVehicles() { List candidates = Arrays.asList(trip1, trip2, trip3, trip4); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyVehicleFirstAssignmentSolverTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyVehicleFirstAssignmentSolverTest.java index 96bbabd..50966df 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyVehicleFirstAssignmentSolverTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/assignment/GreedyVehicleFirstAssignmentSolverTest.java @@ -1,11 +1,13 @@ package org.matsim.alonso_mora.algorithm.assignment; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -52,8 +54,8 @@ public void testOneVehicleOneRequestExample() { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test @@ -71,9 +73,9 @@ public void testTwoIndependentRequests() { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test @@ -92,8 +94,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } { @@ -104,8 +106,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip2)); } { @@ -116,8 +118,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @@ -140,8 +142,8 @@ public void testTwoRequestsWithTwoVehicles() { List candidates = Arrays.asList(trip1, trip2, trip3, trip4); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } { @@ -153,9 +155,9 @@ public void testTwoRequestsWithTwoVehicles() { List candidates = Arrays.asList(trip1, trip2, trip3, trip4); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/RouteTrackerTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/RouteTrackerTest.java index 29951dd..89786cb 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/RouteTrackerTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/RouteTrackerTest.java @@ -1,11 +1,12 @@ package org.matsim.alonso_mora.algorithm.function; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.LinkedList; import java.util.List; import java.util.Optional; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop; import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType; @@ -37,13 +38,13 @@ public void testInitializationWithoutLink() { tracker.update(initialStops); - Assert.assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(7105.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7110.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(7105.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7110.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(4, tracker.getOccupancyAfter(0)); - Assert.assertEquals(3, tracker.getOccupancyAfter(1)); + assertEquals(4, tracker.getOccupancyAfter(0)); + assertEquals(3, tracker.getOccupancyAfter(1)); } @Test @@ -72,13 +73,13 @@ public void testInitializationWithLink() { tracker.update(initialStops); - Assert.assertEquals(7000.0 + 100.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0 + 100.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(7105.0 + 100.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7110.0 + 100.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(7000.0 + 100.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0 + 100.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(7105.0 + 100.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7110.0 + 100.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(4, tracker.getOccupancyAfter(0)); - Assert.assertEquals(3, tracker.getOccupancyAfter(1)); + assertEquals(4, tracker.getOccupancyAfter(0)); + assertEquals(3, tracker.getOccupancyAfter(1)); } @Test @@ -106,30 +107,30 @@ public void testMultipleRequests() { tracker.update(initialStops); - Assert.assertEquals(7100.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7105.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(7100.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7105.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(7205.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7210.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(7205.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7210.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(7310.0, tracker.getArrivalTime(2), 1e-3); - Assert.assertEquals(7315.0, tracker.getDepartureTime(2), 1e-3); + assertEquals(7310.0, tracker.getArrivalTime(2), 1e-3); + assertEquals(7315.0, tracker.getDepartureTime(2), 1e-3); - Assert.assertEquals(7415.0, tracker.getArrivalTime(3), 1e-3); - Assert.assertEquals(7420.0, tracker.getDepartureTime(3), 1e-3); + assertEquals(7415.0, tracker.getArrivalTime(3), 1e-3); + assertEquals(7420.0, tracker.getDepartureTime(3), 1e-3); - Assert.assertEquals(7520.0, tracker.getArrivalTime(4), 1e-3); - Assert.assertEquals(7525.0, tracker.getDepartureTime(4), 1e-3); + assertEquals(7520.0, tracker.getArrivalTime(4), 1e-3); + assertEquals(7525.0, tracker.getDepartureTime(4), 1e-3); - Assert.assertEquals(7625.0, tracker.getArrivalTime(5), 1e-3); - Assert.assertEquals(7630.0, tracker.getDepartureTime(5), 1e-3); + assertEquals(7625.0, tracker.getArrivalTime(5), 1e-3); + assertEquals(7630.0, tracker.getDepartureTime(5), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); - Assert.assertEquals(2, tracker.getOccupancyAfter(1)); - Assert.assertEquals(1, tracker.getOccupancyAfter(2)); - Assert.assertEquals(0, tracker.getOccupancyAfter(3)); - Assert.assertEquals(1, tracker.getOccupancyAfter(4)); - Assert.assertEquals(0, tracker.getOccupancyAfter(5)); + assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(2, tracker.getOccupancyAfter(1)); + assertEquals(1, tracker.getOccupancyAfter(2)); + assertEquals(0, tracker.getOccupancyAfter(3)); + assertEquals(1, tracker.getOccupancyAfter(4)); + assertEquals(0, tracker.getOccupancyAfter(5)); } @Test @@ -163,12 +164,12 @@ public void testGroupRequests() { tracker.update(initialStops); - Assert.assertEquals(2, tracker.getOccupancyAfter(0)); - Assert.assertEquals(3, tracker.getOccupancyAfter(1)); - Assert.assertEquals(2, tracker.getOccupancyAfter(2)); - Assert.assertEquals(0, tracker.getOccupancyAfter(3)); - Assert.assertEquals(3, tracker.getOccupancyAfter(4)); - Assert.assertEquals(0, tracker.getOccupancyAfter(5)); + assertEquals(2, tracker.getOccupancyAfter(0)); + assertEquals(3, tracker.getOccupancyAfter(1)); + assertEquals(2, tracker.getOccupancyAfter(2)); + assertEquals(0, tracker.getOccupancyAfter(3)); + assertEquals(3, tracker.getOccupancyAfter(4)); + assertEquals(0, tracker.getOccupancyAfter(5)); } @Test @@ -196,30 +197,30 @@ public void testMultipleRequestsWithStopAggregation() { tracker.update(initialStops); - Assert.assertEquals(7100.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7105.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(7100.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7105.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(7100.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7105.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(7100.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7105.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(7205.0, tracker.getArrivalTime(2), 1e-3); - Assert.assertEquals(7210.0, tracker.getDepartureTime(2), 1e-3); + assertEquals(7205.0, tracker.getArrivalTime(2), 1e-3); + assertEquals(7210.0, tracker.getDepartureTime(2), 1e-3); - Assert.assertEquals(7205.0, tracker.getArrivalTime(3), 1e-3); - Assert.assertEquals(7210.0, tracker.getDepartureTime(3), 1e-3); + assertEquals(7205.0, tracker.getArrivalTime(3), 1e-3); + assertEquals(7210.0, tracker.getDepartureTime(3), 1e-3); - Assert.assertEquals(7310.0, tracker.getArrivalTime(4), 1e-3); - Assert.assertEquals(7315.0, tracker.getDepartureTime(4), 1e-3); + assertEquals(7310.0, tracker.getArrivalTime(4), 1e-3); + assertEquals(7315.0, tracker.getDepartureTime(4), 1e-3); - Assert.assertEquals(7415.0, tracker.getArrivalTime(5), 1e-3); - Assert.assertEquals(7420.0, tracker.getDepartureTime(5), 1e-3); + assertEquals(7415.0, tracker.getArrivalTime(5), 1e-3); + assertEquals(7420.0, tracker.getDepartureTime(5), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); - Assert.assertEquals(2, tracker.getOccupancyAfter(1)); - Assert.assertEquals(1, tracker.getOccupancyAfter(2)); - Assert.assertEquals(0, tracker.getOccupancyAfter(3)); - Assert.assertEquals(1, tracker.getOccupancyAfter(4)); - Assert.assertEquals(0, tracker.getOccupancyAfter(5)); + assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(2, tracker.getOccupancyAfter(1)); + assertEquals(1, tracker.getOccupancyAfter(2)); + assertEquals(0, tracker.getOccupancyAfter(3)); + assertEquals(1, tracker.getOccupancyAfter(4)); + assertEquals(0, tracker.getOccupancyAfter(5)); } @Test @@ -246,26 +247,26 @@ public void testUpdateIndex() { { List sequence = new LinkedList<>(); sequence.add(new AlonsoMoraStop(StopType.Pickup, linkA, request)); - Assert.assertEquals(0, tracker.update(sequence)); + assertEquals(0, tracker.update(sequence)); - Assert.assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(1, tracker.getOccupancyAfter(0)); } { List sequence = new LinkedList<>(); sequence.add(new AlonsoMoraStop(StopType.Pickup, linkA, request)); sequence.add(new AlonsoMoraStop(StopType.Pickup, linkB, request)); - Assert.assertEquals(1, tracker.update(sequence)); + assertEquals(1, tracker.update(sequence)); - Assert.assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(1, tracker.getOccupancyAfter(0)); - Assert.assertEquals(7105.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7110.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(2, tracker.getOccupancyAfter(1)); + assertEquals(7105.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7110.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(2, tracker.getOccupancyAfter(1)); } { @@ -274,48 +275,48 @@ public void testUpdateIndex() { sequence.add(new AlonsoMoraStop(StopType.Pickup, linkB, request)); sequence.add(new AlonsoMoraStop(StopType.Dropoff, linkA, request)); sequence.add(new AlonsoMoraStop(StopType.Dropoff, linkB, request)); - Assert.assertEquals(2, tracker.update(sequence)); + assertEquals(2, tracker.update(sequence)); - Assert.assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(1, tracker.getOccupancyAfter(0)); - Assert.assertEquals(7105.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7110.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(2, tracker.getOccupancyAfter(1)); + assertEquals(7105.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7110.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(2, tracker.getOccupancyAfter(1)); - Assert.assertEquals(7120.0, tracker.getArrivalTime(2), 1e-3); - Assert.assertEquals(7125.0, tracker.getDepartureTime(2), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(2)); + assertEquals(7120.0, tracker.getArrivalTime(2), 1e-3); + assertEquals(7125.0, tracker.getDepartureTime(2), 1e-3); + assertEquals(1, tracker.getOccupancyAfter(2)); - Assert.assertEquals(7225.0, tracker.getArrivalTime(3), 1e-3); - Assert.assertEquals(7230.0, tracker.getDepartureTime(3), 1e-3); - Assert.assertEquals(0, tracker.getOccupancyAfter(3)); + assertEquals(7225.0, tracker.getArrivalTime(3), 1e-3); + assertEquals(7230.0, tracker.getDepartureTime(3), 1e-3); + assertEquals(0, tracker.getOccupancyAfter(3)); } { List sequence = new LinkedList<>(); sequence.add(new AlonsoMoraStop(StopType.Pickup, linkA, request)); sequence.add(new AlonsoMoraStop(StopType.Dropoff, linkA, request)); - Assert.assertEquals(1, tracker.update(sequence)); + assertEquals(1, tracker.update(sequence)); - Assert.assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(1, tracker.getOccupancyAfter(0)); - Assert.assertEquals(7000.0, tracker.getArrivalTime(1), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(1), 1e-3); - Assert.assertEquals(0, tracker.getOccupancyAfter(1)); + assertEquals(7000.0, tracker.getArrivalTime(1), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(1), 1e-3); + assertEquals(0, tracker.getOccupancyAfter(1)); } { List sequence = new LinkedList<>(); sequence.add(new AlonsoMoraStop(StopType.Pickup, linkB, request)); - Assert.assertEquals(0, tracker.update(sequence)); + assertEquals(0, tracker.update(sequence)); - Assert.assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); - Assert.assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); - Assert.assertEquals(1, tracker.getOccupancyAfter(0)); + assertEquals(7000.0, tracker.getArrivalTime(0), 1e-3); + assertEquals(7005.0, tracker.getDepartureTime(0), 1e-3); + assertEquals(1, tracker.getOccupancyAfter(0)); } } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultRequestGraphTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultRequestGraphTest.java index 387a702..5afd1fb 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultRequestGraphTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultRequestGraphTest.java @@ -1,11 +1,14 @@ package org.matsim.alonso_mora.algorithm.function.graphs; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Collection; import java.util.Optional; import java.util.concurrent.ForkJoinPool; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.function.AlonsoMoraFunction; @@ -29,19 +32,19 @@ public void testBasicMatching() { graph.addRequest(request1, 0.0); - Assert.assertEquals(0, graph.getShareableRequests(request1).size()); - Assert.assertEquals(0, graph.getShareableRequests(request2).size()); + assertEquals(0, graph.getShareableRequests(request1).size()); + assertEquals(0, graph.getShareableRequests(request2).size()); graph.addRequest(request2, 0.0); - Assert.assertEquals(1, graph.getShareableRequests(request1).size()); - Assert.assertEquals(1, graph.getShareableRequests(request2).size()); + assertEquals(1, graph.getShareableRequests(request1).size()); + assertEquals(1, graph.getShareableRequests(request2).size()); - Assert.assertTrue(graph.getShareableRequests(request1).contains(request2)); - Assert.assertTrue(graph.getShareableRequests(request2).contains(request1)); + assertTrue(graph.getShareableRequests(request1).contains(request2)); + assertTrue(graph.getShareableRequests(request2).contains(request1)); } - @Test(expected = VerifyException.class) + @Test public void testAddTwice() { MockRequest request1 = new MockRequest(1); @@ -49,7 +52,10 @@ public void testAddTwice() { RequestGraph graph = new DefaultRequestGraph(function, new ForkJoinPool(1)); graph.addRequest(request1, 0.0); - graph.addRequest(request1, 0.0); + + Assertions.assertThrows(VerifyException.class, () -> { + graph.addRequest(request1, 0.0); + }); } @Test @@ -69,14 +75,14 @@ public void testSelectiveMatching() { graph.addRequest(request7, 0.0); graph.addRequest(request8, 0.0); - Assert.assertEquals(2, graph.getShareableRequests(request1).size()); - Assert.assertEquals(1, graph.getShareableRequests(request7).size()); - Assert.assertEquals(1, graph.getShareableRequests(request8).size()); + assertEquals(2, graph.getShareableRequests(request1).size()); + assertEquals(1, graph.getShareableRequests(request7).size()); + assertEquals(1, graph.getShareableRequests(request8).size()); - Assert.assertTrue(graph.getShareableRequests(request1).contains(request7)); - Assert.assertTrue(graph.getShareableRequests(request1).contains(request8)); - Assert.assertTrue(graph.getShareableRequests(request7).contains(request1)); - Assert.assertTrue(graph.getShareableRequests(request8).contains(request1)); + assertTrue(graph.getShareableRequests(request1).contains(request7)); + assertTrue(graph.getShareableRequests(request1).contains(request8)); + assertTrue(graph.getShareableRequests(request7).contains(request1)); + assertTrue(graph.getShareableRequests(request8).contains(request1)); } private static class MockRequest implements AlonsoMoraRequest { @@ -150,13 +156,13 @@ public boolean isAssigned() { } @Override - public Collection getDrtRequests() { + public DrtRequest getDrtRequest() { // TODO Auto-generated method stub return null; } - + @Override - public Collection getAcceptedDrtRequests() { + public AcceptedDrtRequest getAcceptedDrtRequest() { // TODO Auto-generated method stub return null; } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultVehicleGraphTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultVehicleGraphTest.java index c5178ff..3e2cfde 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultVehicleGraphTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/graphs/DefaultVehicleGraphTest.java @@ -1,5 +1,7 @@ package org.matsim.alonso_mora.algorithm.function.graphs; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -9,8 +11,7 @@ import java.util.Set; import java.util.stream.Collectors; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -46,8 +47,8 @@ public void testSingleRequest() { List trips = graph.stream().collect(Collectors.toList()); // Only one request, so we only expect one trip - Assert.assertEquals(1, trips.size()); - Assert.assertEquals(1, trips.stream().filter(t -> t.getLength() == 1).count()); + assertEquals(1, trips.size()); + assertEquals(1, trips.stream().filter(t -> t.getLength() == 1).count()); } @Test @@ -72,9 +73,9 @@ public void testTwoConnectedRequests() { List trips = graph.stream().collect(Collectors.toList()); // Two connected requests, we have two single rides and one combined - Assert.assertEquals(3, trips.size()); - Assert.assertEquals(2, trips.stream().filter(t -> t.getLength() == 1).count()); - Assert.assertEquals(1, trips.stream().filter(t -> t.getLength() == 2).count()); + assertEquals(3, trips.size()); + assertEquals(2, trips.stream().filter(t -> t.getLength() == 1).count()); + assertEquals(1, trips.stream().filter(t -> t.getLength() == 2).count()); } @Test @@ -98,8 +99,8 @@ public void testTwoUNConnectedRequests() { List trips = graph.stream().collect(Collectors.toList()); // Two unconnected requests, we have two single rides - Assert.assertEquals(2, trips.size()); - Assert.assertEquals(2, trips.stream().filter(t -> t.getLength() == 1).count()); + assertEquals(2, trips.size()); + assertEquals(2, trips.stream().filter(t -> t.getLength() == 1).count()); } @Test @@ -142,9 +143,9 @@ public void testComplexMatching2() { // Only two passengers allowed currently (weight 25), // we expect 5 single passengers rides and 3 + 3 = 6 two-passengres rides - Assert.assertEquals(11, trips.size()); - Assert.assertEquals(5, trips.stream().filter(t -> t.getLength() == 1).count()); - Assert.assertEquals(6, trips.stream().filter(t -> t.getLength() == 2).count()); + assertEquals(11, trips.size()); + assertEquals(5, trips.stream().filter(t -> t.getLength() == 1).count()); + assertEquals(6, trips.stream().filter(t -> t.getLength() == 2).count()); } @Test @@ -188,10 +189,10 @@ public void testComplexMatching3() { // we expect 5 single passengers rides and 3 + 3 = 6 two-passengres rides, and 2 // three-passenger rides - Assert.assertEquals(13, trips.size()); - Assert.assertEquals(5, trips.stream().filter(t -> t.getLength() == 1).count()); - Assert.assertEquals(6, trips.stream().filter(t -> t.getLength() == 2).count()); - Assert.assertEquals(2, trips.stream().filter(t -> t.getLength() == 3).count()); + assertEquals(13, trips.size()); + assertEquals(5, trips.stream().filter(t -> t.getLength() == 1).count()); + assertEquals(6, trips.stream().filter(t -> t.getLength() == 2).count()); + assertEquals(2, trips.stream().filter(t -> t.getLength() == 3).count()); } @Test @@ -241,11 +242,11 @@ public void testComplexMatching4() { // we expect 6 single passengers rides and 3 + 3 + 3 = 9 two-passengres rides, // and 4 three-passenger ride, 1 four-passenger-ride - Assert.assertEquals(21, trips.size()); - Assert.assertEquals(6, trips.stream().filter(t -> t.getLength() == 1).count()); - Assert.assertEquals(9, trips.stream().filter(t -> t.getLength() == 2).count()); - Assert.assertEquals(5, trips.stream().filter(t -> t.getLength() == 3).count()); - Assert.assertEquals(1, trips.stream().filter(t -> t.getLength() == 4).count()); + assertEquals(21, trips.size()); + assertEquals(6, trips.stream().filter(t -> t.getLength() == 1).count()); + assertEquals(9, trips.stream().filter(t -> t.getLength() == 2).count()); + assertEquals(5, trips.stream().filter(t -> t.getLength() == 3).count()); + assertEquals(1, trips.stream().filter(t -> t.getLength() == 4).count()); } static private class MockFunction implements AlonsoMoraFunction { @@ -392,17 +393,17 @@ public boolean isAssigned() { } @Override - public Collection getDrtRequests() { + public DrtRequest getDrtRequest() { // TODO Auto-generated method stub return null; } @Override - public Collection getAcceptedDrtRequests() { + public AcceptedDrtRequest getAcceptedDrtRequest() { // TODO Auto-generated method stub return null; } - + @Override public int getSize() { // TODO Auto-generated method stub diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/EuclideanSequenceGeneratorTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/EuclideanSequenceGeneratorTest.java index 310bb6b..5a23eeb 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/EuclideanSequenceGeneratorTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/EuclideanSequenceGeneratorTest.java @@ -1,11 +1,12 @@ package org.matsim.alonso_mora.algorithm.function.sequence; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.api.core.v01.Coord; import org.matsim.api.core.v01.Id; @@ -28,7 +29,7 @@ private AlonsoMoraRequest mockRequest(double fromLocation, double toLocation, St AlonsoMoraRequest request = Mockito.mock(AlonsoMoraRequest.class); Mockito.when(request.getPickupLink()).thenReturn(fromLink); Mockito.when(request.getDropoffLink()).thenReturn(toLink); - Mockito.when(request.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request.getDrtRequest()).thenReturn(drtRequest); return request; } @@ -58,8 +59,8 @@ public void testOneRequests() { generator.advance(); } - Assert.assertEquals(2, partial); - Assert.assertEquals(1, complete); + assertEquals(2, partial); + assertEquals(1, complete); } @Test @@ -88,8 +89,8 @@ public void testTwoRequests() { generator.advance(); } - Assert.assertEquals(4, partial); - Assert.assertEquals(1, complete); + assertEquals(4, partial); + assertEquals(1, complete); } @Test @@ -128,8 +129,8 @@ public void testTwoRequestsWithAbort() { callIndex++; } - Assert.assertEquals(5, partial); - Assert.assertEquals(1, complete); + assertEquals(5, partial); + assertEquals(1, complete); } @Test diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/ExtensiveSequenceGeneratorTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/ExtensiveSequenceGeneratorTest.java index fcaf757..d3af78c 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/ExtensiveSequenceGeneratorTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/ExtensiveSequenceGeneratorTest.java @@ -1,11 +1,14 @@ package org.matsim.alonso_mora.algorithm.function.sequence; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.contrib.drt.passenger.DrtRequest; import org.mockito.Mockito; @@ -18,7 +21,7 @@ private DrtRequest createDrtRequestMock() { private AlonsoMoraRequest createAlonsoMoraRequestMock() { AlonsoMoraRequest request = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request.getDrtRequests()).thenReturn(Collections.singleton(createDrtRequestMock())); + Mockito.when(request.getDrtRequest()).thenReturn(createDrtRequestMock()); return request; } @@ -42,8 +45,8 @@ public void testOneRequests() { generator.advance(); } - Assert.assertEquals(2, partial); - Assert.assertEquals(1, complete); + assertEquals(2, partial); + assertEquals(1, complete); } @Test @@ -67,8 +70,8 @@ public void testTwoRequests() { generator.advance(); } - Assert.assertEquals(18, partial); - Assert.assertEquals(6, complete); + assertEquals(18, partial); + assertEquals(6, complete); } @Test @@ -91,8 +94,8 @@ public void testOneOnboard() { generator.advance(); } - Assert.assertEquals(1, partial); - Assert.assertEquals(1, complete); + assertEquals(1, partial); + assertEquals(1, complete); } @Test @@ -116,8 +119,8 @@ public void testTwoOnboard() { generator.advance(); } - Assert.assertEquals(4, partial); - Assert.assertEquals(2, complete); + assertEquals(4, partial); + assertEquals(2, complete); } @Test @@ -146,8 +149,8 @@ public void testTwoRequestsWithOneOnboard() { generator.advance(); } - Assert.assertEquals(89, partial); - Assert.assertEquals(30, complete); + assertEquals(89, partial); + assertEquals(30, complete); } @Test @@ -174,8 +177,8 @@ public void testFourRequests() { generator.advance(); } - Assert.assertEquals(7364, partial); - Assert.assertEquals(2520, complete); + assertEquals(7364, partial); + assertEquals(2520, complete); } @Test @@ -186,21 +189,21 @@ public void testTwoRequestsFirstReject() { ExtensiveSequenceGenerator generator = new ExtensiveSequenceGenerator(requests, Collections.emptySet()); - Assert.assertTrue(generator.hasNext()); - Assert.assertEquals(1, generator.get().size()); + assertTrue(generator.hasNext()); + assertEquals(1, generator.get().size()); generator.abort(); - Assert.assertTrue(generator.hasNext()); - Assert.assertEquals(1, generator.get().size()); + assertTrue(generator.hasNext()); + assertEquals(1, generator.get().size()); generator.advance(); - Assert.assertTrue(generator.hasNext()); - Assert.assertEquals(2, generator.get().size()); + assertTrue(generator.hasNext()); + assertEquals(2, generator.get().size()); generator.advance(); - Assert.assertFalse(generator.hasNext()); + assertFalse(generator.hasNext()); } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/InsertiveSequenceGeneratorTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/InsertiveSequenceGeneratorTest.java index 38b3aea..7cf6a27 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/InsertiveSequenceGeneratorTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/function/sequence/InsertiveSequenceGeneratorTest.java @@ -1,11 +1,12 @@ package org.matsim.alonso_mora.algorithm.function.sequence; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.function.sequence.InsertiveSequenceGenerator.IndexCalculator; import org.matsim.contrib.drt.passenger.DrtRequest; @@ -17,16 +18,16 @@ public void testDefaultDelegation() { DrtRequest drtRequest = Mockito.mock(DrtRequest.class); AlonsoMoraRequest request1 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request1.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request1.getDrtRequest()).thenReturn(drtRequest); AlonsoMoraRequest request2 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request2.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request2.getDrtRequest()).thenReturn(drtRequest); AlonsoMoraRequest request3 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request3.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request3.getDrtRequest()).thenReturn(drtRequest); AlonsoMoraRequest request4 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request4.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request4.getDrtRequest()).thenReturn(drtRequest); List requests = new LinkedList<>(); @@ -55,8 +56,8 @@ public void testDefaultDelegation() { generator.advance(); } - Assert.assertEquals(7364, partial); - Assert.assertEquals(2520, complete); + assertEquals(7364, partial); + assertEquals(2520, complete); } @Test @@ -64,16 +65,16 @@ public void testKeepingOrder() { DrtRequest drtRequest = Mockito.mock(DrtRequest.class); AlonsoMoraRequest request1 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request1.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request1.getDrtRequest()).thenReturn(drtRequest); AlonsoMoraRequest request2 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request2.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request2.getDrtRequest()).thenReturn(drtRequest); AlonsoMoraRequest request3 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request3.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request3.getDrtRequest()).thenReturn(drtRequest); AlonsoMoraRequest request4 = Mockito.mock(AlonsoMoraRequest.class); - Mockito.when(request4.getDrtRequests()).thenReturn(Collections.singleton(drtRequest)); + Mockito.when(request4.getDrtRequest()).thenReturn(drtRequest); List requests = new LinkedList<>(); @@ -108,7 +109,7 @@ public void testKeepingOrder() { generator.advance(); } - Assert.assertEquals(1440, partial); - Assert.assertEquals(420, complete); + assertEquals(1440, partial); + assertEquals(420, complete); } } diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolverTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolverTest.java index cbd9df4..7227218 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolverTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/CbcMpsRelocationSolverTest.java @@ -1,7 +1,9 @@ package org.matsim.alonso_mora.algorithm.relocation; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -10,11 +12,9 @@ import java.util.LinkedList; import java.util.List; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.assignment.CbcMpsAssignmentSolver; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; @@ -22,19 +22,19 @@ import org.mockito.Mockito; public class CbcMpsRelocationSolverTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of Cbc solver", CbcMpsAssignmentSolver.checkAvailability()); + @BeforeAll + public static void checkSolver() { + assertTrue(CbcMpsAssignmentSolver.checkAvailability(), "Checking for availability of Cbc solver"); } @Test - public void testTwoVehicesOneDestination() throws IOException { + public void testTwoVehicesOneDestination(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + CbcMpsRelocationSolver solver = new CbcMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution"), 0); + problemFile, // + solutionFile, 0); AlonsoMoraVehicle vehicle = Mockito.mock(AlonsoMoraVehicle.class); @@ -49,10 +49,13 @@ public void testTwoVehicesOneDestination() throws IOException { } @Test - public void testOneVehicesTwoDestinations() throws IOException { + public void testOneVehicesTwoDestinations(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + CbcMpsRelocationSolver solver = new CbcMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution"), 0); + problemFile, // + solutionFile, 0); Link link = Mockito.mock(Link.class); @@ -67,10 +70,13 @@ public void testOneVehicesTwoDestinations() throws IOException { } @Test - public void testComplex() throws IOException { + public void testComplex(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + CbcMpsRelocationSolver solver = new CbcMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution"), 0); + problemFile, // + solutionFile, 0); Link linkA = Mockito.mock(Link.class); Link linkB = Mockito.mock(Link.class); @@ -96,10 +102,13 @@ public void testComplex() throws IOException { } @Test - public void testEmpty() throws IOException { + public void testEmpty(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "problem"); + CbcMpsRelocationSolver solver = new CbcMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution"), 0); + problemFile, // + solutionFile, 0); Collection solution = solver.solve(Collections.emptyList()); diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolverTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolverTest.java index afb5af9..eade6ea 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolverTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/GlpkMpsRelocationSolverTest.java @@ -1,7 +1,9 @@ package org.matsim.alonso_mora.algorithm.relocation; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -10,11 +12,9 @@ import java.util.LinkedList; import java.util.List; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.assignment.GlpkMpsAssignmentSolver; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; @@ -22,19 +22,19 @@ import org.mockito.Mockito; public class GlpkMpsRelocationSolverTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of GLPK solver", GlpkMpsAssignmentSolver.checkAvailability()); + @BeforeAll + static public void checkSolver() { + assertTrue(GlpkMpsAssignmentSolver.checkAvailability(), "Checking for availability of GLPK solver"); } @Test - public void testTwoVehicesOneDestination() throws IOException { + public void testTwoVehicesOneDestination(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + GlpkMpsRelocationSolver solver = new GlpkMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution")); + problemFile, // + solutionFile); AlonsoMoraVehicle vehicle = Mockito.mock(AlonsoMoraVehicle.class); @@ -49,10 +49,13 @@ public void testTwoVehicesOneDestination() throws IOException { } @Test - public void testOneVehicesTwoDestinations() throws IOException { + public void testOneVehicesTwoDestinations(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + GlpkMpsRelocationSolver solver = new GlpkMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution")); + problemFile, // + solutionFile); Link link = Mockito.mock(Link.class); @@ -65,16 +68,19 @@ public void testOneVehicesTwoDestinations() throws IOException { assertEquals(1, solution.size()); assertEquals(relocations.get(0), solution.iterator().next()); } - + @Test - public void testComplex() throws IOException { + public void testComplex(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + GlpkMpsRelocationSolver solver = new GlpkMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution")); - + problemFile, // + solutionFile); + Link linkA = Mockito.mock(Link.class); Link linkB = Mockito.mock(Link.class); - + AlonsoMoraVehicle vehicle1 = Mockito.mock(AlonsoMoraVehicle.class); AlonsoMoraVehicle vehicle2 = Mockito.mock(AlonsoMoraVehicle.class); AlonsoMoraVehicle vehicle3 = Mockito.mock(AlonsoMoraVehicle.class); @@ -89,17 +95,20 @@ public void testComplex() throws IOException { Collection solution = solver.solve(relocations); assertEquals(2, solution.size()); - + List expected = new ArrayList<>(Arrays.asList(relocations.get(0), relocations.get(4))); expected.removeAll(relocations); assertEquals(0, expected.size()); } @Test - public void testEmpty() throws IOException { + public void testEmpty(@TempDir File temporaryFolder) throws IOException { + File problemFile = new File(temporaryFolder, "problem"); + File solutionFile = new File(temporaryFolder, "solution"); + GlpkMpsRelocationSolver solver = new GlpkMpsRelocationSolver(1000, // - temporaryFolder.newFile("problem"), // - temporaryFolder.newFile("solution")); + problemFile, // + solutionFile); Collection solution = solver.solve(Collections.emptyList()); diff --git a/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriterTest.java b/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriterTest.java index f11630f..a1a0118 100644 --- a/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriterTest.java +++ b/core/src/test/java/org/matsim/alonso_mora/algorithm/relocation/MpsRelocationWriterTest.java @@ -1,23 +1,20 @@ package org.matsim.alonso_mora.algorithm.relocation; +import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.List; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; import org.matsim.api.core.v01.network.Link; import org.mockito.Mockito; public class MpsRelocationWriterTest { - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); - @Test - public void testWriter() throws IOException { + public void testWriter(@TempDir File temporaryFolder) throws IOException { List relocations = new LinkedList<>(); AlonsoMoraVehicle vehicle = Mockito.mock(AlonsoMoraVehicle.class); @@ -26,6 +23,6 @@ public void testWriter() throws IOException { relocations.add(new Relocation(vehicle, Mockito.mock(Link.class), 50.0)); MpsRelocationWriter writer = new MpsRelocationWriter(relocations); - writer.write(temporaryFolder.newFile("problem")); + writer.write(new File(temporaryFolder, "problem")); } } diff --git a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java index 514c329..3ce1024 100644 --- a/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java +++ b/core/src/test/java/org/matsim/alonso_mora/run/AlonsoMoraExamplesIT.java @@ -19,7 +19,7 @@ package org.matsim.alonso_mora.run; -import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.net.URL; @@ -32,9 +32,8 @@ import java.util.Random; import java.util.stream.Collectors; -import org.assertj.core.data.Percentage; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.matsim.alonso_mora.AlonsoMoraConfigGroup; import org.matsim.alonso_mora.AlonsoMoraConfigurator; import org.matsim.alonso_mora.MultiModeAlonsoMoraConfigGroup; @@ -42,7 +41,6 @@ import org.matsim.api.core.v01.Id; import org.matsim.api.core.v01.Scenario; import org.matsim.api.core.v01.network.Link; -import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup; import org.matsim.contrib.drt.extension.operations.DrtOperationsParams; import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup; import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesParams; @@ -86,8 +84,8 @@ */ public class AlonsoMoraExamplesIT { - @Rule - public MatsimTestUtils utils = new MatsimTestUtils(); + @RegisterExtension + private MatsimTestUtils utils = new MatsimTestUtils(); @Test public void testRunAlonsoMora() { @@ -137,7 +135,8 @@ public void testRunAlonsoMora() { public void testRunAlonsoMoraWithShifts() { Id.resetCaches(); URL configUrl = IOUtils.extendUrl(ExamplesUtils.getTestScenarioURL("mielec"), "mielec_drt_config.xml"); - Config config = ConfigUtils.loadConfig(configUrl, new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new), new DvrpConfigGroup(), + Config config = ConfigUtils.loadConfig(configUrl, + new MultiModeDrtConfigGroup(DrtWithOperationsConfigGroup::new), new DvrpConfigGroup(), new MultiModeAlonsoMoraConfigGroup(), new OTFVisConfigGroup()); AlonsoMoraConfigGroup amConfig = new AlonsoMoraConfigGroup(); @@ -147,16 +146,17 @@ public void testRunAlonsoMoraWithShifts() { config.controller().setOutputDirectory(utils.getOutputDirectory()); // Remove DRT rebalancer as we want to use AM rebalancer - DrtWithOperationsConfigGroup drtConfig = (DrtWithOperationsConfigGroup) MultiModeDrtConfigGroup.get(config).getModalElements().iterator().next(); + DrtWithOperationsConfigGroup drtConfig = (DrtWithOperationsConfigGroup) MultiModeDrtConfigGroup.get(config) + .getModalElements().iterator().next(); drtConfig.removeParameterSet(drtConfig.getRebalancingParams().get()); - + // shift parameters DrtOperationsParams operationsParams = new DrtOperationsParams(); drtConfig.addParameterSet(operationsParams); - + OperationFacilitiesParams operationFacilitiesParams = new OperationFacilitiesParams(); operationsParams.addParameterSet(operationFacilitiesParams); - + ShiftsParams shiftParams = new ShiftsParams(); operationsParams.addParameterSet(shiftParams); @@ -235,7 +235,8 @@ public void testRunAlonsoMoraWithShifts() { for (DrtConfigGroup drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) { controller.addOverridingModule(new ShiftDrtModeModule(drtCfg)); - controller.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg))); + controller.addOverridingQSimModule( + new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg))); controller.addOverridingQSimModule(new ShiftDvrpFleetQsimModule(drtCfg.getMode())); controller.addOverridingQSimModule(new OperationFacilitiesQSimModule(drtConfig)); } @@ -297,12 +298,11 @@ private void verifyDrtCustomerStatsCloseToExpectedStats(String outputDirectory, double rejectionRate = Double.parseDouble(params.get("rejectionRate")); double totalTravelTimeMean = Double.parseDouble(params.get("totalTravelTime_mean")); - var percentage = Percentage.withPercentage(0.00001); - assertThat(rejectionRate).isCloseTo(expectedStats.rejectionRate, percentage); - assertThat(rejections).isCloseTo(expectedStats.rejections, percentage); - assertThat(waitAverage).isCloseTo(expectedStats.waitAverage, percentage); - assertThat(inVehicleTravelTimeMean).isCloseTo(expectedStats.inVehicleTravelTimeMean, percentage); - assertThat(totalTravelTimeMean).isCloseTo(expectedStats.totalTravelTimeMean, percentage); + assertEquals(rejectionRate, expectedStats.rejectionRate); + assertEquals(rejections, expectedStats.rejections); + assertEquals(waitAverage, expectedStats.waitAverage); + assertEquals(inVehicleTravelTimeMean, expectedStats.inVehicleTravelTimeMean); + assertEquals(totalTravelTimeMean, expectedStats.totalTravelTimeMean); } private static class Stats { diff --git a/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolverTest.java b/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolverTest.java index a744f6e..d53970d 100644 --- a/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolverTest.java +++ b/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexAssignmentSolverTest.java @@ -1,13 +1,14 @@ package org.matsim.alonso_mora.gurobi; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -18,9 +19,9 @@ import org.mockito.Mockito; public class CplexAssignmentSolverTest { - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of CPLEX solver", CplexAssignmentSolver.checkAvailability()); + @BeforeAll + static public void checkSolver() { + assertTrue(CplexAssignmentSolver.checkAvailability(), "Checking for availability of CPLEX solver"); } private AlonsoMoraRequest mockRequest() { @@ -60,8 +61,8 @@ public void testOneVehicleOneRequestExample() { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test @@ -79,9 +80,9 @@ public void testTwoIndependentRequests() { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test @@ -103,8 +104,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @@ -126,8 +127,8 @@ public void testTwoRequestsWithOneVehicleLowPenalty() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } } } diff --git a/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexRelocationSolverTest.java b/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexRelocationSolverTest.java index 25e7d37..934d8ee 100644 --- a/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexRelocationSolverTest.java +++ b/cplex/src/test/java/org/matsim/alonso_mora/gurobi/CplexRelocationSolverTest.java @@ -1,6 +1,6 @@ package org.matsim.alonso_mora.gurobi; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; import org.matsim.api.core.v01.network.Link; diff --git a/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolverTest.java b/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolverTest.java index d5ffcf7..138ac0f 100644 --- a/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolverTest.java +++ b/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniAssignmentSolverTest.java @@ -1,13 +1,14 @@ package org.matsim.alonso_mora.glpk; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -16,9 +17,9 @@ import org.mockito.Mockito; public class GlpkJniAssignmentSolverTest { - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of GLPK solver", GlpkJniAssignmentSolver.checkAvailability()); + @BeforeAll + static public void checkSolver() { + assertTrue(GlpkJniAssignmentSolver.checkAvailability(), "Checking for availability of GLPK solver"); } private AlonsoMoraRequest mockRequest() { @@ -53,8 +54,8 @@ public void testOneVehicleOneRequestExample() { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test @@ -72,9 +73,9 @@ public void testTwoIndependentRequests() { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test @@ -96,8 +97,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @@ -119,8 +120,8 @@ public void testTwoRequestsWithOneVehicleLowPenalty() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } } } diff --git a/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolverTest.java b/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolverTest.java index 086aacd..a23af72 100644 --- a/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolverTest.java +++ b/glpk/src/test/java/org/matsim/alonso_mora/glpk/GlpkJniRelocationSolverTest.java @@ -1,6 +1,6 @@ package org.matsim.alonso_mora.glpk; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; import org.matsim.api.core.v01.network.Link; diff --git a/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolverTest.java b/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolverTest.java index 6b47ff0..b9c4179 100644 --- a/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolverTest.java +++ b/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiAssignmentSolverTest.java @@ -1,13 +1,14 @@ package org.matsim.alonso_mora.gurobi; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraRequest; import org.matsim.alonso_mora.algorithm.AlonsoMoraTrip; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; @@ -18,9 +19,9 @@ import org.mockito.Mockito; public class GurobiAssignmentSolverTest { - @Before - public void checkSolver() { - Assume.assumeTrue("Checking for availability of GLPK solver", GurobiAssignmentSolver.checkAvailability()); + @BeforeAll + static public void checkSolver() { + assertTrue(GurobiAssignmentSolver.checkAvailability(), "Checking for availability of GLPK solver"); } private AlonsoMoraRequest mockRequest() { @@ -60,8 +61,8 @@ public void testOneVehicleOneRequestExample() { List candidates = Arrays.asList(trip); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip)); } @Test @@ -79,9 +80,9 @@ public void testTwoIndependentRequests() { List candidates = Arrays.asList(trip1, trip2); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(2, selection.size()); - Assert.assertTrue(selection.contains(trip1)); - Assert.assertTrue(selection.contains(trip2)); + assertEquals(2, selection.size()); + assertTrue(selection.contains(trip1)); + assertTrue(selection.contains(trip2)); } @Test @@ -103,8 +104,8 @@ public void testTwoRequestsWithOneVehicle() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip3)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip3)); } } @@ -126,8 +127,8 @@ public void testTwoRequestsWithOneVehicleLowPenalty() { List candidates = Arrays.asList(trip1, trip2, trip3); Collection selection = solver.solve(candidates.stream()).trips; - Assert.assertEquals(1, selection.size()); - Assert.assertTrue(selection.contains(trip1)); + assertEquals(1, selection.size()); + assertTrue(selection.contains(trip1)); } } } diff --git a/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiRelocationSolverTest.java b/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiRelocationSolverTest.java index b7bdd3f..37bbe92 100644 --- a/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiRelocationSolverTest.java +++ b/gurobi/src/test/java/org/matsim/alonso_mora/gurobi/GurobiRelocationSolverTest.java @@ -1,6 +1,6 @@ package org.matsim.alonso_mora.gurobi; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.ArrayList; @@ -10,7 +10,7 @@ import java.util.LinkedList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle; import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver.Relocation; import org.matsim.api.core.v01.network.Link; diff --git a/pom.xml b/pom.xml index d02d3ff..e868e1c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,17 +6,22 @@ alonso-mora 1.0.0 pom - Implementation of the fleet dispatcher by Alonso-Mora et al. for MATSim - This package implements the pooled fleet dispatching algorithm introduced by + Implementation of the fleet dispatcher by Alonso-Mora et al. for + MATSim + This package implements the pooled fleet dispatching algorithm + introduced by -Alonso-Mora, J., Samaranayake, S., Wallar, A., Frazzoli, E., Rus, D., 2017. On-demand high-capacity ride-sharing via dynamic trip-vehicle assignment. Proc Natl Acad Sci USA 114, 462–467. + Alonso-Mora, J., Samaranayake, S., Wallar, A., Frazzoli, E., Rus, D., + 2017. On-demand high-capacity ride-sharing via dynamic trip-vehicle + assignment. Proc Natl Acad Sci USA 114, 462–467. -to the MATSim framework. + to the MATSim framework. 11 11 - 16.0-PR2966 + 16.0-PR3034 + 5.10.1 @@ -40,21 +45,21 @@ to the MATSim framework. - org.assertj - assertj-core - 3.15.0 + org.junit.jupiter + junit-jupiter-engine + ${junit.version} test - junit - junit - 4.13.1 + org.junit.jupiter + junit-jupiter + ${junit.version} test org.mockito - mockito-core - 3.3.3 + mockito-junit-jupiter + 5.8.0 test