Package ptolemy.data.ontologies.lattice
Class LatticeOntologySolver
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.moml.MoMLModelAttribute
-
- ptolemy.data.ontologies.OntologySolverBase
-
- ptolemy.data.ontologies.OntologySolver
-
- ptolemy.data.ontologies.lattice.LatticeOntologySolver
-
- All Implemented Interfaces:
java.lang.Cloneable
,Testable
,Changeable
,Configurable
,Debuggable
,DebugListener
,Derivable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
- Direct Known Subclasses:
DeltaConstraintSolver
,ProductLatticeOntologySolver
public class LatticeOntologySolver extends OntologySolver
An instance of this solver contains an ontology, which itself contains a ConceptGraph and default constraints. The LatticeOntologySolver contains an Ontology whose ConceptGraph must be a lattice. It uses the Rehof-Mogensen algorithm to resolve which Concepts are assigned to model components.This class is based on the PropertyConstraintSolver in the properties package by Man-Kit Leung.
- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Man-Kit Leung, Edward A. Lee, Charles Shelton, Ben Lickly, Dai Bui, Beth Latronico
- Pt.AcceptedRating:
- Red (mankit)
- Pt.ProposedRating:
- Red (mankit)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LatticeOntologySolver.ConstraintType
An enumeration type to represent the types of constraints for default constraint settings for actor inputs and outputs, connections and finite state machine transitions.-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<Inequality>
_initialConstraintList
The list of constraints collected from the model, before resolution.protected java.util.List<Inequality>
_resolvedConstraintList
The list of constraints after the ontology resolution algorithm has executed.protected java.util.List<InequalityTerm>
_resolvedUnacceptableList
The list of InequalityTerms that have resolved to an unacceptable concept value.static java.lang.String
ADD_FUNCTION_NAME
The string name of the attribute that defines the arithmetic add concept function for this ontology solver.static java.lang.String
AND_FUNCTION_NAME
The string name of the attribute that defines the logical and concept function for this ontology solver.static java.lang.String
DIVIDE_FUNCTION_NAME
The string name of the attribute that defines the arithmetic divide concept function for this ontology solver.static java.lang.String
MULTIPLY_FUNCTION_NAME
The string name of the attribute that defines the arithmetic multiply concept function for this ontology solver.static java.lang.String
NEGATE_FUNCTION_NAME
The string name of the attribute that defines the arithmetic negation concept function for this ontology solver.static java.lang.String
NOT_FUNCTION_NAME
The string name of the attribute that defines the logical not concept function for this ontology solver.static java.lang.String
OR_FUNCTION_NAME
The string name of the attribute that defines the logical or concept function for this ontology solver.static java.lang.String
RECIPROCAL_FUNCTION_NAME
The string name of the attribute that defines the arithmetic negation concept function for this ontology solver.StringParameter
solverStrategy
A single parameter for quickly selecting common solving strategies, plus a "custom" option to allow a user-defined strategy.StringParameter
solvingFixedPoint
Indicate whether to compute the least or greatest fixed point solution.static java.lang.String
SUBTRACT_FUNCTION_NAME
The string name of the attribute that defines the arithmetic subtract concept function for this ontology solver.-
Fields inherited from class ptolemy.data.ontologies.OntologySolver
_eol, _momlHandler
-
Fields inherited from class ptolemy.data.ontologies.OntologySolverBase
_adapterStore, _nonSettables, _ontologySolverUtilities, _resolvedProperties, ontologySolverUtilitiesWrapper
-
Fields inherited from class ptolemy.moml.MoMLModelAttribute
_model, modelURL
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description LatticeOntologySolver(NamedObj container, java.lang.String name)
Constructor for the OntologySolver.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
_clearLists()
Set the resolved constraint list and the list of unacceptable inequality terms to null.protected OntologyAdapter
_getAdapter(java.lang.Object component)
Return the LatticeOntologyAdapter for the specified component.protected ConceptTermManager
_getConceptTermManager()
Return a new concept term manager.protected LatticeOntologySolver.ConstraintType
_getConstraintType()
Return the constraint type based on the solver strategy and the type of the fixed point.protected void
_resolveConcepts(NamedObj toplevel, java.util.List<Inequality> constraintList)
Resolve the concepts for the given top-level container, subject to the given constraint list.java.lang.Object
clone(Workspace workspace)
Clone the object into the specified workspace.OntologyAdapter
getAdapter(java.lang.Object object)
Return the concept constraint adapter associated with the given object.LatticeOntologyASTNodeAdapter
getAdapter(ASTPtRootNode node)
Returns the adapter that contains concept information for the given AST node.OntologyAdapter
getAdapter(NamedObj component)
Returns the adapter that contains concept information for the given component.java.util.List<InequalityTerm>
getAffectedTerms(InequalityTerm updateTerm)
Get the list of affected InequalityTerms from the OntologySolver's ConceptTermManager.InequalityTerm
getConceptTerm(java.lang.Object object)
Return the concept term from the given object.ConceptTermFactory
getConceptTermManager()
Return the concept term manager that collects and maintains a hash map that maps all model objects to their the inequality terms for the OntologySolver.ConstraintManager
getConstraintManager()
Get the ConstraintManager that collects and maintains all the inequality constraints for the OntologySolver.java.util.Hashtable<java.lang.String,java.lang.String>
getInitialSolverInformation()
Initialize the solver and get the initial statistics for the Lattice OntologySolver.java.util.Hashtable<java.lang.String,java.lang.String>
getResolvedSolverInformation()
Get the statistics for the Lattice OntologySolver after the model has been resolved.protected java.util.List<InequalityTerm>
getUnacceptableTerms()
Return the list of inequality terms that resolved to unacceptable concepts.protected java.lang.String
getUnacceptableTermsAsString()
Return a string representing the list of terms that resolved to unacceptable concepts.boolean
hasUnacceptableTerms()
Returns true if one or more terms resolved to unacceptable concepts, false otherwise (if the solver has not run, or if all terms have acceptable resolved concepts.void
initialize()
Initialize the solver: Reset the solver (superclass) and then collect all of the initial constraints from the model.boolean
isAnnotatedTerm(java.lang.Object object)
Return true if the given model object has been annotated with a manual annotation constraint.boolean
isLeastFixedPoint()
Return true if the solver is finding a least fixed point, and false if the solver is finding a greatest fixed point.void
reset()
Reset the solver.void
resolveConcepts()
Resolve the concept values for the toplevel entity that contains this solver, given the model analyzer that invokes this.void
test()
Run concept inference and check the values match those trained.void
train()
Run concept inference and save the inferred concept values.-
Methods inherited from class ptolemy.data.ontologies.OntologySolver
checkErrors, checkResolutionErrors, configure, displayConcepts, getMoMLHandler, invokeSolver, invokeSolver, isSettable
-
Methods inherited from class ptolemy.data.ontologies.OntologySolverBase
_getAdapter, _getPackageName, _toplevel, cleanConstants, clearResolvedConcept, getAllAdapters, getAllConceptableNamedObjs, getAllContainedOntologies, getAllPropertyables, getAllSolvers, getAttribute, getConcept, getOntology, getOntologySolverUtilities, getParser, getParseTree, markAsNonSettable, resetAll, setConcept, setOntologySolverUtilities
-
Methods inherited from class ptolemy.moml.MoMLModelAttribute
_exportMoMLContents, attributeChanged, getConfigureSource, getConfigureText, getContainedModel
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setContainer, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
-
-
-
Field Detail
-
solvingFixedPoint
public StringParameter solvingFixedPoint
Indicate whether to compute the least or greatest fixed point solution.- "least" Solve for least fixed point
- "greatest" Solve for greatest fixed point
-
solverStrategy
public StringParameter solverStrategy
A single parameter for quickly selecting common solving strategies, plus a "custom" option to allow a user-defined strategy.
-
ADD_FUNCTION_NAME
public static final java.lang.String ADD_FUNCTION_NAME
The string name of the attribute that defines the arithmetic add concept function for this ontology solver.- See Also:
- Constant Field Values
-
SUBTRACT_FUNCTION_NAME
public static final java.lang.String SUBTRACT_FUNCTION_NAME
The string name of the attribute that defines the arithmetic subtract concept function for this ontology solver.- See Also:
- Constant Field Values
-
MULTIPLY_FUNCTION_NAME
public static final java.lang.String MULTIPLY_FUNCTION_NAME
The string name of the attribute that defines the arithmetic multiply concept function for this ontology solver.- See Also:
- Constant Field Values
-
DIVIDE_FUNCTION_NAME
public static final java.lang.String DIVIDE_FUNCTION_NAME
The string name of the attribute that defines the arithmetic divide concept function for this ontology solver.- See Also:
- Constant Field Values
-
NEGATE_FUNCTION_NAME
public static final java.lang.String NEGATE_FUNCTION_NAME
The string name of the attribute that defines the arithmetic negation concept function for this ontology solver.- See Also:
- Constant Field Values
-
RECIPROCAL_FUNCTION_NAME
public static final java.lang.String RECIPROCAL_FUNCTION_NAME
The string name of the attribute that defines the arithmetic negation concept function for this ontology solver.- See Also:
- Constant Field Values
-
NOT_FUNCTION_NAME
public static final java.lang.String NOT_FUNCTION_NAME
The string name of the attribute that defines the logical not concept function for this ontology solver.- See Also:
- Constant Field Values
-
AND_FUNCTION_NAME
public static final java.lang.String AND_FUNCTION_NAME
The string name of the attribute that defines the logical and concept function for this ontology solver.- See Also:
- Constant Field Values
-
OR_FUNCTION_NAME
public static final java.lang.String OR_FUNCTION_NAME
The string name of the attribute that defines the logical or concept function for this ontology solver.- See Also:
- Constant Field Values
-
_initialConstraintList
protected java.util.List<Inequality> _initialConstraintList
The list of constraints collected from the model, before resolution.
-
_resolvedConstraintList
protected java.util.List<Inequality> _resolvedConstraintList
The list of constraints after the ontology resolution algorithm has executed.
-
_resolvedUnacceptableList
protected java.util.List<InequalityTerm> _resolvedUnacceptableList
The list of InequalityTerms that have resolved to an unacceptable concept value. See ConceptTermManager for a definition of unacceptable.
-
-
Constructor Detail
-
LatticeOntologySolver
public LatticeOntologySolver(NamedObj container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Constructor for the OntologySolver.- Parameters:
container
- The model that contains the OntologySolvername
- The name of the OntologySolver- Throws:
IllegalActionException
- If there is any problem creating the OntologySolver object.NameDuplicationException
- If there is already a component in the container with the same name
-
-
Method Detail
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Clone the object into the specified workspace. The new object is not added to the directory of that workspace (you must do this yourself if you want it there). The result is an object with no container.- Overrides:
clone
in classOntologySolver
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- The new object.
- Throws:
java.lang.CloneNotSupportedException
- Not thrown in this base class- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
getAffectedTerms
public java.util.List<InequalityTerm> getAffectedTerms(InequalityTerm updateTerm) throws IllegalActionException
Get the list of affected InequalityTerms from the OntologySolver's ConceptTermManager. FIXME: 01/28/10 Charles Shelton - Not really sure what this method is used for. The call to _conceptTermManager.getAffectedTerms() appears to always return an empty ArrayList.- Parameters:
updateTerm
- This parameter doesn't appear to be used- Returns:
- The list of inequality terms that are affected by the OntologySolver
- Throws:
IllegalActionException
- If an exception is thrown
-
getConstraintManager
public ConstraintManager getConstraintManager()
Get the ConstraintManager that collects and maintains all the inequality constraints for the OntologySolver.- Returns:
- the constraintManager
-
getInitialSolverInformation
public java.util.Hashtable<java.lang.String,java.lang.String> getInitialSolverInformation() throws IllegalActionException
Initialize the solver and get the initial statistics for the Lattice OntologySolver. This will return information about the number of constraints and concept terms generated before the solver executes its algorithm.- Returns:
- A hash table containing string representations of the solver statistics and constraints information, separated by tabs.
- Throws:
IllegalActionException
- If an exception occurs when collecting the constraints.
-
getResolvedSolverInformation
public java.util.Hashtable<java.lang.String,java.lang.String> getResolvedSolverInformation() throws IllegalActionException
Get the statistics for the Lattice OntologySolver after the model has been resolved. This will return information about the number of constraints and concept terms generated after the solver executes its algorithm.- Returns:
- A hash table containing string representations of the solver statistics and constraints information, separated by tabs.
- Throws:
IllegalActionException
- If an exception occurs when collecting the constraints.
-
getAdapter
public LatticeOntologyASTNodeAdapter getAdapter(ASTPtRootNode node) throws IllegalActionException
Returns the adapter that contains concept information for the given AST node.- Parameters:
node
- The given ASTPtRootNode.- Returns:
- The associated concept constraint adapter.
- Throws:
IllegalActionException
- If an exception is thrown in the private _getAdapter method
-
getAdapter
public OntologyAdapter getAdapter(NamedObj component) throws IllegalActionException
Returns the adapter that contains concept information for the given component.- Parameters:
component
- The given component- Returns:
- The associated concept constraint adapter.
- Throws:
IllegalActionException
- If an exception is thrown in the private _getAdapter method
-
getAdapter
public OntologyAdapter getAdapter(java.lang.Object object) throws IllegalActionException
Return the concept constraint adapter associated with the given object.- Overrides:
getAdapter
in classOntologySolverBase
- Parameters:
object
- The given object.- Returns:
- The associated concept constraint adapter.
- Throws:
IllegalActionException
- If an exception is thrown in the private _getAdapter method
-
getConceptTerm
public InequalityTerm getConceptTerm(java.lang.Object object)
Return the concept term from the given object.- Parameters:
object
- The given object.- Returns:
- The concept term of the given object.
-
getConceptTermManager
public ConceptTermFactory getConceptTermManager()
Return the concept term manager that collects and maintains a hash map that maps all model objects to their the inequality terms for the OntologySolver.- Returns:
- The concept term manager for the OntologySolver
-
hasUnacceptableTerms
public boolean hasUnacceptableTerms()
Returns true if one or more terms resolved to unacceptable concepts, false otherwise (if the solver has not run, or if all terms have acceptable resolved concepts.- Returns:
- True if one or more terms resolved to unacceptable concepts, false otherwise.
-
initialize
public void initialize() throws IllegalActionException
Initialize the solver: Reset the solver (superclass) and then collect all of the initial constraints from the model.- Overrides:
initialize
in classOntologySolverBase
- Throws:
IllegalActionException
- If an exception occurs when collecting the constraints.
-
isAnnotatedTerm
public boolean isAnnotatedTerm(java.lang.Object object)
Return true if the given model object has been annotated with a manual annotation constraint.- Parameters:
object
- The model object to be checked to see if it is annotated- Returns:
- true if the model object is annotated, false otherwise
-
isLeastFixedPoint
public boolean isLeastFixedPoint() throws IllegalActionException
Return true if the solver is finding a least fixed point, and false if the solver is finding a greatest fixed point.- Returns:
- True, if solver is solving a least fixed point, false, if it is solving a greatest fixed point.
- Throws:
IllegalActionException
- If the solvingFixedPoint parameter contains an invalid value.
-
reset
public void reset()
Reset the solver. This removes the internal states of the solver (e.g. previously recorded properties, statistics, etc.). Also resets the ConceptTermManager to null and clears the trained constraints.- Overrides:
reset
in classOntologySolver
-
resolveConcepts
public void resolveConcepts() throws IllegalActionException
Resolve the concept values for the toplevel entity that contains this solver, given the model analyzer that invokes this.- Specified by:
resolveConcepts
in classOntologySolverBase
- Throws:
IllegalActionException
- If there is an exception thrown during the OntologySolver resolution.
-
test
public void test() throws IllegalActionException
Run concept inference and check the values match those trained. This simply looks through the conceptable objects and checks that their resolved concepts match the values contained in the __trainedConceptRecordArray attribute.- Throws:
IllegalActionException
- If inference fails or the test resolves to the wrong values.
-
train
public void train() throws IllegalActionException
Run concept inference and save the inferred concept values. For all conceptable model elements, an array of records that maps the full name of the Ptolemy element to the name of the concept to which it was resolved is generated and stored as a parameter of the ontology solver.- Throws:
IllegalActionException
- If inference fails..
-
getUnacceptableTermsAsString
protected java.lang.String getUnacceptableTermsAsString() throws IllegalActionException
Return a string representing the list of terms that resolved to unacceptable concepts. Returns an empty string if the solver has not been run, or if all terms were acceptable. See ConceptTermManager for a definition of acceptable.- Returns:
- A string representing the list of terms that resolved to unacceptable concepts. Can be the empty string.
- Throws:
IllegalActionException
- If the string cannot be formed from the list of inequality terms
-
getUnacceptableTerms
protected java.util.List<InequalityTerm> getUnacceptableTerms()
Return the list of inequality terms that resolved to unacceptable concepts. Returns null if the solver has not been run first, or if all terms were acceptable. See ConceptTermManager for a definition of acceptable.- Returns:
- The list of inequality terms that resolved to unacceptable concepts. Can be null.
-
_clearLists
protected void _clearLists()
Set the resolved constraint list and the list of unacceptable inequality terms to null. Implemented as a protected method so that subclasses may call it.
-
_getAdapter
protected OntologyAdapter _getAdapter(java.lang.Object component) throws IllegalActionException
Return the LatticeOntologyAdapter for the specified component. This instantiates a new OntologyAdapter if it does not already exist for the specified component. This returns specific LatticeOntologyAdapters for the LatticeOntologySolver.- Parameters:
component
- The specified component.- Returns:
- The LatticeOntologyAdapter for the specified component.
- Throws:
IllegalActionException
- Thrown if the LatticeOntologyAdapter cannot be instantiated.
-
_getConceptTermManager
protected ConceptTermManager _getConceptTermManager()
Return a new concept term manager. Subclass can implements a its own manager and override this method to instantiate a instance of the new class.- Returns:
- A concept term manager.
-
_resolveConcepts
protected void _resolveConcepts(NamedObj toplevel, java.util.List<Inequality> constraintList) throws OntologyResolutionException
Resolve the concepts for the given top-level container, subject to the given constraint list.- Parameters:
toplevel
- The top-level containerconstraintList
- The constraint list that we are solving- Throws:
OntologyResolutionException
- If constraints are unsatisfiable
-
_getConstraintType
protected LatticeOntologySolver.ConstraintType _getConstraintType() throws IllegalActionException
Return the constraint type based on the solver strategy and the type of the fixed point. Least fixed points with forward inference give constraints that the sinks be greater that the sources, bidirectional inference requires sources and sinks to be equal, etc.- Returns:
- The enumeration from ConstraintType corresponding to the given solver strategy.
- Throws:
IllegalActionException
- If solver strategy or fixed point type cannot be understood.
-
-