\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class Addition implements IExpression {\r
\r
public IExpression exp1;\r
if(o1 instanceof Array && o2 instanceof Array) {\r
Array la = (Array)o1;\r
Array ra = (Array)o2;\r
- return la.add(ra);\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)+((Double)o2);\r
+ throw new IllegalStateException("Tried to add a non-numerical array");\r
+ }\r
+ });\r
}\r
throw new IllegalStateException();\r
}\r
throw new IllegalStateException();\r
\r
}\r
- \r
- public Array add(Array other) {\r
- Array result = new Array();\r
- Collection<Object> lae = elements();\r
- Collection<Object> rae = other.elements();\r
- if(lae.size() != rae.size()) throw new IllegalStateException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- for(int i=0;i<lae.size();i++) {\r
- Object l = li.next();\r
- Object r = ri.next();\r
- if(l instanceof Double && r instanceof Double) {\r
- result.addElement(((Double)l)+((Double)r));\r
- } else if (l instanceof Array && r instanceof Array) {\r
- Array arr = (Array)l;\r
- Array otherArr = (Array)r;\r
- result.addElement(arr.add(otherArr));\r
- } else {\r
- throw new IllegalStateException();\r
- }\r
- }\r
- return result;\r
- }\r
-\r
- public Array sub(Array other) {\r
- Array result = new Array();\r
- Collection<Object> lae = elements();\r
- Collection<Object> rae = other.elements();\r
- if(lae.size() != rae.size()) throw new IllegalStateException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- for(int i=0;i<lae.size();i++) {\r
- Object l = li.next();\r
- Object r = ri.next();\r
- if(l instanceof Double && r instanceof Double) {\r
- result.addElement(((Double)l)-((Double)r));\r
- } else if (l instanceof Array && r instanceof Array) {\r
- Array arr = (Array)l;\r
- Array otherArr = (Array)r;\r
- result.addElement(arr.sub(otherArr));\r
- } else {\r
- throw new IllegalStateException();\r
- }\r
- }\r
- return result;\r
- }\r
\r
- public Array mul(Array other) {\r
- Array result = new Array();\r
- Collection<Object> lae = elements();\r
- Collection<Object> rae = other.elements();\r
- if(lae.size() != rae.size()) throw new IllegalStateException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- for(int i=0;i<lae.size();i++) {\r
- Object l = li.next();\r
- Object r = ri.next();\r
- if(l instanceof Double && r instanceof Double) {\r
- result.addElement(((Double)l)*((Double)r));\r
- } else if (l instanceof Array && r instanceof Array) {\r
- Array arr = (Array)l;\r
- Array otherArr = (Array)r;\r
- result.addElement(arr.mul(otherArr));\r
- } else {\r
- throw new IllegalStateException();\r
- }\r
- }\r
- return result;\r
- }\r
/*\r
* Both arrays are vectors \r
*/\r
Object modify(Object o);\r
}\r
\r
+ interface Modifier2 {\r
+ Object modify(Object o1, Object o2);\r
+ }\r
+\r
public Array copy(Modifier modifier) {\r
Array result = new Array();\r
for(Object element : elements) {\r
return result;\r
}\r
\r
+ public Array copy2(Array other, Modifier2 modifier) {\r
+ Array result = new Array();\r
+ Collection<Object> es = elements();\r
+ Collection<Object> oes = other.elements();\r
+ if(es.size() != oes.size()) throw new IllegalStateException("Array dimensions do not match");\r
+ Iterator<Object> e = es.iterator();\r
+ Iterator<Object> oe = oes.iterator();\r
+ for(int i=0;i<es.size();i++) {\r
+ Object element = e.next();\r
+ Object otherElement = oe.next();\r
+ if(element instanceof Array) {\r
+ if(otherElement instanceof Array) {\r
+ result.addElement(((Array)element).copy2((Array)otherElement, modifier));\r
+ } else {\r
+ throw new IllegalStateException("Array dimensions do not match");\r
+ }\r
+ } else {\r
+ if(otherElement instanceof Array) {\r
+ throw new IllegalStateException("Array dimensions do not match");\r
+ } else {\r
+ result.addElement(modifier.modify(element, otherElement));\r
+ }\r
+ } \r
+ }\r
+ return result;\r
+ }\r
+\r
public boolean isVector() {\r
return isVector;\r
}\r
if(element instanceof Array) throw new IllegalStateException();\r
if(element instanceof IExpression) {\r
IExpression exp = (IExpression)element;\r
- return exp.evaluate(environment);\r
+ ret.addElement(exp.evaluate(environment));\r
} else {\r
ret.addElement(element);\r
}\r
} else {\r
if(element instanceof Array) {\r
- return ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
+ ret.addElement(((Array)element).subscript(environment, subscripts, position+1));\r
} else {\r
throw new IllegalStateException();\r
}\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class Derivate implements IExpression {\r
\r
private Variable variable;\r
\r
@Override\r
public Object evaluate(IEnvironment _environment) {\r
- Environment environment = (Environment)_environment;\r
-// Double old = (Double)environment.getValue(variable.name + variable.subscriptKey());\r
+ final Environment environment = (Environment)_environment;\r
Object old = variable.evaluate(environment);\r
\r
-// Double old = (Double)environment.getValue(variable.base.index(_environment, subscripts));\r
// FIXME: should not be fixed like this\r
if(old == null) old = 0.0;\r
Object eval = e.evaluate(environment);\r
} else if (eval instanceof Array) {\r
Array arr = (Array)eval;\r
Array oldArray = (Array)old;\r
- Array result = new Array();\r
- for(int i=0;i<arr.dimension();i++) {\r
- Double d = (Double)arr.element(i);\r
- Double o = (Double)oldArray.element(i);\r
- result.addElement(o+environment.step*d);\r
- }\r
- return result;\r
+ \r
+ return oldArray.copy2(arr, new Modifier2() {\r
+\r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ Double oldValue = (Double)o1;\r
+ Double der = (Double)o2;\r
+ return oldValue + environment.step*der;\r
+ }\r
+ \r
+ });\r
+ \r
} else {\r
throw new UnsupportedOperationException();\r
}\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+\r
public class Division implements IExpression {\r
\r
public IExpression exp1;\r
return exp1 + " / " + exp2;\r
}\r
\r
- private Array arrayDiv(Array a, Double d) {\r
- Array result = new Array();\r
- for(Object o : a.elements()) {\r
- if(o instanceof Double) {\r
- result.addElement((Double)o/d);\r
- } else {\r
- throw new IllegalStateException();\r
- }\r
- }\r
- return result;\r
+ private Array arrayDiv(Array a, final Double d) {\r
+ return a.copy(new Modifier() {\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return ((Double)o)/d;\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ });\r
}\r
\r
@Override\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class ElementwiseDivision implements IExpression {\r
\r
public IExpression exp1;\r
if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- Collection<Object> lae = la.elements();\r
- Collection<Object> rae = ra.elements();\r
- if(lae.size() != rae.size()) throw new UnsupportedOperationException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- Array result = new Array();\r
- for(int i=0;i<lae.size();i++) {\r
- double ld = (Double)li.next();\r
- double rd = (Double)ri.next();\r
- result.addElement(ld/rd);\r
- }\r
- return result;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)/((Double)o2);\r
+ throw new IllegalStateException("Tried to divide a non-numerical array");\r
+ }\r
+ \r
+ });\r
} else if(left instanceof Array && right instanceof Double) {\r
Array la = (Array)left;\r
- double rd = (Double)right;\r
- Collection<Object> lae = la.elements();\r
- Iterator<Object> li = lae.iterator();\r
- Array result = new Array();\r
- for(int i=0;i<lae.size();i++) {\r
- double ld = (Double)li.next();\r
- result.addElement(ld/rd);\r
- }\r
- return result;\r
+ final double rd = (Double)right;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return ((Double)o)/rd;\r
+ else throw new IllegalStateException("Tried to divide a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else if(left instanceof Double && right instanceof Array) {\r
+ Array la = (Array)right;\r
+ final double rd = (Double)left;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return rd / ((Double)o);\r
+ else throw new IllegalStateException("Tried to divide a non-numerical array");\r
+ }\r
+ \r
+ });\r
} else if(left instanceof Double && right instanceof Double) {\r
- double ld = (Double)left;\r
- double rd = (Double)right;\r
- return ld*rd;\r
+ return ((Double)left)/((Double)right);\r
} else {\r
throw new UnsupportedOperationException();\r
}\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class ElementwisePower implements IExpression {\r
\r
public IExpression exp1;\r
if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- Collection<Object> lae = la.elements();\r
- Collection<Object> rae = ra.elements();\r
- if(lae.size() != rae.size()) throw new UnsupportedOperationException();\r
- Iterator<Object> li = lae.iterator();\r
- Iterator<Object> ri = rae.iterator();\r
- Array result = new Array();\r
- for(int i=0;i<lae.size();i++) {\r
- double ld = (Double)li.next();\r
- double rd = (Double)ri.next();\r
- result.addElement(Math.pow(ld,rd));\r
- }\r
- return result;\r
- } else throw new UnsupportedOperationException();\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return Math.pow((Double)o1,(Double)o2);\r
+ throw new IllegalStateException("Tried to pow a non-numerical array");\r
+ }\r
+ });\r
+ } else if (left instanceof Array && right instanceof Double) {\r
+ Array la = (Array)left;\r
+ final double rd = (Double)right;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return Math.pow((Double)o,rd);\r
+ else throw new IllegalStateException("Tried to pow a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else if (left instanceof Double && right instanceof Array) {\r
+ Array la = (Array)right;\r
+ final double rd = (Double)left;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return Math.pow(rd,(Double)o);\r
+ else throw new IllegalStateException("Tried to pow a non-numerical array");\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new UnsupportedOperationException();\r
+ }\r
}\r
\r
@Override\r
*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
-import java.util.Collection;\r
-import java.util.Iterator;\r
-import java.util.List;\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class ElementwiseProduct implements IExpression {\r
\r
public IExpression exp1;\r
if(left instanceof Array && right instanceof Array) {\r
Array la = (Array)left;\r
Array ra = (Array)right;\r
- List<Object> lae = la.elements();\r
- List<Object> rae = ra.elements();\r
- if(lae.size() != rae.size()) throw new UnsupportedOperationException();\r
- Array result = new Array(lae.size());\r
- int index = 0;\r
- for(Object o : lae) {\r
- Double ld = (Double)o;\r
- Double rd = (Double)rae.get(index++);\r
- result.addElement(ld*rd);\r
- }\r
- return result;\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)*((Double)o2);\r
+ throw new IllegalStateException("Tried to multiply a non-numerical array");\r
+ }\r
+ });\r
} else if (left instanceof Array && right instanceof Double) {\r
Array la = (Array)left;\r
- Double rd = (Double)right;\r
- List<Object> lae = la.elements();\r
- Array result = new Array(lae.size());\r
- for(Object o : lae) {\r
- Double ld = (Double)o;\r
- result.addElement(ld*rd);\r
- }\r
- return result;\r
+ final double rd = (Double)right;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return ((Double)o)*rd;\r
+ else throw new IllegalStateException("Tried to multiply a non-numerical array");\r
+ }\r
+ \r
+ });\r
} else if (left instanceof Double && right instanceof Array) {\r
- Array ra = (Array)right;\r
- Double ld = (Double)left;\r
- List<Object> rae = ra.elements();\r
- Array result = new Array(rae.size());\r
- for(Object o : rae) {\r
- Double rd = (Double)o;\r
- result.addElement(ld*rd);\r
- }\r
- return result;\r
+ Array la = (Array)right;\r
+ final double rd = (Double)left;\r
+ return la.copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) return ((Double)o)*rd;\r
+ else throw new IllegalStateException("Tried to multiply a non-numerical array");\r
+ }\r
+ \r
+ });\r
} else {\r
throw new UnsupportedOperationException();\r
}\r
import gnu.trove.map.hash.TObjectIntHashMap;\r
\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.Collection;\r
import java.util.HashMap;\r
import java.util.HashSet;\r
public Object evaluateInput(IEnvironment environment, int argPosition);\r
public void setLocals(IEnvironment environment);\r
public int offset();\r
- public Variable[] parameters();\r
+ public Variable[] parameters(int args);\r
}\r
\r
abstract class Fn1 implements Fn {\r
Variable[] parameters;\r
\r
public Fn1(int pCount) {\r
- parameters = new Variable[pCount];\r
- for(int i=0;i<pCount;i++)\r
- parameters[i] = new Variable(new VariableBase("", i));\r
+ if(pCount > 0) {\r
+ parameters = new Variable[pCount];\r
+ for(int i=0;i<pCount;i++)\r
+ parameters[i] = new Variable(new VariableBase("", i));\r
+ }\r
}\r
\r
public int offset() {\r
return 0;\r
}\r
\r
- public Variable[] parameters() {\r
- return parameters;\r
+ public Variable[] parameters(int argc) {\r
+ if(parameters != null) return parameters;\r
+ else {\r
+ Variable[] ret = new Variable[argc];\r
+ for(int i=0;i<argc;i++)\r
+ ret[i] = new Variable(new VariableBase("", i));\r
+ return ret;\r
+ }\r
}\r
\r
@Override\r
});\r
model.functions.put("sum", new Fn1(1) {\r
\r
+ public double sum(Array a) {\r
+ double res = 0;\r
+ for(Object element : a.elements()) {\r
+ if(element instanceof Array) {\r
+ res += sum((Array)element);\r
+ } else if(element instanceof Double) {\r
+ res += (Double)element;\r
+ } else {\r
+ throw new IllegalStateException("Tried to sum a non-numerical array");\r
+ }\r
+ }\r
+ return res;\r
+ }\r
+ \r
@Override\r
public Object evaluate(IEnvironment environment, int argc) {\r
Object value = environment.getValue(0);\r
+ if(value instanceof Double) return (Double)value;\r
Array arr = (Array)value;\r
- double res = 0;\r
- for(Object o : arr.elements())\r
- res += (Double)o;\r
- return res;\r
+ return sum(arr);\r
}\r
\r
});\r
- model.functions.put("ones", new Fn1(1) {\r
+ model.functions.put("ones", new Fn1(-1) {\r
\r
+ private Array make(int[] dims, int pos) {\r
+ Array result = new Array();\r
+ int d = dims[pos];\r
+ if(pos == dims.length - 1) {\r
+ for(int i=0;i<d;i++) result.addElement(1.0);\r
+ } else {\r
+ for(int i=0;i<d;i++) result.addElement(make(dims, pos+1));\r
+ }\r
+ return result;\r
+ }\r
+ \r
@Override\r
public Object evaluate(IEnvironment environment, int argc) {\r
- Object value = environment.getValue(0);\r
- Double size = (Double)value;\r
- Array res = new Array();\r
- for(int i=0;i<size.intValue();i++) res.addElement(1.0);\r
- return res;\r
+ int[] dims = new int[argc];\r
+ for(int i=0;i<argc;i++) {\r
+ Double d = (Double)environment.getValue(0);\r
+ dims[i] = d.intValue();\r
+ }\r
+ return make(dims, 0);\r
}\r
\r
});\r
- model.functions.put("zeros", new Fn1(1) {\r
+ model.functions.put("zeros", new Fn1(-1) {\r
\r
+ private Array make(int[] dims, int pos) {\r
+ Array result = new Array();\r
+ int d = dims[pos];\r
+ if(pos == dims.length - 1) {\r
+ for(int i=0;i<d;i++) result.addElement(0.0);\r
+ } else {\r
+ for(int i=0;i<d;i++) result.addElement(make(dims, pos+1));\r
+ }\r
+ return result;\r
+ }\r
+ \r
@Override\r
public Object evaluate(IEnvironment environment, int argc) {\r
- Object value = environment.getValue(0);\r
- Double size = (Double)value;\r
- Array res = new Array();\r
- for(int i=0;i<size.intValue();i++) res.addElement(0.0);\r
- return res;\r
+ int[] dims = new int[argc];\r
+ for(int i=0;i<argc;i++) {\r
+ Double d = (Double)environment.getValue(i);\r
+ dims[i] = d.intValue();\r
+ }\r
+ System.err.println("zeros " + Arrays.toString(dims));\r
+ return make(dims, 0);\r
}\r
\r
});\r
}\r
\r
@Override\r
- public Variable[] parameters() {\r
+ public Variable[] parameters(int argc) {\r
return parameters;\r
}\r
\r
\r
@Override\r
public Object evaluate(IEnvironment environment) {\r
- return ((Double)exp1.evaluate(environment)) > ((Double)exp2.evaluate(environment));\r
+ Object left = exp1.evaluate(environment);\r
+ Object right = exp2.evaluate(environment);\r
+ return ((Double)left) > ((Double)right);\r
}\r
\r
@Override\r
import java.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.HashMap;\r
+import java.util.List;\r
import java.util.Map;\r
import java.util.TreeMap;\r
\r
argh.add(args.args[i].modification.evaluate(environment));\r
}\r
\r
- Variable[] parameters = fn.parameters();\r
+ Variable[] parameters = fn.parameters(argh.size());\r
\r
for(int i=0;i<args.args.length+1;i++) {\r
Variable var = parameters[i];\r
argh.add(arg);\r
}\r
\r
- Variable[] parameters = fn.parameters();\r
+ Variable[] parameters = fn.parameters(args.args.length);\r
Object[] ps = new Object[parameters.length];\r
+ boolean vector[] = new boolean[parameters.length];\r
\r
int vectorDimension = 0;\r
+ ArrayList<Array> arrs = new ArrayList<Array>();\r
for(int i=0;i<parameters.length;i++) {\r
Variable var = parameters[i];\r
if(i < argh.size()) {\r
} else {\r
ps[i] = fn.evaluateInput(environment, i);\r
}\r
- if(var.base.dimensions == null && ps[i] instanceof Array)\r
- vectorDimension = ((Array)ps[i]).dimension();\r
+ if(var.base.dimensions == null && ps[i] instanceof Array) {\r
+ int dim = ((Array)ps[i]).dimension();\r
+ if(vectorDimension > 0 && dim != vectorDimension) throw new IllegalStateException("Array dimensions do not agree");\r
+ vectorDimension = dim;\r
+ vector[i] = true;\r
+ arrs.add((Array)ps[i]);\r
+ } else {\r
+ vector[i] = false;\r
+ }\r
}\r
\r
if(vectorDimension > 0) {\r
-\r
- Array result = new Array();\r
- \r
- for(int i=0;i<vectorDimension;i++) {\r
-\r
- for(int j=0;j<parameters.length;j++) {\r
- Object o = ps[j];\r
- if(o instanceof Array) {\r
- Object sub = ((Array)o).element(i);\r
- parameters[j].assignPlain(frame, sub);\r
- } else {\r
- parameters[j].assignPlain(frame, o);\r
- }\r
- }\r
- \r
- fn.setLocals(frame);\r
- Object ret = fn.evaluate(frame, args.args.length);\r
- result.addElement(ret);\r
- \r
- }\r
\r
- return result;\r
+ return arrayEvaluate(frame, fn, parameters, ps, vector, arrs);\r
\r
} else {\r
\r
}\r
\r
fn.setLocals(frame);\r
- return fn.evaluate(frame, args.args.length);\r
+ Object value = fn.evaluate(frame, args.args.length); \r
+ return value;\r
\r
}\r
\r
\r
}\r
\r
+ private Array arrayEvaluate(Frame frame, Fn fn, Variable[] parameters, Object[] ps, boolean[] vector, List<Array> arrs) {\r
+ \r
+ Array result = new Array();\r
+\r
+ Array first = arrs.get(0);\r
+ \r
+ int d = first.elements().size();\r
+ if(d == 0) return result;\r
+\r
+ Object firstElement = first.element(0);\r
+ boolean subArray = firstElement instanceof Array;\r
+ \r
+ for(int i=0;i<d;i++) {\r
+\r
+ int vectorIndex = 0;\r
+\r
+ if(subArray) {\r
+\r
+ ArrayList<Array> subArrs = new ArrayList<Array>();\r
+ for(int j=0;j<parameters.length;j++) {\r
+ if(vector[j]) {\r
+ Array a = arrs.get(vectorIndex++);\r
+ Array sub = (Array)a.element(i);\r
+ subArrs.add(sub);\r
+ }\r
+ }\r
+ \r
+ result.addElement(arrayEvaluate(frame, fn, parameters, ps, vector, subArrs));\r
+\r
+ } else {\r
+\r
+ for(int j=0;j<parameters.length;j++) {\r
+ if(vector[j]) {\r
+ Array a = arrs.get(vectorIndex++);\r
+ Object sub = a.element(i);\r
+ parameters[j].assignPlain(frame, sub);\r
+ } else {\r
+ parameters[j].assignPlain(frame, ps[j]);\r
+ }\r
+ }\r
+\r
+ fn.setLocals(frame);\r
+ Object ret = fn.evaluate(frame, parameters.length);\r
+ result.addElement(ret);\r
+ \r
+ }\r
+ \r
+ } \r
+ \r
+ return result;\r
+\r
+ }\r
+ \r
private VariableBase resolveCopy(Map<String,VariableBase> work, VariableBase target) {\r
VariableBase deep = work.get(target.name);\r
if(deep == null) return target;\r
\r
import java.util.Map;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier2;\r
+\r
public class Subtraction implements IExpression {\r
\r
public IExpression exp1;\r
if(o1 instanceof Array && o2 instanceof Array) {\r
Array la = (Array)o1;\r
Array ra = (Array)o2;\r
- return la.sub(ra);\r
+ return la.copy2(ra, new Modifier2() {\r
+ \r
+ @Override\r
+ public Object modify(Object o1, Object o2) {\r
+ if(o1 instanceof Double && o2 instanceof Double) return ((Double)o1)-((Double)o2);\r
+ throw new IllegalStateException("Tried to subtract a non-numerical array");\r
+ }\r
+ });\r
}\r
throw new IllegalStateException();\r
}\r
else return array;\r
\r
} else {\r
- \r
+\r
if(dimension() > 1) {\r
+\r
+ Array array = new Array();\r
+ intoArray(environment, index, 0, array);\r
if(subscripts != null) {\r
- \r
- Array[] sub = SolverUtils.parseSubscripts(environment, subscripts);\r
- if(SolverUtils.isSlice(sub)) {\r
- Array arr = new Array();\r
- intoArray(environment, index, 0, arr);\r
- return arr.slice(sub);\r
- } else { \r
- return environment.getValue(index(environment, subscripts));\r
- }\r
- \r
- } else {\r
- Array array = new Array();\r
- intoArray(environment, index, 0, array);\r
- return array;\r
+ return array.subscript(environment, subscripts);\r
}\r
+ else return array;\r
+\r
+// if(subscripts != null) {\r
+// \r
+// Array[] sub = SolverUtils.parseSubscripts(environment, subscripts);\r
+// if(SolverUtils.isSlice(sub)) {\r
+// Array arr = new Array();\r
+// intoArray(environment, index, 0, arr);\r
+// return arr.slice(sub);\r
+// } else { \r
+// return environment.getValue(index(environment, subscripts));\r
+// }\r
+// \r
+// } else {\r
+// return array;\r
+// }\r
}\r
\r
Object result = environment.getNamedValue(name);\r