|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.lsmp.djep.rpe.RpEval
public final class 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 opportunity.
To use do
JEP j = ...; Node node = ...; RpEval rpe = new RpEval(j); RpCommandList list = rpe.compile(node); double val = rpe.evaluate(list); System.out.println(val); rpe.cleanUp();The compile methods converts the expression represented by node into a string of commands. For example the expression "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 the last object on the stack.
A few cautionary notes: Its very unlikely to be thread safe. It only works over doubles expressions 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 possible:
| 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 expressions 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 ParserVisitorParseException
public final java.lang.Object visit(SimpleNode node,
java.lang.Object data)
throws ParseException
visit in interface ParserVisitorParseException
public final java.lang.Object visit(ASTConstant node,
java.lang.Object data)
throws ParseException
visit in interface ParserVisitorParseException
public final java.lang.Object visit(ASTVarNode node,
java.lang.Object data)
throws ParseException
visit in interface ParserVisitorParseException
public final java.lang.Object visit(ASTFunNode node,
java.lang.Object data)
throws ParseException
visit in interface ParserVisitorParseExceptionpublic final double evaluate(RpCommandList comList)
public void cleanUp()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||