Skip to content

Commit

Permalink
remove drt-case. attempt to make code easier to read. todo: remove co…
Browse files Browse the repository at this point in the history
…mments
tschlenther committed Feb 2, 2024
1 parent a916ea6 commit 9f17787
Showing 3 changed files with 229 additions and 171 deletions.
14 changes: 5 additions & 9 deletions src/main/java/org/matsim/run/RunLeipzigScenario.java
Original file line number Diff line number Diff line change
@@ -99,13 +99,9 @@ public class RunLeipzigScenario extends MATSimApplication {
@CommandLine.Option(names = "--intermodality", defaultValue = "drtAndPtSeparateFromEachOther", description = "Define if drt should be used as access and egress mode for pt.")
private DrtCaseSetup.PtDrtIntermodality ptDrtIntermodality;

public RunLeipzigScenario(@Nullable Config config) {
super(config);
}
public RunLeipzigScenario(@Nullable Config config) { super(config); }

public RunLeipzigScenario() {
super(String.format("input/v%s/leipzig-v%s-10pct.config.xml", VERSION, VERSION));
}
public RunLeipzigScenario() { super(String.format("input/v%s/leipzig-v%s-10pct.config.xml", VERSION, VERSION)); }

public static void main(String[] args) {
MATSimApplication.run(RunLeipzigScenario.class, args);
@@ -191,7 +187,7 @@ protected Config prepareConfig(Config config) {
if (networkOpt.hasDrtArea()) {
//drt
try {
DrtCaseSetup.prepareConfig(config, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null));
DrtCaseSetup.prepareConfig(config, /* drtCase, */ new ShpOptions(networkOpt.getDrtArea(), null, null));
} catch (URISyntaxException e) {
log.fatal(e);
}
@@ -280,7 +276,7 @@ protected void prepareScenario(Scenario scenario) {
// (passt das Netz an aus den mitgegebenen shape files, z.B. parking area, car-free area, ...)

if (networkOpt.hasDrtArea()) {
DrtCaseSetup.prepareScenario(scenario, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION);
DrtCaseSetup.prepareScenario(scenario, /*drtCase, */ new ShpOptions(networkOpt.getDrtArea(), null, null), VERSION);
}

}
@@ -328,7 +324,7 @@ public void install() {
});

if (networkOpt.hasDrtArea()) {
DrtCaseSetup.prepareControler(controler, drtCase, new ShpOptions(networkOpt.getDrtArea(), null, null), ptDrtIntermodality);
DrtCaseSetup.prepareControler(controler,/* drtCase,*/ new ShpOptions(networkOpt.getDrtArea(), null, null), ptDrtIntermodality);
}

if (bike == BicycleHandling.onNetworkWithBicycleContrib) {
378 changes: 223 additions & 155 deletions src/main/java/org/matsim/run/prepare/DrtCaseSetup.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package org.matsim.run.prepare;

import cadyts.utilities.misc.DynamicData;
import ch.sbb.matsim.config.SwissRailRaptorConfigGroup;
import ch.sbb.matsim.routing.pt.raptor.RaptorIntermodalAccessEgress;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.jts.geom.Geometry;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Network;
import org.matsim.application.options.ShpOptions;
import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams;
import org.matsim.contrib.drt.fare.DrtFareParams;
@@ -32,6 +35,8 @@
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.controler.events.StartupEvent;
import org.matsim.core.controler.listener.StartupListener;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.algorithms.TransportModeNetworkFilter;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.extensions.pt.fare.intermodalTripFareCompensator.IntermodalTripFareCompensatorConfigGroup;
import org.matsim.extensions.pt.fare.intermodalTripFareCompensator.IntermodalTripFareCompensatorsConfigGroup;
@@ -62,25 +67,27 @@ public final class DrtCaseSetup {

private static final String errorMessage = "Unexpected value: ";

//this is not nice because the static set is only filled in prepareConfig
static Set<String> drtModes = new HashSet<>();

/**
* Defines if drt is modelled at all (none), with 2 separate modes (twoSeparateServiceAreas) or with 1 single drt mode (oneServiceArea).
* As this class is only triggered if a shp of the drt service area was provided, none is inactive for now
* <br> <b>tschlenther, feb' 02, 2024:</b> all the necessary information (nrOfServices, nrOfVehicles, modes etc.) shall be provided by the shape file, so this enum is strictly not needed.
*/
public enum DrtCase {/*none,*/ twoSeparateServiceAreas, oneServiceArea}
public enum DrtCase {/*none,*/ twoSeparateServiceAreas /*, oneServiceArea*/}

/**
* Defines if intermodality between drt and pt is modelled or not.
*/
public enum PtDrtIntermodality {drtAndPtSeparateFromEachOther, drtAsAccessEgressForPt}

private DrtCaseSetup(){}
public DrtCaseSetup(){ }

/**
* prepare config for drt simulation.
*/
public static void prepareConfig(Config config, DrtCase drtCase, ShpOptions drtArea) throws URISyntaxException {
public static void prepareConfig(Config config,/* DrtCase drtCase,*/ ShpOptions drtAreas) throws URISyntaxException {

MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);
DvrpConfigGroup dvrpConfigGroup = ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class);
@@ -97,66 +104,107 @@ public static void prepareConfig(Config config, DrtCase drtCase, ShpOptions drtA
drtFareParams.timeFare_h = 0.;
drtFareParams.dailySubscriptionFee = 0.;

switch (drtCase) {
case twoSeparateServiceAreas -> {
//flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes
if (multiModeDrtConfigGroup.getModalElements().isEmpty()) {
createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString());
createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString());
}

multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
drtConfigGroup.addParameterSet(drtFareParams);
DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute());
drtModes.add(drtConfigGroup.getMode());


configureNecessaryConfigGroups(config, drtConfigGroup.getMode());
DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams();
drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0;
drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0;
drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000;
// update to real world data
drtSpeedUpParams.initialWaitingTime = 345.6;
// update to real world data
drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6;
drtSpeedUpParams.intervalDetailedIteration = 10000;
drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled;
drtConfigGroup.addParameterSet(drtSpeedUpParams);
});


log.info("reading " + drtAreas.getShapeFile().toString());
for (SimpleFeature feature : drtAreas.readFeatures()) {
// String name = (String) feature.getAttribute("Name");
String drtMode = String.valueOf(feature.getAttribute("mode"));
if (drtMode.equals("null")) {
throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtAreas.getShapeFile().toString());
} else {
drtModes.add(drtMode);
}
}

case oneServiceArea -> {
//"normal" drt, modelled as one single drt mode
if (multiModeDrtConfigGroup.getModalElements().isEmpty()) {
createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt, drtArea.getShapeFile().toString());
}

multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
drtConfigGroup.addParameterSet(drtFareParams);
DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute());
drtModes.add(drtConfigGroup.getMode());

