Repast批量运行飞机登机仿真模型时出现错误的技术求助
Let's work through this batch run issue with your passenger boarding simulation model. First, let's clear up your library-related questions, then dive into the actual likely causes of the error.
Are Standard Java/Repast Libraries Causing the Issue?
Absolutely not. The standard Java libraries (like java.util.Random, java.util.List) and official Repast libraries are core dependencies that Repast is designed to handle seamlessly in both single and batch run modes. You don't need to adjust their placement—Repast automatically loads them correctly during batch execution.
If you were using custom third-party libraries (which you mentioned you aren't), moving them to a lib directory would be straightforward, but that's not your current problem. For completeness, here's how you'd do it if you needed to later:
- Create a
libfolder in your Repast project's root directory if it doesn't exist. - Copy all your custom
.jarfiles into thislibfolder. - In your IDE (Eclipse/IntelliJ), right-click the
.jarfiles and select Build Path > Add to Build Path (Eclipse) or Add as Library (IntelliJ) to ensure they're included in compilation and runtime. - Repast will automatically pick up these libraries during batch runs without extra configuration.
Likely Root Cause: Output Path Logic in Batch Mode
The warnings about missing ModelOutput*.txt files point to a mismatch between where your code is writing output and where Repast expects to find it during batch runs. Here's why this happens:
- In single run mode, your output file is written to your project's root directory (or the working directory of your IDE).
- In batch mode, Repast creates a separate temporary working directory for each instance (like
/var/folders/.../instance_1), and your code is probably still writing to the original project directory instead of the instance-specific temp directory.
Fixes to Try:
- Use Repast's API to Get the Instance Working Directory
Update your output code to write to the correct instance-specific directory instead of a hardcoded relative path. Here's a code snippet to do that:import repast.simphony.engine.environment.RunEnvironment; import repast.simphony.engine.environment.RunInfo; import java.io.File; import java.io.PrintWriter; // Get the current instance's working directory RunInfo runInfo = RunEnvironment.getInstance().getRunController().getCurrentRunInfo(); String workingDir = runInfo.getWorkingDirectory(); File outputFile = new File(workingDir, "ModelOutput.txt"); // Write to the file (example) try (PrintWriter writer = new PrintWriter(outputFile)) { writer.println("Boarding duration: " + yourBoardingDurationVariable); } catch (Exception e) { e.printStackTrace(); // This will help catch file write errors } - Check Batch Run Configuration
Open your Repast batch run settings and confirm that you haven't accidentally disabled output or set an incorrect output path. Ensure the output glob patterns match your actual file naming (the warnings show it's looking forModelOutput*.txt, which matches your filename—so this is probably not the issue, but worth verifying). - View Full Error Stack Trace
TheERROR: InstanceRunner - Error while running modelmessage should have a full stack trace in the logs (look for alogfile in the temp instance directories or your IDE's console). This will reveal the exact exception (e.g., file write permission issues, null pointers) that's causing the run to fail before output is written.
Final Notes
Since your single runs work perfectly, the problem is almost certainly tied to how batch mode handles working directories and output. Fixing your output path logic to use the instance-specific directory should resolve the missing output files and the run error.
内容的提问来源于stack exchange,提问作者Emil Ryd

