Skip to content

Commit

Permalink
update matsim to most recent version, adapted API
Browse files Browse the repository at this point in the history
  • Loading branch information
xinxin-git committed Oct 17, 2023
1 parent 6b20a9b commit 6fb3020
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 40 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>matsim-all</artifactId>

<!-- PR-labelled release -->
<version>16.0-PR2750</version>
<version>16.0-PR2878</version>

<!-- snapshot == not recommended: rather use PR-labelled release!-->
<!-- <version>16.0-SNAPSHOT</matsim.version>-->
Expand Down Expand Up @@ -181,13 +181,13 @@
<dependency>
<groupId>one.util</groupId>
<artifactId>streamex</artifactId>
<version>0.8.1</version>
<version>0.8.2</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>2.13.0</version>
</dependency>

</dependencies>
Expand Down
25 changes: 12 additions & 13 deletions src/main/java/org/matsim/analysis/PotentialServiceAreaAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.network.Node;
import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.freight.carrier.*;
import org.matsim.contrib.freight.controler.FreightUtils;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.network.algorithms.TransportModeNetworkFilter;
import org.matsim.core.population.routes.NetworkRoute;
import org.matsim.core.router.FastAStarLandmarksFactory;
import org.matsim.core.router.speedy.SpeedyALTFactory;
import org.matsim.core.router.util.LeastCostPathCalculator;
import org.matsim.core.router.util.TravelDisutility;
import org.matsim.core.scenario.ScenarioUtils;
Expand All @@ -54,6 +52,7 @@
import org.matsim.core.utils.geometry.transformations.TransformationFactory;
import org.matsim.core.utils.gis.ShapeFileReader;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.freight.carriers.*;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
import org.matsim.vehicles.VehicleUtils;
Expand Down Expand Up @@ -130,7 +129,7 @@ public static void main(String[] args) {

private static void writeStats(Network network, Map<String, PreparedGeometry> serviceAreas, Map<PreparedGeometry, Collection<Stop>> area2Stops, Carriers carriers, Map<Tuple<Id<Stop>, Id<Stop>>, Integer> relations) {
String outputFileName = INPUT_SERVICE_AREAS_SHAPE.substring(0, INPUT_SERVICE_AREAS_SHAPE.lastIndexOf(".")) + "_stats.csv";
LeastCostPathCalculator router = new FastAStarLandmarksFactory(4).createPathCalculator(network, new TravelDisutility() {
LeastCostPathCalculator router = new SpeedyALTFactory().createPathCalculator(network, new TravelDisutility() {
@Override
public double getLinkTravelDisutility(Link link, double time, Person person, Vehicle vehicle) {
return link.getLength();
Expand Down Expand Up @@ -211,23 +210,23 @@ private static double getLongestRouteDistanceBetweenStops(Collection<Stop> stops
@SuppressWarnings("IllegalCatch")
private static Carriers getCarriersWithPlannedRoundTours(Network network, Map<String, PreparedGeometry> serviceAreas, Map<PreparedGeometry, Collection<Stop>> area2Stops) {
Config config = ConfigUtils.createConfig();
config.controler().setLastIteration(0);
config.controller().setLastIteration(0);
config.network().setInputFile(INPUT_NETWORK);
config.controler().setOutputDirectory("D:/KelRide-test/testServiceAreaTours/");
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);
config.controller().setOutputDirectory("D:/KelRide-test/testServiceAreaTours/");
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);

Scenario scenario = ScenarioUtils.loadScenario(config);

//container
Carriers carriers = FreightUtils.addOrGetCarriers(scenario);
Carriers carriers = CarriersUtils.addOrGetCarriers(scenario);
VehicleType type = createVehicleType();
FreightUtils.getCarrierVehicleTypes(scenario).getVehicleTypes().put(type.getId(), type);
CarriersUtils.getCarrierVehicleTypes(scenario).getVehicleTypes().put(type.getId(), type);

//iterate over service areas and create carrier
serviceAreas.forEach((areaName, geom) -> carriers.addCarrier(buildCarrier(areaName, area2Stops.get(geom), network, type)));

try {
FreightUtils.runJsprit(scenario);
CarriersUtils.runJsprit(scenario);
} catch (Exception e) {
log.error(e);
}
Expand Down Expand Up @@ -281,9 +280,9 @@ private static boolean isLinkInsideGeom(Link l, PreparedGeometry geom) {

private static Carrier buildCarrier(String areaName, Collection<Stop> stops, Network network, VehicleType vehicleType) {
//carrier
Carrier carrier = CarrierUtils.createCarrier(Id.create(areaName, Carrier.class));
CarrierUtils.setCarrierMode(carrier, TransportMode.car);
CarrierUtils.setJspritIterations(carrier, 10000);
Carrier carrier = CarriersUtils.createCarrier(Id.create(areaName, Carrier.class));
CarriersUtils.setCarrierMode(carrier, TransportMode.car);
CarriersUtils.setJspritIterations(carrier, 10000);
//we will specify one vehicle and only want one tour
carrier.getCarrierCapabilities().setFleetSize(CarrierCapabilities.FleetSize.FINITE);
carrier.getCarrierCapabilities().getVehicleTypes().add(vehicleType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ private Config prepareConfig() {
config.transit().setVehiclesFile( runDirectory + runId + ".output_transitVehicles.xml.gz");
config.global().setCoordinateSystem("EPSG:25832");
config.plans().setInputFile(null);
config.parallelEventHandling().setNumberOfThreads(null);
config.parallelEventHandling().setEstimatedNumberOfEvents(null);
config.eventsManager().setNumberOfThreads(null);
config.eventsManager().setEstimatedNumberOfEvents(null);
config.global().setNumberOfThreads(1);

EmissionsConfigGroup eConfig = ConfigUtils.addOrGetModule(config, EmissionsConfigGroup.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public Integer call() throws Exception {
}

Config config = ConfigUtils.loadConfig(configPath.toString(), new MultiModeDrtConfigGroup(DrtWithExtensionsConfigGroup::new));
int lastIteration = config.controler().getLastIteration();
String runId = config.controler().getRunId();
int lastIteration = config.controller().getLastIteration();
String runId = config.controller().getRunId();
Path folderOfLastIteration = Path.of(directory.toString() + "/ITERS/it." + lastIteration);
MultiModeDrtConfigGroup multiModeDrtConfigGroup = ConfigUtils.addOrGetModule(config, MultiModeDrtConfigGroup.class);
List<String> modes = new ArrayList<>();
Expand All @@ -99,7 +99,7 @@ public Integer call() throws Exception {
network = NetworkUtils.readNetwork(networkPath.toString());
travelTime = TrafficAnalysis.analyzeTravelTimeFromEvents(network, eventPath.toString());

config.plansCalcRoute().setRoutingRandomness(0);
config.routing().setRoutingRandomness(0);
TravelDisutility travelDisutility = new RandomizingTimeDistanceTravelDisutilityFactory(TransportMode.car, config)
.createTravelDisutility(travelTime);
router = new SpeedyALTFactory().
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/matsim/run/KelheimPtFareModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class KelheimPtFareModule extends AbstractModule {
@Override
public void install() {
// Set the money related thing in the config (planCalcScore) file to 0.
getConfig().planCalcScore().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0);
getConfig().planCalcScore().getModes().get(TransportMode.pt).setMarginalUtilityOfDistance(0);
getConfig().scoring().getModes().get(TransportMode.pt).setDailyMonetaryConstant(0);
getConfig().scoring().getModes().get(TransportMode.pt).setMarginalUtilityOfDistance(0);

// Initialize config group (and also write in the output config)
PtFareConfigGroup ptFareConfigGroup = ConfigUtils.addOrGetModule(this.getConfig(), PtFareConfigGroup.class);
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/matsim/run/RunKelheimRealDrtDemands.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.matsim.contrib.dvrp.run.DvrpQSimComponents;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.VspExperimentalConfigGroup;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
Expand Down Expand Up @@ -59,17 +59,17 @@ public Integer call() throws Exception {
config.plans().setInputFile("./real-drt-demands/" + date + "-drt.plans.xml");
log.info("Setting input plans file to: " + config.plans().getInputFile());

String outputDirectory = Path.of(config.controler().getOutputDirectory()).getParent().toString() + "/" + date;
config.controler().setOutputDirectory(outputDirectory);
log.info("Setting output directory to: " + config.controler().getOutputDirectory());
String outputDirectory = Path.of(config.controller().getOutputDirectory()).getParent().toString() + "/" + date;
config.controller().setOutputDirectory(outputDirectory);
log.info("Setting output directory to: " + config.controller().getOutputDirectory());

config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.info);
config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink);
config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink);
if (!networkChangeEventsFile.equals("")) {
config.network().setTimeVariantNetwork(true);
config.network().setChangeEventsInputFile(networkChangeEventsFile);
}
config.controler()
config.controller()
.setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.overwriteExistingFiles);

Scenario scenario = DrtControlerCreator.createScenarioWithDrtRouteFactory(config);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/matsim/run/RunKelheimScenario.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.groups.PlansCalcRouteConfigGroup;
import org.matsim.core.config.groups.RoutingConfigGroup;
import org.matsim.core.config.groups.VspExperimentalConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
Expand Down Expand Up @@ -146,15 +146,15 @@ protected Config prepareConfig(Config config) {

SnzActivities.addScoringParams(config);

config.controler().setOutputDirectory(sample.adjustName(config.controler().getOutputDirectory()));
config.controller().setOutputDirectory(sample.adjustName(config.controller().getOutputDirectory()));
config.plans().setInputFile(sample.adjustName(config.plans().getInputFile()));
config.controler().setRunId(sample.adjustName(config.controler().getRunId()));
config.controller().setRunId(sample.adjustName(config.controller().getRunId()));

config.qsim().setFlowCapFactor(sample.getSize() / 100.0);
config.qsim().setStorageCapFactor(sample.getSize() / 100.0);

config.vspExperimental().setVspDefaultsCheckingLevel(VspExperimentalConfigGroup.VspDefaultsCheckingLevel.abort);
config.plansCalcRoute().setAccessEgressType(PlansCalcRouteConfigGroup.AccessEgressType.accessEgressModeToLink);
config.routing().setAccessEgressType(RoutingConfigGroup.AccessEgressType.accessEgressModeToLink);

config.global().setRandomSeed(randomSeed);

Expand Down Expand Up @@ -184,7 +184,7 @@ protected Config prepareConfig(Config config) {
}

ConfigUtils.addOrGetModule(config, DvrpConfigGroup.class);
DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfig, config.planCalcScore(), config.plansCalcRoute());
DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfig, config.scoring(), config.routing());
}

// Config is always needed
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/matsim/run/prepare/DrtStopsWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.core.utils.io.IOUtils;
import org.matsim.core.utils.io.MatsimXmlWriter;
import org.matsim.core.utils.io.UncheckedIOException;
import org.matsim.run.RunKelheimScenario;
import org.opengis.feature.simple.SimpleFeature;

Expand Down Expand Up @@ -65,7 +64,7 @@ public final class DrtStopsWriter extends MatsimXmlWriter {
/**
* Write content to specified folder.
*/
public void write() throws UncheckedIOException, IOException {
public void write() throws IOException {
this.openFile(outputFolder + "/" + mode + "-stops.xml");
this.writeXmlHead();
this.writeDoctype("transitSchedule", "http://www.matsim.org/files/dtd/transitSchedule_v1.dtd");
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/org/matsim/run/RunKelheimIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class RunKelheimIntegrationTest {
@Test
public final void runExamplePopulationTest() {
Config config = ConfigUtils.loadConfig("input/test.config.xml");
config.controler().setLastIteration(1);
config.controller().setLastIteration(1);
config.global().setNumberOfThreads(1);
config.qsim().setNumberOfThreads(1);
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);

ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

Expand All @@ -30,8 +30,8 @@ public final void runExamplePopulationTest() {
@Test
public final void runDrtExamplePopulationTest() {
Config config = ConfigUtils.loadConfig("input/test.with-drt.config.xml");
config.controler().setLastIteration(1);
config.controler().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);
config.controller().setLastIteration(1);
config.controller().setOverwriteFileSetting(OutputDirectoryHierarchy.OverwriteFileSetting.deleteDirectoryIfExists);

ConfigUtils.addOrGetModule(config, SimWrapperConfigGroup.class).defaultDashboards = SimWrapperConfigGroup.Mode.disabled;

Expand Down

0 comments on commit 6fb3020

Please sign in to comment.