Skip to content

Commit

Permalink
Merge branch 'master' into h3
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel authored Mar 20, 2024
2 parents 9956761 + d93c98f commit 3efb8cb
Show file tree
Hide file tree
Showing 32 changed files with 602 additions and 375 deletions.
2 changes: 1 addition & 1 deletion contribs/hybridsim/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>hybridsim</name>

<properties>
<protobuf.version>3.25.3</protobuf.version>
<protobuf.version>4.26.0</protobuf.version>
<grpc.version>1.62.2</grpc.version>
</properties>

Expand Down
2 changes: 1 addition & 1 deletion contribs/protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<name>protobuf</name>

<properties>
<protobuf.version>3.25.3</protobuf.version>
<protobuf.version>4.26.0</protobuf.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,17 @@
import org.matsim.api.core.v01.population.Activity;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.ShpOptions;
import org.matsim.application.options.ShpOptions.Index;
import org.matsim.core.config.consistency.UnmaterializedConfigGroupChecker;
import org.matsim.core.gbl.MatsimRandom;
import org.matsim.core.scenario.ProjectionUtils;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.controler.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.freight.carriers.usecases.chessboard.CarrierTravelDisutilities;
import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.config.consistency.UnmaterializedConfigGroupChecker;
import org.matsim.core.config.groups.ControllerConfigGroup;
import org.matsim.core.config.groups.VspExperimentalConfigGroup;
import org.matsim.core.controler.AbstractModule;
import org.matsim.core.controler.Controler;
import org.matsim.core.controler.OutputDirectoryHierarchy;
import org.matsim.core.gbl.Gbl;
import org.matsim.core.gbl.MatsimRandom;
import org.matsim.core.network.NetworkUtils;
import org.matsim.core.population.routes.NetworkRoute;
import org.matsim.core.replanning.GenericPlanStrategyImpl;
Expand All @@ -64,10 +56,17 @@
import org.matsim.core.router.util.LeastCostPathCalculatorFactory;
import org.matsim.core.router.util.TravelDisutility;
import org.matsim.core.router.util.TravelTime;
import org.matsim.core.scenario.ProjectionUtils;
import org.matsim.core.scenario.ScenarioUtils;
import org.matsim.core.scoring.ScoringFunction;
import org.matsim.core.scoring.SumScoringFunction;
import org.matsim.core.utils.geometry.CoordUtils;
import org.matsim.core.utils.geometry.CoordinateTransformation;
import org.matsim.core.utils.geometry.geotools.MGC;
import org.matsim.freight.carriers.*;
import org.matsim.freight.carriers.CarrierCapabilities.FleetSize;
import org.matsim.freight.carriers.controler.*;
import org.matsim.freight.carriers.usecases.chessboard.CarrierTravelDisutilities;
import org.matsim.vehicles.CostInformation;
import org.matsim.vehicles.Vehicle;
import org.matsim.vehicles.VehicleType;
Expand All @@ -77,7 +76,6 @@

import java.io.File;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
Expand All @@ -101,6 +99,7 @@ public class GenerateSmallScaleCommercialTrafficDemand implements MATSimAppComma

// Option 3: Leerkamp (nur in RVR Modell).

// Option: Add prepare class with OSM Analyse and create facility file with results
private static final Logger log = LogManager.getLogger(GenerateSmallScaleCommercialTrafficDemand.class);

