Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
markusstraub committed Nov 27, 2024
1 parent 687ffae commit 52747b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* Heavily inspired by
* org.matsim.contrib.taxi.optimizer.rules.UnplannedRequestZonalRegistry
*/

public class RequestZoneRegistry {
private final ZoneSystem zoneSystem;
private final boolean isOriginZoneRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@

/**
* Collects all DRS trips (requests) from the selected plans of the population.
* These trips are expected to only consist of a single leg, since matched
* requests from a previous iteration must be reset via PlanModificationUndoer.
*
* These trips are expected to be freshly routed / unmatched since
* we reset results from the previous iteration in PlanModificationUndoer.
* Trips should consist of one drs leg and optional access egress legs
* (depending on routing.accessEgressType).
*/
public class RequestsCollector {
private static final Logger LOGGER = LogManager.getLogger();
Expand Down
1 change: 0 additions & 1 deletion src/main/java/at/ac/ait/matsim/drs/run/H3Experiments.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public static void playground() {
System.out.println(directedEdge);
System.out.println(h3core.getHexagonEdgeLengthAvg(res, LengthUnit.m) + "m avg vs. "
+ h3core.edgeLength(directedEdge, LengthUnit.m) + "m actually");

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.common.zones.Zone;
import org.matsim.contrib.common.zones.ZoneSystem;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystem;
import org.matsim.core.network.NetworkUtils;

import at.ac.ait.matsim.drs.DrsTestUtil;
import at.ac.ait.matsim.drs.optimizer.DrsRequest.DrsRiderRequest;
import at.ac.ait.matsim.drs.run.Drs;
import at.ac.ait.matsim.drs.run.DrsConfigGroup;
import at.ac.ait.matsim.drs.util.DrsUtil;

class RequestZoneRegistryTest {
Expand All @@ -31,20 +32,15 @@ class RequestZoneRegistryTest {
public static void setup() {
network = NetworkUtils.readNetwork("data/floridsdorf/network.xml");
DrsUtil.addNewAllowedModeToCarLinks(network, Drs.DRIVER_MODE);
DrsConfigGroup cfg = new DrsConfigGroup();
cfg.setCellSize(800);
zoneSystem = new SquareGridZoneSystem(network, cfg.getCellSize());
request1 = DrsTestUtil.mockRiderRequest(1, 8 * 60 * 60,
network.getLinks().get(Id.createLinkId(1540)), null);
request2 = DrsTestUtil.mockRiderRequest(2, 8 * 60 * 60,
network.getLinks().get(Id.createLinkId(1037)), null);
request3 = DrsTestUtil.mockRiderRequest(3, 8 * 60 * 60,
network.getLinks().get(Id.createLinkId(1674)), null);
}

@BeforeEach
public void beforeEach() {
zoneSystem = new SquareGridZoneSystem(network, 800);
zoneRegistry = RequestZoneRegistry.createRequestZoneRegistry(zoneSystem, true);
request1 = req(1, 1540);
request2 = req(2, 1037);
request3 = req(3, 1674);
}

@Test
Expand Down Expand Up @@ -105,11 +101,18 @@ void testFindNearestRequests() {
zoneRegistry.addRequest(request2);
zoneRegistry.addRequest(request3);
assertEquals(0,
zoneRegistry.findNearestRequests(network.getLinks().get(Id.createLinkId(857)).getFromNode()).count());
zoneRegistry.findNearestRequests(link(857).getFromNode()).count());
assertEquals(1,
zoneRegistry.findNearestRequests(network.getLinks().get(Id.createLinkId(1674)).getFromNode()).count());
zoneRegistry.findNearestRequests(link(1674).getFromNode()).count());
assertEquals(2,
zoneRegistry.findNearestRequests(network.getLinks().get(Id.createLinkId(1541)).getFromNode()).count());
zoneRegistry.findNearestRequests(link(1541).getFromNode()).count());
}

public DrsRiderRequest req(int id, int linkId) {
return DrsTestUtil.mockRiderRequest(id, 8 * 60 * 60, link(linkId), null);
}

public Link link(int linkId) {
return network.getLinks().get(Id.createLinkId(linkId));
}
}

0 comments on commit 52747b7

Please sign in to comment.