ptolemy.caltrop.ddi
Class CSP

java.lang.Object
  extended by ptolemy.caltrop.ddi.AbstractDDI
      extended by ptolemy.caltrop.ddi.CSP
All Implemented Interfaces:
Executable, Initializable, DDI

public class CSP
extends AbstractDDI

Since:
Ptolemy II 4.0
Version:
$Id: CSP.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Christopher Chang
Accepted Rating:
Red (cxh)
Proposed Rating:
Red (cxh)

Field Summary
private  caltrop.interpreter.ast.Action[] _actions
           
private  caltrop.interpreter.ast.Actor _actor
           
private  ConditionalBranchController _cbc
           
private  caltrop.interpreter.Context _context
           
private  caltrop.interpreter.environment.Environment _env
           
private  caltrop.interpreter.ExprEvaluator _eval
           
private  java.util.Map _ioPorts
           
private  TypedAtomicActor _ptActor
           
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
CSP(TypedAtomicActor ptActor, caltrop.interpreter.ast.Actor actor, caltrop.interpreter.Context context, caltrop.interpreter.environment.Environment env)
           
 
Method Summary
private  caltrop.interpreter.environment.Environment _bindActionStateVars(caltrop.interpreter.ast.Decl[] decls, caltrop.interpreter.environment.Environment env)
           
private  caltrop.interpreter.environment.Environment _bindInputPatternVars(caltrop.interpreter.ast.InputPattern[] inputPatterns, java.util.Map inputData, caltrop.interpreter.environment.Environment env)
           
private  java.util.Map _computeOutputData(caltrop.interpreter.ast.OutputExpression[] outputExprs, caltrop.interpreter.environment.Environment env)
           
private  java.util.Map _createIOPortMap()
           
private  void _evaluateBody(caltrop.interpreter.ast.Statement[] body, caltrop.interpreter.environment.Environment env)
           
private  java.util.Map computeRemainingTokens(caltrop.interpreter.ast.Action[] actions, java.util.Map dataSoFar)
           
private  java.util.Map computeSafeTokens(caltrop.interpreter.ast.Action[] actions, java.util.Map dataSoFar)
           
private  caltrop.interpreter.ast.Action[] filterActions(caltrop.interpreter.ast.Action[] actions, java.util.Map dataSoFar)
           
 void fire()
          Fire the actor.
private  void fireAction(caltrop.interpreter.ast.Action action, java.util.Map dataSoFar)
           
private  void fireMatchingAction(caltrop.interpreter.ast.Action[] actions, java.util.Map dataSoFar)
           
private  caltrop.interpreter.ast.InputPattern getInputPattern(java.lang.String name, caltrop.interpreter.ast.Action action)
           
 java.lang.String getName()
          Get the name of the domain that this DDI implements.
 void initialize()
          Begin execution of the actor.
private  boolean isFirable(caltrop.interpreter.ast.Action action, java.util.Map dataSoFar)
           
 boolean isLegalActor()
          Perform static checking on the actor, ensuring its validity in a given domain.
private  boolean isRemainingProfileValid(java.util.Map inputProfile, caltrop.interpreter.ast.Action[] actions)
           
private  void mergeData(java.util.Map oldData, java.util.Map newData)
           
private  boolean moreDataToRead(java.util.Map inputProfile)
           
private  int numTokensNeeded(caltrop.interpreter.ast.InputPattern ip)
           
 boolean postfire()
          This method should be invoked once per iteration, after the last invocation of fire() in that iteration.
 boolean prefire()
          This method should be invoked prior to each invocation of fire().
 void preinitialize()
          This method should be invoked exactly once per execution of a model, before any of these other methods are invoked.
private  void readOneFromRemaining(java.util.Map inputProfile, java.util.Map dataSoFar)
           
private  void readSafeTokens(java.util.Map inputProfile, java.util.Map dataSoFar)
           
private  caltrop.interpreter.ast.Action selectAction(caltrop.interpreter.ast.Action[] actions, java.util.Map dataSoFar)
           
 void setupActor()
          Perform any domain dependent setup.
 
Methods inherited from class ptolemy.caltrop.ddi.AbstractDDI
addInitializable, isFireFunctional, isStrict, iterate, removeInitializable, stop, stopFire, terminate, wrapup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_ptActor

private TypedAtomicActor _ptActor

_actor

private caltrop.interpreter.ast.Actor _actor

_actions

private caltrop.interpreter.ast.Action[] _actions

_context

private caltrop.interpreter.Context _context

_env

private caltrop.interpreter.environment.Environment _env

_eval

private caltrop.interpreter.ExprEvaluator _eval

_ioPorts

private java.util.Map _ioPorts

_cbc

private ConditionalBranchController _cbc
Constructor Detail

CSP

public CSP(TypedAtomicActor ptActor,
           caltrop.interpreter.ast.Actor actor,
           caltrop.interpreter.Context context,
           caltrop.interpreter.environment.Environment env)
Method Detail

isLegalActor

public boolean isLegalActor()
Description copied from interface: DDI
Perform static checking on the actor, ensuring its validity in a given domain.

Returns:
True, if the actor is legal.

