@Override
public void run() {
StoredResultsModel results = null;
File simulationFile = null;
ParametricAnalysisDefinition pad = simd.getParametricAnalysisModel();
pad.createValuesSet();
PAResultsModel parametricAnalysisResultsModel = new PAResultsModel((CommonModel) simd);
for (currentStep = 0; currentStep < pad.getNumberOfSteps(); currentStep++) {
progressWindow.setStepNumber(currentStep + 1);
pad.changeModel(currentStep);
try {
simulationFile = File.createTempFile("~JModelSimulation", ".xml");
simulationFile.deleteOnExit();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "File exception", "Error", JOptionPane.ERROR_MESSAGE);
}
simulationFile.deleteOnExit();
XMLWriter.writeXML(simulationFile, (CommonModel) simd);
simulator = new Dispatcher_jSIMschema(simulationFile);
if (simd.getMaximumDuration().longValue() > 0) {
timer = new PATimerThread(simulator, simd.getMaximumDuration().doubleValue());
timer.start();
}
try {
simulator.solveModel();
} catch (OutOfMemoryError err) {
simulator.abortAllMeasures();
simulator.killSimulation();
progressWindow.stop();
progressWindow.dispose();
gui.showErrorMessage("Out of memory error. Try to run Java Virtual Machine with more heap size (-Xmx<num>m)");
break;
} catch (Exception ex) {
simulator.abortAllMeasures();
simulator.killSimulation();
gui.handleException(ex);
break;
}
File output = simulator.getSimulation().getOutputFile();
output.deleteOnExit();
Document doc = XMLReader.loadXML(output.getAbsolutePath());
results = new StoredResultsModel();
XMLResultsReader.parseXML(doc, results);
for (int i = 0; i < results.getMeasureNumber(); i++) {
Vector thisMes = results.getValues(i);
int measureState = results.getMeasureState(i);
Object value = thisMes.get(0);
boolean valid;
valid = measureState == MeasureDefinition.MEASURE_SUCCESS;
//valueSet[i].add(value);
//validityMap[i].add(Boolean.valueOf(valid));
MeasureValue tempValue = (MeasureValue) value;
parametricAnalysisResultsModel.addSample(i, tempValue.getLowerBound(), tempValue.getMeanValue(), tempValue.getUpperBound(), valid);
}
if (timer != null) {
timer.kill();
//simulator.killSimulation();
}
}
pad.restoreOriginalValues();
if (!stopped) {
progressWindow.finished();
//PAResultsWindow resWin = new PAResultsWindow(simd.getParametricAnalysisModel(),results,valueSet,validityMap);
//progressWindow.hide();
progressWindow.stopAnimation();