Skip to content

Commit

Permalink
add MatsimApplication as an example
Browse files Browse the repository at this point in the history
  • Loading branch information
kainagel committed Apr 25, 2022
1 parent a870cae commit e37f2d8
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
<!-- release -->
<matsim.version>14.0</matsim.version>

<!-- PR release -->
<!-- PR (= pull request) release -->
<!-- <matsim.version>13.1-PR1536</matsim.version> -->

<!-- for dependency sharing in IDE -->
<!-- <matsim.version>14.0-SNAPSHOT</matsim.version> -->
<!-- <matsim.version>15.0-SNAPSHOT</matsim.version>-->

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down Expand Up @@ -134,6 +134,12 @@
<artifactId>emissions</artifactId>
<version>${matsim.version}</version>
</dependency>
<dependency>
<groupId>org.matsim.contrib</groupId>
<artifactId>application</artifactId>
<version>${matsim.version}</version>
</dependency>

<!--Dependencies from where stated above to here are added as a service; they can be removed if you don't need them-->

</dependencies>
Expand Down
70 changes: 70 additions & 0 deletions src/main/java/org/matsim/project/RunMatsimApplication.java
Original file line number Diff line number Diff line change
@@ -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();
}

}

0 comments on commit e37f2d8

Please sign in to comment.