Skip to content

Commit

Permalink
only search for act link if no coord available
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Oct 10, 2024
1 parent 4a7be7e commit 44f1472
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/org/matsim/run/prepare/PrepareDrtScenarioAgents.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.*;
Expand Down Expand Up @@ -62,7 +61,6 @@ public Integer call() throws Exception {
// thus, lausitz.shp should be chosen as an input
PrepareNetwork.prepareDrtNetwork(network, shp.getShapeFile());

// TODO: try if for 3 and 5 it is enough to delete act locations instead of searching for nearest drt link
convertVspRegionalTrainLegsToDrt(population, network);

PopulationUtils.writePopulation(population, output.toString());
Expand Down Expand Up @@ -113,7 +111,6 @@ public static void convertVspRegionalTrainLegsToDrt(Population population, Netwo
// interaction act before leg
if (!act.getType().equals(PT_INTERACTION)) {
logNotPtInteractionAct(person, act, i);
throw new IllegalStateException();
}

if (selected.getPlanElements().get(i - 2) instanceof Activity prev) {
Expand All @@ -140,7 +137,6 @@ public static void convertVspRegionalTrainLegsToDrt(Population population, Netwo
// interaction act after leg
if (!act.getType().equals(PT_INTERACTION)) {
logNotPtInteractionAct(person, act, i);
throw new IllegalStateException();
}
if (selected.getPlanElements().get(i + 2) instanceof Activity next) {
convertToDrtInteractionAndSplitTrip(act, next, filtered);
Expand All @@ -154,7 +150,7 @@ public static void convertVspRegionalTrainLegsToDrt(Population population, Netwo
}
}

public static @NotNull List<Integer> getNewPtLineIndexes(Plan selected) {
public static List<Integer> getNewPtLineIndexes(Plan selected) {
return TripStructureUtils.getLegs(selected).stream()
.filter(l -> l.getRoute().getStartLinkId().toString().contains("pt_vsp_")
&& l.getRoute().getEndLinkId().toString().contains("pt_vsp_"))
Expand All @@ -164,6 +160,7 @@ public static void convertVspRegionalTrainLegsToDrt(Population population, Netwo
private static void logNotPtInteractionAct(Person person, Activity act, int i) {
log.fatal("For selected plan of person {} type {} expected for activity at index {}. Activity has type {} instead. Abort.",
person.getId(), PT_INTERACTION, i, act.getType());
throw new IllegalStateException();
}

private static void logWrongPlanElementType(Person person, int i) {
Expand All @@ -172,18 +169,22 @@ private static void logWrongPlanElementType(Person person, int i) {
}

private static void convertToDrtInteractionAndSplitTrip(Activity act, Activity previous, Network filtered) {
// TODO: test if it is enough to delete link and facility, but keep coord. Correct link shoulb be found automatically then

// The original trip has to be split up because MATSim does not allow trips with 2 different routing modes.
// for the drt subtrip, a dummy act, which is not scored, is created.
if (TripStructureUtils.isStageActivityType(previous.getType())) {
previous.setType(DrtOptions.DRT_DUMMY_ACT_TYPE);
previous.setFacilityId(null);
previous.setLinkId(null);
}
act.setLinkId(NetworkUtils.getNearestLink(filtered, previous.getCoord()).getId());

// only set linkId here, if act has no coord. otherwise the correct link will be found during sim preparation.
if (act.getCoord() == null) {
act.setLinkId(NetworkUtils.getNearestLink(filtered, previous.getCoord()).getId());
act.setCoord(null);
} else {
act.setLinkId(null);
}
act.setFacilityId(null);
act.setCoord(null);
act.setType("drt interaction");
}
}

0 comments on commit 44f1472

Please sign in to comment.