Skip to content

Commit

Permalink
Merge pull request #7 from rolling-stock-scheduling/feature/remove-de…
Browse files Browse the repository at this point in the history
…pendency-on-config

Remove dependency on matsim run output config file
  • Loading branch information
munterfi authored Jul 17, 2024
2 parents b380c80 + bf75150 commit ec09189
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 35,684 deletions.

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class RsschedRequestConfig {
private String runId;
private String inputDirectory;
private String outputDirectory;
private String networkCrs;

public static Builder builder() {
return new Builder();
Expand Down Expand Up @@ -84,6 +85,11 @@ public Builder setOutputDirectory(String outputDirectory) {
return this;
}

public Builder setNetworkCrs(String crs) {
config.networkCrs = crs;
return this;
}

public Builder setFilterStrategy(FilterStrategy filterStrategy) {
config.global.filterStrategy = filterStrategy;
return this;
Expand Down Expand Up @@ -132,9 +138,9 @@ public Builder addMaintenanceSlot(String id, String locationId, LocalDateTime st
* @return The fully configured RequestConfig instance.
*/
public RsschedRequestConfig buildWithDefaults() {
if (config.instanceId == null || config.runId == null || config.inputDirectory == null || config.outputDirectory == null) {
if (config.instanceId == null || config.runId == null || config.inputDirectory == null || config.outputDirectory == null || config.networkCrs == null) {
throw new IllegalStateException(
"Mandatory fields (instanceId, runId, inputDirectory, outputDirectory) must be set.");
"Mandatory fields (instanceId, runId, inputDirectory, outputDirectory, networkCrs) must be set.");
}
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ private void parseScenarioInfoSheet(Sheet sheet) {
case "outputDirectory":
builder.setOutputDirectory(valueCell.getStringCellValue());
break;
case "networkCrs":
builder.setNetworkCrs(valueCell.getStringCellValue());
break;
case "sampleSize":
builder.config.getGlobal().setSampleSize(valueCell.getNumericCellValue());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public EventSource(String runId, String inputFolder) {
@Override
public PassengerPipe fetch() {
var scenarioLoader = new ScenarioLoader(runId, inputFolder);
return new PassengerPipe(runId, scenarioLoader.getEventsFile(), scenarioLoader.load(false), new HashSet<>(),
return new PassengerPipe(runId, scenarioLoader.getEventsFile(), scenarioLoader.load(), new HashSet<>(),
new ArrayList<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public RequestPipeline(RsschedRequestConfig config) {
// set source
super(new ScenarioPassengerCollector(config.getRunId(),
new ScenarioPipeline(config.getInstanceId(), config.getRunId(), config.getInputDirectory(),
config.getOutputDirectory(), config.getGlobal().getFilterStrategy()),
config.getOutputDirectory(), config.getNetworkCrs(), config.getGlobal().getFilterStrategy()),
new PassengerPipeline(config.getInstanceId(), config.getRunId(), config.getInputDirectory(),
config.getOutputDirectory(), config.getGlobal().getFilterStrategy(),
config.getGlobal().getSampleSize(), config.getGlobal().getSeatDurationThreshold())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public class ScenarioPipeline extends Pipeline<ScenarioPipe> {
* @param runId the ID of the scenario run
* @param inputDirectory the input directory containing the scenario data (output files of the simulation)
* @param outputDirectory the output directory to export the processed scenario files
* @param networkCrs the coordinate reference system of the network
* @param filterStrategy the strategy for filtering transit lines
*/
public ScenarioPipeline(String instanceId, String runId, String inputDirectory, String outputDirectory, FilterStrategy filterStrategy) {
public ScenarioPipeline(String instanceId, String runId, String inputDirectory, String outputDirectory, String networkCrs, FilterStrategy filterStrategy) {
// set source
super(new ScenarioSource(runId, inputDirectory));
super(new ScenarioSource(runId, inputDirectory, networkCrs));
// filter transit lines
addFilter(new TransitLineFilter(filterStrategy));
// mask scenario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,22 @@
class ScenarioSource implements DataSource<ScenarioPipe> {
private final String runId;
private final String inputFolder;
private final String networkCrs;

/**
* Constructs a ScenarioLoader object with the specified run ID and input folder.
*
* @param runId the ID of the simulation run
* @param inputFolder the folder containing the output files of the run
*/
public ScenarioSource(String runId, String inputFolder) {
public ScenarioSource(String runId, String inputFolder, String networkCrs) {
this.runId = runId;
this.inputFolder = inputFolder;
this.networkCrs = networkCrs;
}

@Override
public ScenarioPipe fetch() {
return new ScenarioPipe(runId, new ScenarioLoader(runId, inputFolder).load(true));
return new ScenarioPipe(runId, new ScenarioLoader(runId, inputFolder, networkCrs).load());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,44 @@

@Log4j2
public class ScenarioLoader {
private static final String CONFIG_FILE = "output_config.xml";
private static final String NETWORK_FILE = "output_network.xml.gz";
private static final String TRANSIT_SCHEDULE_FILE = "output_transitSchedule.xml.gz";
private static final String TRANSIT_VEHICLES_FILE = "output_transitVehicles.xml.gz";
private static final String EVENTS_FILE = "output_events.xml.gz";
private final String runId;
private final String inputFolder;
private final String networkCrs;

/**
* Constructs a ScenarioLoader object with the specified run ID and input folder.
* Constructs a ScenarioLoader object with the specified run ID, input folder and the CRS.
* <p>
* Note: If a CRS is provided the network will be read.
*
* @param runId the ID of the simulation run
* @param inputFolder the folder containing the output files of the run
* @param networkCrs the coordinate reference system of the network
*/
public ScenarioLoader(String runId, String inputFolder) {
public ScenarioLoader(String runId, String inputFolder, String networkCrs) {
this.runId = runId;
this.inputFolder = inputFolder;
this.networkCrs = networkCrs;
}

/**
* A scenario loader created with this constructor will not load the network.
*/
public ScenarioLoader(String runId, String inputFolder) {
// crs is only needed if network is loaded
this(runId, inputFolder, null);
}

public Scenario load(boolean includeNetwork) {
public Scenario load() {
log.info("Loading scenario {}", runId);
String configFile = buildPath(CONFIG_FILE);
String networkFile = includeNetwork ? buildRelativeFileName(NETWORK_FILE) : null;
String networkFile = networkCrs != null ? buildRelativeFileName(NETWORK_FILE) : null;
String scheduleFile = buildRelativeFileName(TRANSIT_SCHEDULE_FILE);
String vehiclesFile = buildRelativeFileName(TRANSIT_VEHICLES_FILE);
Config config = ConfigUtils.loadConfig(configFile);
Config config = ConfigUtils.createConfig(inputFolder);
config.global().setCoordinateSystem(networkCrs);
config.plans().setInputFile(null);
config.facilities().setInputFile(null);
config.vehicles().setVehiclesFile(null);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/ch/sbb/rssched/client/IntegrationTestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
public class IntegrationTestData {

private static final String BASE_URL = "https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/kelheim/kelheim-v3.0/output/25pct/";
private static final String[] FILE_NAMES = {"kelheim-v3.0-25pct.output_events.xml.gz", "kelheim-v3.0-25pct.output_network.xml.gz", "kelheim-v3.0-25pct.output_transitSchedule.xml.gz", "kelheim-v3.0-25pct.output_transitVehicles.xml.gz", "kelheim-v3.0-25pct.output_config.xml"};
private static final String[] FILE_NAMES = {"kelheim-v3.0-25pct.output_events.xml.gz", "kelheim-v3.0-25pct.output_network.xml.gz", "kelheim-v3.0-25pct.output_transitSchedule.xml.gz", "kelheim-v3.0-25pct.output_transitVehicles.xml.gz"};
private final boolean overwrite;

private static void downloadFile(String url, String outputFilePath) throws IOException {
Expand Down Expand Up @@ -69,6 +69,7 @@ final static class MatsimRun {
public static final String INPUT_DIRECTORY = "integration-test/input/de/kelheim/kelheim-v3.0/25pct/";
public static final String OUTPUT_DIRECTORY = "integration-test/output/de/kelheim/kelheim-v3.0/25pct/";
public static final String ID = "kelheim-v3.0-25pct";
public static final String CRS = "EPSG:25832";
public static final double SAMPLE_SIZE = 0.25;
public static final Set<String> LOCATIONS_IN_KEHLHEIM = Set.of("short_10302.5", "regio_275062", "short_10302.6",
"regio_289114.2", "regio_289114.4", "regio_92976", "short_10302.3", "short_10302.4", "regio_275062.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void testWithConfigBuilder() {
// build request config
RsschedRequestConfig.Builder builder = RsschedRequestConfig.builder().setInstanceId("it_builder")
.setInputDirectory(MatsimRun.INPUT_DIRECTORY).setOutputDirectory(MatsimRun.OUTPUT_DIRECTORY)
.setRunId(MatsimRun.ID).setFilterStrategy(filterStrategy);
.setRunId(MatsimRun.ID).setNetworkCrs(MatsimRun.CRS).setFilterStrategy(filterStrategy);

// add depots
Depots.LOCATIONS.forEach(location -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ void shouldReadConfigFile() throws IOException {
assertEquals("run_1", config.getRunId());
assertEquals("input/folder/path", config.getInputDirectory());
assertEquals("output/folder/path", config.getOutputDirectory());
assertEquals("EPSG:25832", config.getNetworkCrs());

// global settings
assertEquals(0.1, config.getGlobal().getSampleSize());
Expand Down
Binary file not shown.

0 comments on commit ec09189

Please sign in to comment.