Skip to content

Commit

Permalink
Merge branch 'master' into fare-zone-based-pt-pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
simei94 authored Aug 8, 2024
2 parents 3ca6bbe + 12b08e1 commit 0574e22
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ public static void runWithDefaults(Class<? extends MATSimApplication> clazz, Str

if (ApplicationUtils.isRunFromDesktop() && args.length == 0) {

System.setProperty("MATSIM_GUI_DESKTOP", "true");

if (defaultArgs.length > 0) {
String value = String.join(ARGS_DELIMITER, defaultArgs);
System.setProperty("MATSIM_GUI_ARGS", value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ public Integer call() throws Exception {

Gui gui = f.get();

// Set the current working directory to be used in the gui, when run from the command line
// If the gui is run from desktop, the working directory is not overwritten

// Assumption is that starting something from command line, the user expects that the working directory remains the same
if (!System.getProperty("MATSIM_GUI_DESKTOP", "false").equals("true"))
gui.setWorkingDirectory(new File(""));

while (gui.isShowing())
Thread.sleep(250);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.matsim.application.analysis.noise;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.locationtech.jts.geom.Envelope;
import org.matsim.api.core.v01.Coord;
import org.matsim.api.core.v01.Scenario;
Expand All @@ -8,6 +10,7 @@
import org.matsim.application.MATSimAppCommand;
import org.matsim.application.options.InputOptions;
import org.matsim.application.options.OutputOptions;
import org.matsim.application.options.SampleOptions;
import org.matsim.application.options.ShpOptions;
import org.matsim.contrib.noise.NoiseConfigGroup;
import org.matsim.contrib.noise.NoiseOfflineCalculation;
Expand Down Expand Up @@ -38,6 +41,8 @@
)
public class NoiseAnalysis implements MATSimAppCommand {

private static final Logger log = LogManager.getLogger(NoiseAnalysis.class);

@CommandLine.Mixin
private final InputOptions input = InputOptions.ofCommand(NoiseAnalysis.class);
@CommandLine.Mixin
Expand All @@ -46,7 +51,11 @@ public class NoiseAnalysis implements MATSimAppCommand {
@CommandLine.Mixin
private final ShpOptions shp = new ShpOptions();

@CommandLine.Option(names = "--consider-activities", split = ",", description = "Considered activities for noise calculation", defaultValue = "h,w,home,work")
@CommandLine.Mixin
private final SampleOptions sampleOptions = new SampleOptions();

@CommandLine.Option(names = "--consider-activities", split = ",", description = "Considered activities for noise calculation." +
" Use asterisk ('*') for acttype prefixes, if all such acts shall be considered.", defaultValue = "h,w,home*,work*")
private Set<String> considerActivities;

@CommandLine.Option(names = "--noise-barrier", description = "Path to the noise barrier File", defaultValue = "")
Expand Down Expand Up @@ -88,6 +97,16 @@ public Integer call() throws Exception {
noiseParameters.setNoiseBarriersFilePath(noiseBarrierFile);
}

if(! sampleOptions.isSet() && noiseParameters.getScaleFactor() == 1d){
log.warn("You didn't provide the simulation sample size via command line option --sample-size! This means, noise damages are not scaled!!!");
} else if (noiseParameters.getScaleFactor() == 1d){
if (sampleOptions.getSample() == 1d){
log.warn("Be aware that the noise output is not scaled. This might be unintended. If so, assure to provide the sample size via command line option --sample-size, in the SimWrapperConfigGroup," +
"or provide the scaleFactor (the inverse of the sample size) in the NoiseConfigGroup!!!");
}
noiseParameters.setScaleFactor(sampleOptions.getUpscaleFactor());
}

Scenario scenario = ScenarioUtils.loadScenario(config);

String outputFilePath = output.getPath().getParent() == null ? "." : output.getPath().getParent().toString();
Expand Down Expand Up @@ -119,6 +138,7 @@ private Config prepareConfig() {
config.facilities().setInputFile(null);
config.eventsManager().setNumberOfThreads(null);
config.eventsManager().setEstimatedNumberOfEvents(null);
//ts, aug '24: not sure if and why we need to set 1 thread
config.global().setNumberOfThreads(1);

return config;
Expand Down
14 changes: 12 additions & 2 deletions matsim/src/main/java/org/matsim/run/gui/Gui.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public class Gui extends JFrame {

private File configFile;
private File lastUsedDirectory;

/**
* This is the working directory for the simulation. If it is null, the working directory is the directory of the config file.
*/
private File workingDirectory = null;
private ConfigEditor editor = null;
private ScheduleValidatorWindow transitValidator = null;

Expand Down Expand Up @@ -439,6 +444,8 @@ private void startMATSim() {
textStdOut.setText("");
textErrOut.setText("");

String cwd = workingDirectory == null ? new File(txtConfigfilename.getText()).getParent() : workingDirectory.getAbsolutePath();

new Thread(() -> {
String classpath = System.getProperty("java.class.path");
String[] cpParts = classpath.split(File.pathSeparator);
Expand All @@ -457,8 +464,7 @@ private void startMATSim() {
"--add-exports", "java.desktop/sun.java2d=ALL-UNNAMED",
mainClass, txtConfigfilename.getText() };
// see https://jogamp.org/bugzilla/show_bug.cgi?id=1317#c21 and/or https://github.com/matsim-org/matsim-libs/pull/2940
exeRunner = ExeRunner.run(cmdArgs, textStdOut, textErrOut,
new File(txtConfigfilename.getText()).getParent());
exeRunner = ExeRunner.run(cmdArgs, textStdOut, textErrOut, cwd);
int exitcode = exeRunner.waitForFinish();
exeRunner = null;

Expand Down Expand Up @@ -575,6 +581,10 @@ public static void main(String[] args) {
Gui.show("MATSim", RunMatsim.class, args.length == 1 ? new File(args[0]) : null);
}

public void setWorkingDirectory(File cwd) {
this.workingDirectory = cwd;
}

// Is it a problem to make the following available to the outside? If so, why? Would it
// be better to rather copy/paste the above code and start from there? kai, jun/aug'18

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.17.0</version>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down

0 comments on commit 0574e22

Please sign in to comment.