gov.nasa.arc.brahms.vm.data
Class VMExpression

java.lang.Object
  extended by gov.nasa.arc.brahms.common.data.BrahmsObject
      extended by gov.nasa.arc.brahms.common.data.Expression
          extended by gov.nasa.arc.brahms.vm.data.VMExpression
All Implemented Interfaces:
IExpression, gov.nasa.arc.brahms.common.IConstants, IVMExpression, java.io.Serializable

public class VMExpression
extends Expression
implements IVMExpression

The VMExpression is an Expression with extensions for use in the virtual machine. An Expression either represents an operand or a mathematical expression allowing for the mathematical operators +, -, *, /, and %. Expressions with a left and right hand side must have an operator and the evaluated expression must result in a numeric value.

Version:
$Revision: 1.4 $ $Date: 2009/11/23 22:18:57 $ $Author: rnado $
Author:
Ron van Hoof
See Also:
Expression, Serialized Form

Field Summary
 
Fields inherited from interface gov.nasa.arc.brahms.common.IConstants
ABORT, ACTIVECLASS, ACTIVECONCEPT, ACTIVEINSTANCE, AGENT, ANONYMOUS, ANYAGENT, AREA, AREADEF, ASSIGNED, ATTRIBUTE, BASEAREADEF, BASECLASS, BASECONCEPTUALCLASS, BASEGROUP, BASELIBRARY, BOOLEAN, BROADCAST, BUILDING, BYTE, CCLOCK, CDATE, CHAR, CITY, CLASS, CLOCK, COLLECTALL, COMMUNICATE, COMPLETE, COMPOSITE, COMPUTER, CONCEPT, CONCEPTUALCLASS, CONCEPTUALCONCEPT, CONCEPTUALOBJECT, CONTINUE, COPY, CREATEAGENT, CREATEAREA, CREATEOBJECT, current, CURRENT, DATAFRAME, DATE, DB, DETECTABLE, DIV, DOUBLE, EMAIL, EMPTY_STRING, END, ENDACTIVITY, ENTAGENT, EQ, EXCEPTION, EXPR, FACE2FACE, FACTFRAME, FALSE, FAX, FLOAT, FOREACH, FORONE, G2, GE, GEOGRAPHYCONCEPT, GESTURE, GET, GROUP, GT, IMPASSE, INT, INVALID, JAVA, JAVA_TYPE, KNOWN_MODIFIER, KNOWNVAL_MODIFIER, LE, LOCAL, LONG, LT, MAP, MINUS, MOD, MOVE, MULT, NE, NEW, NONE, NOT_MODIFIER, NOWORK, O, OA, OBJECT, ONTOLOGY, PAGER, PARAMETER, PATH, PHONE, PLUS, PRIMITIVE, PRIVATE, PROAGENT, PROTECTED, PRSAGENT, PUBLIC, PUT, RECEIVE, RELATION, sACTIVECLASS, sACTIVECONCEPT, sACTIVEINSTANCE, sAGENT, sARCHIVE, sAREA, sAREADEF, sBOOLEAN, sBYTE, sBYTECODEEXT, sCHAR, sCLASS, sCOMPUTER, sCONCEPT, sCONCEPTUALCLASS, sCONCEPTUALCONCEPT, sCONCEPTUALOBJECT, sCOPY, sCURRENT, sDETECTABLE, sDOUBLE, sEMAIL, sEND, SEND, sFACE2FACE, sFAX, sFILEEXT, sFLOAT, sGEOGRAPHYCONCEPT, sGROUP, SHORT, SIMAGENT, sINT, sJAVA_TYPE, sLONG, sMAP, sNEW, sNONE, sNOWORK, sOBJECT, SOURCECODE, sPAGER, sPARAMETER, sPATH, sPHONE, sPRIVATE, sPROJECTEXT, sPROTECTED, sPUBLIC, sSHORT, sSTART, sSTRING, sSYMBOL, START, STRING, sUNKNOWN, sVOID, SYMBOL, TRUE, UDT, UML, UNASSIGNED, UNDEFINED, unknown, UNKNOWN, UNKNOWN_MODIFIER, V, VARIABLE, VOID, WHENEVER, WORKFRAME, WORLD, XML
 