configureNecessaryConfigGroups(config, drtConfigGroup.getMode());
DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams();
drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0;
drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0;
drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000;
// update to real world data
drtSpeedUpParams.initialWaitingTime = 345.6;
// update to real world data
drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6;
drtSpeedUpParams.intervalDetailedIteration = 10000;
drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled;
drtConfigGroup.addParameterSet(drtSpeedUpParams);

});
if (multiModeDrtConfigGroup.getModalElements().isEmpty()) {
for (String mode : drtModes){
createDrtModeConfigGroup(multiModeDrtConfigGroup, mode);
}
default -> throw new IllegalStateException(errorMessage + (drtCase));
// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString());
// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString());
}

multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
drtConfigGroup.addParameterSet(drtFareParams);
DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute());
// drtModes.add(drtConfigGroup.getMode());

configureNecessaryConfigGroups(config, drtConfigGroup.getMode());
DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams();
drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0;
drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0;
drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000;
// update to real world data
drtSpeedUpParams.initialWaitingTime = 345.6;
// update to real world data
drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6;
drtSpeedUpParams.intervalDetailedIteration = 10000;
drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled;
drtConfigGroup.addParameterSet(drtSpeedUpParams);
});

// switch (drtCase) {
// case twoSeparateServiceAreas -> {
// if (multiModeDrtConfigGroup.getModalElements().isEmpty()) {
// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "North", drtArea.getShapeFile().toString());
// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt + "Southeast", drtArea.getShapeFile().toString());
// }
// //flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes
//
// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
// drtConfigGroup.addParameterSet(drtFareParams);
// DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute());
// drtModes.add(drtConfigGroup.getMode());
//
//
// configureNecessaryConfigGroups(config, drtConfigGroup.getMode());
// DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams();
// drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0;
// drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0;
// drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000;
// // update to real world data
// drtSpeedUpParams.initialWaitingTime = 345.6;
// // update to real world data
// drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6;
// drtSpeedUpParams.intervalDetailedIteration = 10000;
// drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled;
// drtConfigGroup.addParameterSet(drtSpeedUpParams);
// });
//
//
// }
//
// case oneServiceArea -> {
// //"normal" drt, modelled as one single drt mode
// if (multiModeDrtConfigGroup.getModalElements().isEmpty()) {
// createDrtModeConfigGroup(multiModeDrtConfigGroup, TransportMode.drt, drtArea.getShapeFile().toString());
// }
//
// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
// drtConfigGroup.addParameterSet(drtFareParams);
// DrtConfigs.adjustDrtConfig(drtConfigGroup, config.planCalcScore(), config.plansCalcRoute());
// drtModes.add(drtConfigGroup.getMode());
//
// configureNecessaryConfigGroups(config, drtConfigGroup.getMode());
// DrtSpeedUpParams drtSpeedUpParams = new DrtSpeedUpParams();
// drtSpeedUpParams.fractionOfIterationsSwitchOn = 0.0;
// drtSpeedUpParams.fractionOfIterationsSwitchOff = 1.0;
// drtSpeedUpParams.firstSimulatedDrtIterationToReplaceInitialDrtPerformanceParams = 10000;
// // update to real world data
// drtSpeedUpParams.initialWaitingTime = 345.6;
// // update to real world data
// drtSpeedUpParams.initialInVehicleBeelineSpeed = 20/3.6;
// drtSpeedUpParams.intervalDetailedIteration = 10000;
// drtSpeedUpParams.waitingTimeUpdateDuringSpeedUp = DrtSpeedUpParams.WaitingTimeUpdateDuringSpeedUp.Disabled;
// drtConfigGroup.addParameterSet(drtSpeedUpParams);
//
// });
// }
// default -> throw new IllegalStateException(errorMessage + (drtCase));
// }

