]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Added interface for different parameter value generators for sensitivity analysis.
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 3 Jul 2013 12:23:10 +0000 (12:23 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Wed, 3 Jul 2013 12:23:10 +0000 (12:23 +0000)
Implemented Halton sequence generator.
(refs #4365)

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@27681 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ontology/graph.tg
org.simantics.sysdyn.ontology/graph/Sysdyn.pgraph
org.simantics.sysdyn.ontology/src/org/simantics/sysdyn/SysdynResource.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/handlers/newComponents/NewSensitivityAnalysisExperimentNodeHandler.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/SensitivityAnalysisExperimentTab.java
org.simantics.sysdyn/adapters.xml
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/HaltonSequenceGenerator.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/IGenerator.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/RandomGenerator.java [new file with mode: 0644]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/RandomGenerator.java [deleted file]
org.simantics.sysdyn/src/org/simantics/sysdyn/manager/SysdynSensitivityAnalysisExperiment.java

index a01167bedf29b956211c931238a9e095601749ea..d242b0ba169f8a61dc30804ae3fcd5af735cfd3c 100644 (file)
Binary files a/org.simantics.sysdyn.ontology/graph.tg and b/org.simantics.sysdyn.ontology/graph.tg differ
index 9b8873121f0bb86c902c4c378a9ca9a4a40d1206..a4b4fdc6fce7aa533d0adf1310be9ac2aef7d6e1 100644 (file)
@@ -351,6 +351,7 @@ SYSDYN.PlaybackExperiment <T SYSDYN.Experiment
 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
@@ -382,6 +383,10 @@ SYSDYN.Interval <T SYSDYN.ProbabilityDistribution
     @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
 //#####################################################################
index 5d086c8921c1ce00c5cd072d46b12c908cdaeadd..47e988f546fc5fecd065a21ef79a4cccd7d69cc8 100644 (file)
@@ -393,6 +393,7 @@ public class SysdynResource {
     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
@@ -532,6 +533,7 @@ public class SysdynResource {
     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
@@ -560,6 +562,8 @@ public class SysdynResource {
     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
@@ -690,6 +694,7 @@ public class SysdynResource {
     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
@@ -1121,6 +1126,7 @@ public class SysdynResource {
         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
@@ -1260,6 +1266,7 @@ public class SysdynResource {
         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
@@ -1288,6 +1295,8 @@ public class SysdynResource {
         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
@@ -1418,6 +1427,7 @@ public class SysdynResource {
         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
@@ -1859,6 +1869,7 @@ public class SysdynResource {
         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
@@ -1998,6 +2009,7 @@ public class SysdynResource {
         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
@@ -2026,6 +2038,8 @@ public class SysdynResource {
         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
@@ -2156,6 +2170,7 @@ public class SysdynResource {
         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
index 05f5300293e9bb19141a8ed4e2f985f4feced5d1..1a8ae7a953d2b705504b82a5c0e605f8ce31b6c7 100644 (file)
@@ -36,12 +36,15 @@ public class NewSensitivityAnalysisExperimentNodeHandler extends NewExperimentNo
         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
index 12d743f84a322561977ab7d722c8759a2d0cffd6..2001b02fac4405fc6d42da5d7f23ebf25c1e3f8b 100644 (file)
@@ -103,12 +103,13 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo
     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
@@ -129,7 +130,7 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo
         // 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
@@ -148,7 +149,80 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo
         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
@@ -158,7 +232,7 @@ public class SensitivityAnalysisExperimentTab extends LabelPropertyTabContributo
         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
index e370bc2cfa2ecada78e4b150787e8326fe64d840..509cd5eaf7518807ce9556b3d7857a769dea2cde 100644 (file)
         </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
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/HaltonSequenceGenerator.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/HaltonSequenceGenerator.java
new file mode 100644 (file)
index 0000000..15363fd
--- /dev/null
@@ -0,0 +1,95 @@
+/*******************************************************************************\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
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/IGenerator.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/IGenerator.java
new file mode 100644 (file)
index 0000000..5979264
--- /dev/null
@@ -0,0 +1,34 @@
+/*******************************************************************************\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
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/RandomGenerator.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/adapter/generator/RandomGenerator.java
new file mode 100644 (file)
index 0000000..e4a920f
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************\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
diff --git a/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/RandomGenerator.java b/org.simantics.sysdyn/src/org/simantics/sysdyn/manager/RandomGenerator.java
deleted file mode 100644 (file)
index d58578b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************\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
index ea5f79906a9fafe791b48a294b389089f21064dc..c1b8ad508b3f12037654838d95047f378acbc56c 100644 (file)
@@ -23,10 +23,13 @@ import org.eclipse.core.runtime.IProgressMonitor;
 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
@@ -36,6 +39,7 @@ import org.simantics.modelica.data.MatSimulationResult;
 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
@@ -45,8 +49,8 @@ import org.simantics.sysdyn.adapter.SensitivityExperimentParameter;
 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
@@ -56,15 +60,21 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment {
        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
@@ -73,12 +83,12 @@ public class SysdynSensitivityAnalysisExperiment extends SysdynExperiment {
         // 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