Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try #2813

Closed
wants to merge 16 commits into from
Closed

Try #2813

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
0d71ee5
created eventhandler as an example of a java analysis tool. Created o…
synas34 Sep 14, 2023
e93a173
Created a script to generate a line of meshes that have prescribed in…
synas34 Sep 15, 2023
3f8c57f
Created PlansXMLSynthesizer.java to generate an example plans file. I…
synas34 Sep 17, 2023
5c57950
Created RunMatsimUnique.java as an adaptabale run method that can be …
synas34 Sep 20, 2023
671619f
Created RunMatsimUnique.java as an adaptabale run method that can be …
synas34 Sep 20, 2023
d546b1e
Optimising vehicle fleet and plans. changed PlansXMLSynthesizer.java …
synas34 Sep 20, 2023
97f1531
Optimising vehicle fleet and plans. fixed some things
synas34 Sep 20, 2023
c986b3e
Set Rail Link {300, 333, 333, 400, 400, 450, 1000, 1000, 1500, 2000}…
synas34 Oct 4, 2023
118e5bc
Set Rail Link {300, 333, 333, 400, 400, 450, 1000, 1000, 1500, 2000}…
synas34 Oct 4, 2023
b4d8b7b
Used RailLinkCreator.java to generate a transitSchedule.xml file whic…
synas34 Oct 5, 2023
e3059d9
debugged RailLinkCreator.java to have nodes shared between line so th…
synas34 Oct 5, 2023
2874d7c
Updated RailScheduleCreator and RailLinkCreator to create functioning…
synas34 Oct 6, 2023
64afd95
Updated config file and transit files to run pt-car-drt simulation s…
synas34 Oct 6, 2023
3bcf2b1
Incorporated FMLM modes using swissrailraptors own intermodalAccessEg…
synas34 Oct 6, 2023
84f9829
Went through and updated virtual simulation creator scripts and gener…
synas34 Oct 7, 2023
83785f0
Created ScenarioCreator to unify all synthetic data creator methods t…
synas34 Oct 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions contribs/SyntheticModel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!src/main/**/out/
!src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!src/main/**/bin/
!src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
560 changes: 560 additions & 0 deletions contribs/SyntheticModel/production/ConfigCreator/defaultConfig.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
121 changes: 121 additions & 0 deletions contribs/SyntheticModel/src/ConfigCreator/RunMatsimDRT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* *********************************************************************** *
* project: org.matsim.* *
* *
* *********************************************************************** *
* *
* copyright : (C) 2008 by the members listed in the COPYING, *
* LICENSE and WARRANTY file. *
* email : info at matsim dot org *
* *
* *********************************************************************** *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* See also COPYING, LICENSE and WARRANTY file *
* *
* *********************************************************************** */
package ConfigCreator;


import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.run.MultiModeDrtModule;
import org.matsim.contrib.dvrp.run.DvrpModule;
import org.matsim.contrib.dvrp.run.DvrpQSimComponents;
import org.matsim.contrib.otfvis.OTFVisLiveModule;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.config.groups.QSimConfigGroup.SnapshotStyle;
import org.matsim.core.config.groups.QSimConfigGroup.TrafficDynamics;
import org.matsim.core.config.groups.QSimConfigGroup.VehiclesSource;
import org.matsim.core.config.groups.StrategyConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting;
import org.matsim.core.replanning.strategies.DefaultPlanStrategiesModule;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.collections.CollectionUtils;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
import org.matsim.vis.otfvis.OTFVisConfigGroup;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ModeParams;
import org.matsim.contrib.drt.routing.DrtRouteFactory;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.contrib.drt.routing.DrtRoute;
import org.matsim.core.config.groups.PlanCalcScoreConfigGroup.ActivityParams;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;

/**
* @author nagel
*
*/
public class RunMatsimDRT{

public static void main(String[] args) {

Config config;
if ( args==null || args.length==0 || args[0]==null ){
config = ConfigUtils.loadConfig( "scenarios/equil/config_drt.xml",new OTFVisConfigGroup());
} else {
config = ConfigUtils.loadConfig( args );
}

config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists );

// possibly modify config here


MultiModeDrtConfigGroup drtConfig = new MultiModeDrtConfigGroup();
config.addModule(drtConfig);
DvrpConfigGroup dvrpConfig = new DvrpConfigGroup();
config.addModule(dvrpConfig);


String[] modes = { "drt", "walk", "bike" };
config.changeMode().setModes(modes);
//config.subtourModeChoice().setModes(modes);


// ---

Scenario scenario = ScenarioUtils.loadScenario(config) ;

// possibly modify scenario here



scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(DrtRoute.class,
new DrtRouteFactory());

// ---

Controler controler = new Controler( scenario ) ;

// possibly modify controler here


controler.addOverridingModule(new DvrpModule());
controler.addOverridingModule(new MultiModeDrtModule());
controler.configureQSimComponents(DvrpQSimComponents.activateAllModes(drtConfig));


//controler.addOverridingModule( new OTFVisLiveModule() ) ;


// ---

controler.run();
}

}
67 changes: 67 additions & 0 deletions contribs/SyntheticModel/src/ConfigCreator/RunMatsimUnique.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package ConfigCreator;

