From e37f2d8bc5a5aa7a49da916f957eb66f9fde1e4b Mon Sep 17 00:00:00 2001 From: Kai Nagel Date: Mon, 25 Apr 2022 11:59:24 +0200 Subject: [PATCH] add MatsimApplication as an example --- pom.xml | 10 ++- .../matsim/project/RunMatsimApplication.java | 70 +++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/matsim/project/RunMatsimApplication.java diff --git a/pom.xml b/pom.xml index 19f9b9295..f0ea49d44 100644 --- a/pom.xml +++ b/pom.xml @@ -13,11 +13,11 @@ 14.0 - + - + UTF-8 UTF-8 @@ -134,6 +134,12 @@ emissions ${matsim.version} + + org.matsim.contrib + application + ${matsim.version} + + diff --git a/src/main/java/org/matsim/project/RunMatsimApplication.java b/src/main/java/org/matsim/project/RunMatsimApplication.java new file mode 100644 index 000000000..251a7b34a --- /dev/null +++ b/src/main/java/org/matsim/project/RunMatsimApplication.java @@ -0,0 +1,70 @@ +/* *********************************************************************** * + * 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 org.matsim.project; + +import org.apache.logging.log4j.core.tools.picocli.CommandLine; +import org.matsim.api.core.v01.Scenario; +import org.matsim.application.MATSimApplication; +import org.matsim.core.config.Config; +import org.matsim.core.config.ConfigUtils; +import org.matsim.core.controler.Controler; +import org.matsim.core.controler.OutputDirectoryHierarchy.OverwriteFileSetting; +import org.matsim.core.scenario.ScenarioUtils; + +/** + * @author nagel + * + */ +@CommandLine.Command( header = ":: MyScenario ::", version = "1.0") +public class RunMatsimApplication extends MATSimApplication{ + + public static void main(String[] args) { + + Config config; + if ( args==null || args.length==0 || args[0]==null ){ + config = ConfigUtils.loadConfig( "scenarios/equil/config.xml" ); + } else { + config = ConfigUtils.loadConfig( args ); + } + + config.controler().setOverwriteFileSetting( OverwriteFileSetting.deleteDirectoryIfExists ); + + // possibly modify config here + + // --- + + Scenario scenario = ScenarioUtils.loadScenario(config) ; + + // possibly modify scenario here + + // --- + + Controler controler = new Controler( scenario ) ; + + // possibly modify controler here + +// controler.addOverridingModule( new OTFVisLiveModule() ) ; + + + // --- + + controler.run(); + } + +}