Package ptolemy.data.ontologies.lattice
Class LatticeOntologyAdapter
- java.lang.Object
-
- ptolemy.data.ontologies.OntologyAdapter
-
- ptolemy.data.ontologies.lattice.LatticeOntologyAdapter
-
- Direct Known Subclasses:
ActorConstraintsDefinitionAdapter
,AddSubtract
,Const
,Display
,Expression
,Expression
,LatticeOntologyASTNodeAdapter
,LatticeOntologyCompositeAdapter
,MultiplyDivide
,ProductLatticeOntologyAdapter
,RecordAssembler
,RecordDisassembler
,Scale
,UnitsConverter
public class LatticeOntologyAdapter extends OntologyAdapter
The base class for a lattice-based ontology adapter.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Man-Kit Leung, Thomas Mandl, Edward A. Lee
- Pt.AcceptedRating:
- Red (mankit)
- Pt.ProposedRating:
- Red (mankit)
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Inequality>
_ownConstraints
The list of Inequality constraints contained by this LatticeOntologyAdapter.protected java.util.List<Inequality>
_subAdapterConstraints
The list of permanent property constraints.protected boolean
_useDefaultConstraints
Indicate whether this adapter uses the default actor constraints.LatticeOntologySolver.ConstraintType
interconnectConstraintType
The default constraint type for connections between actors.-
Fields inherited from class ptolemy.data.ontologies.OntologyAdapter
_annotationEvaluator, _solver
-
-
Constructor Summary
Constructors Constructor Description LatticeOntologyAdapter(LatticeOntologySolver solver, java.lang.Object component)
Construct the lattice ontology adapter associated with the given component and solver.LatticeOntologyAdapter(LatticeOntologySolver solver, java.lang.Object component, boolean useDefaultConstraints)
Construct the lattice ontology adapter for the given component and property lattice.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_addDefaultConstraints(LatticeOntologySolver.ConstraintType actorConstraintType)
Add default constraints for the actor referred to by this OntologyAdapter based on the given ConstraintType.protected void
_addSubAdapterConstraints()
Iterate through the list of sub adapters and gather the constraints for each one.protected ParseTreeAnnotationEvaluator
_annotationEvaluator()
Create a new ParseTreeAnnotationEvaluator that is tailored for the ontology.protected void
_constrainAttributes()
Set default Inequality constraints for all attributes that can be evaluated to a Concept in the Ontology.protected void
_constrainObject(LatticeOntologySolver.ConstraintType constraintType, java.lang.Object sink, java.util.List sourceList)
Set default constraints between the given object and a list of objects based on the given constraintType.protected void
_constrainObjectLists(LatticeOntologySolver.ConstraintType constraintType, java.util.List sourceList, java.util.List sinkList)
Set the default constraint between the given list of source objects and list of sink objects based on the given constraintType.protected void
_constrainSingleObject(LatticeOntologySolver.ConstraintType constraintType, java.lang.Object source, java.lang.Object sink)
Set the default constraint between the given source and sink object based on the given constraintType.protected java.util.List
_getConstrainedPorts(boolean constraintSource)
Return the list of constrained ports given the flag whether source or sink ports should be constrained.protected static java.util.List
_getConstraintingPorts(boolean constraintSource, TypedIOPort port)
Return the list of constraining ports on a given port, given whether source or sink ports should be constrained.protected java.util.List<OntologyAdapter>
_getSubAdapters()
Return the list of sub-adapters.protected void
_setConnectionConstraintType(LatticeOntologySolver.ConstraintType constraintType)
Set the default constraint type for connections for the model component referred to by this OntologyAdapter for the given OntologySolver, depending on what type of component it is.protected static java.util.List<Inequality>
_union(java.util.List<Inequality> list1, java.util.List<Inequality> list2)
Return the union of the two specified lists of inequality constraints by appending the second list to the end of the first list.java.util.List<Inequality>
constraintList()
Return the constraints of this component.InequalityTerm
getPropertyTerm(java.lang.Object object)
Return the InequalityTerm associated with the given model object.LatticeOntologySolver
getSolver()
Return the associated property solver.boolean
isConstraintSource()
Returns true if the interconnectConstraintType is for sources, false otherwise.void
reinitialize()
Reset and initialize the LatticeOntologyAdapter.void
setAtLeast(java.lang.Object greater, java.lang.Object lesser)
Set an inequality constraint between the two specified objects, such that the concept value of the greater term is greater than or equal to the concept value of the lesser term.void
setAtMost(java.lang.Object lesser, java.lang.Object greater)
Set an inequality constraint between the two specified objects, such that the concept value of the greater term is greater than or equal to the concept value of the lesser term.void
setSameAs(java.lang.Object object1, java.lang.Object object2)
Set two inequality constraints between the specified objects, such that the Concept value of object1 is equal to the Concept value of object2.-
Methods inherited from class ptolemy.data.ontologies.OntologyAdapter
_getASTNodeAdapters, _getAttributeParseTrees, _getPropertyableAttributes, _getSinkPortList, _getSourcePortList, getComponent, getContainerEntity, getName, getParseTree, getPropertyables, putAttribute, setComponent, setEquals, toString
-
-
-
-
Field Detail
-
interconnectConstraintType
public LatticeOntologySolver.ConstraintType interconnectConstraintType
The default constraint type for connections between actors.
-
_ownConstraints
protected java.util.List<Inequality> _ownConstraints
The list of Inequality constraints contained by this LatticeOntologyAdapter.
-
_useDefaultConstraints
protected boolean _useDefaultConstraints
Indicate whether this adapter uses the default actor constraints.
-
_subAdapterConstraints
protected java.util.List<Inequality> _subAdapterConstraints
The list of permanent property constraints.
-
-
Constructor Detail
-
LatticeOntologyAdapter
public LatticeOntologyAdapter(LatticeOntologySolver solver, java.lang.Object component) throws IllegalActionException
Construct the lattice ontology adapter associated with the given component and solver. The constructed adapter implicitly uses the default constraints set by the solver.- Parameters:
solver
- The specified lattice-based ontology solver.component
- The associated component.- Throws:
IllegalActionException
- Thrown if the adapter cannot be initialized.
-
LatticeOntologyAdapter
public LatticeOntologyAdapter(LatticeOntologySolver solver, java.lang.Object component, boolean useDefaultConstraints) throws IllegalActionException
Construct the lattice ontology adapter for the given component and property lattice.- Parameters:
solver
- The specified lattice-based ontology solver.component
- The given component.useDefaultConstraints
- Indicate whether this adapter uses the default actor constraints.- Throws:
IllegalActionException
- Thrown if the adapter cannot be initialized.
-
-
Method Detail
-
constraintList
public java.util.List<Inequality> constraintList() throws IllegalActionException
Return the constraints of this component. The constraints is a list of inequalities. This base class returns the union of the constraints of this component and the constraints for the subcomponents- Returns:
- The constraints of this component.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
getPropertyTerm
public InequalityTerm getPropertyTerm(java.lang.Object object)
Return the InequalityTerm associated with the given model object.- Parameters:
object
- The given model object for which to find the InequalityTerm in the OntologySolver- Returns:
- The InequalityTerm associated with the model object
-
getSolver
public LatticeOntologySolver getSolver()
Return the associated property solver.- Overrides:
getSolver
in classOntologyAdapter
- Returns:
- The associated property solver.
-
isConstraintSource
public boolean isConstraintSource()
Returns true if the interconnectConstraintType is for sources, false otherwise. It will return only true if interconnectConstraintType is set to SOURCE_GE_SINK or EQUALS.- Returns:
- true if the interconnectConstraintType is for sources, false otherwise
-
reinitialize
public void reinitialize() throws IllegalActionException
Reset and initialize the LatticeOntologyAdapter. This clears all the cached constraints and the states of their inequality terms.- Overrides:
reinitialize
in classOntologyAdapter
- Throws:
IllegalActionException
- Thrown ifOntologyAdapter.getPropertyables()
throws it.
-
setAtLeast
public void setAtLeast(java.lang.Object greater, java.lang.Object lesser)
Set an inequality constraint between the two specified objects, such that the concept value of the greater term is greater than or equal to the concept value of the lesser term.- Parameters:
greater
- The model object on the LHS of the ≥ inequalitylesser
- The model object on the RHS of the ≥ inequality
-
setAtMost
public void setAtMost(java.lang.Object lesser, java.lang.Object greater)
Set an inequality constraint between the two specified objects, such that the concept value of the greater term is greater than or equal to the concept value of the lesser term.- Parameters:
lesser
- The model object on the RHS of the ≥ inequalitygreater
- The model object on the LHS of the ≥ inequality
-
setSameAs
public void setSameAs(java.lang.Object object1, java.lang.Object object2)
Set two inequality constraints between the specified objects, such that the Concept value of object1 is equal to the Concept value of object2.- Parameters:
object1
- The model object on the LHS of the equalityobject2
- The model object on the RHS of the equality
-
_addDefaultConstraints
protected void _addDefaultConstraints(LatticeOntologySolver.ConstraintType actorConstraintType) throws IllegalActionException
Add default constraints for the actor referred to by this OntologyAdapter based on the given ConstraintType.- Parameters:
actorConstraintType
- The given ConstraintType for the default constraints for the actor referred to by this OntologyAdapter- Throws:
IllegalActionException
- If an exception is thrown- See Also:
LatticeOntologySolver.ConstraintType
-
_addSubAdapterConstraints
protected void _addSubAdapterConstraints() throws IllegalActionException
Iterate through the list of sub adapters and gather the constraints for each one. Note that the adapter stores a new set of constraints each time this is invoked. Therefore, multiple invocations will generate excessive constraints and result in inefficiency during resolution.- Throws:
IllegalActionException
- Thrown if there is any errors in getting the sub adapters and gathering the constraints for each one.
-
_annotationEvaluator
protected ParseTreeAnnotationEvaluator _annotationEvaluator()
Create a new ParseTreeAnnotationEvaluator that is tailored for the ontology. This class parses the user-defined ontology constraint annotations in the model containing the LatticeOntologySolver.- Specified by:
_annotationEvaluator
in classOntologyAdapter
- Returns:
- a new ParseTreeConstraintAnnotationEvaluator object
-
_constrainAttributes
protected void _constrainAttributes()
Set default Inequality constraints for all attributes that can be evaluated to a Concept in the Ontology. This method parses each attribute and sets a default constraint between the root AST node and its attribute, if the attribute was parseable.
-
_constrainObject
protected void _constrainObject(LatticeOntologySolver.ConstraintType constraintType, java.lang.Object sink, java.util.List sourceList) throws IllegalActionException
Set default constraints between the given object and a list of objects based on the given constraintType. The given object is the sink and the list of objects are the sources.- Parameters:
constraintType
- The given ConstraintType to be used for the default constraintssink
- The given object that represents the sink for the default constraintssourceList
- The list of objects passed in as a List that represents the sources for the default constraints- Throws:
IllegalActionException
- If an exception is thrown- See Also:
LatticeOntologySolver.ConstraintType
-
_constrainObjectLists
protected void _constrainObjectLists(LatticeOntologySolver.ConstraintType constraintType, java.util.List sourceList, java.util.List sinkList) throws IllegalActionException
Set the default constraint between the given list of source objects and list of sink objects based on the given constraintType.- Parameters:
constraintType
- The given ConstraintType to be used for the default constraintsourceList
- A list of source objectssinkList
- A list of sink objects- Throws:
IllegalActionException
- If an exception is thrown- See Also:
LatticeOntologySolver.ConstraintType
-
_constrainSingleObject
protected void _constrainSingleObject(LatticeOntologySolver.ConstraintType constraintType, java.lang.Object source, java.lang.Object sink) throws IllegalActionException
Set the default constraint between the given source and sink object based on the given constraintType.- Parameters:
constraintType
- The given ConstraintType to be used for the default constraintsource
- The source object for the default constraintssink
- The sink object for the default constraints- Throws:
IllegalActionException
- If an exception is thrown- See Also:
LatticeOntologySolver.ConstraintType
-
_getConstrainedPorts
protected java.util.List _getConstrainedPorts(boolean constraintSource)
Return the list of constrained ports given the flag whether source or sink ports should be constrained. If source ports are constrained, it returns the list of input ports of the associated actor; otherwise, it returns the list of output ports.- Parameters:
constraintSource
- The flag that indicates whether source or sink ports are constrained.- Returns:
- The list of constrained ports.
-
_getConstraintingPorts
protected static java.util.List _getConstraintingPorts(boolean constraintSource, TypedIOPort port)
Return the list of constraining ports on a given port, given whether source or sink ports should be constrained.- Parameters:
constraintSource
- The flag that indicates whether source or sink ports are constrained.port
- The given port.- Returns:
- The list of constraining ports.
-
_getSubAdapters
protected java.util.List<OntologyAdapter> _getSubAdapters() throws IllegalActionException
Return the list of sub-adapters. By default, this returns the list of ASTNode adapters that are associated with the expressions of the propertyable attributes.- Overrides:
_getSubAdapters
in classOntologyAdapter
- Returns:
- The list of sub-adapters.
- Throws:
IllegalActionException
- Not thrown in this base class.
-
_setConnectionConstraintType
protected void _setConnectionConstraintType(LatticeOntologySolver.ConstraintType constraintType) throws IllegalActionException
Set the default constraint type for connections for the model component referred to by this OntologyAdapter for the given OntologySolver, depending on what type of component it is. This method is recursive and will set the default constraints for the OntologyAdapters for all subcomponents of this model component as well.- Parameters:
constraintType
- The default ConstraintType for generic model component connections; will be used if the model component is not one of the following types for Ptolemy expression language AST nodes; will be used it the model component is an AST node- Throws:
IllegalActionException
- If an exception is thrown- See Also:
LatticeOntologySolver.ConstraintType
-
_union
protected static java.util.List<Inequality> _union(java.util.List<Inequality> list1, java.util.List<Inequality> list2)
Return the union of the two specified lists of inequality constraints by appending the second list to the end of the first list.- Parameters:
list1
- The first list.list2
- The second list.- Returns:
- The union of the two lists.
-
-