Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous fixes for headless legacy #362

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions gama.headless/src/gama/headless/common/HeadLessErrors.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public abstract class HeadLessErrors {

/** The Constant NOT_EXIST_FILE_ERROR. */
public static final int NOT_EXIST_FILE_ERROR = 4;

/** The Constant HPC_PARAMETER_ERROR. */
public static final int HPC_PARAMETER_ERROR = 5;
//
// /** The Constant HPC_PARAMETER_ERROR. */
// public static final int HPC_PARAMETER_ERROR = 5;

/** The Constant INPUT_NOT_DEFINED. */
public static final int INPUT_NOT_DEFINED = 6;
public static final int INPUT_NOT_DEFINED = 5 /* 6 */;

/** The Constant OUTPUT_NOT_DEFINED. */
public static final int OUTPUT_NOT_DEFINED = 7;
public static final int OUTPUT_NOT_DEFINED = 6 /* 7 */;

/** The Constant ERRORS. */
private final static String[] ERRORS =
Expand All @@ -46,7 +46,7 @@ public abstract class HeadLessErrors {
"Launching error... try again",
"Unable to create directory at #. Check your file permission!",
"Unable to create directory at #. Directory already exist!",
"Unable to read input file #. File not exist!",
"Unable to read input file #. File does not exist!",
"Input file is not defined",
"Output directory is not defined"};

Expand Down
23 changes: 16 additions & 7 deletions gama.headless/src/gama/headless/runtime/HeadlessApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ private boolean checkParameters(final List<String> args) {
size = size - 4;
mustContainInFile = mustContainOutFolder = false;
}

if (args.contains(GAML_PARAMETER)) {
size = size - 2;
}
lesquoyb marked this conversation as resolved.
Show resolved Hide resolved

// Runner verification
// ========================
Expand All @@ -319,11 +323,15 @@ private boolean checkParameters(final List<String> args) {
// Check and create output folder
Globals.OUTPUT_PATH = args.get(args.size() - 1);
final File output = new File(Globals.OUTPUT_PATH);
if (!output.exists()) { output.mkdir(); }
if (!output.exists() && !output.mkdir()) {
return showError(HeadLessErrors.PERMISSION_ERROR, Globals.OUTPUT_PATH);
}
// Check and create output image folder
Globals.IMAGES_PATH = Globals.OUTPUT_PATH + "/snapshot";
final File images = new File(Globals.IMAGES_PATH);
if (!images.exists()) { images.mkdir(); }
if (!images.exists() && !images.mkdir()) {
return showError(HeadLessErrors.PERMISSION_ERROR, Globals.IMAGES_PATH);
}
}
if (mustContainInFile) {
final int inIndex = args.size() - (mustContainOutFolder ? 2 : 1);
Expand Down Expand Up @@ -658,10 +666,11 @@ public void runBatchSimulation(final String experimentName, final String pathToM
*/
public void runGamlSimulation(final List<String> args)
throws IOException, GamaCompilationFailedException, InterruptedException {
final String pathToModel = args.get(args.size() - 1);
assertIsAModelFile(pathToModel);
final String argExperimentName = args.get(args.size() - 2);
final String argGamlFile = args.get(args.size() - 1);

final String argExperimentName = args.get(args.size() - 3);
final String argGamlFile = args.get(args.size() - 2);
final String argOutDir = args.get(args.size() - 1);
assertIsAModelFile(argGamlFile);

Integer numberOfCores =
args.contains(THREAD_PARAMETER) ? Integer.parseInt(after(args, THREAD_PARAMETER)) : null;
Expand All @@ -674,7 +683,7 @@ public void runGamlSimulation(final List<String> args)
}
}
if (selectedJob == null) return;
Globals.OUTPUT_PATH = args.get(args.size() - 3);
Globals.OUTPUT_PATH = argOutDir;

selectedJob.setBufferedWriter(new XMLWriter(Globals.OUTPUT_PATH + "/" + Globals.OUTPUT_FILENAME + ".xml"));
processorQueue.setNumberOfThreads(numberOfCores != null ? numberOfCores : SimulationRuntime.DEFAULT_NB_THREADS);
Expand Down
11 changes: 8 additions & 3 deletions gama.headless/src/gama/headless/xml/XMLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
********************************************************************************************************/
package gama.headless.xml;

import java.io.*;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

import gama.headless.core.*;
import gama.headless.common.DataType;
import gama.headless.job.ExperimentJob;
import gama.headless.job.ListenedVariable;

Expand Down Expand Up @@ -66,7 +69,9 @@ public void close() {
public void writeResultStep(final long step, final ListenedVariable[] vars) {
StringBuilder sb = new StringBuilder().append("\t<Step id='").append(step).append("' >\n");
for ( int i = 0; i < vars.length; i++ ) {
sb.append("\t\t<Variable name='").append(vars[i].getName()).append("' type='").append(vars[i].getDataType().name()).append("'>").append(vars[i].getValue())
sb.append("\t\t<Variable name='").append(vars[i].getName())
.append("' type='").append((vars[i].getDataType() == null ? DataType.UNDEFINED : vars[i].getDataType()).name())
.append("'>").append(vars[i].getValue())
.append("</Variable>\n");
}
sb.append("\t</Step>\n");
Expand Down