Skip to content

Commit

Permalink
Merge branch 'master' into feat/raptor-transport-mode-utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbischoff authored Mar 18, 2024
2 parents ac875ac + 9ddb2e3 commit 2791bba
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ public static void main(String[] args) {
@Override
public Integer call() throws Exception {

SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, Path.of(shp.getShapeFile()), crs.getInputCRS(), crs.getTargetCRS(), freeSpeedFactor);
// since ShpOptions.getShapeFile() no longer is a path but a string, we have to check if it is defined before creating SumoNetworkConverter to
// preserve the possibility to run the converter without a shp file, otherwise, when calling Path.of(shp.getShapeFile) a NullPointerException is caused -sme0324
Path path = null;

if (shp.isDefined()) {
path = Path.of(shp.getShapeFile());
}

SumoNetworkConverter converter = SumoNetworkConverter.newInstance(input, output, path, 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 @@ -15,6 +15,7 @@
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.api.core.v01.population.Leg;
import org.matsim.api.core.v01.population.Person;
import org.matsim.contrib.dynagent.DynAgent;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.core.controler.MatsimServices;
Expand Down Expand Up @@ -94,22 +95,25 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> linkId) {
Leg currentLeg = (Leg) planAgent.getCurrentPlanElement();
Gbl.assertIf(this.fissConfigGroup.sampledModes.contains(currentLeg.getMode()));
NetworkRoute networkRoute = (NetworkRoute) currentLeg.getRoute();
Person person = planAgent.getCurrentPlan().getPerson();
Vehicle vehicle = this.matsimServices.getScenario().getVehicles().getVehicles()
.get(networkRoute.getVehicleId());

// update travel time with travel times of last iteration
double newTravelTime = 0.0;
// start and end link are not consideres in NetworkRoutingModule for travel time
// start and end link are not considered in NetworkRoutingModule for travel time
for (Id<Link> routeLinkId : networkRoute.getLinkIds()) {
newTravelTime += this.travelTime.getLinkTravelTime(network.getLinks().get(routeLinkId),
now + newTravelTime, null, null);
now + newTravelTime, person, vehicle);
}
LOG.debug("New travelTime: {}, was {}", newTravelTime,
networkRoute.getTravelTime().orElseGet(() -> Double.NaN));
networkRoute.setTravelTime(newTravelTime);
}
// remove vehicle of teleported agent from parking spot
QVehicle removedVehicle = null;
if (agent instanceof MobsimDriverAgent) {
Id<Vehicle> vehicleId = ((MobsimDriverAgent) agent).getPlannedVehicleId();
if (agent instanceof MobsimDriverAgent driverAgent) {
Id<Vehicle> vehicleId = driverAgent.getPlannedVehicleId();
QVehicle vehicle = qNetsimEngine.getVehicles().get(vehicleId);
QLinkI qLinkI = (QLinkI) this.qNetsimEngine.getNetsimNetwork().getNetsimLink(linkId);
removedVehicle = qLinkI.removeParkedVehicle(vehicleId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.*;

import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -159,10 +153,12 @@ private Map<String, DescriptiveStatistics> createZonalStats() {
public void notifyShutdown(ShutdownEvent event) {
String crs = event.getServices().getConfig().global().getCoordinateSystem();
Collection<SimpleFeature> features = convertGeometriesToSimpleFeatures(crs);
String fileName = event.getServices()
if(!features.isEmpty()) {
String fileName = event.getServices()
.getControlerIO()
.getOutputFilename("drt_waitStats" + "_" + drtCfg.getMode() + "_zonal.shp");
GeoFileWriter.writeGeometries(features, fileName);
.getOutputFilename("drt_waitStats" + "_" + drtCfg.getMode() + "_zonal.gpkg");
GeoFileWriter.writeGeometries(features, fileName);
}
}

private Collection<SimpleFeature> convertGeometriesToSimpleFeatures(String targetCoordinateSystem) {
Expand All @@ -172,9 +168,10 @@ private Collection<SimpleFeature> convertGeometriesToSimpleFeatures(String targe
} catch (IllegalArgumentException e) {
log.warn("Coordinate reference system \""
+ targetCoordinateSystem
+ "\" is unknown. Please set a crs in config global. Will try to create drt_waitStats_"
+ "\" is unknown. Please set a crs in config global. Will not create drt_waitStats_"
+ drtCfg.getMode()
+ "_zonal.shp anyway.");
+ "_zonal.gpkg.");
return Collections.emptyList();
}

simpleFeatureBuilder.setName("drtZoneFeature");
Expand Down
2 changes: 1 addition & 1 deletion matsim/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.6.0</version>
<version>3.7.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly-release.xml</descriptor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ public enum CleanIterations {
private static final String COMPRESSION_TYPE = "compressionType";
private static final String EVENT_TYPE_TO_CREATE_SCORING_FUNCTIONS = "createScoringFunctionType";

private static final String MEMORY_OBSERVER_INTERVAL = "memoryObserverInterval";

/*package*/ static final String MOBSIM = "mobsim";
public enum MobsimType {qsim, JDEQSim, hermes}

Expand Down Expand Up @@ -109,6 +111,8 @@ public enum MobsimType {qsim, JDEQSim, hermes}

private CleanIterations cleanItersAtEnd = CleanIterations.keep;

private int memoryObserverInterval = 60;

public ControllerConfigGroup() {
super(GROUP_NAME);
}
Expand Down Expand Up @@ -151,6 +155,7 @@ public final Map<String, String> getComments() {
"to a file. `0' disables snapshots writing completely");
map.put(DUMP_DATA_AT_END, "true if at the end of a run, plans, network, config etc should be dumped to a file");
map.put(CLEAN_ITERS_AT_END, "Defines what should be done with the ITERS directory when a simulation finished successfully");
map.put(MEMORY_OBSERVER_INTERVAL, "Defines the interval for printing memory usage to the log in [seconds]. Must be positive. Defaults to 60.");
return map;
}

Expand Down Expand Up @@ -427,6 +432,17 @@ public EventTypeToCreateScoringFunctions getEventTypeToCreateScoringFunctions()
public void setEventTypeToCreateScoringFunctions(EventTypeToCreateScoringFunctions eventTypeToCreateScoringFunctions) {
this.eventTypeToCreateScoringFunctions = eventTypeToCreateScoringFunctions;
}

@StringGetter(MEMORY_OBSERVER_INTERVAL)
public int getMemoryObserverInterval() {
return memoryObserverInterval;
}

@StringSetter(MEMORY_OBSERVER_INTERVAL)
public void setMemoryObserverInterval(int memoryObserverInterval) {
this.memoryObserverInterval = memoryObserverInterval;
}

// ---
int writePlansUntilIteration = 1 ;
public int getWritePlansUntilIteration() {
Expand All @@ -450,5 +466,8 @@ protected void checkConsistency(Config config) {
log.warn( "this is not recommended, as it might result in a directory containing output from several model runs" );
log.warn( "prefer the options "+OverwriteFileSetting.deleteDirectoryIfExists+" or "+OverwriteFileSetting.failIfDirectoryExists );
}
if(config.controller().getMemoryObserverInterval() < 0) {
log.warn("Memory observer interval is negative. Simulation will most likely crash.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ final void setupOutputDirectory(OutputDirectoryHierarchy controlerIO) {
}

protected final void run(final Config config) {
MemoryObserver.start(60);
MemoryObserver.start(config.controller().getMemoryObserverInterval());
MatsimRuntimeModifications.MyRunnable runnable = new MatsimRuntimeModifications.MyRunnable() {
@Override
public void run() throws MatsimRuntimeModifications.UnexpectedShutdownException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.matsim.utils.objectattributes.AttributeConverter;

Expand All @@ -29,19 +30,15 @@
* @author mrieser
*/
public class StringConverter implements AttributeConverter<String> {
private final Map<String, String> stringCache = new HashMap<String, String>(1000);
private final Map<String, String> stringCache = new ConcurrentHashMap<>(1000);

@Override
public String convert(String value) {
String s = this.stringCache.get(value);
if (s == null) {
s = value;
this.stringCache.put(s, s);
}
return s;
return stringCache.computeIfAbsent(value, k -> k);
}

@Override
public String convertToString(Object o) {
return (String) o;
}
}
}
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
<maven.compiler.release>17</maven.compiler.release>
<argLine></argLine>

<log4j.version>2.23.0</log4j.version>
<log4j.version>2.23.1</log4j.version>
<geotools.version>29.5</geotools.version>
<osmosis.version>0.49.2</osmosis.version>
<jts.version>1.19.0</jts.version>
<guice.version>7.0.0</guice.version>
<jackson.version>2.16.1</jackson.version>
<jackson.version>2.16.2</jackson.version>
<jogl.version>2.5.0</jogl.version>
<junit.version>5.10.2</junit.version>
</properties>
Expand Down Expand Up @@ -118,7 +118,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
<version>1.26.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
Expand Down Expand Up @@ -200,7 +200,7 @@
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<version>2.25.0</version>
<version>2.26.1</version>
</dependency>

<dependency>
Expand Down

0 comments on commit 2791bba

Please sign in to comment.