]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Error handling for circular dependencies in Sysdyn models: should not throw StackOver...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 23 Jun 2014 07:00:04 +0000 (07:00 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Mon, 23 Jun 2014 07:00:04 +0000 (07:00 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29682 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn/src/org/simantics/sysdyn/representation/Variability.java

index 27f33a69b79ce4df484e41d2e5799fc52a170f3d..7ccc8155ee0f6d241d5a7de9963c365a045701ff 100644 (file)
@@ -1,5 +1,5 @@
 /*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
+ * Copyright (c) 2007, 2012, 2014 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
@@ -28,6 +28,7 @@ import org.simantics.sysdyn.representation.utils.RepresentationUtils;
  * Variability of a variable in system dynamics models. \r
  * \r
  * @author Teemu Lempinen\r
+ * @author Tuomas Miettinen\r
  *\r
  */\r
 public enum Variability {\r
@@ -164,23 +165,28 @@ public enum Variability {
      * @return Variabilty of a variable\r
      */\r
     static public Variability getVariability(IndependentVariable variable) {\r
-       if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) {\r
-               \r
-               /* \r
-                * Game experiments cannot use as many parameter variables as normal experiments.\r
-                * If a parameter variable is changed, other parameter values depending on that \r
-                * parameter value are not automatically changed.\r
-                * \r
-                * Something of a hack: \r
-                * Allow variable references, if there are not incoming dependencies to the variable.\r
-                * This enables the use of derived variables for initial values of stocks.\r
-                */\r
-               if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty())\r
-                       return getVariability(variable, true, null);\r
-               else\r
-                       return getVariability(variable, false, null);\r
-       } else {\r
-               return getVariability(variable, true, null);\r
+       try {\r
+                       if(RepresentationUtils.isPartOfGameExperiment(variable) && !(variable instanceof Stock)) {\r
+                               \r
+                               /* \r
+                                * Game experiments cannot use as many parameter variables as normal experiments.\r
+                                * If a parameter variable is changed, other parameter values depending on that \r
+                                * parameter value are not automatically changed.\r
+                                * \r
+                                * Something of a hack: \r
+                                * Allow variable references, if there are not incoming dependencies to the variable.\r
+                                * This enables the use of derived variables for initial values of stocks.\r
+                                */\r
+                               if(variable.getIncomingDependencies() == null || variable.getIncomingDependencies().isEmpty())\r
+                                       return getVariability(variable, true, null);\r
+                               else\r
+                                       return getVariability(variable, false, null);\r
+                       } else {\r
+                               return getVariability(variable, true, null);\r
+                       }\r
+       } catch (StackOverflowError e) {\r
+               // For circular dependencies; selecting continuous for a good guess.\r
+               return Variability.CONTINUOUS;\r
        }\r
     }\r
 \r