Link Search Menu Expand Document

Use Tramola-Changesets with MATSim

Tramola allows to edit scenario data (network, public transport schedule) and start runs with the modified scenario. If you do not want to start a run in Tramola, but still want to have the modified network and transit schedule, you can download the changes from Tramola and apply them to your existing MATSim Scenario.

Tramola’s open-source MATSim-Integrations project provides all the necessary code and examples to integrate apply changesets to a MATSim scenario.

First, create the changes in Tramola, save then, then download the changes as changeset.json.

Next, you have to write some code. In your code project, make sure to add the following dependency:

<repositories>
  <repository>
    <id>tramola-integrations-gitlab</id>
    <url>https://gitlab.com/api/v4/groups/2317058/-/packages/maven</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>com.simunto.tramola</groupId>
    <artifactId>tramola-changeset</artifactId>
    <version>24.1.0-SNAPSHOT</version>
  </dependency>
</dependencies>

Try to use the latest version listed in the code repository.

public class Run { 
  public static void main(String[] args) {
    String configFilename = args[0];
    
    // load scenario
    Config config = ConfigUtils.loadConfig(configFilename);
    Scenario scenario = ScenarioUtils.loadScenario(config);

    // load 1 or more changesets to apply
    List<Changeset> changesets = new ArrayList<>();
    try (BufferedReader reader = IOUtils.getBufferedReader("/path/to/changeset.json")) {
      Changeset changeset = Changeset.read(reader);
      changesets.add(changeset);
    } catch (IOException e) {
      e.printStackTrace();
    }

    // apply the changes to the scenario, use the correct CRS of your scenario
    // (Tramola uses EPSG:4326 to store coordinate value in the changests)
    ChangesetApplier applier = new ChangesetApplier(scenario, TransformationFactory.getCoordinateTransformation("EPSG:4326", "EPSG:25833"));
    applier.applyChanges(changesets);

    // write out the modified scenario
    new NetworkWriter(scenario.getNetwork()).write("/path/to/network_modified.xml");
    new TransitScheduleWriter(scenario.getTransitSchedule()).writeFile("/path/to/schedule_modified.xml");
    new MatsimVehicleWriter(scenario.getTransitVehicles()).writeFile("/path/to/vehicles_modified.xml");
  }
}