//drt modes have to be set as network modes in dvrp CfgGroup
dvrpConfigGroup.networkModes = drtModes;
//after adding mode specific multiModeDrtParams -> adjust
@@ -166,7 +214,7 @@ public static void prepareConfig(Config config, DrtCase drtCase, ShpOptions drtA
* prepare scenario for drt simulation. more specifically, create input vehicles and stops files.
* this method does not (!?) change the network. For this, please refer to NetworkOptions.prepareDRT
*/
public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOptions drtArea, String version) {
public static void prepareScenario(Scenario scenario,/* DrtCase drtCase, */ ShpOptions drtAreas, String version) {

scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(DrtRoute.class, new DrtRouteFactory());
// (matsim core does not know about DRT routes. This makes it possible to read them before the controler is there.)
@@ -176,98 +224,114 @@ public static void prepareScenario(Scenario scenario, DrtCase drtCase, ShpOption
CreateDrtStopsFromNetwork drtStopsCreator = new CreateDrtStopsFromNetwork();
MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(scenario.getConfig(), MultiModeDrtConfigGroup.class);

String drtMode;
switch (drtCase) {
case twoSeparateServiceAreas -> {
// String drtMode;
// switch (drtCase) {
// case twoSeparateServiceAreas -> {
//flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes

log.info("reading " + drtArea.getShapeFile().toString());
for (SimpleFeature feature : drtArea.readFeatures()) {
log.info("reading " + drtAreas.getShapeFile().toString());
for (SimpleFeature feature : drtAreas.readFeatures()) {
// for (String drtMode : this.drtModes2Feature.keySet()) {
// String name = (String) feature.getAttribute("Name");
drtMode = String.valueOf(feature.getAttribute("mode"));
String drtMode = String.valueOf(feature.getAttribute("mode"));
if (drtMode.equals("null")) {
throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtArea.getShapeFile().toString());
throw new IllegalArgumentException("could not find 'mode' attribute in the given shape file at " + drtAreas.getShapeFile().toString());
}
Integer noVehicles = (Integer) feature.getAttribute("noVehicles");
if (noVehicles.equals(null)){
throw new IllegalArgumentException("could not find 'noVehicles' attribute in the given shape file at " + drtArea.getShapeFile().toString());
throw new IllegalArgumentException("could not find 'noVehicles' attribute in the given shape file at " + drtAreas.getShapeFile().toString());
}

log.info("attempting to create " + noVehicles + " drt vehicles for mode " + drtMode);
log.info("filtering network for mode " + drtMode + ". Before, the number of links equals " + scenario.getNetwork().getLinks().size());
Network filteredNetwork = NetworkUtils.createNetwork();
TransportModeNetworkFilter filter = new TransportModeNetworkFilter(scenario.getNetwork());
filter.filter(filteredNetwork, Sets.newHashSet(drtMode));
log.info("filtered network contains " + filteredNetwork.getLinks().size() + " links");

new LeipzigDrtVehicleCreator().createDrtVehiclesForSingleArea(scenario.getVehicles(), scenario.getNetwork(),
log.info("attempting to create " + noVehicles + " drt vehicles for mode " + drtMode);
new LeipzigDrtVehicleCreator().createDrtVehiclesForSingleArea(scenario.getVehicles(), filteredNetwork,
feature, noVehicles, drtMode);

//normally the following code would be set in prepareConfig, but..
//.. the stops creator relies on a network with drt modes. Drt modes are added in RunLeipzigScenario.prepareScenario()..
//.. so stops are created after that step -sme0823
multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {

//path, tho which stops.xml is saved
URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml");
File stopsFile = null;
try {
stopsFile = new File(path.toURI());
} catch (URISyntaxException e) {
log.fatal(e);
// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
DrtConfigGroup drtConfigGroup = multiModeDrtConfigGroup.getModalElements().stream().
filter(cfg -> cfg.getMode().equals(drtMode))
.findFirst().orElseThrow();
{
//path, tho which stops.xml is saved
URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtMode + "-stops.xml");
// URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-area.shp");
File file = null;
try {
file = new File(path.toURI());
} catch (URISyntaxException e) {
log.fatal(e);
}


//create drt stops and save them next to config -> put it as input stops file.
//unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723
drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, (Geometry) feature.getDefaultGeometry(),
drtAreas.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(),
file.toString(), drtAreas);

//naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523
drtConfigGroup.transitStopFile = file.toString();

// new ShapeFileWriter().writeGeometries(List.of(feature), file.toString());
// drtConfigGroup.drtServiceAreaShapeFile = file.toString();
// drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.serviceAreaBased; //TODO move this to prepareConfig

// configureNecessaryConfigGroups(scenario.getConfig(), drtConfigGroup.getMode());
}

//create drt stops and save them next to config -> put it as input stops file.
//unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723
drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, (Geometry) feature.getDefaultGeometry(),
drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(),
stopsFile.toString(), drtArea);

//naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523
drtConfigGroup.transitStopFile = stopsFile.toString();

configureNecessaryConfigGroups(scenario.getConfig(), drtConfigGroup.getMode());
});
// });
}
}

case oneServiceArea -> {
//"normal" drt, modelled as one single drt mode
drtMode = TransportMode.drt;

//make the 400 configurable??? -sme0723
new LeipzigDrtVehicleCreator().createDrtVehicles(scenario.getVehicles(), scenario.getNetwork(),
drtArea, 400, drtMode);

//normally the following code would be set in prepareConfig, but..
//.. the stops creator relies on a network with drt modes. Drt modes are added in RunLeipzigScenario.prepareScenario()..
//.. so stops are created after that step -sme0823
multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {

//path, tho which stops.xml is saved
URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml");
File stopsFile = null;
try {
stopsFile = new File(path.toURI());
} catch (URISyntaxException e) {
log.fatal(e);
}

//create drt stops and save them next to config -> put it as input stops file.
//unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723
drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, drtArea.getGeometry(),
drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(),
stopsFile.toString(), drtArea);

//naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523
drtConfigGroup.transitStopFile = stopsFile.toString();

});

}
default -> throw new IllegalStateException(errorMessage + (drtCase));
}
// }