Constructor Summary
VMExpression()
          Constructor, creates a new expression
VMExpression(Operand lhs, int operator, Operand rhs)
          Constructor, creates a new expression with the specified left hand side, operator and right hand side.
VMExpression(VMOperand lhs)
          Constructor, creates a new expression with only the specified left hand side.
 
Method Summary
 void buildRSN(gov.nasa.arc.brahms.vm.engine.rsn.ReasoningStateNetwork rsn, gov.nasa.arc.brahms.vm.engine.rsn.IRSNFrameNode frame, gov.nasa.arc.brahms.vm.engine.rsn.RSNActivityRefNode actref, int modifier)
          Adds this expression to the reasoning state network to build up a reasoning state network that maintains a state of what statements matched with the expression.
 boolean evaluate(gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame, int modifier, int relop, gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameEvaluationRecord evalRcd, java.util.LinkedList values)
          Evaluates the expression as part of a value comparison determining whether or not the expression has a successfull match with a statement.
 java.util.List<java.lang.Object> evaluate(VMActiveInstanceCtx agent, VMFrameCtx frame)
          Evaluates the expression to produce a list of values.
 java.util.LinkedList resolveAsLhs(VMActiveInstanceCtx agent, VMFrameCtx frame, int strategy)
          Resolves this expression considering it a left hand side in a comparison.
 java.util.LinkedList resolveAsRhs(VMActiveInstanceCtx agent, VMFrameCtx frame, int strategy)
          Resolves this expression considering it a right hand side in a comparison.
 
Methods inherited from class gov.nasa.arc.brahms.common.data.Expression
getCollectType, getLhs, getOperator, getParameters, getRhs, getVariables, setCollectType, setID, setLhs, setOperator, setRhs, toString
 
Methods inherited from class gov.nasa.arc.brahms.common.data.BrahmsObject
delete, export, getFile, getID, getLine, getSerialNumber, isBCC, isDynamic, isLoaded, isResolved, setBCC, setDynamic, setFile, setID, setLine, setLoaded, setResolved, setSerialNumber
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.nasa.arc.brahms.common.data.IExpression
export
 

Constructor Detail

VMExpression

public VMExpression()
Constructor, creates a new expression


VMExpression

public VMExpression(VMOperand lhs)
Constructor, creates a new expression with only the specified left hand side.

Parameters:
lhs - the left hand side operand

VMExpression

public VMExpression(Operand lhs,
                    int operator,
                    Operand rhs)
Constructor, creates a new expression with the specified left hand side, operator and right hand side.

Parameters:
lhs - the left hand side operand
operator - the operator (+, -, *, /, %)
rhs - the right hand side operand
See Also:
VMOperand, IConstants.PLUS, IConstants.MINUS, IConstants.MULT, IConstants.DIV, IConstants.MOD
Method Detail

resolveAsLhs

public java.util.LinkedList resolveAsLhs(VMActiveInstanceCtx agent,
                                         VMFrameCtx frame,
                                         int strategy)
                                  throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves this expression considering it a left hand side in a comparison. As a left hand side the expression cannot contain an operator and right hand side to serve as a expression resolving to a numeric value. The expression resolves itself by resolving the left hand side operand.

Note:This method is only usable with consequences, detectables, and transfer definitions, not with preconditions. Left hand side of preconditions can contain expressions which are not handled by this method.

Parameters:
agent - the agent from which the belief set is to be used to resolve this expression
frame - the frame in which this expression is used, used to resolve variables
strategy - the strategy to use to resolve this operand as a left hand side. NONE if an OA is not to be resolved, FACTS if facts are to be used to resolve an OA, BELIEFS if beliefs are to be used to resolve an OA
Returns:
LinkedList a list of ExpressionValue's that can be used for the left hand side of statements to be created as a result of the resolution.
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the method was unable to get access to dynamic or static model elements
VMError - if an invalid element is encountered in the expressions when considering this as a left hand side.
See Also:
resolveAsRhs(gov.nasa.arc.brahms.vm.rt.VMActiveInstanceCtx, gov.nasa.arc.brahms.vm.rt.VMFrameCtx, int), IVMComparison.NONE, IVMComparison.FACTS, IVMComparison.BELIEFS

