From fd38e2e7291abcb959024fc36f4ec18525b46435 Mon Sep 17 00:00:00 2001 From: villberg Date: Mon, 28 Apr 2014 08:19:53 +0000 Subject: [PATCH] Fixed some bugs encountered in Strada-model refs #4765 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29369 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../fi/semantum/sysdyn/solver/Addition.java | 1 + .../src/fi/semantum/sysdyn/solver/Array.java | 65 ++++++++++++++++--- .../fi/semantum/sysdyn/solver/Constant.java | 7 +- .../fi/semantum/sysdyn/solver/Division.java | 1 + .../semantum/sysdyn/solver/Environment.java | 9 +++ .../src/fi/semantum/sysdyn/solver/Model.java | 1 - .../sysdyn/solver/Multiplication.java | 1 + .../fi/semantum/sysdyn/solver/Negation.java | 4 +- .../src/fi/semantum/sysdyn/solver/Parser.java | 2 +- .../src/fi/semantum/sysdyn/solver/Solver.java | 8 ++- .../semantum/sysdyn/solver/SolverUtils.java | 24 ++++--- .../semantum/sysdyn/solver/Subtraction.java | 5 +- .../fi/semantum/sysdyn/solver/Variable.java | 11 +++- .../semantum/sysdyn/solver/VariableBase.java | 2 +- 14 files changed, 113 insertions(+), 28 deletions(-) diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java index a407ca4e..b2ec695c 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Addition.java @@ -33,6 +33,7 @@ public class Addition implements IExpression { public Object evaluate(IEnvironment environment) { Object o1 = exp1.evaluate(environment); Object o2 = exp2.evaluate(environment); + if(o1 == null || o2 == null) return null; if(o1 instanceof Double && o2 instanceof Double) { return (Double)o1 + (Double)o2; } diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java index a14e5ace..233838d9 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Array.java @@ -20,6 +20,8 @@ import fi.semantum.sysdyn.solver.SolverUtils.Slice; public class Array implements IExpression { + public static final Array FULL = new Array(); + private ArrayList elements = new ArrayList(); public Array() { @@ -171,29 +173,57 @@ public class Array implements IExpression { return true; } - public Array slice(Slice[] indices) { + public Array slice(Array[] indices) { if(indices.length == 1) { Array result = new Array(); - for(int i=indices[0].start;i<=indices[0].end;i++) { - result.addElement(element(i)); + for(Object r : indices[0].elements) { + Double d = (Double)r; + int index = d.intValue(); + result.addElement(element(index)); } return result; } - if(indices.length != 2) throw new IllegalStateException(); + if(indices.length == 2) { + if(indices[1] == Array.FULL) { + Double d = (Double)indices[0].element(0); + int index = d.intValue(); + return (Array)elements.get(index); + } else { + Array result = new Array(); + for(Object o : elements) { + Array a = (Array)o; + Double d = (Double)indices[1].element(0); + int index = d.intValue(); + result.addElement(a.element(index)); + } + return result; + } + } - if(indices[1] == Slice.FULL) { - return (Array)elements.get(indices[0].start); - } else { + if(indices.length == 3) { Array result = new Array(); - for(Object o : elements) { - Array a = (Array)o; - result.addElement(a.element(indices[1].start)); + for(int i=0;i 1) { if(subscripts != null) { - Slice[] sub = SolverUtils.parseSubscripts(environment, subscripts); + Array[] sub = SolverUtils.parseSubscripts(environment, subscripts); if(SolverUtils.isSlice(sub)) { Array arr = new Array(); intoArray(environment, index, 0, arr); -- 2.47.1