// case oneServiceArea -> {
// //"normal" drt, modelled as one single drt mode
// drtMode = TransportMode.drt;
//
// //make the 400 configurable??? -sme0723
// new LeipzigDrtVehicleCreator().createDrtVehicles(scenario.getVehicles(), scenario.getNetwork(),
// drtArea, 400, drtMode);
//
// //normally the following code would be set in prepareConfig, but..
// //.. the stops creator relies on a network with drt modes. Drt modes are added in RunLeipzigScenario.prepareScenario()..
// //.. so stops are created after that step -sme0823
// multiModeDrtConfigGroup.getModalElements().forEach(drtConfigGroup -> {
//
// //path, tho which stops.xml is saved
// URL path = IOUtils.extendUrl(scenario.getConfig().getContext(), "leipzig-v" + version + "-" + drtConfigGroup.getMode() + "-stops.xml");
// File stopsFile = null;
// try {
// stopsFile = new File(path.toURI());
// } catch (URISyntaxException e) {
// log.fatal(e);
// }
//
// //create drt stops and save them next to config -> put it as input stops file.
// //unfortunately there is no scenario.setDrtStops, so we have to do this workaround. -sme0723
// drtStopsCreator.processNetworkForStopCreation(scenario.getNetwork(), true, drtArea.getGeometry(),
// drtArea.getShapeFile().toString() + "_" + drtConfigGroup.getMode() + "_stops.csv", drtConfigGroup.getMode(),
// stopsFile.toString(), drtArea);
//
// //naming pattern comes from @DrtStopsWriter line 81. Should be ok to hard code it here. -sme0523
// drtConfigGroup.transitStopFile = stopsFile.toString();
//
// });
//
// }
// default -> throw new IllegalStateException(errorMessage + (drtCase));
// }
}

