Class Configuration

    • Method Detail

      • getResolutionState

        public IAssignmentState getResolutionState()
        Returns the assignment state to be used when assigning values in the configuration.
        Returns:
        the resolution state
      • getProject

        public Project getProject()
        Returns the related project.
        Returns:
        the related project
      • isApproximatelyFrozen

        public boolean isApproximatelyFrozen()
        Return whether this configuration is exactly or approximative (heuristicall) frozen.
        Returns:
        false for exact freezing, true for approximative freezing
      • register

        public void register​(IConfigurationChangeListener listener)
        Registers a new listener.
        Parameters:
        listener - A Listener which should be informed in case of changes.
      • unregister

        public boolean unregister​(IConfigurationChangeListener listener)
        Unregisters an listener.
        Parameters:
        listener - The listener which should be unregistered.
        Returns:
        true if this configuration contained the specified listener
      • getModelInfo

        private ModelInfo<Project> getModelInfo()
        Returns the related model information instance.
        Returns:
        the model information instance
      • init

        private void init()
        This method creates the list of IDecisionVariables with initial value settings based on the given project.
      • addVariables

        private void addVariables​(java.util.List<AbstractVariable> topLevelDeclarations,
                                  boolean visible)
        Creates IDecisionVariables for all given AbstractVariables and adds them to the configuration. Part of the createVariables() method and should only be called from this method.
        Parameters:
        topLevelDeclarations - The variables to add.
        visible - indicates whether the variable is visible to the user:
        • true: The variable is visible by the user and can be displayed in the GUI and so on.
        • false: The variable is not visible by the user but must be considered in reasoning, instantiation, and so on.
      • createDecision

        public IDecisionVariable createDecision​(AbstractVariable decl)
                                         throws ConfigurationException
        Creates a visible decision in this configuration. The declaration must be on top-level and not created before.
        Parameters:
        decl - the declaration to create the decision for
        Returns:
        the created decision variable, may be null if the conditions are not met
        Throws:
        ConfigurationException - in case that creating the variable failed
      • createDecision

        private IDecisionVariable createDecision​(AbstractVariable decl,
                                                 boolean visible)
                                          throws ConfigurationException
        Creates a decision in this configuration.
        Parameters:
        decl - the declaration to create the decision for
        visible - whether the variable shall be visible
        Returns:
        the created decision variable
        Throws:
        ConfigurationException - in case that creating the variable failed
      • freezeValues

        public void freezeValues​(Project project,
                                 FilterType filter)
        Sets AssignmentState.FROZEN state to already frozen variables.
        Parameters:
        project - the project to be frozen
        filter - the filter type
      • refresh

        public void refresh()
        This method calls atm only the init() Method.
      • addDecision

        private void addDecision​(IDecisionVariable variable)
        Adda a decision.
        Parameters:
        variable - the decision to be added
      • getDecisionCount

        public int getDecisionCount()
        Returns the number of decisions.
        Returns:
        the number of decisions
      • clear

        public void clear()
        Clears all decisions.
      • removeDecision

        public boolean removeDecision​(IDecisionVariable variable)
        Remove a specific decision.
        Parameters:
        variable - the decision to be removed
        Returns:
        true if this operation was successful, false else
      • removeFromAllInstances

        private void removeFromAllInstances​(IDecisionVariable variable)
        Removes variable from all instances.
        Parameters:
        variable - the variable to be removed
      • getName

        public java.lang.String getName()
        Returns the name of the configuration.
        Returns:
        the name of the configuration
      • notifyReplaced

        public void notifyReplaced​(Project oldProject,
                                   Project newProject)
        Description copied from interface: IModelListener
        Is called to notify that oldModel is replaced by newModel. The listener registrations for oldModel will be adjusted accordingly.
        Do not modify the the listeners of oldModel or newModel during this method.
        Specified by:
        notifyReplaced in interface IModelListener<Project>
        Parameters:
        oldProject - the old model being replaced
        newProject - the new model (the replacement)
      • toProject

        public Project toProject​(boolean ownProject)
                          throws ConfigurationException
        Turns this configuration into a project, e.g. for writing.
        Parameters:
        ownProject - return an own project (true) or add the configuration to project (false)
        Returns:
        the project or null if not implemented (default)
        Throws:
        ConfigurationException - in case of any configuration errors
      • allInstancesVariableChanged

        private void allInstancesVariableChanged​(IDecisionVariable var)
        Changes the all instance cache if var or one of its nested elements changed. Precondition is that allInstances was already built up.
        Parameters:
        var - the changed variable
      • addAttributeDecision

        protected void addAttributeDecision​(Attribute attribute,
                                            Value value,
                                            IAssignmentState state)
                                     throws ConfigurationException
        Adds an attribute decision to this configuration. This method is a specific functionality for user interaction. Subclass this class and make it accessible if needed, otherwise it may break the value protection provided by this class.
        Parameters:
        attribute - the attribute for which the decision shall be created
        value - the value of the attribute (may be null)
        state - the assignment state
        Throws:
        ConfigurationException - in case of type conflicts
      • freeze

        public void freeze​(IFreezeSelector selector)
        Freezes on the whole configuration.
        Specified by:
        freeze in interface IConfigurationElement
        Parameters:
        selector - the selector deciding what to freeze
      • freeze

        public void freeze​(java.lang.String nestedElement)
        Freezes a single variable (must be a top layer element).
        Specified by:
        freeze in interface IConfigurationElement
        Parameters:
        nestedElement - The name of the top layer variable.
      • dereference

        public static IDecisionVariable dereference​(IDecisionVariable var)
        Dereferences a variable.
        Parameters:
        var - the variable to be dereferenced (may be null)
        Returns:
        the dereferenced variable (null if var was null)
      • findInParents

        public static IDecisionVariable findInParents​(IDecisionVariable var,
                                                      java.lang.String name)
        Finds a variable called name in the decision variable parents of var, starting at the direct parent of var, thus, returning the variable with name of the closest enclosing scope.
        Parameters:
        var - the variable to start at
        name - the name of the variable to find
        Returns:
        the found variable or null if ther is none
      • getDecision

        public IDecisionVariable getDecision​(java.lang.String varName,
                                             boolean dereference)
                                      throws ModelQueryException
        Returns the decision variable for a potentially nested/qualified name from this configuration.
        Parameters:
        varName - the name of the variable
        dereference - dereference intermediary reference variables
        Returns:
        the variable or null if none exists
        Throws:
        ModelQueryException - in case that querying the model fails
      • getDecision

        private IDecisionVariable getDecision​(IDecisionVariable var,
                                              java.lang.String varName,
                                              boolean dereference)
                                       throws ModelQueryException
        Returns the decision variable for a potentially nested/qualified name from this configuration using with var as current search context.
        Parameters:
        var - the variable to search within (null for a top-level call)
        varName - the name of the variable
        dereference - dereference intermediary reference variables
        Returns:
        the variable or null if none exists
        Throws:
        ModelQueryException - in case that querying the model fails
      • getAllInstances

        public Value getAllInstances​(IDatatype type)
        Returns all instances of the given type and sub-types.
        Specified by:
        getAllInstances in interface IConfiguration
        Parameters:
        type - the type to look for
        Returns:
        all instances of var, may be null if the instances cannot be retrieved, e.g., in case of an integer variable
      • collectAllInstances

        private void collectAllInstances​(IDecisionVariable var,
                                         IDatatype type,
                                         java.util.Map<IDatatype,​Reference> referenceTypes,
                                         java.util.Map<IDecisionVariable,​ReferenceValue> instances)
        Collects all instances of type starting at var and stores results into referenceTypes and instances.
        Parameters:
        var - the variable to collect the instances from
        type - the type to collect
        referenceTypes - the reference types for data types (to be modified as a side effect)
        instances - the actual instances of type (to be modified as a side effect)
      • mapVariable

        public static IDecisionVariable mapVariable​(IDecisionVariable var,
                                                    Configuration cfg)
        Maps a variable to its configuration following nested elements up and down.
        Parameters:
        var - the variable to be mapped
        cfg - the configuration containing the top-level variables
        Returns:
        the mapped variable, null if there is no mapping
      • getInstanceName

        public static java.lang.String getInstanceName​(IDecisionVariable var)
        Returns the instance name of a decision variable. This name is composed from the names of the given variable and its parent variables. Please note that the instance name is typically different from the qualified name of the declaration, which, in case of compound slots, leads to the variable in the compound definition. The result is unqualified regarding the top-level variable.
        Parameters:
        var - the variable to return the name for (may be null)
        Returns:
        the instance name (may be empty if var == null
      • getInstanceName

        public static java.lang.String getInstanceName​(IDecisionVariable var,
                                                       boolean qualified)
        Returns the instance name of a decision variable. This name is composed from the names of the given variable and its parent variables. Please note that the instance name is typically different from the qualified name of the declaration, which, in case of compound slots, leads to the variable in the compound definition.
        Parameters:
        var - the variable to return the name for (may be null)
        qualified - whether the name of the top-level variable shall be qualified
        Returns:
        the instance name (may be empty if var == null
      • equalsByInstanceName

        public static boolean equalsByInstanceName​(IDecisionVariable var1,
                                                   IDecisionVariable var2)
        Returns whether two decision variables are equal via their instance name. Please note that this method is faster and less resource consuming than comparing the respective results of getInstanceName(IDecisionVariable) as it compares the individual names rather than composing the full name and performing the comparison then.
        Parameters:
        var1 - the first variable to be compared (may be null)
        var2 - the second variable to be compared (may be null)
        Returns:
        true if the variables are equal by their instance name, false if they are not equal, in particular if one is null
      • printConfig

        public static void printConfig​(java.io.PrintStream out,
                                       Configuration cfg)
        Prints a configuration to out. [debugging]
        Parameters:
        out - the output stream
        cfg - the configuration to print
      • printVariable

        private static void printVariable​(java.io.PrintStream out,
                                          IDecisionVariable var,
                                          java.lang.String indent)
        Prints a variable to out. [debugging]
        Parameters:
        out - the output stream
        var - the variable to print
        indent - the indentation
      • removeDerivedValues

        public void removeDerivedValues()
        Removes all by a reasoner propagated values from the configuration to clean it up.
      • prune

        public void prune()
        Creates a copy of the underlying Project and removes elements which are not needed for a runtime reasoning, e.g., constraints containing only frozen variables or comments.
        Attention: This method creates a modified, shallow copy of the visited project. Thus, the original project becomes invalid through this visitation. This visitor should only be used if the original is no longer needed, e.g., for performance tweaks in a automated setup which does not save any data.
      • shareQueryCacheWith

        public void shareQueryCacheWith​(Configuration configToShare)
        Shares the cache of this Configuration with configToShare. This is useful if configToShare is a temporary Configuration / projection and can reuse queries based this Configuration.
        Parameters:
        configToShare - A temporary configuration which may reuse the cache from this config.
      • getNestedElement

        public static IDecisionVariable getNestedElement​(IDecisionVariable base,
                                                         java.lang.String name)
        Returns an element for base specified by its name. This method is not recursive!
        Parameters:
        base - the base variable to search on (may be null)
        name - the name of the nested element
        Returns:
        the nested element (may be null if not found or base is null)
      • getTopLevelDecision

        public static IDecisionVariable getTopLevelDecision​(IDecisionVariable var)
        Returns the top-level decision variable of var.
        Parameters:
        var - the variable
        Returns:
        the top-level decision variable, eventually var, null if there is none
      • dereference

        public static Value dereference​(IConfiguration conf,
                                        Value value)
        Dereferences a value.
        Parameters:
        conf - the configuration access
        value - the value to be dereferenced
        Returns:
        the dereferenced value