import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.drt.run.DrtControlerCreator;
import org.matsim.contrib.drt.run.MultiModeDrtConfigGroup;
import org.matsim.contrib.dvrp.run.DvrpConfigGroup;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.QSimConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.pt.analysis.VehicleTracker;
import org.matsim.vis.otfvis.OTFVisConfigGroup;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.Id;
import org.matsim.pt.analysis.TransitRouteAccessEgressAnalysis;
import org.matsim.pt.transitSchedule.api.TransitRoute;
import org.matsim.pt.transitSchedule.api.TransitSchedule;

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;


public class RunMatsimUnique {

public static void main(String[] args) throws IOException {

Config config;
if ( args==null || args.length==0 || args[0]==null ){
config = ConfigUtils.loadConfig( "examples/scenarios/UrbanLine/3x1km/config.xml", new MultiModeDrtConfigGroup(),
new DvrpConfigGroup(), new OTFVisConfigGroup() );
} else {
config = ConfigUtils.loadConfig( args );
}

config.controler().setOverwriteFileSetting( OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists );
config.controler().setOutputDirectory("examples/scenarios/UrbanLine/output");
// possibly modify config here
config.qsim().setSimStarttimeInterpretation(QSimConfigGroup.StarttimeInterpretation.onlyUseStarttime);
config.qsim().setSimEndtimeInterpretation((QSimConfigGroup.EndtimeInterpretation.onlyUseEndtime));

Controler controler = DrtControlerCreator.createControler(config, false);

Scenario scenario = controler.getScenario();
TransitSchedule transitSchedule = scenario.getTransitSchedule();
TransitRoute transitRoute = transitSchedule.getTransitLines().get(Id.create("Shuttle", TransitRoute.class)).getRoutes().get(Id.create("Suburbs", TransitRoute.class));
VehicleTracker vehicleTracker = new VehicleTracker();

TransitRouteAccessEgressAnalysis analysis = new TransitRouteAccessEgressAnalysis(transitRoute, vehicleTracker);

// Add the analysis and vehicle tracker as event handlers
controler.getEvents().addHandler(analysis);
controler.getEvents().addHandler(vehicleTracker);

// Run the simulation
controler.run();

// Print the statistics after the simulation
analysis.printStats();

Desktop.getDesktop().open(new File(config.controler().getOutputDirectory() + "/modestats_stackedbar.png"));


}
}
154 changes: 154 additions & 0 deletions contribs/SyntheticModel/src/ConfigCreator/ScenarioCreator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package ConfigCreator;

import NetworkCreator.SyntheticNetworkCreator;
import PlansCreator.PlansXMLSynthesizer;
import PlansCreator.RandomCoordinatesGenerator;
import TransitCreator.RailLinkCreator;
import TransitCreator.RailScheduleCreator;
import TransitCreator.VehicleCreator;

import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.List;


