Skip to content

Commit

Permalink
complete bike on net / teleported config
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Mar 25, 2024
1 parent dedfe72 commit 9785653
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
40 changes: 32 additions & 8 deletions src/main/java/org/matsim/run/RunMexicoCityScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class RunMexicoCityScenario extends MATSimApplication {

@CommandLine.Option(names = "--annealing", defaultValue = "true", description = "Defines if replanning annealing is used or not.")
private boolean annealing;
@CommandLine.Option(names = "--bikes-on-network", defaultValue = "false", description = "Define how bicycles are handled: True: as network mode, false: as teleported mode.")
@CommandLine.Option(names = "--bikes-on-network", defaultValue = "true", description = "Define how bicycles are handled: True: as network mode, false: as teleported mode.")
private boolean bikeOnNetwork;

@CommandLine.Option(names = "--repurpose-lanes", defaultValue = "false", description = "Enables the simulation of a lane repurposing scenario (car -> bike): See class PrepareNetwork for details.")
Expand Down Expand Up @@ -147,17 +147,41 @@ protected Config prepareConfig(Config config) {
}

if (bikeOnNetwork) {
// remove bike as teleported mode (standard)
config.routing().removeTeleportedModeParams(TransportMode.bike);
Set<String> networkModes = new HashSet<>();
networkModes.addAll(config.routing().getNetworkModes());
networkModes.add(TransportMode.bike);
config.routing().setNetworkModes(networkModes);
// remove bike as teleported mode + add as network mode
if (config.routing().getTeleportedModeParams().containsKey(TransportMode.bike)) {
config.routing().removeTeleportedModeParams(TransportMode.bike);
}

if (!config.routing().getNetworkModes().contains(TransportMode.bike)) {
Set<String> networkModes = new HashSet<>();
networkModes.addAll(config.routing().getNetworkModes());
networkModes.add(TransportMode.bike);
config.routing().setNetworkModes(networkModes);

config.qsim().setMainModes(networkModes);
config.qsim().setMainModes(networkModes);
}

log.info("Deleted bike as a teleported mode and add added it as a network mode. Bike will be simulated on the network.");
} else {
// remove bike as network mode + add bike as teleported mode
if (config.routing().getNetworkModes().contains(TransportMode.bike)) {

Set<String> networkModes = new HashSet<>(config.routing().getNetworkModes()
.stream()
.filter(m -> !m.equals(TransportMode.bike))
.toList());

config.routing().setNetworkModes(networkModes);
}

if (!config.routing().getTeleportedModeParams().containsKey(TransportMode.bike)) {
RoutingConfigGroup.TeleportedModeParams bike = new RoutingConfigGroup.TeleportedModeParams(TransportMode.bike);
bike.setBeelineDistanceFactor(1.3);
bike.setTeleportedModeSpeed(3.1388889);

config.routing().addTeleportedModeParams(bike);
}

log.info("Bike will be simulated as teleported mode.");
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/matsim/run/RunMexicoCityIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

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

public class RunMexicoCityIntegrationTest {
class RunMexicoCityIntegrationTest {

String URL = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/mx/mexico-city/mexico-city-v1.0/input/";

@Test
public void runPoint1PctIntegrationTest() {
void runPoint1PctIntegrationTest() {

double sampleSize = 0.001;
double sampleSize = 0.0001;

Path outputPath = Path.of("output/it-" + sampleSize * 100 + "pct");
Path outputPath = Path.of("output/it-0.1pct");

Config config = ConfigUtils.loadConfig("input/v1.0/mexico-city-v1.0-1pct.input.config.xml");

Expand All @@ -36,7 +36,7 @@ public void runPoint1PctIntegrationTest() {

ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

assert MATSimApplication.execute(RunMexicoCityScenario.class, config, "run", "--1pct", "--bikes-on-network",
assert MATSimApplication.execute(RunMexicoCityScenario.class, config, "run", "--1pct",
"--income-area", "input/v1.0/nivel_amai/nivel_amai.shp") == 0 : "Must return non error code";

assertThat(outputPath)
Expand Down

0 comments on commit 9785653

Please sign in to comment.