Skip to content

Commit

Permalink
chore: update MATSim version (#257)
Browse files Browse the repository at this point in the history
* chore: update MATSim version
  • Loading branch information
tkchouaki authored Sep 18, 2024
1 parent ea96dd7 commit ed29048
Show file tree
Hide file tree
Showing 24 changed files with 97 additions and 77 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:

steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21
- name: Build with Maven
run: mvn test -B -Dmatsim.preferLocalDtds=true
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.commons.lang3.ArrayUtils;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
import org.geotools.api.feature.simple.SimpleFeature;
import org.locationtech.jts.geom.Geometry;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.emissions.analysis.EmissionGridAnalyzer;
Expand All @@ -14,7 +15,6 @@
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.io.MatsimNetworkReader;
import org.matsim.core.utils.gis.ShapeFileReader;
import org.opengis.feature.simple.SimpleFeature;

public class RunComputeEmissionsGrid {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.apache.commons.lang3.ArrayUtils;
import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
import org.geotools.api.feature.simple.SimpleFeature;
import org.locationtech.jts.geom.Coordinate;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
Expand All @@ -30,7 +31,6 @@
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.core.utils.gis.PolylineFeatureFactory;
import org.matsim.core.utils.gis.ShapeFileWriter;
import org.opengis.feature.simple.SimpleFeature;

public class RunExportEmissionsNetwork {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,22 @@
import org.matsim.core.population.io.PopulationReader;
import org.matsim.core.population.io.PopulationWriter;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.vehicles.MatsimVehicleWriter;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleUtils;
import org.matsim.vehicles.Vehicles;
import org.matsim.vehicles.VehiclesFactory;
import org.matsim.vehicles.*;

public class RunInsertVehicles {

static public void insertVehicles(Config config, Scenario scenario) {
Vehicles vehicles = scenario.getVehicles();
VehiclesFactory factory = vehicles.getFactory();

vehicles.addVehicleType(VehicleUtils.getDefaultVehicleType());
VehicleType vehicleType = VehicleUtils.createVehicleType(Id.create("defaultVehicleType", VehicleType.class));
vehicles.addVehicleType(vehicleType);
for (Person person : scenario.getPopulation().getPersons().values()) {
Map<String, Id<Vehicle>> personVehicles = new HashMap<>();

for (String mode : config.routing().getNetworkModes()) {
Vehicle vehicle = factory.createVehicle(Id.createVehicleId(person.getId().toString() + ":" + mode),
VehicleUtils.getDefaultVehicleType());
vehicleType);
vehicles.addVehicle(vehicle);

personVehicles.put(mode, vehicle.getId());
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/eqasim/core/scenario/SpatialUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import java.util.LinkedList;
import java.util.List;

import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.api.data.DataStore;
import org.geotools.api.data.DataStoreFinder;
import org.geotools.api.data.SimpleFeatureSource;
import org.geotools.api.feature.simple.SimpleFeature;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureSource;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.MultiPolygon;
import org.locationtech.jts.geom.Polygon;
import org.opengis.feature.simple.SimpleFeature;

public class SpatialUtils {
static public Polygon loadPolygon(URL url, String attribute, String value) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eqasim.core.simulation.mode_choice.AbstractEqasimExtension;
import org.eqasim.core.simulation.termination.EqasimTerminationModule;
import org.matsim.api.core.v01.Scenario;
import org.matsim.contribs.discrete_mode_choice.modules.DiscreteModeChoiceModule;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.CommandLine.ConfigurationException;
import org.matsim.core.config.Config;
Expand Down Expand Up @@ -111,7 +112,7 @@ static public void main(String[] args) throws ConfigurationException, IOExceptio
// Cut population
Injector populationCutterInjector = new InjectorBuilder(scenario) //
.addOverridingModules(configurator.getModules().stream()
.filter(module -> !(module instanceof AbstractEqasimExtension)).toList()) //
.filter(module -> !(module instanceof AbstractEqasimExtension) && !(module instanceof DiscreteModeChoiceModule)).toList()) //
.addOverridingModule(
new PopulationCutterModule(extent, numberOfThreads, 40, cmd.getOption("events-path"))) //
.addOverridingModule(new CutterTravelTimeModule(travelTime)) //
Expand Down Expand Up @@ -169,7 +170,7 @@ static public void main(String[] args) throws ConfigurationException, IOExceptio
// Final routing
Injector routingInjector = new InjectorBuilder(scenario) //
.addOverridingModules(configurator.getModules().stream()
.filter(module -> !(module instanceof AbstractEqasimExtension)).toList()) //
.filter(module -> !(module instanceof AbstractEqasimExtension) && !(module instanceof DiscreteModeChoiceModule)).toList()) //
.addOverridingModule(new PopulationRouterModule(numberOfThreads, 100, false)) //
.addOverridingModule(new CutterTravelTimeModule(travelTime)) //
.addOverridingModule(new TimeInterpretationModule()) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import java.util.List;
import java.util.Optional;

import org.geotools.data.DataStore;
import org.geotools.data.DataStoreFinder;
import org.geotools.api.data.DataStore;
import org.geotools.api.data.DataStoreFinder;
import org.geotools.api.data.SimpleFeatureReader;
import org.geotools.api.data.SimpleFeatureSource;
import org.geotools.api.feature.simple.SimpleFeature;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureReader;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.geopkg.FeatureEntry;
import org.geotools.geopkg.GeoPackage;
import org.locationtech.jts.geom.Coordinate;
Expand All @@ -25,7 +26,6 @@
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import org.matsim.api.core.v01.Coord;
import org.opengis.feature.simple.SimpleFeature;

public class ShapeScenarioExtent implements ScenarioExtent {
private final GeometryFactory factory = new GeometryFactory();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.eqasim.core.simulation.modes.drt.utils;

import java.io.File;
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.eqasim.core.components.config.EqasimConfigGroup;
import org.eqasim.core.misc.ClassUtils;
Expand All @@ -17,7 +14,9 @@
import org.eqasim.core.simulation.mode_choice.constraints.leg_time.LegTimeConstraintConfigGroup;
import org.eqasim.core.simulation.mode_choice.constraints.leg_time.LegTimeConstraintModule;
import org.eqasim.core.simulation.mode_choice.constraints.leg_time.LegTimeConstraintSingleLegConfigGroup;
import org.matsim.contrib.drt.analysis.zonal.DrtZonalSystemParams;
import org.matsim.contrib.common.zones.systems.grid.square.SquareGridZoneSystemParams;
import org.matsim.contrib.drt.analysis.zonal.DrtZoneSystemParams;
import org.matsim.contrib.drt.optimizer.constraints.DefaultDrtOptimizationConstraintsSet;
import org.matsim.contrib.drt.optimizer.insertion.DrtInsertionSearchParams;
import org.matsim.contrib.drt.optimizer.insertion.extensive.ExtensiveInsertionSearchParams;
import org.matsim.contrib.drt.optimizer.rebalancing.RebalancingParams;
Expand All @@ -40,7 +39,7 @@

public class AdaptConfigForDrt {

public static void adapt(Config config, Map<String, String> vehiclesPathByDrtMode, Map<String, String> operationalSchemes, Map<String, String> drtUtilityEstimators, Map<String, String> drtCostModels, Map<String, String> addLegTimeConstraint, String qsimEndtime, String modeAvailability) throws MalformedURLException {
public static void adapt(Config config, Map<String, String> vehiclesPathByDrtMode, Map<String, String> operationalSchemes, Map<String, String> drtUtilityEstimators, Map<String, String> drtCostModels, Map<String, String> addLegTimeConstraint, String qsimEndtime, String modeAvailability) {
if(!config.getModules().containsKey(DvrpConfigGroup.GROUP_NAME)) {
config.addModule(new DvrpConfigGroup());
}
Expand Down Expand Up @@ -69,25 +68,27 @@ public static void adapt(Config config, Map<String, String> vehiclesPathByDrtMod
drtConfigGroup.mode = drtMode;
drtConfigGroup.operationalScheme = DrtConfigGroup.OperationalScheme.valueOf(operationalSchemes.get(drtMode));
drtConfigGroup.stopDuration = 15.0;
drtConfigGroup.maxWaitTime = 600;
drtConfigGroup.maxTravelTimeAlpha = 1.5;
drtConfigGroup.maxTravelTimeBeta = 300.0;
DefaultDrtOptimizationConstraintsSet defaultDrtOptimizationConstraintsSet = (DefaultDrtOptimizationConstraintsSet) drtConfigGroup.addOrGetDrtOptimizationConstraintsParams().addOrGetDefaultDrtOptimizationConstraintsSet();
defaultDrtOptimizationConstraintsSet.maxWaitTime = 600;
defaultDrtOptimizationConstraintsSet.maxTravelTimeAlpha= 1.5;
defaultDrtOptimizationConstraintsSet.maxTravelTimeBeta = 300.0;
drtConfigGroup.vehiclesFile = vehiclesPathByDrtMode.get(drtMode);

DrtInsertionSearchParams searchParams = new ExtensiveInsertionSearchParams();
drtConfigGroup.addDrtInsertionSearchParams(searchParams);
drtConfigGroup.setDrtInsertionSearchParams(searchParams);

RebalancingParams rebalancingParams = new RebalancingParams();
rebalancingParams.interval =1800;
rebalancingParams.addParameterSet(new PlusOneRebalancingStrategyParams());
drtConfigGroup.addParameterSet(rebalancingParams);

DrtZonalSystemParams drtZonalSystemParams = new DrtZonalSystemParams();
drtZonalSystemParams.zonesGeneration = DrtZonalSystemParams.ZoneGeneration.GridFromNetwork;
drtZonalSystemParams.cellSize = 500.0;
drtZonalSystemParams.targetLinkSelection = DrtZonalSystemParams.TargetLinkSelection.mostCentral;
drtConfigGroup.addParameterSet(drtZonalSystemParams);
DrtZoneSystemParams drtZonalSystemParams = new DrtZoneSystemParams();
drtZonalSystemParams.targetLinkSelection = DrtZoneSystemParams.TargetLinkSelection.mostCentral;
SquareGridZoneSystemParams squareGridZoneSystemParams = new SquareGridZoneSystemParams();
squareGridZoneSystemParams.cellSize = 500;

drtZonalSystemParams.addParameterSet(squareGridZoneSystemParams);
drtConfigGroup.addParameterSet(drtZonalSystemParams);
multiModeDrtConfigGroup.addParameterSet(drtConfigGroup);

// Set up choice model
Expand Down Expand Up @@ -146,7 +147,7 @@ public static Map<String, Map<String, String>> extractDrtInfo(String[] drtModeNa
Map<String, String> resultingMap;

if(drtModeNames.length == currentElements.length) {
resultingMap = IntStream.range(0, drtModeNames.length).boxed().collect(Collectors.toMap(integer -> drtModeNames[integer], (Function<Integer, String>) integer -> currentElements[integer]));
resultingMap = IntStream.range(0, drtModeNames.length).boxed().collect(Collectors.toMap(integer -> drtModeNames[integer], integer -> currentElements[integer]));
} else {
if(currentElements.length != 1) {
throw new IllegalStateException(String.format("When the number of provided drt mode names is not equal to the number of provided %s," +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import jakarta.validation.constraints.NotNull;
import org.eqasim.core.simulation.modes.feeder_drt.router.access_egress_selector.ClosestAccessEgressStopSelectorParameterSet;
import org.matsim.contrib.util.ReflectiveConfigGroupWithConfigurableParameterSets;
import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets;
import org.matsim.core.config.ReflectiveConfigGroup;

public class AccessEgressStopSelectorParams extends ReflectiveConfigGroupWithConfigurableParameterSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.matsim.contrib.common.util.ReflectiveConfigGroupWithConfigurableParameterSets;
import org.matsim.contrib.dvrp.run.Modal;
import org.matsim.contrib.util.ReflectiveConfigGroupWithConfigurableParameterSets;

public class FeederDrtConfigGroup extends ReflectiveConfigGroupWithConfigurableParameterSets implements Modal {
public static final String GROUP_NAME = "feederDrt";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import org.eqasim.core.simulation.modes.transit_with_abstract_access.abstract_access.AbstractAccessItem;
import org.eqasim.core.simulation.modes.transit_with_abstract_access.abstract_access.AbstractAccessesFileReader;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.CommandLine;
import org.matsim.core.config.Config;
Expand All @@ -12,8 +13,7 @@
import org.matsim.core.utils.gis.PointFeatureFactory;
import org.matsim.core.utils.gis.ShapeFileWriter;
import org.matsim.pt.transitSchedule.api.TransitScheduleReader;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;

import java.util.Collection;
import java.util.LinkedList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.eqasim.core.tools;

import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.locationtech.jts.geom.Coordinate;
import org.matsim.api.core.v01.Scenario;
import org.matsim.api.core.v01.population.Activity;
Expand All @@ -13,8 +14,7 @@
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.core.utils.gis.PointFeatureFactory;
import org.matsim.core.utils.gis.ShapeFileWriter;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;

import java.util.*;
import java.util.stream.Collectors;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.eqasim.core.misc.ClassUtils;
import org.eqasim.core.simulation.EqasimConfigurator;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
Expand All @@ -25,9 +26,8 @@
import org.matsim.core.router.TripStructureUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.utils.geometry.geotools.MGC;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;
import org.geotools.api.feature.simple.SimpleFeatureType;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.HashSet;
import java.util.LinkedList;

import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.geotools.feature.DefaultFeatureCollection;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
Expand All @@ -20,9 +21,8 @@
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.io.MatsimNetworkReader;
import org.matsim.core.utils.geometry.geotools.MGC;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;
import org.geotools.api.feature.simple.SimpleFeatureType;

public class ExportNetworkToGeopackage {
public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.HashSet;
import java.util.LinkedList;

import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.locationtech.jts.geom.Coordinate;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
Expand All @@ -14,8 +15,7 @@
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.core.utils.gis.PolylineFeatureFactory;
import org.matsim.core.utils.gis.ShapeFileWriter;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;

public class ExportNetworkToShapefile {
public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.stream.Collectors;

import org.apache.commons.lang3.BooleanUtils;
import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.locationtech.jts.geom.Coordinate;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.IdSet;
Expand All @@ -22,8 +23,7 @@
import org.matsim.pt.transitSchedule.api.TransitLine;
import org.matsim.pt.transitSchedule.api.TransitRoute;
import org.matsim.pt.transitSchedule.api.TransitScheduleReader;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;

public class ExportTransitLinesToShapefile {
public static void main(String[] args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Collection;
import java.util.LinkedList;

import org.geotools.api.referencing.crs.CoordinateReferenceSystem;
import org.locationtech.jts.geom.Coordinate;
import org.matsim.api.core.v01.Scenario;
import org.matsim.core.config.CommandLine;
Expand All @@ -14,8 +15,7 @@
import org.matsim.core.utils.gis.ShapeFileWriter;
import org.matsim.pt.transitSchedule.api.TransitScheduleReader;
import org.matsim.pt.transitSchedule.api.TransitStopFacility;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.geotools.api.feature.simple.SimpleFeature;

public class ExportTransitStopsToShapefile {
public static void main(String[] args) throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion core/src/test/java/org/eqasim/TestEmissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
import org.matsim.vehicles.Vehicles;
import org.opengis.feature.simple.SimpleFeature;
import org.geotools.api.feature.simple.SimpleFeature;

public class TestEmissions {

Expand Down
Loading

0 comments on commit ed29048

Please sign in to comment.