Skip to content

Commit

Permalink
try to make first test run
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 committed Aug 29, 2024
1 parent 7acdaa5 commit f0c0d20
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
49 changes: 13 additions & 36 deletions src/main/java/org/matsim/run/RunLausitzDrtScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,21 @@ public static void main(String[] args) {
@Nullable
@Override
protected Config prepareConfig(Config config) {
// TODO: have a look in config.xml if there is more configs to be adapted to make it "ready" for drt -> do this here
// TODO: add drt stops / shp file here?! OR create stops / shp in code?!
// TODO: add drt to mdoeparams, add as network mode, add as main mode? add to SMC, add to scoring params?!
// TODO: add drt speedup params, add drt fare params?!

// TODO: talk to CL about whether to use new drt approach (see kelheim) or not.. and how to implement it

// apply all config changes from base scenario class
baseScenario.prepareConfig(config);

DvrpConfigGroup dvrpConfigGroup = ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class);
dvrpConfigGroup.networkModes = Set.of(TransportMode.drt);



MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);

if (multiModeDrtConfigGroup.getModalElements().isEmpty()) {
DrtConfigGroup drtConfigGroup = new DrtConfigGroup();
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.stopbased;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.serviceAreaBased;
drtConfigGroup.stopDuration = 60.;
// TODO: shp files have been created and are located on sjhared svn
drtConfigGroup.transitStopFile = "";
drtConfigGroup.drtServiceAreaShapeFile = drtAreaShp;

// optimization params now are in its own paramSet, hence the below lines
DrtOptimizationConstraintsParams optimizationConstraints = new DrtOptimizationConstraintsParams();
Expand All @@ -113,9 +107,6 @@ protected Config prepareConfig(Config config) {
optimizationConstraints.addParameterSet(optimizationConstraintsSet);
drtConfigGroup.addParameterSet(optimizationConstraints);
drtConfigGroup.addParameterSet(new ExtensiveInsertionSearchParams());
// TODO: talk to KN whether to put in fare params here.. logic could be: we assume that everybody has a Deutschlandticket so no fare at all is charged?!
// this may draw more than the costumer, who want to take the train in Ruhland?! So maybe it makes sense to apply a baseFare and give it back to the agents after the sim via person money event?
// OR just put in drt fare via scoring mode params
multiModeDrtConfigGroup.addParameterSet(drtConfigGroup);
}

Expand All @@ -130,7 +121,7 @@ protected Config prepareConfig(Config config) {
ScoringConfigGroup scoringConfigGroup = ConfigUtils.addOrGetModule(config, ScoringConfigGroup.class);

if (!scoringConfigGroup.getModes().containsKey(TransportMode.drt)) {
// TODO: talk to KN about this ASC value. Either set it equal to PT or 0??
// ASC drt = ASC pt as discussed in PHD seminar24
// add mode params for drt if missing and set ASC + marg utility of traveling = 0
scoringConfigGroup.addModeParams(new ScoringConfigGroup.ModeParams(TransportMode.drt)
.setConstant(scoringConfigGroup.getModes().get(TransportMode.pt).getConstant())
Expand All @@ -154,8 +145,6 @@ protected Config prepareConfig(Config config) {

@Override
protected void prepareScenario(Scenario scenario) {
// TODO

// apply all scenario changes from base scenario class
baseScenario.prepareScenario(scenario);

Expand All @@ -168,6 +157,8 @@ protected void prepareScenario(Scenario scenario) {
// add drt as allowed mode for whole Lausitz region
Geometry geometry = new ShpOptions(drtAreaShp, null, null).getGeometry();

// with the estimator, drt is teleported, but we may need drt as an allowed mode for
// separate drt post simulation
for (Link link : scenario.getNetwork().getLinks().values()) {
if (link.getAllowedModes().contains(TransportMode.car)) {
boolean isInside = MGC.coord2Point(link.getFromNode().getCoord()).within(geometry) ||
Expand Down Expand Up @@ -196,32 +187,19 @@ protected void prepareScenario(Scenario scenario) {
capacity.setSeats(1);

scenario.getVehicles().addVehicleType(drtType);
}

//TODO: is the following if clause needed when using the DRT Estimator?!
// TODO: @CL where does the estimator draw its vehicles from? Are vehicle types even needed?
// --> No vehicle file is needed if DRT estimator is used. But the vehicle file can be specified as usual.
// if there are no vehicles of above type: add some
if (scenario.getVehicles().getVehicles().values().stream().filter(v -> v.getType().getId().equals(drtTypeId)).toList().isEmpty()) {

for (int i = 1; i <= 10; i++) {
Vehicle vehicle = VehicleUtils.createVehicle(Id.createVehicleId(TransportMode.drt + "_" + i), scenario.getVehicles().getVehicleTypes().get(drtTypeId));
vehicle.getAttributes().putAttribute("dvrpMode", TransportMode.drt);
// TODO: put linkId
vehicle.getAttributes().putAttribute("startLink", "ABC");
vehicle.getAttributes().putAttribute("serviceBeginTime", 0.);
vehicle.getAttributes().putAttribute("serviceEndTime", 86400.);
scenario.getVehicles().addVehicle(vehicle);
}

Vehicle drtDummy = VehicleUtils.createVehicle(Id.createVehicleId("drtDummy"), drtType);
drtDummy.getAttributes().putAttribute("dvrpMode", TransportMode.drt);
drtDummy.getAttributes().putAttribute("startLink", "706048410#0");
drtDummy.getAttributes().putAttribute("serviceBeginTime", 0.);
drtDummy.getAttributes().putAttribute("serviceEndTime", 86400.);

scenario.getVehicles().addVehicle(drtDummy);
}
}

@Override
protected void prepareControler(Controler controler) {
// TODO

Config config = controler.getConfig();

// apply all controller changes from base scenario class
Expand All @@ -237,7 +215,6 @@ protected void prepareControler(Controler controler) {

MultiModeDrtConfigGroup multiModeDrtConfigGroup = MultiModeDrtConfigGroup.get(config);
for (DrtConfigGroup drtConfigGroup : multiModeDrtConfigGroup.getModalElements()) {
// TODO uncomment theses after the new estimator is merged to the matsim-lib master branch
controler.addOverridingModule(new AbstractModule() {
@Override
public void install() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/matsim/run/RunIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ void runScenarioIncludingDrt() {

assert MATSimApplication.execute(RunLausitzDrtScenario.class, config,
"--1pct",
"--drt-shp", "C:/Users/Simon/Documents/vsp-projects/matsim-lausitz/input/shp/lausitz.shp",
"--iterations", "1",
"--config:plans.inputPlansFile", "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/lausitz/input/v1.0/lausitz-v1.0-1pct.plans-initial.xml.gz",
"--output", utils.getOutputDirectory(),
"--config:controller.overwriteFiles=deleteDirectoryIfExists") == 0 : "Must return non error code";

}

@Test
Expand Down

0 comments on commit f0c0d20

Please sign in to comment.