ptolemy.actor
Class RelationWidthInference

java.lang.Object
  extended by ptolemy.actor.RelationWidthInference

public class RelationWidthInference
extends java.lang.Object

A class that offers convenience utility methods to infer the widths of relations in a composite actor.

Since:
Ptolemy II 8.0
Version:
$Id: RelationWidthInference.java 59167 2010-09-21 17:08:02Z cxh $
Author:
Bert Rodiers
Proposed Rating:
Red (rodiers)

Field Summary
private  boolean _inferringWidths
           
private  boolean _needsWidthInference
           
private  CompositeActor _topLevel
           
 
Constructor Summary
RelationWidthInference(CompositeActor topLevel)
          Create RelationWidthInference, the algorithm for width inference.
 
Method Summary
private static void _checkConsistency(IOPort port)
          Check whether the widths at a port are consistent.
protected static java.util.Set<IORelation> _relationsWithUnspecifiedWidths(java.util.List<?> relationList)
          Filter the relations for which the width still has to be inferred.
private static boolean _updateRelationsFromDefaultWidth(IOPort port, java.util.List<IORelation> updatedRelations)
          Infer the width for the relations connected to the port (which should have a default width).
private static boolean _updateRelationsFromMultiport(IOPort port, java.util.List<IORelation> updatedRelations)
          Infer the width for the relations connected to the port.
 boolean inferringWidths()
          Determine whether widths are currently being inferred or not.
 void inferWidths()
          Infer the width of the relations for which no width has been specified yet.
 boolean needsWidthInference()
          Return whether the current widths of the relation in the model are no longer valid anymore and the widths need to be inferred again.
 void notifyConnectivityChange()
          Notify the width inference algorithm that the connectivity in the model changed (width of relation changed, relations added, linked to different ports, ...).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_inferringWidths

private boolean _inferringWidths

_needsWidthInference

private boolean _needsWidthInference

_topLevel

private CompositeActor _topLevel
Constructor Detail

RelationWidthInference

public RelationWidthInference(CompositeActor topLevel)
Create RelationWidthInference, the algorithm for width inference. Also set the top level to the value given as argument.

Parameters:
topLevel - The top level CompositeActor.
Throws:
java.lang.IllegalArgumentException - If the specified actor is not the top level container. That is, its container is not null.
Method Detail

inferringWidths

public boolean inferringWidths()
Determine whether widths are currently being inferred or not.

Returns:
True When widths are currently being inferred.

inferWidths

public void inferWidths()
                 throws IllegalActionException
Infer the width of the relations for which no width has been specified yet. The specified actor must be the top level container of the model.

Throws:
IllegalActionException - If the widths of the relations at port are not consistent or if the width cannot be inferred for a relation.

needsWidthInference

public boolean needsWidthInference()
Return whether the current widths of the relation in the model are no longer valid anymore and the widths need to be inferred again.

Returns:
True when width inference needs to be executed again.

notifyConnectivityChange

public void notifyConnectivityChange()
Notify the width inference algorithm that the connectivity in the model changed (width of relation changed, relations added, linked to different ports, ...). This will invalidate the current width inference.


_relationsWithUnspecifiedWidths

protected static java.util.Set<IORelation> _relationsWithUnspecifiedWidths(java.util.List<?> relationList)
                                                                    throws IllegalActionException
Filter the relations for which the width still has to be inferred.

Parameters:
relationList - The relations that need to be filtered.
Returns:
The relations for which the width still has to return.
Throws:
IllegalActionException - If the expression for the width cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.

_checkConsistency

private static void _checkConsistency(IOPort port)
                               throws IllegalActionException
Check whether the widths at a port are consistent. Consistent means that the input and output width is either zero or that the input width is equal to the output width.

Parameters:
port - The port which will be checked.
Throws:
IllegalActionException - If the widths of the relations at port are not consistent.

_updateRelationsFromMultiport

private static boolean _updateRelationsFromMultiport(IOPort port,
                                                     java.util.List<IORelation> updatedRelations)
                                              throws IllegalActionException
Infer the width for the relations connected to the port. If the width can be inferred, update the width and add the relations for which the width has been updated.

Parameters:
port - The port for whose connected relations the width should be inferred.
updatedRelations - The relations for which the width has been updated.
Returns:
true When this constraint is still useful (can be used to extra more information).
Throws:
IllegalActionException - If the widths of the relations at port are not consistent.

_updateRelationsFromDefaultWidth

private static boolean _updateRelationsFromDefaultWidth(IOPort port,
                                                        java.util.List<IORelation> updatedRelations)
                                                 throws IllegalActionException
Infer the width for the relations connected to the port (which should have a default width). If the width can be inferred, update the width and add the relations for which the width has been updated.

Parameters:
port - The port for whose connected relations the width should be inferred.
updatedRelations - The relations for which the width has been updated.
Returns:
true When this constraint is still useful (can be used to extra more information).
Throws:
IllegalActionException - If the expression for the width cannot be parsed or cannot be evaluated, or if the result of evaluation violates type constraints, or if the result of evaluation is null and there are variables that depend on this one.