From 061d304f558f2d76734aa49b9d4865417e628f75 Mon Sep 17 00:00:00 2001 From: miettinen Date: Fri, 28 Jun 2013 11:58:49 +0000 Subject: [PATCH] In sensitivity runs, add the index of run to the charts. This makes it (somewhat) easier to see which parameter combinations yield which results, and it also solves the problem of auto zoom of the range axis of a chart (refs #4332). In sensitivity analysis with many individual runs, do not update the datasets to charts in each iteration (total number of updates currently limited to 20). git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27666 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../simantics/modelica/data/SimulationResult.java | 2 -- .../simantics/sysdyn/ui/trend/CategoryDataset.java | 7 +++++-- .../org/simantics/sysdyn/ui/trend/PieDataset.java | 3 +++ .../org/simantics/sysdyn/ui/trend/TrendView.java | 7 +++++-- .../sysdyn/ui/trend/XYDatasetRequest.java | 3 +++ .../org/simantics/sysdyn/ui/values/ValueView.java | 3 +++ .../org/simantics/sysdyn/manager/MemoryResult.java | 13 ++++++++++++- .../simantics/sysdyn/manager/SysdynDataSet.java | 7 +++++++ .../SysdynSensitivityAnalysisExperiment.java | 14 +++++++++----- 9 files changed, 47 insertions(+), 12 deletions(-) diff --git a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java index 96f1c5a3..3f187058 100644 --- a/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java +++ b/org.simantics.modelica/src/org/simantics/modelica/data/SimulationResult.java @@ -465,8 +465,6 @@ public class SimulationResult { // We should never need to go there unless some change in // the logic of reading variables are made. // Also helps in seeking memory leaks. - System.err.println("Find me and add a comment that I was printed, please."); - // If it seems that in no case we need to go here, comment this try catch. return null; } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/CategoryDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/CategoryDataset.java index aaa0ec25..4a5f80f2 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/CategoryDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/CategoryDataset.java @@ -210,8 +210,11 @@ public class CategoryDataset extends AbstractDataset implements org.simantics.jf value = va[va.length - 1]; } String label = graph.getPossibleRelatedValue(r, Layer0.getInstance(graph).HasLabel); // Called to refresh paints when label changes - String name = dataset.name; - series.add(new TempSeries(label == null || label.isEmpty() ? name : label, dataset.result, value)); + String name = label == null || label.isEmpty() ? dataset.name : label; + if (dataset.resultIndex != null) { + name += "(" + dataset.resultIndex + ")"; + } + series.add(new TempSeries(name, dataset.result, value)); } } catch (MissingVariableException e) { // Do nothing, if variable was not found. Move on to the next series diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PieDataset.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PieDataset.java index 0f2b57a6..3eb92c57 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PieDataset.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/PieDataset.java @@ -233,6 +233,9 @@ public class PieDataset extends AbstractDataset implements org.simantics.jfreech } String name = label == null || label.isEmpty() ? dataset.name : label; + if (dataset.resultIndex != null) { + name += "(" + dataset.resultIndex + ")"; + } if(dataset.result != null) name = name + " : " + dataset.result; colorMap.put(name, color); diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java index 9b2fa61b..d3a33699 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/TrendView.java @@ -103,10 +103,13 @@ public class TrendView extends ViewPart { @Override public Comparable getSeriesKey(int series) { SysdynDataSet sds = sets[series]; + String name = sds.name; + if(sds.resultIndex != null) + name += "(" + sds.resultIndex + ")"; if(sds.result == null) - return sds.name; + return name; else - return sds.name + " : " + sds.result; + return name + " : " + sds.result; } @Override diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/XYDatasetRequest.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/XYDatasetRequest.java index ce388411..2a34593a 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/XYDatasetRequest.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/XYDatasetRequest.java @@ -159,6 +159,9 @@ public class XYDatasetRequest implements Read results; private File resultFile; + private Integer resultIndex = null; private SimulationResult simulationResult; @@ -72,7 +73,7 @@ public class MemoryResult extends SysdynResult { ds = simulationResult.readVariable(variable, resultFile); if(ds != null) { - SysdynDataSet sds = new SysdynDataSet(variable, getResultName(), ds.times, ds.values); + SysdynDataSet sds = new SysdynDataSet(variable, getResultName(), ds.times, ds.values, resultIndex); results.put(variable, sds); return sds; } @@ -231,4 +232,14 @@ public class MemoryResult extends SysdynResult { public @Arguments({String.class, String.class}) TreeMap labels; public @Arguments({TreeMap.class, Double.class, Double.class}) TreeMap[] segments; } + + /** + * Set the index of the run; used when the individual time series of a variable are shown in + * the same JFreeChart. + * @param currentRun The index of the run + */ + public void setResultIndex(int resultIndex) { + this.resultIndex = resultIndex; + } + } diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java index 89e53db5..a98ad679 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynDataSet.java @@ -22,7 +22,14 @@ import org.simantics.modelica.data.DataSet; public class SysdynDataSet extends DataSet { public String result; // Name of the result file if this is not the result of the current simulation + public Integer resultIndex = null; + public SysdynDataSet(String name, String result, double[] times, double[] values, Integer resultIndex) { + super(name, times, values); + this.result = result; + this.resultIndex = resultIndex; + } + public SysdynDataSet(String name, String result, double[] times, double[] values) { super(name, times, values); this.result = result; diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java index 0273ec9f..e139e379 100644 --- a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java +++ b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java @@ -56,7 +56,7 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment { ArrayList> parameterMaps = new ArrayList>(); int parametersSize = parameters.size(); - // Get seed + // Get seed and number of runs try { session.syncRequest(new ReadRequest() { @Override @@ -64,14 +64,15 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment { SysdynResource SR = SysdynResource.getInstance(graph); seed = graph.getPossibleRelatedValue(experiment, SR.SensitivityAnalysisExperiment_randomSeed, Bindings.INTEGER); numberOfRuns = graph.getPossibleRelatedValue(experiment, SR.SensitivityAnalysisExperiment_numberOfValues, Bindings.INTEGER); - //refreshRate = numberOfRuns / 20 + 1; - refreshRate = 1; } }); } catch (DatabaseException e) { e.printStackTrace(); } + // Refresh rate for charts + refreshRate = numberOfRuns / 20 + 1; + // Generate values for parameters (randomly) RandomGenerator randomGenerator = new RandomGenerator(seed, parametersSize); @@ -123,7 +124,7 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment { File resFile = new File(experimentParameters.get(ModelicaManager.RESULT_FILE_NAME)); boolean updateMonitors = currentRun % refreshRate == 0 || currentRun == numberOfRuns - 1; - Thread resultThread = getResultThread(resFile, experimentParameters, monitor, progressMonitor, updateMonitors); + Thread resultThread = getResultThread(resFile, experimentParameters, monitor, progressMonitor, updateMonitors, currentRun); resultThread.run(); process = null; @@ -200,13 +201,15 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment { * @param inits * @param monitor * @param progressMonitor + * @param currentRun * @return */ protected Thread getResultThread(final File resFile, final HashMap experimentParameters, final IModelicaMonitor monitor, final IProgressMonitor progressMonitor, - final boolean updateMonitors) { + final boolean updateMonitors, + final int currentRun) { return new Thread() { @Override public void run() { @@ -250,6 +253,7 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment { getCurrentResults().add(currentResult); currentResult.setResult(result); currentResult.setResultFile(resFile); + currentResult.setResultIndex(currentRun); if(updateMonitors) resultsChanged(); -- 2.47.1