Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MATSim #73

Merged
merged 41 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
0fab39a
refactored PHbyModeCalculator
paulheinr Nov 23, 2023
5508bf0
Merge branch 'master' into faster-mode-analysis
paulheinr Nov 24, 2023
c2ebc79
fix test
paulheinr Nov 24, 2023
ff5746f
refactored analysis of ph, pkm and trips/legs
paulheinr Dec 1, 2023
025af2a
refactored TravelDistanceStats
paulheinr Dec 1, 2023
651cac1
more flexibility to customise network skim calculation
manserpa Dec 1, 2023
6fe7a3c
removed every core dependency of isCreateGraph
paulheinr Dec 1, 2023
57cc8ec
removed all dependencies of isCreateGraph
paulheinr Dec 1, 2023
196f70e
adapted controller config group
paulheinr Dec 1, 2023
820ef8f
feat: add functionality to treat interaction activity in withinday re…
sebhoerl Dec 2, 2023
e31c73e
Merge branch 'master' into more-adaptable-network-skim-calculation
jfbischoff Dec 4, 2023
278194c
Merge pull request #2977 from manserpa/more-adaptable-network-skim-ca…
jfbischoff Dec 4, 2023
a0273f6
fix : handle spaces in comma-separated qsim config values (#2958)
Nitnelav Dec 4, 2023
339601a
build(deps): bump org.mockito:mockito-core from 5.7.0 to 5.8.0
dependabot[bot] Dec 4, 2023
2c17af4
Merge pull request #2981 from matsim-org/dependabot/maven/org.mockito…
michalmac Dec 4, 2023
bdb7adc
Drt estimator improvements (#2982)
rakow Dec 4, 2023
d5faa08
build(deps): bump org.apache.maven.plugins:maven-javadoc-plugin
dependabot[bot] Dec 4, 2023
69e13e7
Merge pull request #2980 from matsim-org/dependabot/maven/org.apache.…
michalmac Dec 4, 2023
7d727bb
build(deps): bump com.github.luben:zstd-jni from 1.5.5-10 to 1.5.5-11
dependabot[bot] Dec 4, 2023
e562584
Merge pull request #2979 from matsim-org/dependabot/maven/com.github.…
michalmac Dec 4, 2023
d2d15b9
build(deps): bump osmosis.version from 0.49.1 to 0.49.2
dependabot[bot] Dec 4, 2023
2356414
Merge pull request #2978 from matsim-org/dependabot/maven/osmosis.ver…
michalmac Dec 4, 2023
40b8947
allow orphan setters on config groups in order to provide backwards c…
paulheinr Dec 5, 2023
6f00e43
build(deps): bump org.checkerframework:checker-qual
dependabot[bot] Dec 5, 2023
6cfdc99
corrected TravelDistanceStats
paulheinr Dec 5, 2023
6eb0bf5
Merge branch 'master' into faster-mode-analysis
paulheinr Dec 5, 2023
20b43dc
Merge pull request #2983 from matsim-org/dependabot/maven/org.checker…
michalmac Dec 5, 2023
c092055
sharing factor and pooling rate for DRT
nkuehnel Dec 6, 2023
4390990
build(deps): bump io.grpc:grpc-all from 1.59.1 to 1.60.0
dependabot[bot] Dec 6, 2023
37fa78f
Merge pull request #2986 from matsim-org/dependabot/maven/io.grpc-grp…
michalmac Dec 6, 2023
0109267
build(deps): bump org.apache.httpcomponents.client5:httpclient5
dependabot[bot] Dec 6, 2023
a8cccff
Merge pull request #2985 from matsim-org/dependabot/maven/org.apache.…
michalmac Dec 6, 2023
401e802
Merge branch 'master' into drtSharingFactor
steffenaxer Dec 6, 2023
b489fd4
Merge branch 'master' into faster-mode-analysis
paulheinr Dec 7, 2023
fcd4f03
Merge pull request #2955 from matsim-org/faster-mode-analysis
paulheinr Dec 7, 2023
4f97de8
update sharing metrics code
nkuehnel Dec 7, 2023
d9c6d10
Merge branch 'master' into drtSharingFactor
nkuehnel Dec 7, 2023
3f46341
update to #2955
nkuehnel Dec 7, 2023
787e0bb
change file names from pooling stats to sharing metrics
nkuehnel Dec 7, 2023
7985778
Merge pull request #2984 from moia-oss/drtSharingFactor
nkuehnel Dec 7, 2023
739c036
Allow URLs to shape files on command line (#2987)
rakow Dec 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contribs/analysis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.3</version>
<version>5.3</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ScenarioOptions {
private String scenarioArgs;

@CommandLine.Option(names = "--population", description = "Path to input population")
private Path populationPath;
private String populationPath;

private Config config;

Expand All @@ -35,7 +35,7 @@ public Config getConfig() {
config = ConfigUtils.loadConfig(configPath);

if (populationPath != null)
config.plans().setInputFile(populationPath.toString());
config.plans().setInputFile(populationPath);
}

return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.data.shapefile.ShapefileDataStoreFactory;
import org.geotools.referencing.CRS;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.index.strtree.AbstractNode;
import org.locationtech.jts.index.strtree.Boundable;
import org.locationtech.jts.index.strtree.ItemBoundable;
Expand All @@ -20,20 +18,27 @@
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.core.utils.geometry.transformations.TransformationFactory;
import org.matsim.core.utils.gis.ShapeFileReader;
import org.matsim.core.utils.io.IOUtils;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.FactoryException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import javax.annotation.Nullable;
import picocli.CommandLine;

import javax.annotation.Nullable;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
* Reusable class for shape file options.
Expand All @@ -45,7 +50,7 @@ public final class ShpOptions {
private static final Logger log = LogManager.getLogger(ShpOptions.class);

@CommandLine.Option(names = "--shp", description = "Optional path to shape file used for filtering", required = false)
private Path shp;
private String shp;

@CommandLine.Option(names = "--shp-crs", description = "Overwrite coordinate system of the shape file")
private String shpCrs;
Expand All @@ -60,22 +65,72 @@ public ShpOptions() {
* Constructor to use shape options manually.
*/
public ShpOptions(Path shp, @Nullable String shpCrs, @Nullable Charset shpCharset) {
this.shp = shp == null ? null : shp.toString();
this.shpCrs = shpCrs;
this.shpCharset = shpCharset;
}

/**
* Constructor to use shape options manually.
*/
public ShpOptions(String shp, @Nullable String shpCrs, @Nullable Charset shpCharset) {
this.shp = shp;
this.shpCrs = shpCrs;
this.shpCharset = shpCharset;
}

/**
* Opens datastore to a shape-file.
*/
public static ShapefileDataStore openDataStore(String shp) throws IOException {

FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();

URL url = IOUtils.resolveFileOrResource(shp);

ShapefileDataStore ds;
if (shp.endsWith(".shp"))
ds = (ShapefileDataStore) factory.createDataStore(url);
else if (shp.endsWith(".zip")) {

// Zip files will only work with local files
URI uri;
try (ZipInputStream zip = new ZipInputStream(IOUtils.getInputStream(url))) {

ZipEntry entry;
while ((entry = zip.getNextEntry()) != null) {
if (entry.getName().endsWith(".shp"))
break;
}

if (entry == null)
throw new IllegalArgumentException("No .shp file found in the zip.");

log.info("Using {} from {}", entry.getName(), shp);
uri = new URI("jar:" + url + "!/" + entry.getName());
} catch (URISyntaxException e) {
throw new IllegalArgumentException("Could not create URI for zip file: " + url, e);
}

ds = (ShapefileDataStore) factory.createDataStore(uri.toURL());
} else {
throw new IllegalArgumentException("Shape file must either be .zip or .shp, but was: " + shp);
}

return ds;
}

/**
* Return whether a shape was set.
*/
public boolean isDefined() {
return shp != null && !shp.toString().isBlank() && !shp.toString().equals("none");
return shp != null && !shp.isBlank() && !shp.equals("none");
}

/**
* Get the provided input crs.
*/
public Path getShapeFile() {
public String getShapeFile() {
return shp;
}

Expand All @@ -94,8 +149,6 @@ public String getShapeCrs() {
public List<SimpleFeature> readFeatures() {
if (shp == null)
throw new IllegalStateException("Shape file path not specified");
if (!Files.exists(shp))
throw new IllegalStateException(String.format("Shape file %s does not exists", shp));

try {
ShapefileDataStore ds = openDataStore(shp);
Expand All @@ -108,57 +161,33 @@ public List<SimpleFeature> readFeatures() {
}
}

/**
* Opens datastore to a shape-file.
*/
public static ShapefileDataStore openDataStore(Path shp) throws IOException {

FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();

ShapefileDataStore ds;
if (shp.toString().endsWith(".shp"))
ds = (ShapefileDataStore) factory.createDataStore(shp.toUri().toURL());
else if (shp.toString().endsWith(".zip")) {

FileSystem fs = FileSystems.newFileSystem(shp, ClassLoader.getSystemClassLoader());
Optional<Path> match = Files.walk(fs.getPath("/"))
.filter(p -> p.toString().endsWith(".shp"))
.findFirst();

if (match.isEmpty())
throw new IllegalArgumentException("No .shp file found in the zip.");

log.info("Using {} from {}", match.get(), shp);
ds = (ShapefileDataStore) factory.createDataStore(match.get().toUri().toURL());
} else {
throw new IllegalArgumentException("Shape file must either be .zip or .shp, but was: " + shp);
}

return ds;
}

/**
* Return the union of all geometries in the shape file.
*/
public Geometry getGeometry() {

Collection<SimpleFeature> features = readFeatures();
if (features.size() < 1) {
if (features.isEmpty()) {
throw new IllegalStateException("There is no feature in the shape file. Aborting...");
}
Geometry geometry = (Geometry) features.iterator().next().getDefaultGeometry();
if (features.size() > 1) {
for (SimpleFeature simpleFeature : features) {
if (simpleFeature.getDefaultGeometry() == null) {
log.warn("Features {} has no geometry", simpleFeature);
continue;
}

Geometry subArea = (Geometry) simpleFeature.getDefaultGeometry();
geometry = geometry.union(subArea);
}
if (features.size() == 1) {
return (Geometry) features.iterator().next().getDefaultGeometry();
}

GeometryFactory factory = ((Geometry) features.iterator().next().getDefaultGeometry()).getFactory();

GeometryCollection geometryCollection = (GeometryCollection) factory.buildGeometry(
features.stream()
.filter(f -> f.getDefaultGeometry() != null)
.map(f -> (Geometry) f.getDefaultGeometry()).toList()
);

if (geometryCollection.isEmpty()) {
throw new IllegalStateException("There are noe geometries in the shape file.");
}
return geometry;

return geometryCollection.union();
}

/**
Expand All @@ -172,8 +201,6 @@ public Index createIndex(String queryCRS, String attr, Set<String> filter) {

if (!isDefined())
throw new IllegalStateException("Shape file path not specified");
if (!Files.exists(shp))
throw new IllegalStateException(String.format("Shape file %s does not exists", shp));
if (queryCRS == null)
throw new IllegalArgumentException("Query crs must not be null!");

Expand Down Expand Up @@ -242,8 +269,7 @@ public final class Index {
* @param ct coordinate transform from query to target crs
* @param attr attribute for the result of {@link #query(Coord)}
*/
Index(CoordinateTransformation ct, String attr, @Nullable Set<String> filter)
throws IOException {
Index(CoordinateTransformation ct, String attr, @Nullable Set<String> filter) throws IOException {
ShapefileDataStore ds = openDataStore(shp);

if (shpCharset != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,10 @@ public Integer call() throws Exception {
return 1;
}

if (shp.getShapeFile() == null) {
if (!shp.isDefined()) {
throw new IllegalArgumentException("Shape file must be given!");
}

if (!Files.exists(shp.getShapeFile())) {
log.error("Shape file {} does not exists", shp.getShapeFile());
return 1;
}

List<SimpleFeature> features = shp.readFeatures();

Map<String, SimpleFeature> map = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void main(String[] args) {
@Override
public Integer call() throws Exception {

SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, shp.getShapeFile(), crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor);
SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, Path.of(shp.getShapeFile()), crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor);

Network network = NetworkUtils.createNetwork();
Lanes lanes = LanesUtils.createLanesContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public Integer call() throws IOException, InvalidAttributeValueException, Execut

Collection<SimpleFeature> polygonsInShape = null;
shp = new ShpOptions(shapeFilePath, shapeCRS, null);
if (shp.getShapeFile() != null && Files.exists(shp.getShapeFile())) {
if (shp.isDefined()) {
log.warn("Use of shpFile. Locations for the carriers and the demand only in shp: " + shp.getShapeFile());
polygonsInShape = shp.readFeatures();
crsTransformationFromNetworkToShape = shp.createTransformation(networkCRS);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.matsim.application.options;

import org.junit.Assert;
import org.assertj.core.data.Offset;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -60,7 +60,7 @@ public void all() {
List<SimpleFeature> ft = index.getAll();

assertThat(ft)
.hasSize(578)
.hasSize(4906)
.hasSize(Set.copyOf(ft).size());

}
Expand All @@ -77,15 +77,9 @@ public void testGetGeometry() {

ShpOptions shp = new ShpOptions(input, null, null);
Geometry geometry = shp.getGeometry() ;
Geometry expectedGeometry = new GeometryFactory().createEmpty(2);

List<SimpleFeature> features = shp.readFeatures();
assertThat(geometry.getArea())
.isCloseTo(1.9847543618489646E-4, Offset.offset(1e-8));

for(SimpleFeature feature : features) {
Geometry geometryToJoin = (Geometry) feature.getDefaultGeometry();
expectedGeometry = expectedGeometry.union(geometryToJoin);
}

Assert.assertTrue(geometry.equals(expectedGeometry));
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void notifyIterationEnds(IterationEndsEvent event) {
}
}

if (this.matsimServices.getConfig().controller().isCreateGraphs()) {
int createGraphsInterval = this.matsimServices.getConfig().controller().getCreateGraphsInterval();
if (createGraphsInterval > 0 && event.getIteration() % createGraphsInterval == 0) {
DefaultTableXYDataset xyDataset = createXYDataset(times, profiles);
generateImage(xyDataset, TimeProfileCharts.ChartType.Line);
generateImage(xyDataset, TimeProfileCharts.ChartType.StackedArea);
Expand All @@ -103,7 +104,7 @@ private DefaultTableXYDataset createXYDataset(double[] times, Map<String, double
profiles.forEach((name, profile) -> {
XYSeries series = new XYSeries(name, true, false);
for (int i = 0; i < times.length; i++) {
series.add((double)times[i] / 3600, profile[i]);
series.add((double) times[i] / 3600, profile[i]);
}
seriesList.add(series);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,13 @@ public void notifyMobsimBeforeCleanup(@SuppressWarnings("rawtypes") MobsimBefore
}
}

for (ChartType t : chartTypes) {
generateImage(header, t);
int createGraphsInterval = matsimServices.getConfig().controller().getCreateGraphsInterval();
boolean createGraphs = createGraphsInterval >0 && matsimServices.getIterationNumber() % createGraphsInterval == 0;

if(createGraphs){
for (ChartType t : chartTypes) {
generateImage(header, t);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public double estimate(EstimatorContext context, String mode, Leg leg, ModeAvail

OptionalTime departureTime = leg.getDepartureTime();

DrtEstimator estimator = Objects.requireNonNull(estimators.get(mode), String.format("No drt estimator found for mode %s. Check warnings for errors.", mode));
DrtEstimator estimator = Objects.requireNonNull(estimators.get(mode), String.format("No drt estimator found for mode %s. Check log for errors.", mode));

DrtEstimator.Estimate est = estimator.estimate(route, departureTime);
ModeUtilityParameters params = context.scoring.modeParams.get(mode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public ShiftAnalysisControlerListener(Config config, DrtConfigGroup drtConfigGro

@Override
public void notifyIterationEnds(IterationEndsEvent event) {
boolean createGraphs = event.getServices().getConfig().controller().isCreateGraphs();
int createGraphsInterval = event.getServices().getConfig().controller().getCreateGraphsInterval();
boolean createGraphs = createGraphsInterval >0 && event.getIteration() % createGraphsInterval == 0;

writeAndPlotShiftDurationComparison(shiftDurationXY.getShift2plannedVsActualDuration(),
writeAndPlotShiftDurationComparison(shiftDurationXY.getShift2plannedVsActualDuration(),
filename(event, "shiftDurationComparison", ".png"),
filename(event, "shiftDurationComparison", ".csv"),
createGraphs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public void notifyIterationStarts(final IterationStartsEvent event) {
public void notifyIterationEnds(final IterationEndsEvent event) {
this.shiftHistogram.write(matsimServices.getControlerIO().getIterationFilename(event.getIteration(), drtConfigGroup.getMode() + "_" + "shiftHistogram.txt"));
this.printStats();
boolean createGraphs = event.getServices().getConfig().controller().isCreateGraphs();
int createGraphsInterval = event.getServices().getConfig().controller().getCreateGraphsInterval();
boolean createGraphs = createGraphsInterval >0 && event.getIteration() % createGraphsInterval == 0;

if (createGraphs) {
ShiftHistogramChart.writeGraphic(this.shiftHistogram, matsimServices.getControlerIO().getIterationFilename(event.getIteration(),drtConfigGroup.getMode() + "_" + "shiftHistogram.png"));
}
Expand Down
Loading