/**
* prepare controler for drt simulation.
*/
public static void prepareControler(Controler controler, DrtCase drtCase, ShpOptions drtArea, PtDrtIntermodality ptDrtIntermodality) {
public static void prepareControler(Controler controler,/* DrtCase drtCase,*/ ShpOptions drtAreas, PtDrtIntermodality ptDrtIntermodality) {

MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(controler.getConfig(), MultiModeDrtConfigGroup.class);
controler.addOverridingModule(new DvrpModule());
@@ -290,31 +354,31 @@ public void install() {
}
}

switch (drtCase) {
case twoSeparateServiceAreas -> {
// switch (drtCase) {
// case twoSeparateServiceAreas -> {
//flexa case with 2 separate drt bubbles (north and southeast) -> 2 separate drt modes

//if intermodality between pt and drt -> only railways are tagged as intermodal stations (this is how it is handled in reality) -sme0723
if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) {
preparePtDrtIntermodality(controler, drtArea, true);
}
}

case oneServiceArea -> {
//"normal" drt, modelled as one single drt mode

if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) {
preparePtDrtIntermodality(controler, drtArea, false);
preparePtDrtIntermodality(controler, drtAreas, true);
}
}
default -> throw new IllegalStateException(errorMessage + (drtCase));
}
// }
//
// case oneServiceArea -> {
// //"normal" drt, modelled as one single drt mode
//
// if (ptDrtIntermodality.equals(PtDrtIntermodality.drtAsAccessEgressForPt)) {
// preparePtDrtIntermodality(controler, drtArea, false);
// }
// }
// default -> throw new IllegalStateException(errorMessage + (drtCase));
// }
}

