*******************************************************************************/\r
package fi.semantum.sysdyn.solver;\r
\r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
import gnu.trove.list.array.TIntArrayList;\r
import gnu.trove.map.hash.TObjectIntHashMap;\r
\r
@Override\r
public Object evaluate(IEnvironment environment, int argc) {\r
Object value = environment.getValue(0);\r
- Double result = (Double)value;\r
- double res = result.intValue(); \r
- return res;\r
+ if(value instanceof Double) {\r
+ return ((Double)value).intValue();\r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return ((Double)o).intValue();\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ model.functions.put("ceil", new Fn1(1) {\r
+\r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ Object value = environment.getValue(0);\r
+ if(value instanceof Double) {\r
+ return Math.ceil((Double)value);\r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return Math.ceil((Double)o);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ model.functions.put("floor", new Fn1(1) {\r
+\r
+ @Override\r
+ public Object evaluate(IEnvironment environment, int argc) {\r
+ Object value = environment.getValue(0);\r
+ if(value instanceof Double) {\r
+ return Math.floor((Double)value);\r
+ } else if(value instanceof Array) {\r
+ return ((Array)value).copy(new Modifier() {\r
+\r
+ @Override\r
+ public Object modify(Object o) {\r
+ if(o instanceof Double) {\r
+ return Math.floor((Double)o);\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
+ }\r
+ \r
+ });\r
+ } else {\r
+ throw new IllegalStateException();\r
+ }\r
}\r
\r
});\r
return res;\r
}\r
\r
+ });\r
+ model.functions.put("ones", new Fn1(1) {\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
+ }\r
+ \r
+ });\r
+ model.functions.put("zeros", new Fn1(1) {\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
+ }\r
+ \r
});\r
model.functions.put("delay", new Fn1(4) {\r
\r