From e69555d965b78bf8bd38344600b19a99aad6b5ae Mon Sep 17 00:00:00 2001 From: villberg Date: Mon, 19 May 2014 06:29:30 +0000 Subject: [PATCH] refs #4856 git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@29508 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../META-INF/MANIFEST.MF | 3 +- .../semantum/sysdyn/solver/Environment.java | 66 +++++++++++++++---- .../src/fi/semantum/sysdyn/solver/Solver.java | 34 ++++++++-- 3 files changed, 85 insertions(+), 18 deletions(-) diff --git a/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF b/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF index 3256e513..b1284b63 100644 --- a/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF +++ b/fi.semantum.sysdyn.solver/META-INF/MANIFEST.MF @@ -8,7 +8,8 @@ Bundle-Vendor: Semantum Oy Require-Bundle: org.eclipse.core.runtime, org.simantics.utils;bundle-version="1.1.0", org.simantics.databoard;bundle-version="0.6.5", - org.simantics.utils.datastructures;bundle-version="1.1.0" + org.simantics.utils.datastructures;bundle-version="1.1.0", + gnu.trove3;bundle-version="3.0.3" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Export-Package: fi.semantum.sysdyn.solver diff --git a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java index 849a8c99..ec454891 100644 --- a/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java +++ b/fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Environment.java @@ -11,11 +11,16 @@ *******************************************************************************/ package fi.semantum.sysdyn.solver; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.map.hash.TObjectIntHashMap; + import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.Map; +import java.util.Set; import java.util.TreeMap; interface Fn { @@ -67,6 +72,8 @@ final public class Environment implements IEnvironment, ISystem { public int size; public Object[] valueTable; + + public TObjectIntHashMap keyIndexMap = new TObjectIntHashMap(); HashMap> history = new HashMap>(); @@ -384,53 +391,77 @@ final public class Environment implements IEnvironment, ISystem { return; } + String prefix2 = prefix; + if(d== 0) prefix2 += "["; + if(d>0) prefix2 += ","; + for(int i=0;i keys) { + public int length(int[] dimension) { + int result = 1; + for(int d : dimension) result *=d; + return result; + } + + public void addVariable(String name, int index, int[] dimensions, ArrayList keys, TIntArrayList indices, Set used) { -// int dimensions[] = base.dimensions; + if(!used.add(name)) return; + if(dimensions == null) { keys.add(name); + indices.add(index); } else { addIndexed(dimensions, keys, name, 0); + for(int i=0;i keys) { - addVariable(var.base.name, var.base.dimensions, keys); + public void addVariable(Variable var, ArrayList keys, TIntArrayList indices, Set used) { + addVariable(var.base.name, var.base.index, var.base.dimensions, keys, indices, used); } public String[] getValueKeyArray() { ArrayList keys = new ArrayList(); + TIntArrayList indices = new TIntArrayList(); + Set used = new HashSet(); for (int i = 0; i < model.assignmentArray.length; i++) { - addVariable(model.assignmentArray[i].target, keys); + addVariable(model.assignmentArray[i].target, keys, indices, used); } for (int i = 0; i < model.derivativeArray.length; i++) { - addVariable(model.derivativeArray[i].target, keys); + addVariable(model.derivativeArray[i].target, keys, indices, used); } // NOTE: there is room for optimization as parameter values that do not // change should only be obtained once (and parameter values that do // change are (possibly) included in assignments or derivatives) for(int i = 0; i < model.parameterArray.length; i++) { - addVariable(model.parameterArray[i].variable, keys); + addVariable(model.parameterArray[i].variable, keys, indices, used); } for(Map.Entry entry : model.copies.entrySet()) { - addVariable(entry.getKey(), entry.getValue().dimensions, keys); + addVariable(entry.getKey(), entry.getValue().index, entry.getValue().dimensions, keys, indices, used); } - + valueArray = new double[keys.size()]; + keyIndexMap.clear(); + for(int i=0;i used = new HashSet(); + for (int i = 0; i < model.assignmentArray.length; i++) { Variable v = model.assignmentArray[i].target; + if(!used.add(v.base.name)) continue; for(int index=0;index entry : model.copies.entrySet()) { VariableBase base = entry.getValue(); + if(!used.add(base.name)) continue; for(int index=0;index