resolveAsRhs

public java.util.LinkedList resolveAsRhs(VMActiveInstanceCtx agent,
                                         VMFrameCtx frame,
                                         int strategy)
                                  throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Resolves this expression considering it a right hand side in a comparison. As a right hand side the expression can contain an operator and a left and right hand side operand. Both operands can themselves be expressions. If an operator and right hand side are present this expression is to be resolved to a list of numeric values. Any object attribute pairs found are resolved to values. The values can be numeric values but can also be object values if no operators are used. To resolve the object/attribute pairs the belief set of the agent is used and optionally also the fact set in the world state of the virtual machine. This method has access to the world state directly, it is therefore not passed.

Parameters:
agent - the agent from which the belief set is to be used to resolve this expression
frame - the frame in which this expression is used, used to resolve variables
strategy - the strategy to use to resolve this operand as a right hand side. FACTS if facts are to be used to resolve an OA, BELIEFS if beliefs are to be used to resolve an OA
Returns:
LinkedList a list of ExpressionValue's that can be used for the right hand side of statements to be created as a result of the resolution
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if the method was unable to get access to dynamic or static model elements
VMError - if an invalid element is encountered in the expressions when considering this as a right hand side.
See Also:
resolveAsLhs(gov.nasa.arc.brahms.vm.rt.VMActiveInstanceCtx, gov.nasa.arc.brahms.vm.rt.VMFrameCtx, int), IVMComparison.FACTS, IVMComparison.BELIEFS

buildRSN

public void buildRSN(gov.nasa.arc.brahms.vm.engine.rsn.ReasoningStateNetwork rsn,
                     gov.nasa.arc.brahms.vm.engine.rsn.IRSNFrameNode frame,
                     gov.nasa.arc.brahms.vm.engine.rsn.RSNActivityRefNode actref,
                     int modifier)
              throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Adds this expression to the reasoning state network to build up a reasoning state network that maintains a state of what statements matched with the expression.

Parameters:
rsn - the ReasoningStateNetwork to be built
frame - the RSNFrameNode for the frame in which this expression is used.
actref - the optional RSNActivityRefNode for the activity reference referencing a composite activity in which the frame and the precondition are specified.
modifier - the modifier of the (pre)condition
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an error occurs in building up the RSN with this expression

evaluate

public boolean evaluate(gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode frame,
                        int modifier,
                        int relop,
                        gov.nasa.arc.brahms.vm.engine.rsn.RSNFrameNode.FrameEvaluationRecord evalRcd,
                        java.util.LinkedList values)
                 throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Evaluates the expression as part of a value comparison determining whether or not the expression has a successfull match with a statement. If so the expression evaluates to true.

Parameters:
frame - the RSNFrameNode for the frame in which the expression's precondition is specified
modifier - the modifier of the (pre)condition
relop - relational operator used to find OA matches, -1 if relop can be ignored, otherwise one of Relation.EQ or Relation.NE
evalRcd - the record in which to store bindings for variables and statements matching preconditions
values - the list of values matching the expression, or a variable binding if we're dealing with a post-assigned variable that has no values assigned yet.
Returns:
true if the expression evaluates to true, false otherwise
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an internal error occurs

evaluate

public java.util.List<java.lang.Object> evaluate(VMActiveInstanceCtx agent,
                                                 VMFrameCtx frame)
                                          throws gov.nasa.arc.brahms.common.exceptions.BrahmsException
Evaluates the expression to produce a list of values. Multiple values are possible as the expression may contain collectall variables with multiple values

Specified by:
evaluate in interface IVMExpression
Parameters:
agent - the VMActiveInstanceCtx for the agent performing the expression evaluation
frame - the VMFrameCtx for the frame that is being executed -- contains variable contexts for variables used in the evaluation
Returns:
List<Object> the list of values resulting from the expression evaluation
Throws:
gov.nasa.arc.brahms.common.exceptions.BrahmsException - if an error occurs during the expression evaluation


Copyright © 1997-2012 All Rights Reserved.