private enum CreationOption {
Expand All @@ -118,6 +117,12 @@ private enum SmallScaleCommercialTrafficType {
@CommandLine.Parameters(arity = "1", paramLabel = "INPUT", description = "Path to the config for small scale commercial generation")
private Path configPath;

@CommandLine.Option(names = "--pathToInvestigationAreaData", description = "Path to the investigation area data")
private Path pathToInvestigationAreaData;

@CommandLine.Option(names = "--pathToExistingDataDistributionToZones", description = "Path to the existing data distribution to zones. This is only needed if the option useExistingDataDistribution is selected.")
private Path pathToExistingDataDistributionToZones;

@CommandLine.Option(names = "--sample", description = "Scaling factor of the small scale commercial traffic (0, 1)", required = true)
private double sample;

Expand All @@ -136,15 +141,30 @@ private enum SmallScaleCommercialTrafficType {
@CommandLine.Option(names = "--includeExistingModels", description = "If models for some segments exist they can be included.")
private boolean includeExistingModels;

@CommandLine.Option(names = "--regionsShapeFileName", description = "Path of the region shape file.")
private Path shapeFileRegionsPath;

@CommandLine.Option(names = "--regionsShapeRegionColumn", description = "Name of the region column in the region shape file.")
private String regionsShapeRegionColumn;

@CommandLine.Option(names = "--zoneShapeFileName", description = "Path of the zone shape file.")
private Path shapeFileZonePath;

@CommandLine.Option(names = "--zoneShapeFileNameColumn", description = "Name of the unique column of the name/Id of each zone in the zones shape file.")
private String shapeFileZoneNameColumn;

@CommandLine.Option(names = "--buildingsShapeFileName", description = "Path of the buildings shape file")
private Path shapeFileBuildingsPath;

@CommandLine.Option(names = "--shapeFileBuildingTypeColumn", description = "Name of the unique column of the building type in the buildings shape file.")
private String shapeFileBuildingTypeColumn;

@CommandLine.Option(names = "--landuseShapeFileName", description = "Path of the landuse shape file")
private Path shapeFileLandusePath;

@CommandLine.Option(names = "--shapeFileLanduseTypeColumn", description = "Name of the unique column of the landuse type in the landuse shape file.")
private String shapeFileLanduseTypeColumn;

@CommandLine.Option(names = "--shapeCRS", description = "CRS of the three input shape files (zones, landuse, buildings")
private String shapeCRS;

Expand All @@ -170,6 +190,7 @@ private enum SmallScaleCommercialTrafficType {
private Index indexZones;
private Index indexBuildings;
private Index indexLanduse;
private Index indexInvestigationAreaRegions;

public static void main(String[] args) {
System.exit(new CommandLine(new GenerateSmallScaleCommercialTrafficDemand()).execute(args));
Expand Down Expand Up @@ -226,29 +247,32 @@ public Integer call() throws Exception {
if (!Files.exists(shapeFileZonePath)) {
throw new Exception("Required districts shape file {} not found" + shapeFileZonePath.toString());
}
Path inputDataDirectory = Path.of(config.getContext().toURI()).getParent();
if (!Files.exists(shapeFileRegionsPath)) {
throw new Exception("Required regions shape file {} not found" + shapeFileRegionsPath.toString());
}

indexZones = SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, shapeCRS);
indexBuildings = SmallScaleCommercialTrafficUtils.getIndexBuildings(shapeFileBuildingsPath, shapeCRS);
indexLanduse = SmallScaleCommercialTrafficUtils.getIndexLanduse(shapeFileLandusePath, shapeCRS);
indexZones = SmallScaleCommercialTrafficUtils.getIndexZones(shapeFileZonePath, shapeCRS, shapeFileZoneNameColumn);
indexBuildings = SmallScaleCommercialTrafficUtils.getIndexBuildings(shapeFileBuildingsPath, shapeCRS, shapeFileBuildingTypeColumn);
indexLanduse = SmallScaleCommercialTrafficUtils.getIndexLanduse(shapeFileLandusePath, shapeCRS, shapeFileLanduseTypeColumn);
indexInvestigationAreaRegions = SmallScaleCommercialTrafficUtils.getIndexRegions(shapeFileRegionsPath, shapeCRS, regionsShapeRegionColumn);

Map<String, Object2DoubleMap<String>> resultingDataPerZone = LanduseBuildingAnalysis
.createInputDataDistribution(output, landuseCategoriesAndDataConnection, inputDataDirectory,
.createInputDataDistribution(output, landuseCategoriesAndDataConnection,
usedLanduseConfiguration.toString(), indexLanduse, indexZones,
indexBuildings, buildingsPerZone);

Map<String, Map<Id<Link>, Link>> regionLinksMap = filterLinksForZones(scenario, indexZones, buildingsPerZone);
indexBuildings, indexInvestigationAreaRegions, shapeFileZoneNameColumn, buildingsPerZone, pathToInvestigationAreaData,
pathToExistingDataDistributionToZones);
Map<String, Map<Id<Link>, Link>> linksPerZone = filterLinksForZones(scenario, indexZones, buildingsPerZone);

switch (usedSmallScaleCommercialTrafficType) {
case commercialPersonTraffic, goodsTraffic ->
createCarriersAndDemand(output, scenario, resultingDataPerZone, regionLinksMap,
createCarriersAndDemand(output, scenario, resultingDataPerZone, linksPerZone,
usedSmallScaleCommercialTrafficType.toString(),
includeExistingModels);
case completeSmallScaleCommercialTraffic -> {
createCarriersAndDemand(output, scenario, resultingDataPerZone, regionLinksMap, "commercialPersonTraffic",
createCarriersAndDemand(output, scenario, resultingDataPerZone, linksPerZone, "commercialPersonTraffic",
includeExistingModels);
includeExistingModels = false; // because already included in the step before
createCarriersAndDemand(output, scenario, resultingDataPerZone, regionLinksMap, "goodsTraffic",
createCarriersAndDemand(output, scenario, resultingDataPerZone, linksPerZone, "goodsTraffic",
includeExistingModels);
}
default -> throw new RuntimeException("No traffic type selected.");
Expand All @@ -260,7 +284,7 @@ public Integer call() throws Exception {
new CarrierPlanWriter(CarriersUtils.addOrGetCarriers(scenario))
.write(scenario.getConfig().controller().getOutputDirectory() + "/"
+ scenario.getConfig().controller().getRunId() + ".output_CarrierDemand.xml");
solveSeparatedVRPs(scenario, regionLinksMap);
solveSeparatedVRPs(scenario, linksPerZone);
}
}
if (config.controller().getRunId() == null)
Expand Down Expand Up @@ -424,7 +448,7 @@ private void solveSeparatedVRPs(Scenario originalScenario, Map<String, Map<Id<Li

private void createCarriersAndDemand(Path output, Scenario scenario,
Map<String, Object2DoubleMap<String>> resultingDataPerZone,
Map<String, Map<Id<Link>, Link>> regionLinksMap, String smallScaleCommercialTrafficType,
Map<String, Map<Id<Link>, Link>> linksPerZone, String smallScaleCommercialTrafficType,
boolean includeExistingModels) throws Exception {

ArrayList<String> modesORvehTypes;
Expand All @@ -444,13 +468,13 @@ else if (smallScaleCommercialTrafficType.equals("commercialPersonTraffic"))
.createTrafficVolume_stop(resultingDataPerZone, output, sample, modesORvehTypes, smallScaleCommercialTrafficType);

if (includeExistingModels) {
SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, regionLinksMap);
TrafficVolumeGeneration.reduceDemandBasedOnExistingCarriers(scenario, regionLinksMap, smallScaleCommercialTrafficType,
SmallScaleCommercialTrafficUtils.readExistingModels(scenario, sample, linksPerZone);
TrafficVolumeGeneration.reduceDemandBasedOnExistingCarriers(scenario, linksPerZone, smallScaleCommercialTrafficType,
trafficVolumePerTypeAndZone_start, trafficVolumePerTypeAndZone_stop);
}
final TripDistributionMatrix odMatrix = createTripDistribution(trafficVolumePerTypeAndZone_start,
trafficVolumePerTypeAndZone_stop, smallScaleCommercialTrafficType, scenario, output, regionLinksMap);
createCarriers(scenario, odMatrix, resultingDataPerZone, smallScaleCommercialTrafficType, regionLinksMap);
trafficVolumePerTypeAndZone_stop, smallScaleCommercialTrafficType, scenario, output, linksPerZone);
createCarriers(scenario, odMatrix, resultingDataPerZone, smallScaleCommercialTrafficType, linksPerZone);
}

/**
Expand Down Expand Up @@ -970,7 +994,7 @@ private TripDistributionMatrix createTripDistribution(
Collections.shuffle(listOfZones, rnd);
for (String stopZone : listOfZones) {
odMatrix.setTripDistributionValue(startZone, stopZone, modeORvehType, purpose, smallScaleCommercialTrafficType,
network, regionLinksMap, resistanceFactor);
network, regionLinksMap, resistanceFactor, shapeFileZoneNameColumn);
}
}
}
Expand Down
Loading

0 comments on commit 3efb8cb

Please sign in to comment.