/**
* if no modal params existing, we have to create them.
*/
private static void createDrtModeConfigGroup(MultiModeDrtConfigGroup multiModeDrtConfigGroup, String mode, String pathToShp) {
private static void createDrtModeConfigGroup(MultiModeDrtConfigGroup multiModeDrtConfigGroup, String mode/*, String pathToShp*/) {
DrtConfigGroup drtConfigGroup = new DrtConfigGroup();
drtConfigGroup.mode = mode;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.stopbased;
@@ -330,19 +394,23 @@ private static void createDrtModeConfigGroup(MultiModeDrtConfigGroup multiModeDr
ExtensiveInsertionSearchParams insertionSearchParams = new ExtensiveInsertionSearchParams();
drtConfigGroup.addParameterSet(insertionSearchParams);

//add rebalancing params and configure standard values
RebalancingParams rebalancingParams = new RebalancingParams();

MinCostFlowRebalancingStrategyParams rebalancingStrategyParams = new MinCostFlowRebalancingStrategyParams();
rebalancingStrategyParams.targetAlpha = 0.5;
rebalancingStrategyParams.targetBeta = 0.5;
rebalancingParams.addParameterSet(rebalancingStrategyParams);
drtConfigGroup.addParameterSet(rebalancingParams);

DrtZonalSystemParams zonalSystemParams = new DrtZonalSystemParams();
zonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.ShapeFile;
zonalSystemParams.zonesShapeFile = new File(pathToShp).getAbsolutePath();
drtConfigGroup.addParameterSet(zonalSystemParams);
//we do not simulate drt explicitly anymore, so rebalancing is commented out. tschlenther feb' 24
{
// //add rebalancing params and configure standard values
// RebalancingParams rebalancingParams = new RebalancingParams();
//
// MinCostFlowRebalancingStrategyParams rebalancingStrategyParams = new MinCostFlowRebalancingStrategyParams();
// rebalancingStrategyParams.targetAlpha = 0.5;
// rebalancingStrategyParams.targetBeta = 0.5;
// rebalancingParams.addParameterSet(rebalancingStrategyParams);
// drtConfigGroup.addParameterSet(rebalancingParams);
//
// DrtZonalSystemParams zonalSystemParams = new DrtZonalSystemParams();
// zonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.ShapeFile;
// zonalSystemParams.zonesShapeFile = new File(pathToShp).getAbsolutePath(); //this needs to be adjusted: should only be the one corresponding feature and not the whole shape file!!
// drtConfigGroup.addParameterSet(zonalSystemParams);
//
}

multiModeDrtConfigGroup.addParameterSet(drtConfigGroup);
}
@@ -387,7 +455,7 @@ private static void preparePtDrtIntermodality(Controler controler, ShpOptions sh

ConfigUtils.addOrGetModule(controler.getConfig(), MultiModeDrtConfigGroup.class).getModalElements().stream().findFirst().ifPresent(drtConfigGroup ->
drtConfigGroup.getDrtFareParams().ifPresent(drtFareParams ->
prepareDrtFareCompensation(controler, drtModes, drtFareParams.baseFare)));
prepareDrtFareCompensation(controler, drtModes, drtFareParams.baseFare))); //this only works if prepareConfig was called with the same ShpOptions
}

private static void prepareDrtFareCompensation(Controler controler, Set<String> nonPtModes, Double ptBaseFare) {
Original file line number Diff line number Diff line change
@@ -151,13 +151,7 @@ public void createDrtVehiclesForSingleArea(Vehicles vehicles, Network network, S
}
}

log.info("filtering network for mode " + drtMode + ". Before, the number of links equals " + network.getLinks().size());
Network filteredNetwork = NetworkUtils.createNetwork();
TransportModeNetworkFilter filter = new TransportModeNetworkFilter(network);
filter.filter(filteredNetwork, Sets.newHashSet(drtMode));
log.info("filtered network contains " + filteredNetwork.getLinks().size() + " links");

createVehiclesByRandomPointInShape(feature, filteredNetwork, noVehiclesPerArea, serviceStartTime,
createVehiclesByRandomPointInShape(feature, network, noVehiclesPerArea, serviceStartTime,
serviceEndTime, 1, drtType, drtMode, vehicles);
}

0 comments on commit 9f17787

Please sign in to comment.