public class ScenarioCreator {

private static final String SCENARIO_PATH = "examples/scenarios/UrbanLine/3x1km";

public static void main(String[] args) throws Exception {

// 1. Create network.xml
createNetwork();

// 2. Create households.xml and commercial.xml
createHouseholdsAndCommercialCoordinates();

// 3. Create plans.xml
createPlans();

// 4. Create transitschedule.xml
createRailSchedule();

// 5. Create transitVehicles.xml
createVehicles();


System.out.println("Scenario files successfully created.");
}

private static void createNetwork() throws Exception {
List<Integer> slicesList = List.of(
// 30, 27, 26, //main core
// 21, 20, 19, 18, 17, //urban area
// 16, 15, 14, 13, 12, 11, 10, 9, //suburban transition
// 8, 8, 8, 7, 7, 7,
27, 27, 27 //suburb
);
SyntheticNetworkCreator.main(new String[]{SCENARIO_PATH}, slicesList);
}

private static void createHouseholdsAndCommercialCoordinates() throws Exception {
List<Integer> households = List.of(
// 8000, 10000, 10000, //main core
// 6000, 7000, 5000, 4000, 4200, //urban area
// 2000, 1800, 1500, 1300, 1200, 1000, 900, 800, //suburban transition
// 900, 800, 800, 700, 700, 800,
800, 500, 700 //suburb
);
List<Double> decayRates = List.of(
// 0.1, 0.6, 0.7 ,// main core
// 0.1, 0.7, 0.5, 0.3, 0.2, 0.2, // urban area
// 0.2, 0.2, 0.5, 0.1, 0.8, 0.9, 0.9, 0.8, // suburban transition
// 0.9, 0.8, 0.7, 0.5, 0.5, 0.4,
0.3, 0.4, 0.9 //suburb
);
List<Integer> commercial = List.of(
// 1500, 1500, 1500, //main core
// 1000, 1000, 1000, 1000, 1000, //urban area
// 250, 250, 250, 250, 250, 250, 250, 250, //suburban transition
// 220, 220, 220, 70, 70, 50,
50, 70, 70 //suburb
);

RandomCoordinatesGenerator generator = new RandomCoordinatesGenerator(households, decayRates);
generator.writeToXML(SCENARIO_PATH, "households.xml");

generator = new RandomCoordinatesGenerator(commercial, decayRates);
generator.writeToXML(SCENARIO_PATH, "commercial.xml");
}

private static void createPlans() throws ParserConfigurationException, IOException, SAXException {
PlansXMLSynthesizer synthesizer = new PlansXMLSynthesizer(SCENARIO_PATH);
int numberOfPlansToGenerate = 500; // specify the desired number of plans here
synthesizer.synthesize(numberOfPlansToGenerate);
}

private static void createRailSchedule() throws IOException {

double[] distances = {
// First half: links from 700 to 1500
700.0, 742.0, 868.0, 910.0,
// 952.0, 1036.0, 1246.0, 1414.0, 1456.0,
// // Next quarter: links from 1500 to 3000
// 1666.0, 1998.0, 2330.0, 2994.0,
// // last bit: 10 links from 2500 to 3500
// 2765.0, 2895.0
};

String[] times = {
// 5 AM to 6 AM: Early morning, every 15 minutes
"05:00:00", "05:15:00", "05:30:00", "05:45:00",
// 6 AM to 7:30 AM: Morning rush, every 5 minutes
"06:00:00", "06:05:00", "06:10:00", "06:15:00", "06:20:00", "06:25:00", "06:30:00",
"06:35:00", "06:40:00", "06:45:00", "06:50:00", "06:55:00", "07:00:00", "07:05:00",
"07:10:00", "07:15:00", "07:20:00", "07:25:00", "07:30:00",
// 7:30 AM to 9 AM: Peak rush, every 3-4 minutes
"07:33:00", "07:37:00", "07:40:00", "07:44:00", "07:48:00", "07:52:00", "07:56:00",
"08:00:00", "08:04:00", "08:08:00", "08:12:00", "08:16:00", "08:20:00", "08:24:00",
"08:28:00", "08:32:00", "08:36:00", "08:40:00", "08:44:00", "08:48:00", "08:52:00",
"08:56:00",
// 9 AM to 4 PM: Off-peak, every 10 minutes
"09:00:00", "09:10:00", "09:20:00", "09:30:00", "09:40:00", "09:50:00",
"10:00:00", "10:10:00", "10:20:00", "10:30:00", "10:40:00", "10:50:00",
"11:00:00", "11:10:00", "11:20:00", "11:30:00", "11:40:00", "11:50:00",
"12:00:00", "12:10:00", "12:20:00", "12:30:00", "12:40:00", "12:50:00",
"13:00:00", "13:10:00", "13:20:00", "13:30:00", "13:40:00", "13:50:00",
"14:00:00", "14:10:00", "14:20:00", "14:30:00", "14:40:00", "14:50:00",
"15:00:00", "15:10:00", "15:20:00", "15:30:00", "15:40:00", "15:50:00",
// 4 PM to 7 PM: Evening rush, every 5 minutes
"16:00:00", "16:05:00", "16:10:00", "16:15:00", "16:20:00", "16:25:00",
"16:30:00", "16:35:00", "16:40:00", "16:45:00", "16:50:00", "16:55:00",
"17:00:00", "17:05:00", "17:10:00", "17:15:00", "17:20:00", "17:25:00",
"17:30:00", "17:35:00", "17:40:00", "17:45:00", "17:50:00", "17:55:00",
// 7 PM to 10 PM: Evening, every 10 minutes
"18:00:00", "18:10:00", "18:20:00", "18:30:00", "18:40:00", "18:50:00",
"19:00:00", "19:10:00", "19:20:00", "19:30:00", "19:40:00", "19:50:00",
"20:00:00", "20:10:00", "20:20:00", "20:30:00", "20:40:00", "20:50:00",
"21:00:00", "21:10:00", "21:20:00", "21:30:00", "21:40:00", "21:50:00",
// 10 PM to 12 AM: Late evening, every 15 minutes
"22:00:00", "22:15:00", "22:30:00", "22:45:00", "23:00:00", "23:15:00", "23:30:00", "23:45:00",
};

String[] vehicleRefIds = new String[times.length];
for (int i = 0; i < times.length; i++) {
vehicleRefIds[i] = "tr_" + ((i % 25) + 1); // rotates between tr_1, tr_2, .... tr_25
}

RailScheduleCreator scheduleCreator = new RailScheduleCreator();

scheduleCreator.generateSchedule(SCENARIO_PATH, times, vehicleRefIds, distances);

}

private static void createVehicles(){
VehicleCreator vehicleCreator = new VehicleCreator();
int veh_no = 25; // specify the desired number of vehicles here
vehicleCreator.createTrain(SCENARIO_PATH, veh_no);
}

}


Loading