Java Code Examples for org.matsim.core.config.ConfigUtils#loadConfig()
The following examples show how to use
org.matsim.core.config.ConfigUtils#loadConfig() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VideoGenerator.java From amodeus with GNU General Public License v2.0 | 6 votes |
@Override public void run() { try { // load options ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault()); Config config = ConfigUtils.loadConfig(scenarioOptions.getSimulationConfigName()); final File outputSubDirectory = new File(config.controler().getOutputDirectory()).getAbsoluteFile(); GlobalAssert.that(outputSubDirectory.isDirectory()); ReferenceFrame referenceFrame = scenarioOptions.getLocationSpec().referenceFrame(); /** reference frame needs to be set manually in IDSCOptions.properties file */ Network network = NetworkLoader.fromNetworkFile(new File(config.network().getInputFile())); export(network, referenceFrame, scenarioOptions, outputSubDirectory); System.out.println("successfully finished video generation"); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: Preparer.java From amodeus with GNU General Public License v2.0 | 6 votes |
public Preparer(File workingDirectory) throws IOException { // Static.setup(); /** amodeus options */ scenOpt = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault()); /** MATSim config */ config = ConfigUtils.loadConfig(scenOpt.getPreparerConfigName()); Scenario scenario = ScenarioUtils.loadScenario(config); /** adaption of MATSim network, e.g., radius cutting */ Network network = scenario.getNetwork(); this.network = NetworkPreparer.run(network, scenOpt); /** adaption of MATSim population, e.g., radius cutting */ this.population = scenario.getPopulation(); }
Example 3
Source File: PT2MATSimExample.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * 2. A MATSim network of the area is required. If no such network is already available, * the PT2MATSim package provides the possibility to use OSM-maps as data-input. * * Here as an example, the OSM-extract of the city centre of Waterloo, Canada, is converted. */ public static void createOsmConfigFile(String configFile) { // Create a default createOsmConfigFile-Config: CreateDefaultOsmConfig.main(new String[]{inter + "OsmConverterConfigDefault.xml"}); // Open the createOsmConfigFile Config and set the parameters to the required values // (usually done manually by opening the config with a simple editor) Config osmConverterConfig = ConfigUtils.loadConfig( inter + "OsmConverterConfigDefault.xml", new OsmConverterConfigGroup()); OsmConverterConfigGroup osmConfig = ConfigUtils.addOrGetModule(osmConverterConfig, OsmConverterConfigGroup.class); osmConfig.setOsmFile(input + "addison.osm.gz"); osmConfig.setOutputCoordinateSystem(addisonCountyEPSG); osmConfig.setOutputNetworkFile(inter + "addison.xml.gz"); // Save the createOsmConfigFile config (usually done manually) new ConfigWriter(osmConverterConfig).write(configFile); }
Example 4
Source File: PT2MATSimExample.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
/** * 3. The core of the PT2MATSim-package is the mapping process of the schedule to the network. * * Here as an example, the unmapped schedule of GrandRiverTransit (previously converted from GTFS) is mapped * to the converted OSM network of the Waterloo Area, Canada. */ public static void createMapperConfigFile(String configFile) { // Create a mapping config: CreateDefaultPTMapperConfig.main(new String[]{ inter + "MapperConfigDefault.xml"}); // Open the mapping config and set the parameters to the required values // (usually done manually by opening the config with a simple editor) Config config = ConfigUtils.loadConfig( inter + "MapperConfigDefault.xml", PublicTransitMappingConfigGroup.createDefaultConfig()); PublicTransitMappingConfigGroup ptmConfig = ConfigUtils.addOrGetModule(config, PublicTransitMappingConfigGroup.class); ptmConfig.setInputNetworkFile(inter + "addison.xml.gz"); ptmConfig.setOutputNetworkFile(output + "addison_multimodalnetwork.xml.gz"); ptmConfig.setOutputScheduleFile(output+ "addison_schedule.xml.gz"); ptmConfig.setOutputStreetNetworkFile(output + "addison_streetnetwork.xml.gz"); ptmConfig.setInputScheduleFile(inter + "schedule_unmapped.xml.gz"); ptmConfig.setScheduleFreespeedModes(CollectionUtils.stringToSet("rail, light_rail")); // Save the mapping config // (usually done manually) new ConfigWriter(config).write(configFile); }
Example 5
Source File: RunTaxiExample.java From matsim-maas with GNU General Public License v2.0 | 5 votes |
public static void run(String configFile, boolean otfvis, int lastIteration) { // load config Config config = ConfigUtils.loadConfig(configFile, new MultiModeTaxiConfigGroup(), new DvrpConfigGroup(), new OTFVisConfigGroup()); config.controler().setLastIteration(lastIteration); TaxiControlerCreator.createControler(config, otfvis).run(); }
Example 6
Source File: RunStopBasedDrtExample.java From matsim-maas with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { Config config = ConfigUtils.loadConfig("scenarios/cottbus/drtconfig_stopbased.xml", new MultiModeDrtConfigGroup(), new DvrpConfigGroup(), new OTFVisConfigGroup(), new DrtFaresConfigGroup()); run(config, false); }
Example 7
Source File: RunDoorToDoorDrtExample.java From matsim-maas with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { Config config = ConfigUtils.loadConfig(COTTBUS_DOOR2DOOR_CONFIG, new MultiModeDrtConfigGroup(), new DvrpConfigGroup(), new OTFVisConfigGroup(), new DrtFaresConfigGroup()); run(config, false); }
Example 8
Source File: TestViewer.java From amodeus with GNU General Public License v2.0 | 5 votes |
private TestViewer(File workingDirectory) throws IOException { // Static.setup(); ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault()); /** load options */ Config config = ConfigUtils.loadConfig(scenarioOptions.getSimulationConfigName()); System.out.println("MATSim config file: " + scenarioOptions.getSimulationConfigName()); final File outputSubDirectory = new File(config.controler().getOutputDirectory()).getAbsoluteFile(); if (!outputSubDirectory.isDirectory()) throw new RuntimeException("output directory: " + outputSubDirectory.getAbsolutePath() + " not found."); System.out.println("outputSubDirectory=" + outputSubDirectory.getAbsolutePath()); File outputDirectory = outputSubDirectory.getParentFile(); System.out.println("showing simulation results from outputDirectory=" + outputDirectory); /** geographic information, .e.g., coordinate system */ LocationSpec locationSpec = scenarioOptions.getLocationSpec(); ReferenceFrame referenceFrame = locationSpec.referenceFrame(); /** MATSim simulation network */ Network network = NetworkLoader.fromConfigFile(new File(workingDirectory, scenarioOptions.getString("simuConfig"))); System.out.println("INFO network loaded"); System.out.println("INFO total links " + network.getLinks().size()); System.out.println("INFO total nodes " + network.getNodes().size()); /** initializing the viewer */ MatsimAmodeusDatabase db = MatsimAmodeusDatabase.initialize(network, referenceFrame); amodeusComponent = AmodeusComponent.createDefault(db, workingDirectory); /** virtual network layer, should not cause problems if layer does not exist */ amodeusComponent.virtualNetworkLayer.setVirtualNetwork(VirtualNetworkGet.readDefault(network, scenarioOptions)); /** starting the viewer */ viewerConfig = ViewerConfig.from(db, workingDirectory); System.out.println("Used viewer config: " + viewerConfig); AmodeusViewerFrame amodeusViewerFrame = new AmodeusViewerFrame(amodeusComponent, outputDirectory, network, scenarioOptions); amodeusViewerFrame.setDisplayPosition(viewerConfig.settings.coord, viewerConfig.settings.zoom); amodeusViewerFrame.jFrame.setSize(viewerConfig.settings.dimensions); amodeusViewerFrame.jFrame.setVisible(true); }
Example 9
Source File: LPTimeInvariantTest.java From amodeus with GNU General Public License v2.0 | 5 votes |
@BeforeClass public static void setUp() throws IOException { System.out.println(LPTimeInvariant.class.getName()); // copy scenario data into main directory File scenarioDirectory = new File(Locate.repoFolder(LPTimeInvariantTest.class, "amodeus"), "resources/testScenario"); System.out.println("scenarioDirectory: " + scenarioDirectory); File workingDirectory = MultiFileTools.getDefaultWorkingDirectory(); GlobalAssert.that(workingDirectory.isDirectory()); TestFileHandling.copyScnearioToMainDirectory(scenarioDirectory.getAbsolutePath(), workingDirectory.getAbsolutePath()); /* input data */ scenarioOptions = new ScenarioOptions(scenarioDirectory, ScenarioOptionsBase.getDefault()); File configFile = new File(scenarioOptions.getPreparerConfigName()); System.out.println("configFile: " + configFile.getAbsolutePath()); AmodeusConfigGroup avCg = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(configFile.getAbsolutePath(), avCg); GeneratorConfig genConfig = avCg.getModes().values().iterator().next().getGeneratorConfig(); int numRt = genConfig.getNumberOfVehicles(); endTime = (int) config.qsim().getEndTime().seconds(); Scenario scenario = ScenarioUtils.loadScenario(config); network = scenario.getNetwork(); population = scenario.getPopulation(); // create 2 node virtual network scenarioOptions.setProperty(ScenarioOptionsBase.NUMVNODESIDENTIFIER, "2"); VirtualNetworkCreator virtualNetworkCreator = scenarioOptions.getVirtualNetworkCreator(); virtualNetwork2 = virtualNetworkCreator.create(network, population, scenarioOptions, numRt, endTime); // create 3 node virtual network scenarioOptions.setProperty(ScenarioOptionsBase.NUMVNODESIDENTIFIER, "3"); virtualNetworkCreator = scenarioOptions.getVirtualNetworkCreator(); virtualNetwork3 = virtualNetworkCreator.create(network, population, scenarioOptions, numRt, endTime); }
Example 10
Source File: LPEmptyTest.java From amodeus with GNU General Public License v2.0 | 5 votes |
@BeforeClass public static void setUp() throws IOException { System.out.println(LPTimeInvariant.class.getName()); // copy scenario data into main directory File scenarioDirectory = new File(Locate.repoFolder(LPEmptyTest.class, "amodeus"), "resources/testScenario"); System.out.println("scenarioDirectory: " + scenarioDirectory); File workingDirectory = MultiFileTools.getDefaultWorkingDirectory(); GlobalAssert.that(workingDirectory.isDirectory()); TestFileHandling.copyScnearioToMainDirectory(scenarioDirectory.getAbsolutePath(), workingDirectory.getAbsolutePath()); /* input data */ scenarioOptions = new ScenarioOptions(scenarioDirectory, ScenarioOptionsBase.getDefault()); File configFile = new File(scenarioOptions.getPreparerConfigName()); System.out.println("configFile: " + configFile.getAbsolutePath()); AmodeusConfigGroup avCg = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(configFile.getAbsolutePath(), avCg); GeneratorConfig genConfig = avCg.getModes().values().iterator().next().getGeneratorConfig(); int numRt = genConfig.getNumberOfVehicles(); endTime = (int) config.qsim().getEndTime().seconds(); Scenario scenario = ScenarioUtils.loadScenario(config); network = scenario.getNetwork(); population = scenario.getPopulation(); // create 2 node virtual network scenarioOptions.setProperty(ScenarioOptionsBase.NUMVNODESIDENTIFIER, "2"); VirtualNetworkCreator virtualNetworkCreator = scenarioOptions.getVirtualNetworkCreator(); virtualNetwork2 = virtualNetworkCreator.create(network, population, scenarioOptions, numRt, endTime); // create 3 node virtual network scenarioOptions.setProperty(ScenarioOptionsBase.NUMVNODESIDENTIFIER, "3"); virtualNetworkCreator = scenarioOptions.getVirtualNetworkCreator(); virtualNetwork3 = virtualNetworkCreator.create(network, population, scenarioOptions, numRt, endTime); }
Example 11
Source File: PopulationToolsTestVN2.java From amodeus with GNU General Public License v2.0 | 5 votes |
@BeforeClass public static void setup() throws IOException { // copy scenario data into main directory File scenarioDirectory = new File(Locate.repoFolder(PopulationToolsTestVN2.class, "amodeus"), "resources/testScenario"); File workingDirectory = MultiFileTools.getDefaultWorkingDirectory(); GlobalAssert.that(workingDirectory.exists()); TestFileHandling.copyScnearioToMainDirectory(scenarioDirectory.getAbsolutePath(), workingDirectory.getAbsolutePath()); /* input data */ scenarioOptions = new ScenarioOptions(scenarioDirectory, ScenarioOptionsBase.getDefault()); File configFile = new File(scenarioOptions.getPreparerConfigName()); AmodeusConfigGroup avCg = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(configFile.getAbsolutePath(), avCg); GeneratorConfig genConfig = avCg.getModes().values().iterator().next().getGeneratorConfig(); int numRt = genConfig.getNumberOfVehicles(); endTime = (int) config.qsim().getEndTime().seconds(); Scenario scenario = ScenarioUtils.loadScenario(config); network = scenario.getNetwork(); population = scenario.getPopulation(); // create 2 node virtual network scenarioOptions.setProperty(ScenarioOptionsBase.NUMVNODESIDENTIFIER, "2"); VirtualNetworkCreator virtualNetworkCreator = scenarioOptions.getVirtualNetworkCreator(); virtualNetwork2 = virtualNetworkCreator.create(network, population, scenarioOptions, numRt, endTime); Link node0 = (Link) virtualNetwork2.getVirtualNode(0).getLinks().toArray()[0]; Link node1 = (Link) virtualNetwork2.getVirtualNode(1).getLinks().toArray()[0]; requestsSingle3.add(new Request(10, node0, node1)); requests3.add(new Request(0, node0, node1)); requests3.add(new Request(3600, node1, node0)); requests3.add(new Request(30 * 3600 - 1, node1, node0)); requests3.add(new Request(3600, node0, node0)); }
Example 12
Source File: VehicleToVSGeneratorTester.java From amodeus with GNU General Public License v2.0 | 5 votes |
@BeforeClass public static void setup() throws IOException { /** input data */ File scenarioDirectory = new File(Locate.repoFolder(VehicleToVSGenerator.class, "amodeus"), "resources/testScenario"); scenarioOptions = new ScenarioOptions(scenarioDirectory, ScenarioOptionsBase.getDefault()); File configFile = new File(scenarioOptions.getPreparerConfigName()); AmodeusConfigGroup avCg = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(configFile.getAbsolutePath(), avCg); GeneratorConfig genConfig = avCg.getModes().values().iterator().next().getGeneratorConfig(); int numRt = genConfig.getNumberOfVehicles(); int endTime = (int) config.qsim().getEndTime().seconds(); Scenario scenario = ScenarioUtils.loadScenario(config); network = scenario.getNetwork(); population = scenario.getPopulation(); scenarioOptions.setProperty(ScenarioOptionsBase.NUMVNODESIDENTIFIER, "3"); VirtualNetworkCreator virtualNetworkCreator = scenarioOptions.getVirtualNetworkCreator(); virtualNetwork = virtualNetworkCreator.create(network, population, scenarioOptions, numRt, endTime); /** creating dummy config with 10 vehicles */ operatorConfig = new AmodeusModeConfig(AmodeusModeConfig.DEFAULT_MODE); GeneratorConfig avGeneratorConfig = operatorConfig.getGeneratorConfig(); avGeneratorConfig.setType("strategy"); avGeneratorConfig.setNumberOfVehicles(10); travelData000 = new StaticTravelData(virtualNetwork.getvNetworkID(), Array.zeros(3, 3, 3), Array.zeros(3, 3, 3), Array.zeros(3, 3, 3), Array.zeros(3), "", endTime); travelData123 = new StaticTravelData(virtualNetwork.getvNetworkID(), Array.zeros(3, 3, 3), Array.zeros(3, 3, 3), Array.zeros(3, 3, 3), Tensors.vector(1, 2, 3), "", endTime); travelData334 = new StaticTravelData(virtualNetwork.getvNetworkID(), Array.zeros(3, 3, 3), Array.zeros(3, 3, 3), Array.zeros(3, 3, 3), Tensors.vector(3, 3, 4), "", endTime); }
Example 13
Source File: PublicTransitMapper.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * Routes the unmapped MATSim Transit Schedule to the network using the file * paths specified in the config. Writes the resulting schedule and network to xml files.<p/> * * @see CreateDefaultPTMapperConfig * * @param configFile the PublicTransitMapping config file */ public static void run(String configFile) { // Load config, input schedule and input network Config configAll = ConfigUtils.loadConfig(configFile, new PublicTransitMappingConfigGroup()); PublicTransitMappingConfigGroup config = ConfigUtils.addOrGetModule(configAll, PublicTransitMappingConfigGroup.class); TransitSchedule schedule = config.getInputScheduleFile() == null ? null : ScheduleTools.readTransitSchedule(config.getInputScheduleFile()); Network network = config.getInputNetworkFile() == null ? null : NetworkTools.readNetwork(config.getInputNetworkFile()); // Run PTMapper PTMapper.mapScheduleToNetwork(schedule, network, config); // or: new PTMapper(schedule, network).run(config); // Write the schedule and network to output files (if defined in config) if(config.getOutputNetworkFile() != null && config.getOutputScheduleFile() != null) { log.info("Writing schedule and network to file..."); try { ScheduleTools.writeTransitSchedule(schedule, config.getOutputScheduleFile()); NetworkTools.writeNetwork(network, config.getOutputNetworkFile()); } catch (Exception e) { log.error("Cannot write to output directory!"); } if(config.getOutputStreetNetworkFile() != null) { NetworkTools.writeNetwork(NetworkTools.createFilteredNetworkByLinkMode(network, Collections.singleton(TransportMode.car)), config.getOutputStreetNetworkFile()); } } else { log.info("No output paths defined, schedule and network are not written to files."); } }
Example 14
Source File: RunRobotaxiExample.java From matsim-maas with GNU General Public License v2.0 | 4 votes |
public static void run(String configFile, boolean otfvis) { Config config = ConfigUtils.loadConfig(configFile, new DvrpConfigGroup(), new TaxiFaresConfigGroup(), new OTFVisConfigGroup(), new MultiModeTaxiConfigGroup()); createControler(config, otfvis).run(); }
Example 15
Source File: TestServer.java From amodeus with GNU General Public License v2.0 | 4 votes |
public void simulate() throws Exception { boolean waitForClients = scenarioOptions.getBoolean("waitForClients"); StaticHelper.setup(); LocationSpec locationSpec = scenarioOptions.getLocationSpec(); ReferenceFrame referenceFrame = locationSpec.referenceFrame(); // open server port for clients to connect to SimulationServer.INSTANCE.startAcceptingNonBlocking(); SimulationServer.INSTANCE.setWaitForClients(waitForClients); // load MATSim configs - including av.xml where dispatcher is selected. System.out.println("loading config file " + configFile.getAbsoluteFile()); GlobalAssert.that(configFile.exists()); // Test whether the config file // directory exists DvrpConfigGroup dvrpConfigGroup = new DvrpConfigGroup(); dvrpConfigGroup.setTravelTimeEstimationAlpha(0.05); Config config = ConfigUtils.loadConfig(configFile.toString(), new AmodeusConfigGroup(), dvrpConfigGroup); config.planCalcScore().addActivityParams(new PlanCalcScoreConfigGroup.ActivityParams("activity")); config.qsim().setStartTime(0.0); config.qsim().setSimStarttimeInterpretation(StarttimeInterpretation.onlyUseStarttime); for (ActivityParams activityParams : config.planCalcScore().getActivityParams()) // TODO @sebhoerl fix this to meaningful values, remove, or add comment // this was added because there are sometimes problems, is there a more elegant option? activityParams.setTypicalDuration(3600.0); String outputdirectory = config.controler().getOutputDirectory(); System.out.println("outputdirectory = " + outputdirectory); // load scenario for simulation Scenario scenario = ScenarioUtils.loadScenario(config); Network network = scenario.getNetwork(); Population population = scenario.getPopulation(); GlobalAssert.that(Objects.nonNull(network) && Objects.nonNull(population)); MatsimAmodeusDatabase db = MatsimAmodeusDatabase.initialize(network, referenceFrame); Controler controller = new Controler(scenario); AmodeusConfigurator.configureController(controller, db, scenarioOptions); // run simulation controller.run(); // close port for visualization SimulationServer.INSTANCE.stopAccepting(); Analysis analysis = Analysis.setup(scenarioOptions, new File(workingDirectory, "output/001"), network, db); analysis.addAnalysisExport(ate); analysis.addAnalysisExport(new RoboTaxiHistoriesExportFromEvents(network, config)); analysis.addAnalysisExport(new RequestHistoriesExportFromEvents(network, config)); analysis.run(); }
Example 16
Source File: TestPreparer.java From amodeus with GNU General Public License v2.0 | 4 votes |
private TestPreparer(File workingDirectory) throws Exception { System.out.println("working directory: " + workingDirectory); // run preparer in simulation working directory ScenarioOptions scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault()); // load Settings from IDSC Options File configFile = new File(scenarioOptions.getPreparerConfigName()); AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(configFile.getAbsolutePath(), avConfigGroup); Scenario scenario = ScenarioUtils.loadScenario(config); GeneratorConfig avGeneratorConfig = // avConfigGroup.getModes().values().iterator().next().getGeneratorConfig(); int numRt = avGeneratorConfig.getNumberOfVehicles(); int endTime = (int) config.qsim().getEndTime().seconds(); // 1) cut network (and reduce population to new network) networkPrepared = scenario.getNetwork(); NetworkPreparer.run(networkPrepared, scenarioOptions); // 2) adapt the population to new network populationPrepared = scenario.getPopulation(); // To make Test input data consistent (e.g. avoid people departing fom "tram" links) SnapToClosestNetworkLink.run(populationPrepared, networkPrepared, TransportMode.car); PopulationPreparer.run(networkPrepared, populationPrepared, scenarioOptions, config, 10); // 3) create virtual Network // Amodeus uses internally a mode-filtered network (default is the car network). The provided // VirtualNetwork needs to be consistent with this node-filtered network. Network roadNetwork = NetworkUtils.createNetwork(); new TransportModeNetworkFilter(networkPrepared).filter(roadNetwork, Collections.singleton("car")); new NetworkCleaner().run(roadNetwork); VirtualNetworkPreparer virtualNetworkPreparer = VirtualNetworkPreparer.INSTANCE; VirtualNetwork<Link> virtualNetwork = // virtualNetworkPreparer.create(roadNetwork, populationPrepared, scenarioOptions, numRt, endTime); // 4) create TravelData /** reading the customer requests */ StaticTravelData travelData = StaticTravelDataCreator.create( // scenarioOptions.getWorkingDirectory(), // virtualNetwork, roadNetwork, populationPrepared, // scenarioOptions.getdtTravelData(), numRt, endTime); File travelDataFile = new File(scenarioOptions.getVirtualNetworkDirectoryName(), scenarioOptions.getTravelDataName()); TravelDataIO.writeStatic(travelDataFile, travelData); // 5) save a simulation config file // IncludeActTypeOf.BaselineCH(config); // Only needed in Some Scenarios ConfigCreator.createSimulationConfigFile(config, scenarioOptions); }
Example 17
Source File: SocketServer.java From amod with GNU General Public License v2.0 | 4 votes |
/** runs a simulation run using input data from Amodeus.properties, av.xml and MATSim config.xml * * @throws MalformedURLException * @throws Exception */ public void simulate(StringSocket stringSocket, int numReqTot, // File workingDirectory) throws MalformedURLException, Exception { Static.setup(); /** working directory and options */ scenarioOptions = new ScenarioOptions(workingDirectory, ScenarioOptionsBase.getDefault()); /** set to true in order to make server wait for at least 1 client, for * instance viewer client, for fals the ScenarioServer starts the simulation * immediately */ boolean waitForClients = scenarioOptions.getBoolean("waitForClients"); configFile = new File(scenarioOptions.getSimulationConfigName()); /** geographic information */ LocationSpec locationSpec = scenarioOptions.getLocationSpec(); referenceFrame = locationSpec.referenceFrame(); /** open server port for clients to connect to */ SimulationServer.INSTANCE.startAcceptingNonBlocking(); SimulationServer.INSTANCE.setWaitForClients(waitForClients); /** load MATSim configs - including av.xml configurations, load routing packages */ GlobalAssert.that(configFile.exists()); DvrpConfigGroup dvrpConfigGroup = new DvrpConfigGroup(); dvrpConfigGroup.setTravelTimeEstimationAlpha(0.05); Config config = ConfigUtils.loadConfig(configFile.toString(), new AmodeusConfigGroup(), dvrpConfigGroup); config.planCalcScore().addActivityParams(new ActivityParams("activity")); // TODO @Sebastian fix this to meaningful values, remove, or add comment // this was added because there are sometimes problems, is there a more elegant option? for (ActivityParams activityParams : config.planCalcScore().getActivityParams()) { activityParams.setTypicalDuration(3600.0); } /** load MATSim scenario for simulation */ Scenario scenario = ScenarioUtils.loadScenario(config); AddCoordinatesToActivities.run(scenario); network = scenario.getNetwork(); Population population = scenario.getPopulation(); GlobalAssert.that(Objects.nonNull(network)); GlobalAssert.that(Objects.nonNull(population)); Objects.requireNonNull(network); MatsimAmodeusDatabase db = MatsimAmodeusDatabase.initialize(network, referenceFrame); Controler controller = new Controler(scenario); AmodeusConfigurator.configureController(controller, db, scenarioOptions); /** try to load link speed data and use for speed adaption in network */ try { File linkSpeedDataFile = new File(scenarioOptions.getLinkSpeedDataName()); System.out.println(linkSpeedDataFile.toString()); LinkSpeedDataContainer lsData = LinkSpeedUtils.loadLinkSpeedData(linkSpeedDataFile); controller.addOverridingQSimModule(new TrafficDataModule(lsData)); } catch (Exception exception) { System.err.println("Unable to load linkspeed data, freeflow speeds will be used in the simulation."); exception.printStackTrace(); } controller.addOverridingModule(new SocketModule(stringSocket, numReqTot)); /** Custom router that ensures same network speeds as taxis in original data set. */ controller.addOverridingModule(new AbstractModule() { @Override public void install() { bind(TaxiTravelTimeRouter.Factory.class); AmodeusUtils.bindRouterFactory(binder(), TaxiTravelTimeRouter.class.getSimpleName()).to(TaxiTravelTimeRouter.Factory.class); } }); /** adding the dispatcher to receive and process string fleet commands */ controller.addOverridingModule(new AbstractModule() { @Override public void install() { AmodeusUtils.registerDispatcherFactory(binder(), "SocketDispatcherHost", SocketDispatcherHost.Factory.class); } }); /** adding an initial vehicle placer */ controller.addOverridingModule(new AbstractModule() { @Override public void install() { AmodeusUtils.bindGeneratorFactory(binder(), RandomDensityGenerator.class.getSimpleName()).// to(RandomDensityGenerator.Factory.class); } }); /** run simulation */ controller.run(); /** close port for visualizaiton */ SimulationServer.INSTANCE.stopAccepting(); /** perform analysis of simulation */ /** output directory for saving results */ outputDirectory = new File(config.controler().getOutputDirectory()); }
Example 18
Source File: ScenarioParameters.java From amodeus with GNU General Public License v2.0 | 4 votes |
public ScenarioParameters(ScenarioOptions scenOptions) { System.out.println("scenOptions.getSimulationConfigName: " + scenOptions.getSimulationConfigName()); AmodeusConfigGroup avConfigGroup = new AmodeusConfigGroup(); Config config = ConfigUtils.loadConfig(scenOptions.getSimulationConfigName(), avConfigGroup); // TODO: This assumes that there is only one mode registered for Amodeus. There are two ways to go // forward. Either we need to put in a check somewhere that when Amodeus is used with ScenarioOptions // that there is really only one mode registered. Alternatives are to make he ScenarioOptions multimodal // or to put all ScenarioOptions into the AmodeusModeConfig. This will happen anyways (for the MATSim // users, but I would keep a fallback to the ScenarioOptions file anyways). AmodeusModeConfig operatorConfig = avConfigGroup.getModes().values().iterator().next(); DispatcherConfig dispatcherConfig = operatorConfig.getDispatcherConfig(); SafeConfig safeConfig = SafeConfig.wrap(dispatcherConfig); GeneratorConfig generatorConfig = operatorConfig.getGeneratorConfig(); redispatchPeriod = safeConfig.getInteger(DISPATCHPERIODSTRING, UNDEFINED_INT); rebalancingPeriod = safeConfig.getInteger(REBALANCINGPERIODSTRING, UNDEFINED_INT); dispatcher = dispatcherConfig.getType(); vehicleGenerator = generatorConfig.getType(); Scenario scenario = ScenarioUtils.loadScenario(config); distanceHeuristic = safeConfig.getString(DISTANCEHEURISTICSTRING, UNDEFINED_STRING); populationSize = scenario.getPopulation().getPersons().values().size(); virtualNetworkCreator = scenOptions.getString(ScenarioOptionsBase.VIRTUALNETWORKCREATORIDENTIFIER); Network network = scenario.getNetwork(); if (Objects.isNull(network.getName())) networkName = "no network name found in network.xml"; else networkName = network.getName(); VirtualNetwork<Link> virtualNetwork = null; try { virtualNetwork = VirtualNetworkGet.readDefault(network, scenOptions); } catch (IOException e) { System.err.println("INFO not able to load virtual network for report"); e.printStackTrace(); } virtualNodesCount = Objects.isNull(virtualNetwork) // ? UNDEFINED_INT : virtualNetwork.getvNodesCount(); iterations = config.controler().getLastIteration(); }
Example 19
Source File: RunDRTClass.java From matsim-maas with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) { Config config = ConfigUtils.loadConfig(args[0], new MultiModeDrtConfigGroup(), new DvrpConfigGroup(), new OTFVisConfigGroup(), new DrtFaresConfigGroup()); run(config, false); }
Example 20
Source File: Osm2MultimodalNetwork.java From pt2matsim with GNU General Public License v2.0 | 3 votes |
/** * Converts an osm file to a MATSim network. The input and output file as well * as conversion parameters are defined in the config file. Run {@link CreateDefaultOsmConfig} * to create a default config. * * @param configFile the config.xml file */ public static void run(String configFile) { Config configAll = ConfigUtils.loadConfig(configFile, new OsmConverterConfigGroup()); OsmConverterConfigGroup config = ConfigUtils.addOrGetModule(configAll, OsmConverterConfigGroup.GROUP_NAME, OsmConverterConfigGroup.class ); run(config); }