Skip to content

Commit

Permalink
add TaxiTaskBaseType enum; make TaxiTaskType extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmac committed Jul 7, 2020
1 parent 7eacd75 commit 545e978
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.matsim.contrib.dvrp.router.DvrpGlobalRoutingNetworkProvider;
import org.matsim.contrib.dvrp.run.QSimScopeObjectListener;
import org.matsim.contrib.dvrp.schedule.Task;
import org.matsim.contrib.taxi.schedule.TaxiTaskType;
import org.matsim.contrib.taxi.schedule.TaxiTaskBaseType;
import org.matsim.contrib.util.CSVLineBuilder;
import org.matsim.contrib.util.CompactCSVWriter;
import org.matsim.core.controler.events.IterationEndsEvent;
Expand Down Expand Up @@ -104,9 +104,9 @@ public void handleEvent(LinkEnterEvent event) {
data.addToActualTourLength(link.getLength());

Task t = (fleet.getVehicles().get(event.getVehicleId())).getSchedule().getCurrentTask();
if (t.getTaskType().equals(TaxiTaskType.EMPTY_DRIVE)) {
data.addToActualEmptyMeters(link.getLength());
}
if (TaxiTaskBaseType.EMPTY_DRIVE.isBaseTypeOf(t)) {
data.addToActualEmptyMeters(link.getLength());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.matsim.contrib.taxi.schedule.TaxiDropoffTask;
import org.matsim.contrib.taxi.schedule.TaxiPickupTask;
import org.matsim.contrib.taxi.schedule.TaxiStayTask;
import org.matsim.contrib.taxi.schedule.TaxiTaskType;
import org.matsim.contrib.taxi.schedule.TaxiTaskBaseType;
import org.matsim.core.mobsim.framework.MobsimTimer;

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ private PFAVActionCreator(PassengerEngine passengerEngine, VrpLegFactory legFact
@Override
public DynAction createAction(DynAgent dynAgent, DvrpVehicle vehicle, double now) {
Task task = vehicle.getSchedule().getCurrentTask();
switch ((TaxiTaskType)task.getTaskType()) {
switch (TaxiTaskBaseType.getBaseType(task)) {
case EMPTY_DRIVE:
case OCCUPIED_DRIVE:
return legFactory.create(vehicle);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/matsim/pfav/privateAV/PFAVRetoolTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.schedule.StayTask;
import org.matsim.contrib.taxi.schedule.TaxiTaskType;
import org.matsim.contrib.taxi.schedule.TaxiDropoffTask;

/**
* @author tschlenther
Expand All @@ -44,7 +44,7 @@ class PFAVRetoolTask extends StayTask {
* but pickup task type is somehow used for TaxiStatsCalculator in correspondence with a request (which we do not have here, so we use dropoff type.
* furthermore, if it was of type stay, the task could be removed by the taxischeduler if there is delay in the schedule
*/
super(TaxiTaskType.DROPOFF, beginTime, endTime, link);
super(TaxiDropoffTask.TYPE, beginTime, endTime, link);
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/org/matsim/pfav/privateAV/PFAVScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@
import org.matsim.contrib.taxi.schedule.TaxiOccupiedDriveTask;
import org.matsim.contrib.taxi.schedule.TaxiPickupTask;
import org.matsim.contrib.taxi.schedule.TaxiStayTask;
import org.matsim.contrib.taxi.schedule.TaxiTaskType;
import org.matsim.contrib.taxi.schedule.TaxiTaskBaseType;
import org.matsim.contrib.taxi.scheduler.TaxiScheduleInquiry;
import org.matsim.contrib.taxi.scheduler.TaxiScheduler;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.mobsim.framework.MobsimTimer;
import org.matsim.core.router.FastAStarEuclideanFactory;
import org.matsim.core.router.util.LeastCostPathCalculator;
import org.matsim.core.router.util.TravelDisutility;
import org.matsim.core.router.util.TravelTime;

import com.google.inject.name.Named;
Expand Down Expand Up @@ -89,7 +87,7 @@ void updateBeforeNextTask(DvrpVehicle vehicle) {
updateTimeline(vehicle);
Task currentTask = schedule.getCurrentTask();

switch ((TaxiTaskType)currentTask.getTaskType()) {
switch (TaxiTaskBaseType.getBaseType(currentTask)) {
case PICKUP:
if (!taxiCfg.isDestinationKnown()) {
appendResultingTasksAfterPickup(vehicle);
Expand Down Expand Up @@ -370,7 +368,7 @@ void scheduleRequest(DvrpVehicle vehicle, TaxiRequest request) {
Schedule schedule = vehicle.getSchedule();
Task lastTask = Schedules.getLastTask(schedule);

if (lastTask.getTaskType() != TaxiTaskType.STAY) {
if (!TaxiTaskBaseType.STAY.isBaseTypeOf(lastTask)) {
throw new IllegalStateException();
} else {

Expand Down Expand Up @@ -514,7 +512,7 @@ private void updateTimelineImpl(DvrpVehicle vehicle, double newEndTime) {
private final static double REMOVE_STAY_TASK = Double.NEGATIVE_INFINITY;

private double calcNewEndTime(DvrpVehicle vehicle, Task task, double newBeginTime) {
switch ((TaxiTaskType)task.getTaskType()) {
switch (TaxiTaskBaseType.getBaseType(task)) {
case STAY: {
if (Schedules.getLastTask(vehicle.getSchedule()).equals(task)) {// last task
// even if endTime=beginTime, do not remove this task!!! A taxi schedule should end with WAIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import org.matsim.contrib.dvrp.path.VrpPathWithTravelData;
import org.matsim.contrib.dvrp.schedule.DriveTask;
import org.matsim.contrib.taxi.schedule.TaxiTaskType;
import org.matsim.contrib.taxi.schedule.TaxiOccupiedDriveTask;

/**
* @author tschlenther
*
*/
class PFAVServiceDriveTask extends DriveTask {
PFAVServiceDriveTask(VrpPathWithTravelData path) {
super(TaxiTaskType.OCCUPIED_DRIVE, path);
super(TaxiOccupiedDriveTask.TYPE, path);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/matsim/pfav/privateAV/PFAVServiceTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.dvrp.schedule.StayTask;
import org.matsim.contrib.freight.carrier.CarrierService;
import org.matsim.contrib.taxi.schedule.TaxiTaskType;
import org.matsim.contrib.taxi.schedule.TaxiDropoffTask;

/**
* @author tschlenther
Expand All @@ -37,7 +37,7 @@ class PFAVServiceTask extends StayTask {
* @param link
*/
PFAVServiceTask(double beginTime, double endTime, Link link, CarrierService service) {
super(TaxiTaskType.DROPOFF, beginTime, endTime, link);
super(TaxiDropoffTask.TYPE, beginTime, endTime, link);
this.service = service;
}

Expand Down

0 comments on commit 545e978

Please sign in to comment.