|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.lsmp.djep.rpe.RpEval
A fast evaluation algorithm for equations over Doubles, does not work with vectors or matricies. This is based around reverse polish notation and is optimised for speed at every oportunity.
To use do
JEP j = ...; Node node = ...; RpEval rpe = new RpEval(j); RpCommandList list = rpe.compile(node); double val rpRes = rpe.evaluate(list); System.out.println(val); rpe.cleanUp();The compile methods converts the expresion represented by node into a string of commands. For example the expresion "1+2*3" will be converted into the sequence of commands
Constant no 1 (pushes constant onto stack) Constant no 2 Constant no 3 Multiply scalers (multiplies last two entries on stack) Add scalers (adds last two entries on stack)The evaluate method executes these methods sequentially using a stack and returns thoe last object on the stack.
A few cautionary notes: Its very unlikely to be thread safe. It only works over doubles expresions with complex numbers or strings will cause problems. It only works for expressions involving scalers.
Implementation notes A lot of things have been done to make it as fast as posible:
Constructor Summary | |
RpEval(JEP jep)
|
Method Summary | |
void |
cleanUp()
Removes observers and other cleanup needed when evaluator no longer used. |
RpCommandList |
compile(Node node)
Compile the expresions to produce a set of commands in reverse Polish notation. |
double |
evaluate(RpCommandList comList)
Evaluate the expression. |
java.lang.Object |
visit(ASTConstant node,
java.lang.Object data)
|
java.lang.Object |
visit(ASTFunNode node,
java.lang.Object data)
|
java.lang.Object |
visit(ASTStart node,
java.lang.Object data)
|
java.lang.Object |
visit(ASTVarNode node,
java.lang.Object data)
|
java.lang.Object |
visit(SimpleNode node,
java.lang.Object data)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public RpEval(JEP jep)
Method Detail |
public final RpCommandList compile(Node node) throws ParseException
ParseException
public final java.lang.Object visit(ASTStart node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public final java.lang.Object visit(SimpleNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public final java.lang.Object visit(ASTConstant node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public final java.lang.Object visit(ASTVarNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public final java.lang.Object visit(ASTFunNode node, java.lang.Object data) throws ParseException
visit
in interface ParserVisitor
ParseException
public final double evaluate(RpCommandList comList)
public void cleanUp()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |