SYSDYN.SensitivityAnalysisExperiment <T SYSDYN.Experiment
>-- SYSDYN.SensitivityAnalysisExperiment.parameterList --> L0.List <R L0.IsComposedOf : L0.FunctionalRelation
>-- SYSDYN.SensitivityAnalysisExperiment.randomSeed --> L0.Integer <R L0.HasProperty : L0.FunctionalRelation
+ >-- SYSDYN.SensitivityAnalysisExperiment.method --> SYSDYN.ValueGeneratorMethod <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SensitivityAnalysisExperiment.resultRefreshRate --> L0.Integer <R L0.HasProperty : L0.FunctionalRelation
>-- SYSDYN.SensitivityAnalysisExperiment.numberOfValues --> L0.Integer <R L0.HasProperty : L0.FunctionalRelation
@L0.assert SYSDYN.SensitivityAnalysisExperiment.randomSeed 123
@L0.assert SYSDYN.Interval.minValue 0.0
@L0.assert SYSDYN.Interval.maxValue 10.0
+SYSDYN.ValueGeneratorMethod <T L0.Entity
+SYSDYN.RandomGenerator <T SYSDYN.ValueGeneratorMethod
+SYSDYN.HaltonSequenceGenerator <T SYSDYN.ValueGeneratorMethod
+
//#####################################################################
// Results and history datasets
//#####################################################################
public final Resource GameExperiment_stepDuration_Inverse;\r
public final Resource GameExperiment_stepLength;\r
public final Resource GameExperiment_stepLength_Inverse;\r
+ public final Resource HaltonSequenceGenerator;\r
public final Resource HasEquationOrEmpty;\r
public final Resource HasEquationOrEmpty_Inverse;\r
public final Resource HasHeadTerminal;\r
public final Resource Profiles_IssueWarnings;\r
public final Resource Profiles_ShadowVisualizations;\r
public final Resource Profiles_SimulationPlaybackColours;\r
+ public final Resource RandomGenerator;\r
public final Resource Redeclaration;\r
public final Resource Redeclaration_replacedEnumeration;\r
public final Resource Redeclaration_replacedEnumeration_Inverse;\r
public final Resource SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse;\r
public final Resource SensitivityAnalysisExperiment_Parameter_variable;\r
public final Resource SensitivityAnalysisExperiment_Parameter_variable_Inverse;\r
+ public final Resource SensitivityAnalysisExperiment_method;\r
+ public final Resource SensitivityAnalysisExperiment_method_Inverse;\r
public final Resource SensitivityAnalysisExperiment_numberOfValues;\r
public final Resource SensitivityAnalysisExperiment_numberOfValues_Inverse;\r
public final Resource SensitivityAnalysisExperiment_parameterList;\r
public final Resource Validations_constraint;\r
public final Resource Validations_issue;\r
public final Resource Validations_listeningConstraint;\r
+ public final Resource ValueGeneratorMethod;\r
public final Resource Valve;\r
public final Resource ValveSymbol;\r
public final Resource ValveSymbol_orientation;\r
public static final String GameExperiment_stepDuration_Inverse = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepDuration/Inverse";\r
public static final String GameExperiment_stepLength = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepLength";\r
public static final String GameExperiment_stepLength_Inverse = "http://www.simantics.org/Sysdyn-1.1/GameExperiment/stepLength/Inverse";\r
+ public static final String HaltonSequenceGenerator = "http://www.simantics.org/Sysdyn-1.1/HaltonSequenceGenerator";\r
public static final String HasEquationOrEmpty = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty";\r
public static final String HasEquationOrEmpty_Inverse = "http://www.simantics.org/Sysdyn-1.1/HasEquationOrEmpty/Inverse";\r
public static final String HasHeadTerminal = "http://www.simantics.org/Sysdyn-1.1/HasHeadTerminal";\r
public static final String Profiles_IssueWarnings = "http://www.simantics.org/Sysdyn-1.1/Profiles/IssueWarnings";\r
public static final String Profiles_ShadowVisualizations = "http://www.simantics.org/Sysdyn-1.1/Profiles/ShadowVisualizations";\r
public static final String Profiles_SimulationPlaybackColours = "http://www.simantics.org/Sysdyn-1.1/Profiles/SimulationPlaybackColours";\r
+ public static final String RandomGenerator = "http://www.simantics.org/Sysdyn-1.1/RandomGenerator";\r
public static final String Redeclaration = "http://www.simantics.org/Sysdyn-1.1/Redeclaration";\r
public static final String Redeclaration_replacedEnumeration = "http://www.simantics.org/Sysdyn-1.1/Redeclaration/replacedEnumeration";\r
public static final String Redeclaration_replacedEnumeration_Inverse = "http://www.simantics.org/Sysdyn-1.1/Redeclaration/replacedEnumeration/Inverse";\r
public static final String SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/Parameter/propabilityDistribution/Inverse";\r
public static final String SensitivityAnalysisExperiment_Parameter_variable = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/Parameter/variable";\r
public static final String SensitivityAnalysisExperiment_Parameter_variable_Inverse = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/Parameter/variable/Inverse";\r
+ public static final String SensitivityAnalysisExperiment_method = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/method";\r
+ public static final String SensitivityAnalysisExperiment_method_Inverse = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/method/Inverse";\r
public static final String SensitivityAnalysisExperiment_numberOfValues = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/numberOfValues";\r
public static final String SensitivityAnalysisExperiment_numberOfValues_Inverse = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/numberOfValues/Inverse";\r
public static final String SensitivityAnalysisExperiment_parameterList = "http://www.simantics.org/Sysdyn-1.1/SensitivityAnalysisExperiment/parameterList";\r
public static final String Validations_constraint = "http://www.simantics.org/Sysdyn-1.1/Validations/constraint";\r
public static final String Validations_issue = "http://www.simantics.org/Sysdyn-1.1/Validations/issue";\r
public static final String Validations_listeningConstraint = "http://www.simantics.org/Sysdyn-1.1/Validations/listeningConstraint";\r
+ public static final String ValueGeneratorMethod = "http://www.simantics.org/Sysdyn-1.1/ValueGeneratorMethod";\r
public static final String Valve = "http://www.simantics.org/Sysdyn-1.1/Valve";\r
public static final String ValveSymbol = "http://www.simantics.org/Sysdyn-1.1/ValveSymbol";\r
public static final String ValveSymbol_orientation = "http://www.simantics.org/Sysdyn-1.1/ValveSymbol/orientation";\r
GameExperiment_stepDuration_Inverse = getResourceOrNull(graph, URIs.GameExperiment_stepDuration_Inverse);\r
GameExperiment_stepLength = getResourceOrNull(graph, URIs.GameExperiment_stepLength);\r
GameExperiment_stepLength_Inverse = getResourceOrNull(graph, URIs.GameExperiment_stepLength_Inverse);\r
+ HaltonSequenceGenerator = getResourceOrNull(graph, URIs.HaltonSequenceGenerator);\r
HasEquationOrEmpty = getResourceOrNull(graph, URIs.HasEquationOrEmpty);\r
HasEquationOrEmpty_Inverse = getResourceOrNull(graph, URIs.HasEquationOrEmpty_Inverse);\r
HasHeadTerminal = getResourceOrNull(graph, URIs.HasHeadTerminal);\r
Profiles_IssueWarnings = getResourceOrNull(graph, URIs.Profiles_IssueWarnings);\r
Profiles_ShadowVisualizations = getResourceOrNull(graph, URIs.Profiles_ShadowVisualizations);\r
Profiles_SimulationPlaybackColours = getResourceOrNull(graph, URIs.Profiles_SimulationPlaybackColours);\r
+ RandomGenerator = getResourceOrNull(graph, URIs.RandomGenerator);\r
Redeclaration = getResourceOrNull(graph, URIs.Redeclaration);\r
Redeclaration_replacedEnumeration = getResourceOrNull(graph, URIs.Redeclaration_replacedEnumeration);\r
Redeclaration_replacedEnumeration_Inverse = getResourceOrNull(graph, URIs.Redeclaration_replacedEnumeration_Inverse);\r
SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_Parameter_propabilityDistribution_Inverse);\r
SensitivityAnalysisExperiment_Parameter_variable = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_Parameter_variable);\r
SensitivityAnalysisExperiment_Parameter_variable_Inverse = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_Parameter_variable_Inverse);\r
+ SensitivityAnalysisExperiment_method = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_method);\r
+ SensitivityAnalysisExperiment_method_Inverse = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_method_Inverse);\r
SensitivityAnalysisExperiment_numberOfValues = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_numberOfValues);\r
SensitivityAnalysisExperiment_numberOfValues_Inverse = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_numberOfValues_Inverse);\r
SensitivityAnalysisExperiment_parameterList = getResourceOrNull(graph, URIs.SensitivityAnalysisExperiment_parameterList);\r
Validations_constraint = getResourceOrNull(graph, URIs.Validations_constraint);\r
Validations_issue = getResourceOrNull(graph, URIs.Validations_issue);\r
Validations_listeningConstraint = getResourceOrNull(graph, URIs.Validations_listeningConstraint);\r
+ ValueGeneratorMethod = getResourceOrNull(graph, URIs.ValueGeneratorMethod);\r
Valve = getResourceOrNull(graph, URIs.Valve);\r
ValveSymbol = getResourceOrNull(graph, URIs.ValveSymbol);\r
ValveSymbol_orientation = getResourceOrNull(graph, URIs.ValveSymbol_orientation);\r
SysdynResource sr = SysdynResource.getInstance(graph);\r
Layer0 L0 = Layer0.getInstance(graph);\r
\r
+ Resource method = GraphUtils.create2(graph, sr.RandomGenerator);\r
+ graph.claim(experiment, sr.SensitivityAnalysisExperiment_method, method);\r
+\r
Resource distribution = GraphUtils.create2(graph, sr.UniformDistribution,\r
sr.UniformDistribution_minValue, 0.0,\r
sr.UniformDistribution_maxValue, 10.0);\r
\r
Resource parameter = GraphUtils.create2(graph, sr.SensitivityAnalysisExperiment_Parameter,\r
- sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution,\r
+ sr.SensitivityAnalysisExperiment_Parameter_propabilityDistribution, distribution,\r
sr.SensitivityAnalysisExperiment_Parameter_variable, ChartUtils.emptyVariableName,\r
L0.PartOf, experiment);\r
\r
private Resource experiment;\r
\r
private boolean dirty = false;\r
+ private boolean dirtyMethod = false;\r
\r
private DisposableListener<Collection<Resource>> contentListener;\r
\r
@Override\r
public void createControls(Composite body, IWorkbenchSite site,\r
- final ISessionContext context, WidgetSupport support) {\r
+ final ISessionContext context, final WidgetSupport support) {\r
support.register(this);\r
\r
Composite composite = new RemoveFocusBeforeExperimentComposite(body, SWT.NONE);\r
// Label\r
Composite labelComposite = new Composite(content, SWT.NONE);\r
GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(labelComposite);\r
- GridLayoutFactory.fillDefaults().numColumns(6).applyTo(labelComposite);\r
+ GridLayoutFactory.fillDefaults().numColumns(8).applyTo(labelComposite);\r
Label label = new Label(labelComposite, SWT.NONE);\r
label.setText("Name");\r
\r
n.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_numberOfValues));\r
n.setInputValidator(new IntegerValidator());\r
n.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), n.getWidget())));\r
- GridDataFactory.fillDefaults().hint(80, SWT.DEFAULT).applyTo(n.getWidget());\r
+ GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(n.getWidget());\r
+ \r
+ label = new Label(labelComposite, SWT.NONE);\r
+ label.setText("Method");\r
+ \r
+ TrackedCombo methodSelector = new TrackedCombo(labelComposite, support, SWT.DROP_DOWN);\r
+ methodSelector.setItemFactory(new ReadFactoryImpl<Resource, Map<String,Object>>() {\r
+\r
+ @Override\r
+ public Map<String, Object> perform(ReadGraph graph, Resource input) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ Map<String, Object> items = new HashMap<String, Object>();\r
+\r
+ items.put("Halton", SR.HaltonSequenceGenerator);\r
+ items.put("Random", SR.RandomGenerator);\r
+ \r
+ return items;\r
+ }\r
+\r
+ });\r
+ methodSelector.setSelectionFactory(new ReadFactoryImpl<Resource, String>() {\r
+\r
+ @Override\r
+ public String perform(ReadGraph graph, Resource parameter) throws DatabaseException {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ Resource method = graph.getPossibleObject(parameter, SR.SensitivityAnalysisExperiment_method);\r
+ if(method == null)\r
+ return null;\r
+ \r
+ if(graph.isInstanceOf(method, SR.RandomGenerator))\r
+ return "Random";\r
+ else if(graph.isInstanceOf(method, SR.HaltonSequenceGenerator))\r
+ return "Halton";\r
+ else\r
+ return "";\r
+\r
+ }\r
+ });\r
+ methodSelector.addModifyListener(new ComboModifyListenerImpl<Resource>() {\r
+\r
+ @Override\r
+ public void applyText(WriteGraph graph, Resource input, String text)\r
+ throws DatabaseException {\r
+ if(text == null || text.isEmpty())\r
+ return;\r
+\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+\r
+ Resource type = SR.RandomGenerator;\r
+\r
+ if("Halton".equals(text))\r
+ type = SR.HaltonSequenceGenerator;\r
+ \r
+ graph.deny(input, SR.SensitivityAnalysisExperiment_method);\r
+\r
+ GraphUtils.create2(graph, type,\r
+ SR.SensitivityAnalysisExperiment_method_Inverse, input);\r
+\r
+ dirtyMethod = true;\r
+ }\r
+ });\r
+ methodSelector.addModifyListener(new TextModifyListener() {\r
+\r
+ @Override\r
+ public void modifyText(TrackedModifyEvent e) {\r
+ if(dirtyMethod) {\r
+ support.update();\r
+ dirtyMethod = false;\r
+ propertyContainer.setContent(content);\r
+ Point size = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);\r
+ propertyContainer.setMinSize(size);\r
+ }\r
+ }\r
+ });\r
\r
label = new Label(labelComposite, SWT.NONE);\r
label.setText("Seed");\r
seed.addModifyListener(new IntegerPropertyModifier(context, SysdynResource.URIs.SensitivityAnalysisExperiment_randomSeed));\r
seed.setInputValidator(new IntegerValidator());\r
seed.setColorProvider(new SysdynBasicColorProvider(new LocalResourceManager(JFaceResources.getResources(), seed.getWidget())));\r
- GridDataFactory.fillDefaults().hint(80, SWT.DEFAULT).applyTo(seed.getWidget());\r
+ GridDataFactory.fillDefaults().hint(50, SWT.DEFAULT).applyTo(seed.getWidget());\r
\r
// (Ontology-based) GraphExplorer displaying range axis and variables mapped to those axis\r
explorer = new AxisAndVariablesExplorerComposite(ArrayMap.keys(\r
</type>\r
</target>\r
\r
+ <target\r
+ interface="org.simantics.sysdyn.adapter.generator.IGenerator">\r
+ <type\r
+ uri="http://www.simantics.org/Sysdyn-0.0/RandomGenerator"\r
+ class="org.simantics.sysdyn.adapter.generator.RandomGenerator">\r
+ <graph/> \r
+ <this />\r
+ </type>\r
+ <type\r
+ uri="http://www.simantics.org/Sysdyn-0.0/HaltonSequenceGenerator"\r
+ class="org.simantics.sysdyn.adapter.generator.HaltonSequenceGenerator">\r
+ <graph/> \r
+ <this />\r
+ </type>\r
+ </target>\r
+ \r
<target\r
interface="org.simantics.sysdyn.adapter.SensitivityExperimentParameter">\r
<type\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.adapter.generator;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Halton sequence generator that creates ArrayLists of Doubles between 0 and 1.\r
+ * \r
+ * @author Tuomas Miettinen\r
+ */\r
+public class HaltonSequenceGenerator implements IGenerator {\r
+ \r
+ private int dimension;\r
+ private int index = 0;\r
+ private ArrayList<Integer> primes;\r
+ \r
+ private void getPrimes() {\r
+ int newPrime = 2;\r
+ while (primes.size() < dimension) {\r
+ boolean isPrime = true;\r
+ for (int p : primes) {\r
+ if (newPrime % p == 0) {\r
+ ++newPrime;\r
+ isPrime = false;\r
+ break;\r
+ }\r
+ }\r
+ if (isPrime) {\r
+ primes.add(newPrime); \r
+ }\r
+ }\r
+ }\r
+ \r
+ public HaltonSequenceGenerator(ReadGraph graph, Resource method) {\r
+ \r
+ try {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ Resource experiment = graph.getPossibleObject(method, SR.SensitivityAnalysisExperiment_method_Inverse);\r
+ Resource parameterListResource = graph.getPossibleObject(experiment, SR.SensitivityAnalysisExperiment_parameterList);\r
+ dimension = ListUtils.getListNodes(graph, parameterListResource).size();\r
+\r
+ primes = new ArrayList<Integer>();\r
+ getPrimes();\r
+ \r
+ initialize();\r
+ } catch (DatabaseException e) {\r
+ \r
+ }\r
+ }\r
+\r
+ public static double getHalton(int index, int base) {\r
+ ++index; // Map indexes to start from 1;\r
+ double result = 0;\r
+ double f = 1.0 / base;\r
+ while (index > 0) {\r
+ result = result + f * (index % base);\r
+ index = index / base;\r
+ f = f / base;\r
+ }\r
+ return result;\r
+ }\r
+ \r
+ public List<Double> next() {\r
+ ArrayList<Double> retval = new ArrayList<Double>();\r
+ for (int i = 0; i < dimension; ++i) {\r
+ int base = primes.get(i);\r
+ double halton = getHalton(index, base);\r
+ retval.add(halton);\r
+ }\r
+ ++index;\r
+ return retval;\r
+ }\r
+ \r
+ public void initialize() {\r
+ index = 0;\r
+ }\r
+\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.adapter.generator;\r
+\r
+import java.util.List;\r
+\r
+/**\r
+ * Interface for parameter value generators. \r
+ * \r
+ * @author Tuomas Miettinen\r
+ *\r
+ */\r
+public interface IGenerator {\r
+\r
+ /**\r
+ * Get the next parameter combination.\r
+ * @return list of generated parameter values \r
+ */\r
+ public List<Double> next();\r
+ \r
+ /**\r
+ * Initialize the generator.\r
+ */\r
+ public void initialize();\r
+}\r
--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2013 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.sysdyn.adapter.generator;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Random;\r
+\r
+import org.simantics.databoard.Bindings;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.utils.ListUtils;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.sysdyn.SysdynResource;\r
+\r
+/**\r
+ * Random generator that creates ArrayLists of random Doubles between 0 and 1.\r
+ * \r
+ * @author Tuomas Miettinen\r
+ */\r
+\r
+public class RandomGenerator implements IGenerator {\r
+ \r
+ private int seed;\r
+ private int dimension;\r
+ private Random random;\r
+ \r
+ public RandomGenerator(ReadGraph graph, Resource method) {\r
+ \r
+ try {\r
+ SysdynResource SR = SysdynResource.getInstance(graph);\r
+ Resource experiment = graph.getPossibleObject(method, SR.SensitivityAnalysisExperiment_method_Inverse);\r
+ seed = graph.getPossibleRelatedValue(experiment, SR.SensitivityAnalysisExperiment_randomSeed, Bindings.INTEGER);\r
+ \r
+ Resource parameterListResource = graph.getPossibleObject(experiment, SR.SensitivityAnalysisExperiment_parameterList);\r
+ dimension = ListUtils.getListNodes(graph, parameterListResource).size();\r
+\r
+ initialize();\r
+ } catch (DatabaseException e) {\r
+ \r
+ }\r
+ }\r
+\r
+ public List<Double> next() {\r
+ ArrayList<Double> randoms = new ArrayList<Double>();\r
+ for (int i = 0; i < dimension; ++i)\r
+ randoms.add(random.nextDouble());\r
+ return randoms;\r
+ }\r
+ \r
+ public void initialize() {\r
+ random = new Random(this.seed);\r
+ }\r
+\r
+}\r
+++ /dev/null
-/*******************************************************************************\r
- * Copyright (c) 2013 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.sysdyn.manager;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Random;\r
-\r
-/**\r
- * Random generator that creates ArrayLists of random Doubles between 0 and 1.\r
- * \r
- * @author Tuomas Miettinen\r
- */\r
-\r
-public class RandomGenerator {\r
- \r
- private int seed;\r
- private int dimension;\r
- private Random random;\r
- \r
- public RandomGenerator(int seed, int dimension) {\r
- this.dimension = dimension;\r
- this.seed = seed;\r
- random = new Random(this.seed);\r
- }\r
- \r
- public ArrayList<Double> next() {\r
- ArrayList<Double> randoms = new ArrayList<Double>();\r
- for (int i = 0; i < dimension; ++i)\r
- randoms.add(random.nextDouble());\r
- return randoms;\r
- }\r
- \r
- public void initialize() {\r
- random = new Random(this.seed);\r
- }\r
-\r
-}\r
import org.simantics.databoard.Bindings;\r
import org.simantics.db.ReadGraph;\r
import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
import org.simantics.db.common.request.ReadRequest;\r
+import org.simantics.db.common.request.WriteRequest;\r
import org.simantics.db.common.utils.ListUtils;\r
import org.simantics.db.exception.DatabaseException;\r
import org.simantics.db.request.Read;\r
+import org.simantics.layer0.utils.direct.GraphUtils;\r
import org.simantics.modelica.IModelicaMonitor;\r
import org.simantics.modelica.ModelicaKeys;\r
import org.simantics.modelica.ModelicaManager;\r
import org.simantics.modelica.data.SimulationResult;\r
import org.simantics.sysdyn.SysdynResource;\r
import org.simantics.sysdyn.adapter.SensitivityExperimentParameter;\r
+import org.simantics.sysdyn.adapter.generator.IGenerator;\r
\r
/**\r
* Sensitivity analysis experiment\r
public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment {\r
\r
private ArrayList<MemoryResult> results = null;\r
- private int seed = 124;\r
private int numberOfRuns = 0;\r
+ private IGenerator valueGenerator = null;\r
\r
public SysdynSensitivityAnalysisExperiment(Resource experiment, Resource model) {\r
super(experiment, model);\r
ArrayList<HashMap<String, String>> parameterMaps = new ArrayList<HashMap<String, String>>();\r
int parametersSize = parameters.size();\r
\r
- // Get seed and number of runs\r
+ // Get method and number of runs\r
try {\r
- session.syncRequest(new ReadRequest() {\r
+ session.syncRequest(new WriteRequest() {\r
@Override\r
- public void run(ReadGraph graph) throws DatabaseException {\r
+ public void perform(WriteGraph graph) throws DatabaseException {\r
SysdynResource SR = SysdynResource.getInstance(graph);\r
- seed = graph.getPossibleRelatedValue(experiment, SR.SensitivityAnalysisExperiment_randomSeed, Bindings.INTEGER);\r
numberOfRuns = graph.getPossibleRelatedValue(experiment, SR.SensitivityAnalysisExperiment_numberOfValues, Bindings.INTEGER);\r
+ Resource methodResource = graph.getPossibleObject(experiment, SR.SensitivityAnalysisExperiment_method);\r
+ if (methodResource == null) {\r
+ methodResource = GraphUtils.create2(graph, SR.RandomGenerator);\r
+ graph.claim(experiment, SR.SensitivityAnalysisExperiment_method, methodResource);\r
+ }\r
+ valueGenerator = graph.adapt(methodResource, IGenerator.class);\r
}\r
+\r
});\r
} catch (DatabaseException e) {\r
e.printStackTrace();\r
// Refresh rate for charts\r
refreshRate = numberOfRuns / 20 + 1;\r
\r
- // Generate values for parameters (randomly)\r
- RandomGenerator randomGenerator = new RandomGenerator(seed, parametersSize);\r
+ // Initialize the random generator\r
+ valueGenerator.initialize();\r
\r
- // Determine the changed paramters and their values for each individual run\r
+ // Determine the changed parameters and their values for each individual run\r
for (int i = 0; i < numberOfRuns; ++i) {\r
- ArrayList<Double> randoms = randomGenerator.next();// multi-dimensional random\r
+ List<Double> randoms = valueGenerator.next();// multi-dimensional random\r
HashMap<String, String> parameterMap = new HashMap<String, String>(parametersSize);\r
for (int j = 0; j < parametersSize; ++j) {\r
SensitivityExperimentParameter p = parameters.get(j);\r