Class Resolver

    • Constructor Detail

      • Resolver

        public Resolver​(Configuration config,
                        ReasonerConfiguration reasonerConfig)
        Main constructor that activates Resolver constructor.
        Parameters:
        config - Configuration to reason on.
        reasonerConfig - the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)
    • Method Detail

      • translateValueTypeChange

        void translateValueTypeChange​(IDecisionVariable variable,
                                      Value newValue,
                                      Value oldValue)
        Translates/reschedules a change of value types for compound values. Precondition: constraints are correctly assigned before, oldValue != newValue and both, oldValue and newValue are not null.
        Parameters:
        variable - the variable
        newValue - the new value (in variable
        oldValue - the old value
      • cleanupConstraints

        java.util.List<Constraint> cleanupConstraints​(IDecisionVariable variable,
                                                      boolean clear,
                                                      java.util.Set<Compound> deleteFilter)
        Obtains and if specified clears old constraints in the internal reasoner data structures.
        Parameters:
        variable - the variable to return the constraints for
        clear - true for clear variables, false for leave them as they are
        deleteFilter - compound types dictating those constraints having them as attached object that shall be deleted while others shall be left untouched (may be null for delete all constraints if clear is true.
        Returns:
        the constraints stored for variable, may be null
      • moveOtherConstraintsToConstraintBase

        void moveOtherConstraintsToConstraintBase​(IDecisionVariable variable)
        Moves (temporary) constraints in otherConstraints as created by constraint translation to the constraint base. Relates constraints with #variable.
        Parameters:
        variable - the variable to relate constraints to (may be null, ignored then)
      • reschedule

        void reschedule​(AbstractVariable declaration)
        Tries rescheduling the given constraints. Does not add a constraint to the constraint base if already scheduled.
        Parameters:
        declaration - the variable declaration to reschedule
      • reschedule

        void reschedule​(IDecisionVariable var)
        Tries rescheduling the given constraints. Does not add a constraint to the constraint base if already scheduled.
        Parameters:
        var - the variable to reschedule
      • reschedule

        private void reschedule​(java.util.Collection<Constraint> constraints)
        Tries rescheduling the given constraints. Does not add a constraint to the constraint base if already scheduled.
        Parameters:
        constraints - the constraints to reschedule (may be null)
      • notifyResolved

        public void notifyResolved​(IDecisionVariable compound,
                                   java.lang.String slotName,
                                   IDecisionVariable resolved)
        Description copied from interface: IResolutionListener
        Is called to notify about the resolution of the compound slot slotName in compound to var.
        Specified by:
        notifyResolved in interface IResolutionListener
        Parameters:
        compound - the compound variable
        slotName - the slot to be resolved
        resolved - the resolved slot variable
      • evaluateConstraintBase

        private void evaluateConstraintBase​(long start,
                                            Project project)
        Evaluates all constraints in the constraint base.
        Parameters:
        start - the start point in time for reasoning statistics
        project - the project to evaluate
        See Also:
        evaluateConstraints(Project)
      • evaluateConstraints

        private void evaluateConstraints​(Project project)
        Evaluates and reschedules failed constraints.
        Parameters:
        project - the project to evaluate the constraints for
        See Also:
        resolve()
      • evaluateConstraint

        private void evaluateConstraint​(Constraint constraint,
                                        boolean top)
        Evaluates constraint and if available, in case of default constraints, also all related initializing default constraints as one block. This combination allows to have an initializing value assignment, to consider the default constraints, e.g., in refined compounds, and to allow the default constraints to consist of dependent, complex expressions, that can only be evaluated by a reasoner.
        Parameters:
        constraint - the constraint to be evaluated
        top - is this a top-level or a nested call
        See Also:
        evaluateConstraint(Constraint, ConstraintSyntaxTree)
      • evaluateConstraint

        private void evaluateConstraint​(Constraint constraint,
                                        ConstraintSyntaxTree cst)
        Evaluates a single constraint.
        Parameters:
        constraint - the constraint
        cst - the constraint syntax tree already extracted from constraint
      • translateDerivedDatatypeConstraints

        private void translateDerivedDatatypeConstraints​(AbstractVariable decl,
                                                         IDatatype type,
                                                         DecisionVariableDeclaration localDecl,
                                                         IModelElement parent,
                                                         int refCounter,
                                                         ConstraintSyntaxTree cAcc)
        Extracts, translates and collects the internal constraints of type (if derived or, transitively, a reference datatype) and stores the constraints in #derivedTypeConstraints.
        Parameters:
        decl - VariableDeclaration of DerivedDatatype
        type - the type to translate
        localDecl - the declaration of an iterator variable if quantified constraints shall be created, null for normal constraints
        parent - the parent model element for creating constraint instances
        refCounter - the number of intermediary reference types on the path from the top-most call (call with 0)
        cAcc - compound access to be used instead of decl, may be null
      • translateAnnotationDeclaration

        private void translateAnnotationDeclaration​(Attribute decl,
                                                    IDecisionVariable variable,
                                                    ConstraintSyntaxTree cAcc,
                                                    boolean qualifyAttribute)
        Translates an annotation declaration.
        Parameters:
        decl - AbstractVariable with annotations.
        variable - IDecisionVariable with annotations.
        cAcc - CompoundAccess null if variable is not nested, else accessor expression to variable.
        qualifyAttribute - whether the attribute must be explicitly qualified via cAcc
      • translateDeclaration

        private void translateDeclaration​(AbstractVariable decl,
                                          IDecisionVariable var,
                                          ConstraintSyntaxTree cAcc)
        Translates the (transitive) defaults and type constraints for a declaration.
        Parameters:
        decl - The AbstractVariable for which the default value should be resolved.
        var - the instance of decl (may be null for type-based translation).
        cAcc - if variable is a nested compound.
      • addDefaultConstraint

        private void addDefaultConstraint​(AbstractVariable decl,
                                          ConstraintSyntaxTree defaultValue,
                                          Resolver.DefaultConstraints tmp,
                                          boolean enable,
                                          IDecisionVariable var)
        Adds a default constraint.
        Parameters:
        decl - The AbstractVariable for which the default value should be resolved.
        defaultValue - the default value expression
        tmp - temporary storage structure for default value constraints (usually given, may be null) if no transfer (default constraints to block evaluation) shall happen
        enable - whether transfer (default constraints to block evaluation) shall happen at all
        var - the instance of decl (may be null for type-based translation).
      • checkTypeCast

        private static ConstraintSyntaxTree checkTypeCast​(IDatatype declType,
                                                          IDatatype actType,
                                                          AbstractVariable decl,
                                                          ConstraintSyntaxTree cAcc)
        Inserts a type cast if needed.
        Parameters:
        declType - the declared type
        actType - the actual type
        decl - the variable declaration (for the access if cAcc is null)
        cAcc - the actual access expression
        Returns:
        cAcc if no cast is needed, a cast to actType based on cAcc or decl if cAcc is null
      • translateContainerDeclaration

        private void translateContainerDeclaration​(AbstractVariable decl,
                                                   IDecisionVariable var,
                                                   IDatatype type,
                                                   ConstraintSyntaxTree cAcc)
        Translates the (transitive) defaults and type constraints for a container declaration.
        Parameters:
        decl - The AbstractVariable for which the default value should be resolved.
        var - the instance of decl (may be null for type-based translation).
        type - the (specific) datatype (Container)
        cAcc - compound access expression
      • translateCompoundContainer

        private void translateCompoundContainer​(AbstractVariable decl,
                                                Compound type,
                                                IDatatype declaredContainedType,
                                                ConstraintSyntaxTree cAcc)
        Translates an entire compound container decl including defaults and constraints for the specific type cmpType (iterate through all relevant types).
        Parameters:
        decl - the declaration
        type - the compound type to translate for
        declaredContainedType - the declared contained type of decl
        cAcc - compound access to decl if needed (may be null)
      • registerCompoundSlotMapping

        private void registerCompoundSlotMapping​(Compound type,
                                                 ConstraintSyntaxTree cAcc,
                                                 Variable declVar)
        Registers the slot mappings for compound slots of type. Considers shadowed slots and maps them to the most specific (non-shadowed) slot.
        Parameters:
        type - the compound type
        cAcc - the accessor expression (may be null)
        declVar - the compound variable as expression
      • translateCompoundContent

        private void translateCompoundContent​(AbstractVariable decl,
                                              IDecisionVariable variable,
                                              Compound type,
                                              ConstraintSyntaxTree cAcc)
        Translates the compound content.
        Parameters:
        decl - the compound variable (self, instead of cAcc)
        variable - the decision variable holding decl, may be null - ignored then
        type - the (specific) compound type
        cAcc - the compound access expression
      • getNestedAccessor

        private ConstraintSyntaxTree getNestedAccessor​(AbstractVariable nestedDecl,
                                                       ConstraintSyntaxTree cAcc)
        Returns the accessor for a nested variable declaration. Prefer a cAcc based accessor if given, else use a cached one from contexts. In particular, this is required to have type cast in the accessor if given from outside.
        Parameters:
        nestedDecl - the nested declaration
        cAcc - the actual compound accessor
        Returns:
        the accessor to nesteDecl
      • processCompoundEvals

        private void processCompoundEvals​(Compound cmpType,
                                          ConstraintSyntaxTree selfEx,
                                          AbstractVariable self,
                                          IDecisionVariable variable)
        Method for extracting constraints from compounds eval blocks (also refined compounds).
        Parameters:
        cmpType - Compound to be analyzed
        selfEx - an expression representing self (ignored if null, self and selfEx shall never both be specified/not null).
        self - an variable declaration representing self (ignored if null).
        variable - optional variable for registering constraints
      • processEvalConstraints

        private void processEvalConstraints​(PartialEvaluationBlock evalBlock,
                                            ConstraintSyntaxTree selfEx,
                                            AbstractVariable self,
                                            IDecisionVariable variable)
        Method for handling eval blocks - searching for nested eval blocks and extracting constraints.
        Parameters:
        evalBlock - Eval block to be processed.
        selfEx - an expression representing self (ignored if null, self and selfEx shall never both be specified/not null).
        self - an variable declaration representing self (ignored if null).
        variable - optional variable for registering constraints
      • createContainerConstraintValueConstraints

        void createContainerConstraintValueConstraints​(ContainerValue val,
                                                       ConstraintSyntaxTree selfEx,
                                                       AbstractVariable self,
                                                       IModelElement parent,
                                                       IDecisionVariable nestedVariable)
        Checks a container value for nested constraint values, i.e., values of nested constraint variables.
        Parameters:
        val - the container value
        selfEx - expression representing self, must never be not null in conjunction with self
        self - the variable declaration representing self, must never be not null in conjunction with self
        parent - the parent for new constraints
        nestedVariable - the variable holding the constraint value
      • translateAnnotationAssignments

        private void translateAnnotationAssignments​(AttributeAssignment assignment,
                                                    IDecisionVariable var,
                                                    java.util.List<AttributeAssignment.Assignment> effectiveAssignments,
                                                    ConstraintSyntaxTree compound)
        Translates attribute assignments. It is important to recall that in case of nested (orthogonal) attribute assignments, the outer one(s) must also be applied to the inner ones.
        Parameters:
        assignment - Attribute assignments on top-level.
        var - variable holding the assignment, may be null for translating types
        effectiveAssignments - the list of effective current assignments, use null if not recursive.
        compound - Parent CompoundAccess.
      • translateAnnotationAssignment

        private void translateAnnotationAssignment​(AttributeAssignment.Assignment assignment,
                                                   DecisionVariableDeclaration element,
                                                   ConstraintSyntaxTree compound)
        Method for creating attribute constraint for a specific element.
        Parameters:
        assignment - Attribute assignment constraint.
        element - Elements to which the attribute is assigned.
        compound - Nesting compound if there is one, may be null for none.
      • translateConstraints

        private void translateConstraints​(Project project)
        Translates and collects all constraints in project by adding the collected constraints to the constraintBase.
        Parameters:
        project - the project to translate the constraints for
        See Also:
        resolve()
      • addConstraint

        private void addConstraint​(ConstraintList target,
                                   Constraint constraint,
                                   boolean checkForInitializers,
                                   IDecisionVariable variable,
                                   IDecisionVariable register)
        Adding a constraint to a constraint set, checking for contained container/compound initializers if requested.
        Parameters:
        target - the target container for assignment constraints (higher priority)
        constraint - the constraint (may be modified as a side effect)
        checkForInitializers - check also for initializers if (true), add only if (false)
        variable - the actually (nested) variable, used to relate the created constraint to, may be null. This information is particularly relevant for constraints arising from constraint variables.
        register - variable to register against, may be null
      • analyzeEvaluationResult

        private void analyzeEvaluationResult​(Constraint constraint)
        Records information about the evaluation result, failed evaluation messages.
        Parameters:
        constraint - the constraint to record the actual messages for
      • substituteVariables

        ConstraintSyntaxTree substituteVariables​(ConstraintSyntaxTree cst,
                                                 ConstraintSyntaxTree selfEx,
                                                 AbstractVariable self,
                                                 ConstraintSyntaxTree acc)
        Method for using SubstitutionVisitor for constraint transformation. Uses the actual variable mapping in #varMap and may consider a mapping for self.
        Parameters:
        cst - Constraint to be transformed.
        selfEx - an expression representing self (ignored if null, self and selfEx shall never both be specified/not null).
        self - an variable declaration representing self (ignored if null).
        acc - optional accessor expression that shall be excluded from mapping (ignored if null)
        Returns:
        Transformed constraint.
      • getFailedConstraintPart

        private ConstraintSyntaxTree getFailedConstraintPart()
        Method for checking part of a failed constraints against null.
        Returns:
        null or part of a failed constraint.
      • getConstraintVariable

        IDecisionVariable getConstraintVariable​(Constraint constraint)
        Returns the variable currently assigned to constraint.
        Parameters:
        constraint - the constraint to look for
        Returns:
        the variable, may be null for none.
      • constraintCount

        int constraintCount()
        Method for returning the overall count of evaluated constraints in the model.
        Returns:
        number of evaluated constraints.
      • variableCount

        int variableCount()
        Method for returning the overall number of variables in the model.
        Returns:
        number of variables.
      • variableInConstraintCount

        int variableInConstraintCount()
        Method for returning the number of variables involved in constraints.
        Returns:
        number of variables.
      • reevaluationCount

        int reevaluationCount()
        Method for returning the overall number of reevaluations in the model.
        Returns:
        number of reevaluations.
      • setIncremental

        boolean setIncremental​(boolean incremental)
        Sets whether reasoning shall happen incrementally.
        Parameters:
        incremental - if reasoning shall happen incrementally
        Returns:
        the old value of the incremental flag before changing to incremental
        See Also:
        #setConsiderFrozenConstraints(boolean)
      • createEvaluationVisitor

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

        boolean hasTimeout()
        Returns whether reasoning stopped due to a timeout.
        Returns:
        true for timeout, false else
      • wasStopped

        boolean wasStopped()
        Returns whether reasoning was stopped due to a user-request.
        Returns:
        true for stopped, false else
      • isRunning

        boolean isRunning()
        Returns whether the reasoner is (still) operating.
        Returns:
        true for operating, false else
      • stop

        boolean stop()
        Stops/terminates reasoning. If possible, a reasoner shall stop the reasoning operations as quick as possible. A reasoner must not implement this operation.
        Returns:
        true if the reasoner tries to stop, false else (operation not implemented)
      • markForReuse

        void markForReuse()
        Marks this instance for re-use. Must be called before the first call to resolve(). Works intentionally only once.
      • clear

        void clear()
        Clears this instance for reuse to free most of the resources.
        See Also:
        markForReuse(), reInit()
      • reInit

        void reInit()
        Re-initializes this resolver instance to allocated resources only if really needed.
        See Also:
        markForReuse(), reInit()
      • getEvaluationTime

        long getEvaluationTime()
        Returns the time used for evaluation.
        Returns:
        the time in ms
      • getTranslationTime

        long getTranslationTime()
        Returns the time used for translation.
        Returns:
        the time in ms
      • setAssignmentState

        void setAssignmentState​(IAssignmentState state)
        Sets the desired assignment state. The default value is AssignmentState.DERIVED, but specific reasoning operations such as configuration initialization may require a different state.
        Parameters:
        state - the state to use
      • addAssignedVariableToScope

        final void addAssignedVariableToScope​(IDecisionVariable variable)
        Adds an assigned variable to the current scope.
        Parameters:
        variable - the variable to add to the scope
      • contextContainsMapping

        final boolean contextContainsMapping​(AbstractVariable var)
        Returns whether the current context contains a mapping for var.
        Parameters:
        var - the variable to look for
        Returns:
        true if there is a mapping, false else
      • contextRegisterMapping

        final void contextRegisterMapping​(AbstractVariable var,
                                          ConstraintSyntaxTree acc)
        Registers a mapping between the variable var and its actual access expression acc into the current top-most context. Overrides any existing mapping in the top-most context. Preceeds any existing mapping in a previous still active context.
        Parameters:
        var - the variable
        acc - the access expression
      • notifyRescheduling

        final void notifyRescheduling​(boolean inRescheduling)
        Notifies the resolver that following translations happen as part of constraint re-scheduling (or not).
        Parameters:
        inRescheduling - are we in re-scheduling
      • inRescheduling

        public boolean inRescheduling()
        Description copied from interface: TypeCache.IConstraintTarget
        Returns whether the constraint target is currently in re-scheduling and, thus, e.g., default constraints shall not be added.
        Specified by:
        inRescheduling in interface TypeCache.IConstraintTarget
        Returns:
        true for re-scheduling, false else