Class AssignmentResolver


  • public class AssignmentResolver
    extends java.lang.Object
    Resolves the initial assignment settings for a configuration.
    • Starts resolving of values inside the inner most imported Project and continues until it arrives at the main project of the Configuration. Thus, interim assignments shall be considered correctly.
    • This "simple Reasoner" is not intended to find inconsistencies/errors inside the model. If multiple constraints lead to different value assignments for the same variable, one of these values will be randomly assigned.
    TODO: Still open points, which are not considered yet:
    Author:
    El-Sharkawy
    • Constructor Detail

      • AssignmentResolver

        public AssignmentResolver​(Configuration config)
        Sole constructor for this class. Will not start resolving values, this must be done via calling the resolve() method.
        Parameters:
        config - The configuration for which assignments shall be resolved.
    • Method Detail

      • findInstancesOfNestedVariavbles

        private void findInstancesOfNestedVariavbles​(IDecisionVariable variable)
        Recursive method to collect all nested IDecisionVariable. Part of the constructor.
        Parameters:
        variable - A already collected variable, may containing nested variables (must not be null.
      • createEvaluationVisitor

        protected EvaluationVisitor createEvaluationVisitor()
        Factory method for creating the evaluation visitor.
        Returns:
        the evaluation visitor
      • resolve

        public void resolve()
        Resolves the (initial) values of the configuration. This is done as follows:
        1. Resolve default values of variable declarations
        2. Resolve values of assignments
      • resolveAnnotationAssignments

        private void resolveAnnotationAssignments​(Project project)
        Sets the (re-)assigned annotation values for all annotation of all variables for the current Project.
        Parameters:
        project - The current project for which annotation assignments shall be resolved.
      • resolveAnnotationAssignments

        private void resolveAnnotationAssignments​(AttributeAssignment assignBlock,
                                                  java.util.Map<java.lang.String,​Value> annotationAssignments,
                                                  java.util.List<IDecisionVariable> parents)
        Recursive method for resolving annotation assignments (part of resolveAnnotationAssignments(Project).
        Parameters:
        assignBlock - The current visited assignment block.
        annotationAssignments - A tuple of (, ) for the current annotation block. If a nested block is found, these values must be copied into a new map as nested blocks can have other values and also further elements can be found after a block was visited.
        parents - A list of IDecisionVariables which shall currently be treated as parents for retrieving (nested) IDecisionVariables during visitation. Can be empty or null if the current parent is the whole project.
      • resolveDefaultValues

        protected void resolveDefaultValues​(Project project)
        Part of the resolve() method. Resolves default values of variable declarations.
        Parameters:
        project - The current project for which assignments shall be resolved.
      • resolveDefaultValue

        public static boolean resolveDefaultValue​(IDecisionVariable variable,
                                                  EvaluationVisitor evaluator)
        Resolves default values of a particular variable. No conflict handler is used.
        Parameters:
        variable - the instance to resolve the default values for.
        evaluator - the (re-usable) expression evaluator to utilize, may be null then a temporary one is created
        Returns:
        true if a default value could be resolved and assigned to variable, false otherwise.
        See Also:
        resolveDefaultValueForDeclaration(AbstractVariable, IDecisionVariable)
      • resolveDefaultValue

        public static boolean resolveDefaultValue​(IDecisionVariable variable)
        Resolves default values of a particular variable. The evaluator is created on demand, no conflict handler is used.
        Parameters:
        variable - the instance to resolve the default values for.
        Returns:
        true if a default value could be resolved and assigned to variable, false otherwise.
        See Also:
        resolveDefaultValue(IDecisionVariable, EvaluationVisitor)
      • augmentValue

        private static Value augmentValue​(Value value,
                                          IDecisionVariable variable,
                                          EvaluationVisitor evaluator,
                                          IConfiguration config,
                                          AssignmentResolver conflictHandler)
        If a value of a refined compound shall the first time be assigned to a variable of a super compound (polymorphic values), then also the default values of the refined compounds shall be taken into account and augment the value. Otherwise, an inconsistent configuration structure may later lead to invalid values.
        Parameters:
        value - the value to be checked
        variable - the variable to assign the value to
        evaluator - the (re-usable) expression evaluator to utilize
        config - the configuration to rely on (shall be consistent with variable)
        conflictHandler - optional instance to call conflictingDefault(AbstractVariable) on, may be null
        Returns:
        the (augmented) value
      • resolveDefaultValueForDeclaration

        protected boolean resolveDefaultValueForDeclaration​(AbstractVariable decl,
                                                            IDecisionVariable variable)
        Resolves default values of a particular declaration.
        Parameters:
        decl - The AbstractVariable for which the default value should be resolved.
        variable - the instance of decl.
        Returns:
        true if a default value could be resolved and assigned to variable, false otherwise.
        See Also:
        resolveDefaultValues(Project)
      • resolveAssignments

        protected void resolveAssignments​(Project project)
        Part of the resolve() method. Resolves assignments.
        Parameters:
        project - Project The current project for which assignments shall be resolved.
      • conflictingConstraint

        protected void conflictingConstraint​(Constraint constraint)
        Will be called after a failure was detected in a Constraint.
        Parameters:
        constraint - The violated Constraint.
      • findImportedProjects

        private void findImportedProjects​(java.util.List<Project> projects)
        Fills the stack of imported Projects. The innermost import will be on top of the stack (List). The main Project of the Configuration will be on bottom. No project will be listed multiple times.
        Parameters:
        projects - The list of all included projects, which are used inside the configuration.
      • findImportedProjects

        private void findImportedProjects​(Project project,
                                          java.util.List<Project> projects,
                                          java.util.Set<Project> done)
        Fills the stack of imported Projects recursively.
        Parameters:
        project - the project to be considered
        projects - the list of all included projects (modified as a side effect)
        done - already considered projects