Skip to content

Commit

Permalink
Merge pull request #3003 from matsim-org/fix-full-integration-on-windows
Browse files Browse the repository at this point in the history
Fix full integration on windows
  • Loading branch information
michalmac authored Dec 18, 2023
2 parents adbaf7d + 15913fc commit d3e0716
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ static QuadTree<PtStop> readPtStops(String ptStopInputFile, final BoundingBox bb

QuadTree<PtStop> qTree = new QuadTree<PtStop>(bb.getXMin(), bb.getYMin(), bb.getXMax(), bb.getYMax() );

try {
BufferedReader bwPtStops = IOUtils.getBufferedReader(ptStopInputFile);

try (BufferedReader bwPtStops = IOUtils.getBufferedReader(ptStopInputFile)) {
String separator = ",";

// read header
Expand Down Expand Up @@ -63,9 +61,9 @@ else if(wrnCntParse == 20)
// create pt stop coordinate
Coord ptStopCoord = new Coord(Double.parseDouble(parts[xCoordIDX]), Double.parseDouble(parts[yCoordIDX]));

boolean isInBoundary = qTree.getMaxEasting() >= ptStopCoord.getX() &&
qTree.getMinEasting() <= ptStopCoord.getX() &&
qTree.getMaxNorthing() >= ptStopCoord.getY() &&
boolean isInBoundary = qTree.getMaxEasting() >= ptStopCoord.getX() &&
qTree.getMinEasting() <= ptStopCoord.getX() &&
qTree.getMaxNorthing() >= ptStopCoord.getY() &&
qTree.getMinNorthing() <= ptStopCoord.getY();
if(!isInBoundary){
if(wrnCntSkip < 20)
Expand Down Expand Up @@ -100,7 +98,7 @@ static void fillODMatrix(Matrix odMatrix, Map<Id<PtStop>, PtStop> ptStopHashMap,
int valueIDX = 2; // column index for travel time or distance value

final double EMPTY_ENTRY = 999999.; // indicates that a value is not set (VISUM specific)
final String SEPARATOR = ";"; //
final String SEPARATOR = ";"; //

String line = null; // line from input file
String parts[] = null; // values accessible via array
Expand Down Expand Up @@ -141,7 +139,7 @@ else if(wrnCntParam == 20)
Id<PtStop> destinationPtStopID = Id.create(parts[destinationPtStopIDX], PtStop.class);

// check if a pt stop with the given id exists
if( ptStopHashMap.containsKey(originPtStopID) &&
if( ptStopHashMap.containsKey(originPtStopID) &&
ptStopHashMap.containsKey(destinationPtStopID)){

// add to od matrix
Expand All @@ -152,7 +150,7 @@ else if(wrnCntParam == 20)
// if(wrnCntId == 20){
// log.error( "Found " + wrnCntId + " warnings of type 'pt stop id not found'. There is probably something seriously wrong. Please check. Reasons for this error may be:");
// log.error( "The list of pt stops is incomplete or the stop ids of the VISUM files do not match the ids from the pt stop file.");
// } else
// } else
if(! ptStopHashMap.containsKey(originPtStopID) && wrnCntId < 20)
log.warn("Could not find an item in QuadTree (i.e. pt station has no coordinates) with pt stop id:" + originPtStopID);
else if(! ptStopHashMap.containsKey(destinationPtStopID) && wrnCntId < 20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.matsim.contrib.matrixbasedptrouter;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -84,16 +85,19 @@ public static PtMatrix createPtMatrix(RoutingConfigGroup plansCalcRoute, Boundin
String ptTravelTimeInputFile = ippcm.getPtTravelTimesInputFile();
String ptTravelDistanceInputFile = ippcm.getPtTravelDistancesInputFile();

BufferedReader brTravelTimes = IOUtils.getBufferedReader(ptTravelTimeInputFile);
log.info("Creating travel time OD matrix from VISUM pt stop 2 pt stop travel times file: " + ptTravelTimeInputFile);
final Map<Id<PtStop>, PtStop> ptStopsMap = PtMatrix.convertQuadTree2HashMap(ptStops);
FileUtils.fillODMatrix(originDestinationTravelTimeMatrix, ptStopsMap, brTravelTimes, true);
log.info("Done creating travel time OD matrix. " + originDestinationTravelTimeMatrix.toString());

log.info("Creating travel distance OD matrix from VISUM pt stop 2 pt stop travel distance file: " + ptTravelDistanceInputFile);
BufferedReader brTravelDistances = IOUtils.getBufferedReader(ptTravelDistanceInputFile);
FileUtils.fillODMatrix(originDestinationTravelDistanceMatrix, ptStopsMap, brTravelDistances, false);
log.info("Done creating travel distance OD matrix. " + originDestinationTravelDistanceMatrix.toString());
try (BufferedReader brTravelTimes = IOUtils.getBufferedReader(ptTravelTimeInputFile);
BufferedReader brTravelDistances = IOUtils.getBufferedReader(ptTravelDistanceInputFile);
) {
log.info("Creating travel time OD matrix from VISUM pt stop 2 pt stop travel times file: " + ptTravelTimeInputFile);
final Map<Id<PtStop>, PtStop> ptStopsMap = PtMatrix.convertQuadTree2HashMap(ptStops);
FileUtils.fillODMatrix(originDestinationTravelTimeMatrix, ptStopsMap, brTravelTimes, true);
log.info("Done creating travel time OD matrix. " + originDestinationTravelTimeMatrix.toString());
log.info("Creating travel distance OD matrix from VISUM pt stop 2 pt stop travel distance file: " + ptTravelDistanceInputFile);
FileUtils.fillODMatrix(originDestinationTravelDistanceMatrix, ptStopsMap, brTravelDistances, false);
log.info("Done creating travel distance OD matrix. " + originDestinationTravelDistanceMatrix.toString());
} catch (IOException e) {
throw new RuntimeException(e);
}

log.info("Done creating OD matrices with pt stop to pt stop travel times and distances.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.api.io.TempDir;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.TransportMode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ void main(VehiclesSource vehiclesSource, boolean usingPersonIdForMissingVehicleI
config.qsim().setVehiclesSource(vehiclesSource );
config.qsim().setUsePersonIdForMissingVehicleId(usingPersonIdForMissingVehicleId );

config.controller().setOutputDirectory(helper.getOutputDirectory());
config.controller()
.setOutputDirectory(
helper.getOutputDirectory(vehiclesSource.name() + "_" + usingPersonIdForMissingVehicleId + "_" + providingVehiclesInPerson));
config.controller().setLastIteration(0);
config.controller().setWriteEventsInterval(1);
config.controller().setCreateGraphs(false);
Expand Down
23 changes: 6 additions & 17 deletions matsim/src/test/java/org/matsim/testcases/MatsimTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,6 @@ public final class MatsimTestUtils implements BeforeEachCallback, AfterEachCallb

private Class<?> testClass = null;
private String testMethodName = null;
private String testParameterSetIndex = null;

//captures the method name (group 1) and optionally the index of the parameter set (group 2; only if the test is parametrised)
//The matching may fail if the parameter set name does not start with {index} (at least one digit is required at the beginning)
private static final Pattern METHOD_PARAMETERS_WITH_INDEX_PATTERN = Pattern.compile(
"([\\S]*)(?:\\[(\\d+)[\\s\\S]*\\])?");


public MatsimTestUtils() {
MatsimRandom.reset();
Expand All @@ -95,13 +88,7 @@ public MatsimTestUtils() {
@Override
public void beforeEach(ExtensionContext extensionContext) {
this.testClass = extensionContext.getTestClass().orElseThrow();

Matcher matcher = METHOD_PARAMETERS_WITH_INDEX_PATTERN.matcher(extensionContext.getTestMethod().orElseThrow().getName());
if (!matcher.matches()) {
throw new RuntimeException("The name of the test parameter set must start with {index}");
}
this.testMethodName = matcher.group(1);
this.testParameterSetIndex = matcher.group(2); // null for non-parametrised tests
this.testMethodName = extensionContext.getRequiredTestMethod().getName();
}

@Override
Expand Down Expand Up @@ -232,10 +219,12 @@ private void createOutputDirectory() {
* @return path to the output directory for this test
*/
public String getOutputDirectory() {
return getOutputDirectory("");
}

public String getOutputDirectory(String subDir) {
if (this.outputDirectory == null) {
String subDirectoryForParametrisedTests = testParameterSetIndex == null ? "" : testParameterSetIndex + "/";
this.outputDirectory = "test/output/" + this.testClass.getCanonicalName().replace('.', '/') + "/" + getMethodName()+ "/"
+ subDirectoryForParametrisedTests;
this.outputDirectory = "test/output/" + this.testClass.getCanonicalName().replace('.', '/') + "/" + getMethodName()+ "/" + subDir;
}
createOutputDirectory();
return this.outputDirectory;
Expand Down

0 comments on commit d3e0716

Please sign in to comment.