setupActor

public void setupActor()
Description copied from interface: DDI
Perform any domain dependent setup. This can include hanging various attributes off of the actor, for example, the rate of the input and output ports.


getName

public java.lang.String getName()
Description copied from interface: DDI
Get the name of the domain that this DDI implements.

Returns:
The name of the domain that this DDI implements.

fire

public void fire()
          throws IllegalActionException
Description copied from interface: Executable
Fire the actor. This may be invoked several times between invocations of prefire() and postfire(). Output data may (and normally will) be produced. Typically, the fire() method performs the computation associated with an actor. This method is not required to have bounded execution. However, after endFire() is called, this method should return in bounded time.

Throws:
IllegalActionException - If firing is not permitted.

_evaluateBody

private void _evaluateBody(caltrop.interpreter.ast.Statement[] body,
                           caltrop.interpreter.environment.Environment env)

_bindActionStateVars

private caltrop.interpreter.environment.Environment _bindActionStateVars(caltrop.interpreter.ast.Decl[] decls,
                                                                         caltrop.interpreter.environment.Environment env)

_bindInputPatternVars

private caltrop.interpreter.environment.Environment _bindInputPatternVars(caltrop.interpreter.ast.InputPattern[] inputPatterns,
                                                                          java.util.Map inputData,
                                                                          caltrop.interpreter.environment.Environment env)

initialize

public void initialize()
                throws IllegalActionException
Description copied from interface: Initializable
Begin execution of the actor. This is invoked exactly once after the preinitialization phase. Since type resolution is done in the preinitialization phase, along with topology changes that may be requested by higher-order function actors, an actor can produce output data and schedule events in the initialize() method.

Throws:
IllegalActionException - If execution is not permitted.

postfire

public boolean postfire()
                 throws IllegalActionException
Description copied from interface: Executable
This method should be invoked once per iteration, after the last invocation of fire() in that iteration. The postfire() method should not produce output data on output ports of the actor. It returns true if the execution can proceed into the next iteration, false if the actor does not wish to be fired again. This method typically wraps up an iteration, which may involve updating local state or updating displays.

Returns:
True if the execution can continue.
Throws:
IllegalActionException - If postfiring is not permitted.

prefire

public boolean prefire()
                throws IllegalActionException
Description copied from interface: Executable
This method should be invoked prior to each invocation of fire(). It returns true if the fire() method can be invoked, given the current status of the inputs and parameters of the actor. Thus this method will typically check preconditions for a firing, if there are any. In an opaque, non-atomic entity, it may move data into an inner subsystem.

Returns:
True if the iteration can proceed.
Throws:
IllegalActionException - If prefiring is not permitted.

preinitialize

public void preinitialize()
                   throws IllegalActionException
Description copied from interface: Initializable
This method should be invoked exactly once per execution of a model, before any of these other methods are invoked. For actors, this is invoked prior to type resolution and may trigger changes in the topology, changes in the type constraints.

Throws:
IllegalActionException - If initializing is not permitted.

_createIOPortMap

private java.util.Map _createIOPortMap()

_computeOutputData

private java.util.Map _computeOutputData(caltrop.interpreter.ast.OutputExpression[] outputExprs,
                                         caltrop.interpreter.environment.Environment env)

computeSafeTokens

private java.util.Map computeSafeTokens(caltrop.interpreter.ast.Action[] actions,
                                        java.util.Map dataSoFar)

numTokensNeeded

private int numTokensNeeded(caltrop.interpreter.ast.InputPattern ip)

getInputPattern

private caltrop.interpreter.ast.InputPattern getInputPattern(java.lang.String name,
                                                             caltrop.interpreter.ast.Action action)

readSafeTokens

private void readSafeTokens(java.util.Map inputProfile,
                            java.util.Map dataSoFar)

mergeData

private void mergeData(java.util.Map oldData,
                       java.util.Map newData)

filterActions

private caltrop.interpreter.ast.Action[] filterActions(caltrop.interpreter.ast.Action[] actions,
                                                       java.util.Map dataSoFar)

computeRemainingTokens

private java.util.Map computeRemainingTokens(caltrop.interpreter.ast.Action[] actions,
                                             java.util.Map dataSoFar)

isRemainingProfileValid

private boolean isRemainingProfileValid(java.util.Map inputProfile,
                                        caltrop.interpreter.ast.Action[] actions)

readOneFromRemaining

private void readOneFromRemaining(java.util.Map inputProfile,
                                  java.util.Map dataSoFar)

moreDataToRead

private boolean moreDataToRead(java.util.Map inputProfile)

fireMatchingAction

private void fireMatchingAction(caltrop.interpreter.ast.Action[] actions,
                                java.util.Map dataSoFar)

fireAction

private void fireAction(caltrop.interpreter.ast.Action action,
                        java.util.Map dataSoFar)

selectAction

private caltrop.interpreter.ast.Action selectAction(caltrop.interpreter.ast.Action[] actions,
                                                    java.util.Map dataSoFar)

isFirable

private boolean isFirable(caltrop.interpreter.ast.Action action,
                          java.util.Map dataSoFar)