Skip to content

Commit

Permalink
add test for occupancy change
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel committed Dec 21, 2023
1 parent 6bfddfa commit ef66ebb
Showing 1 changed file with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,9 @@

package org.matsim.contrib.drt.optimizer.insertion;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.google.common.collect.Sets;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
Expand All @@ -37,6 +32,7 @@
import org.matsim.contrib.drt.optimizer.insertion.InsertionDetourTimeCalculator.DropoffDetourInfo;
import org.matsim.contrib.drt.optimizer.insertion.InsertionDetourTimeCalculator.PickupDetourInfo;
import org.matsim.contrib.drt.optimizer.insertion.InsertionGenerator.Insertion;
import org.matsim.contrib.drt.passenger.AcceptedDrtRequest;
import org.matsim.contrib.drt.passenger.DrtRequest;
import org.matsim.contrib.drt.schedule.DefaultDrtStopTask;
import org.matsim.contrib.drt.stops.DefaultStopTimeCalculator;
Expand All @@ -46,8 +42,12 @@
import org.matsim.contrib.dvrp.fleet.ImmutableDvrpVehicleSpecification;
import org.matsim.testcases.fakes.FakeLink;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Michal Maciejewski (michalm)
Expand Down Expand Up @@ -444,6 +444,32 @@ void startEmpty_twoStops_groupExceedsCapacityAtFirstStop() {
);
}

@Test
void testWaypointOccupancyChange() {
int occupancy = 0;
AcceptedDrtRequest acceptedReq5Pax = AcceptedDrtRequest.createFromOriginalRequest(drtRequest5Pax);
AcceptedDrtRequest acceptedReq2Pax = AcceptedDrtRequest.createFromOriginalRequest(drtRequest2Pax);

Waypoint.Stop stop2 = stop(0, link("stop2"), occupancy);
//dropoff 5 pax
stop2.task.addDropoffRequest(acceptedReq5Pax);
occupancy -= stop2.getOccupancyChange();
Assertions.assertEquals(5, occupancy);

Waypoint.Stop stop1 = stop(0, link("stop1"), occupancy);
//dropoff 2 pax, pickup 5
stop1.task.addDropoffRequest(acceptedReq2Pax);
stop1.task.addPickupRequest(acceptedReq5Pax);
occupancy -= stop1.getOccupancyChange();
Assertions.assertEquals(2, occupancy);


Waypoint.Stop stop0 = stop(0, link("stop0"), occupancy);
stop0.task.addPickupRequest(acceptedReq2Pax);
occupancy -= stop0.getOccupancyChange();
Assertions.assertEquals(0, occupancy);
}

private Link link(String id) {
return new FakeLink(Id.createLinkId(id));
}
Expand Down

0 comments on commit ef66ebb

Please sign in to comment.