Class Resolver

java.lang.Object
net.ssehub.easy.reasoning.sseReasoner.Resolver
All Implemented Interfaces:
TypeCache.IConstraintTarget, net.ssehub.easy.varModel.cstEvaluation.IResolutionListener

final class Resolver extends Object implements net.ssehub.easy.varModel.cstEvaluation.IResolutionListener, TypeCache.IConstraintTarget
Constraint identifier, resolver and executor. Assumption that constraints are not evaluated in parallel (see some comments). This resolver can be re-used. Therefore, call markForReuse() before the first call to resolve() and after reasoning completed, call clear(). When performing a further reasoning on this instance, call reInit().
Author:
Sizonenko, El-Sharkawy, Holger Eichelberger
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
    Implements a compound annotation mapper.
    private class 
    Visits the contents of a project for translation.
    private static class 
    Storage for two sub-types of default constraints, namely primary default constraints that can be evaluated directly, e.g., constants (Resolver.DefaultConstraints.defaultConstraints) and more complex constraints with dependencies (Resolver.DefaultConstraints.deferredDefaultConstraints).
    private class 
    Implements a processor for constraints, for which variables (including the variable mapping) shall be substituted and the result shall be added to otherConstraints.
    private static class 
    Represents the state of the resolver/reasoner to be kept in case of incremental reasoning.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
     
    private net.ssehub.easy.varModel.confModel.IAssignmentState
     
    private net.ssehub.easy.varModel.confModel.Configuration
     
    private net.ssehub.easy.reasoning.core.reasoner.ConstraintBase
     
    private int
     
    private ContextStack
     
     
     
    private Set<net.ssehub.easy.varModel.model.Project>
     
    private long
     
    private long
     
    private EvalVisitor
     
     
    private boolean
     
    private boolean
     
     
    private boolean
     
    private boolean
     
    private boolean
     
    private static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger
     
    private static final int
     
    private static final int
     
    private static final int
     
    private net.ssehub.easy.reasoning.core.reasoner.ConstraintList
     
     
    private net.ssehub.easy.varModel.model.Project
     
    private List<net.ssehub.easy.varModel.model.Project>
     
     
    private net.ssehub.easy.reasoning.core.reasoner.ReasonerConfiguration
     
    private int
     
     
    private boolean
     
     
     
     
    private Stack<net.ssehub.easy.reasoning.core.reasoner.ConstraintBase>
     
    private net.ssehub.easy.reasoning.core.reasoner.ConstraintList
     
    private long
     
    private Set<net.ssehub.easy.varModel.confModel.IDecisionVariable>
     
    private int
     
     
    private int
     
    private VariablesMap
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Resolver(net.ssehub.easy.varModel.confModel.Configuration config, net.ssehub.easy.reasoning.core.reasoner.ReasonerConfiguration reasonerConfig)
    Main constructor that activates Resolver constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) final void
    addAssignedVariableToScope(net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
    Adds an assigned variable to the current scope.
    final void
    addConstraint(net.ssehub.easy.reasoning.core.reasoner.ConstraintList target, boolean first, net.ssehub.easy.varModel.model.Constraint constraint, net.ssehub.easy.varModel.confModel.IDecisionVariable register)
    Adds a constraint to the (preliminary) constraint base.
    private void
    addConstraint(net.ssehub.easy.reasoning.core.reasoner.ConstraintList target, net.ssehub.easy.varModel.model.Constraint constraint, boolean checkForInitializers, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.confModel.IDecisionVariable register)
    Adding a constraint to a constraint set, checking for contained container/compound initializers if requested.
    private void
    addDefaultConstraint(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree defaultValue, Resolver.DefaultConstraints tmp, boolean enable, net.ssehub.easy.varModel.confModel.IDecisionVariable var)
    Adds a default constraint.
    private void
    analyzeEvaluationResult(net.ssehub.easy.varModel.model.Constraint constraint)
    Records information about the evaluation result, failed evaluation messages.
    private static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    checkTypeCast(net.ssehub.easy.varModel.model.datatypes.IDatatype declType, net.ssehub.easy.varModel.model.datatypes.IDatatype actType, net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Inserts a type cast if needed.
    (package private) List<net.ssehub.easy.varModel.model.Constraint>
    cleanupConstraints(net.ssehub.easy.varModel.confModel.IDecisionVariable variable, boolean clear, Set<net.ssehub.easy.varModel.model.datatypes.Compound> deleteFilter)
    Obtains and if specified clears old constraints in the internal reasoner data structures.
    (package private) void
    Clears this instance for reuse to free most of the resources.
    private void
    conflictingDefault(net.ssehub.easy.varModel.model.AbstractVariable decl)
    Will be called after a failure was detected in a default constraint of an AbstractVariable.
    (package private) int
    Method for returning the overall count of evaluated constraints in the model.
    (package private) final boolean
    contextContainsMapping(net.ssehub.easy.varModel.model.AbstractVariable var)
    Returns whether the current context contains a mapping for var.
    (package private) final void
    contextRegisterMapping(net.ssehub.easy.varModel.model.AbstractVariable var, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc)
    Registers a mapping between the variable var and its actual access expression acc into the current top-most context.
    (package private) net.ssehub.easy.varModel.model.Constraint
    createConstraintVariableConstraint(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.model.IModelElement parent, net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
    Creates a constraint for a (nested) constraint variable.
    (package private) net.ssehub.easy.varModel.model.Constraint
    createConstraintVariableConstraint(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.model.AbstractVariable self, boolean checkForInitializers, net.ssehub.easy.varModel.model.IModelElement parent, net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
    Creates a constraint for a (nested) constraint variable adding the result to otherConstraints.
    (package private) void
    createContainerConstraintValueConstraints(net.ssehub.easy.varModel.model.values.ContainerValue val, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.model.IModelElement parent, net.ssehub.easy.varModel.confModel.IDecisionVariable nestedVariable)
    Checks a container value for nested constraint values, i.e., values of nested constraint variables.
    protected net.ssehub.easy.varModel.cstEvaluation.EvaluationVisitor
    Factory method for creating the evaluation visitor.
    private void
    evaluateConstraint(net.ssehub.easy.varModel.model.Constraint constraint, boolean top)
    Evaluates constraint and if available, in case of default constraints, also all related initializing default constraints as one block.
    private void
    evaluateConstraint(net.ssehub.easy.varModel.model.Constraint constraint, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst)
    Evaluates a single constraint.
    private void
    evaluateConstraintBase(long start, net.ssehub.easy.varModel.model.Project project)
    Evaluates all constraints in the constraint base.
    private void
    evaluateConstraints(net.ssehub.easy.varModel.model.Project project)
    Evaluates and reschedules failed constraints.
    (package private) net.ssehub.easy.varModel.confModel.IDecisionVariable
    getConstraintVariable(net.ssehub.easy.varModel.model.Constraint constraint)
    Returns the variable currently assigned to constraint.
    (package private) long
    Returns the time used for evaluation.
    private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    Method for checking part of a failed constraints against null.
    (package private) FailedElements
    Method for retrieving FailedElements with failed Constraints and IDecisionVariables.
    private net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    getNestedAccessor(net.ssehub.easy.varModel.model.AbstractVariable nestedDecl, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Returns the accessor for a nested variable declaration.
    (package private) long
    Returns the time used for translation.
    (package private) boolean
    Returns whether reasoning stopped due to a timeout.
    boolean
    Returns whether the constraint target is currently in re-scheduling and, thus, e.g., default constraints shall not be added.
    (package private) boolean
    Returns whether the reasoner is (still) operating.
    void
    localVariableCreated(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var)
     
    void
    localVariableDisposed(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var)
     
    (package private) void
    Marks this instance for re-use.
    (package private) void
    moveOtherConstraintsToConstraintBase(net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
    Moves (temporary) constraints in otherConstraints as created by constraint translation to the constraint base.
    (package private) final void
    notifyRescheduling(boolean inRescheduling)
    Notifies the resolver that following translations happen as part of constraint re-scheduling (or not).
    void
    notifyResolved(net.ssehub.easy.varModel.confModel.IDecisionVariable compound, String slotName, net.ssehub.easy.varModel.confModel.IDecisionVariable resolved)
     
    void
    notifyResolved(net.ssehub.easy.varModel.model.AbstractVariable declaration, net.ssehub.easy.varModel.confModel.IDecisionVariable resolved)
     
    private void
    processCompoundEvals(net.ssehub.easy.varModel.model.datatypes.Compound cmpType, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
    Method for extracting constraints from compounds eval blocks (also refined compounds).
    private void
    processEvalConstraints(net.ssehub.easy.varModel.model.PartialEvaluationBlock evalBlock, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
    Method for handling eval blocks - searching for nested eval blocks and extracting constraints.
    (package private) int
    Method for returning the overall number of reevaluations in the model.
    private void
    registerCompoundMapping(net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, net.ssehub.easy.varModel.cst.Variable declVar)
    Registers the mapping for a compound type.
    private void
    registerCompoundSlotMapping(net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, net.ssehub.easy.varModel.cst.Variable declVar)
    Registers the slot mappings for compound slots of type.
    (package private) void
    Re-initializes this resolver instance to allocated resources only if really needed.
    private void
    reschedule(Collection<net.ssehub.easy.varModel.model.Constraint> constraints)
    Tries rescheduling the given constraints.
    (package private) void
    reschedule(net.ssehub.easy.varModel.confModel.IDecisionVariable var)
    Tries rescheduling the given constraints.
    (package private) void
    reschedule(net.ssehub.easy.varModel.model.AbstractVariable declaration)
    Tries rescheduling the given constraints.
    void
    Resolves the (initial) values of the configuration.
    (package private) void
    setAssignmentState(net.ssehub.easy.varModel.confModel.IAssignmentState state)
    Sets the desired assignment state.
    (package private) boolean
    setIncremental(boolean incremental)
    Sets whether reasoning shall happen incrementally.
    (package private) boolean
    Stops/terminates reasoning.
    (package private) net.ssehub.easy.varModel.cst.ConstraintSyntaxTree
    substituteVariables(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc)
    Method for using SubstitutionVisitor for constraint transformation.
    private net.ssehub.easy.reasoning.core.reasoner.DefaultConstraint
    transfer(net.ssehub.easy.reasoning.core.reasoner.DefaultConstraint constraint, Resolver.DefaultConstraints tmp, boolean enable)
    Temporarily transfers the default constraint lists between defaultConstraints and tmp.
    private void
    translateAnnotationAssignment(net.ssehub.easy.varModel.model.AttributeAssignment.Assignment assignment, net.ssehub.easy.varModel.model.DecisionVariableDeclaration element, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree compound)
    Method for creating attribute constraint for a specific element.
    private void
    translateAnnotationAssignments(net.ssehub.easy.varModel.model.AttributeAssignment assignment, net.ssehub.easy.varModel.confModel.IDecisionVariable var, List<net.ssehub.easy.varModel.model.AttributeAssignment.Assignment> effectiveAssignments, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree compound)
    Translates attribute assignments.
    private void
    translateAnnotationDeclaration(net.ssehub.easy.varModel.model.Attribute decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, boolean qualifyAttribute)
    Translates an annotation declaration.
    private void
    translateAnnotationDeclarations(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Translates annotation declarations.
    private void
    translateCompoundContainer(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.model.datatypes.IDatatype declaredContainedType, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Translates an entire compound container decl including defaults and constraints for the specific type cmpType (iterate through all relevant types).
    private void
    translateCompoundContent(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Translates the compound content.
    private int
    translateCompoundDeclaration(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, net.ssehub.easy.varModel.model.datatypes.Compound type, int mode)
    Translates translating compound type declarations, but only if not ContextStack.alreadyProcessed(IDatatype) in nested collection/compound types.
    private void
    translateConstraints(net.ssehub.easy.varModel.model.Project project)
    Translates and collects all constraints in project by adding the collected constraints to the constraintBase.
    private void
    translateContainerDeclaration(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.model.datatypes.IDatatype type, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Translates the (transitive) defaults and type constraints for a container declaration.
    private void
    translateDeclaration(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Translates the (transitive) defaults and type constraints for a declaration.
    private void
    translateDerivedDatatypeConstraints(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.model.datatypes.IDatatype type, net.ssehub.easy.varModel.model.DecisionVariableDeclaration localDecl, net.ssehub.easy.varModel.model.IModelElement parent, int refCounter, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
    Extracts, translates and collects the internal constraints of type (if derived or, transitively, a reference datatype) and stores the constraints.
    (package private) void
    translateValueTypeChange(net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.model.values.Value newValue, net.ssehub.easy.varModel.model.values.Value oldValue)
    Translates/reschedules a change of value types for compound values.
    (package private) int
    Method for returning the overall number of variables in the model.
    (package private) int
    Method for returning the number of variables involved in constraints.
    (package private) boolean
    Returns whether reasoning was stopped due to a user-request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOGGER

      private static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger LOGGER
    • MODE_COMPOUND_REGISTER

      private static final int MODE_COMPOUND_REGISTER
      See Also:
    • MODE_COMPOUND_TRANSLATE

      private static final int MODE_COMPOUND_TRANSLATE
      See Also:
    • MODE_COMPOUND_NONE

      private static final int MODE_COMPOUND_NONE
      See Also:
    • reasonerConfig

      private net.ssehub.easy.reasoning.core.reasoner.ReasonerConfiguration reasonerConfig
    • config

      private net.ssehub.easy.varModel.confModel.Configuration config
    • incremental

      private boolean incremental
    • reuseInstance

      private boolean reuseInstance
    • assignmentState

      private net.ssehub.easy.varModel.confModel.IAssignmentState assignmentState
    • inRescheduling

      private boolean inRescheduling
    • evaluator

      private EvalVisitor evaluator
    • failedElements

      private FailedElements failedElements
    • scopeAssignments

      private ScopeAssignments scopeAssignments
    • variablesMap

      private VariablesMap variablesMap
    • copiedState

      private Resolver.ReasonerState copiedState
    • tmpBase

      private Stack<net.ssehub.easy.reasoning.core.reasoner.ConstraintBase> tmpBase
    • constraintBase

      private net.ssehub.easy.reasoning.core.reasoner.ConstraintBase constraintBase
    • defaultConstraints

      private Resolver.DefaultConstraints defaultConstraints
    • topLevelConstraints

      private net.ssehub.easy.reasoning.core.reasoner.ConstraintList topLevelConstraints
    • otherConstraints

      private net.ssehub.easy.reasoning.core.reasoner.ConstraintList otherConstraints
    • projects

      private List<net.ssehub.easy.varModel.model.Project> projects
    • constraintCounter

      private int constraintCounter
    • variablesInConstraintsCounter

      private int variablesInConstraintsCounter
    • reevaluationCounter

      private int reevaluationCounter
    • variablesCounter

      private int variablesCounter
    • hasTimeout

      private boolean hasTimeout
    • isRunning

      private boolean isRunning
    • wasStopped

      private boolean wasStopped
    • translationTime

      private long translationTime
    • evaluationTime

      private long evaluationTime
    • project

      private net.ssehub.easy.varModel.model.Project project
    • doneProjects

      private transient Set<net.ssehub.easy.varModel.model.Project> doneProjects
    • usedVariables

      private transient Set<net.ssehub.easy.varModel.confModel.IDecisionVariable> usedVariables
    • substVisitor

      private transient SubstitutionVisitor substVisitor
    • contexts

      private transient ContextStack contexts
    • simpleAssignmentFinder

      private transient VariablesInNotSimpleAssignmentConstraintsFinder simpleAssignmentFinder
    • projectVisitor

      private transient Resolver.ConstraintTranslationVisitor projectVisitor
    • variablesFinder

      private transient VariablesInConstraintFinder variablesFinder
    • otherConstraintsProc

      private transient Resolver.OtherConstraintsProcessor otherConstraintsProc
    • annotationMapper

      private transient Resolver.CompoundAnnotationMapper annotationMapper
    • rescheduler

      private transient RescheduleValueChangeVisitor rescheduler
    • initChecker

      private transient CheckInitializerVisitor initChecker
    • endTimestamp

      private transient long endTimestamp
    • inTopLevelEvals

      private transient boolean inTopLevelEvals
  • Constructor Details

    • Resolver

      public Resolver(net.ssehub.easy.varModel.confModel.Configuration config, net.ssehub.easy.reasoning.core.reasoner.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 Details

    • localVariableCreated

      public void localVariableCreated(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var)
      Specified by:
      localVariableCreated in interface net.ssehub.easy.varModel.cstEvaluation.IResolutionListener
    • localVariableDisposed

      public void localVariableDisposed(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var)
      Specified by:
      localVariableDisposed in interface net.ssehub.easy.varModel.cstEvaluation.IResolutionListener
    • translateValueTypeChange

      void translateValueTypeChange(net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.model.values.Value newValue, net.ssehub.easy.varModel.model.values.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

      List<net.ssehub.easy.varModel.model.Constraint> cleanupConstraints(net.ssehub.easy.varModel.confModel.IDecisionVariable variable, boolean clear, Set<net.ssehub.easy.varModel.model.datatypes.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(net.ssehub.easy.varModel.confModel.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(net.ssehub.easy.varModel.model.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(net.ssehub.easy.varModel.confModel.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(Collection<net.ssehub.easy.varModel.model.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(net.ssehub.easy.varModel.confModel.IDecisionVariable compound, String slotName, net.ssehub.easy.varModel.confModel.IDecisionVariable resolved)
      Specified by:
      notifyResolved in interface net.ssehub.easy.varModel.cstEvaluation.IResolutionListener
    • notifyResolved

      public void notifyResolved(net.ssehub.easy.varModel.model.AbstractVariable declaration, net.ssehub.easy.varModel.confModel.IDecisionVariable resolved)
      Specified by:
      notifyResolved in interface net.ssehub.easy.varModel.cstEvaluation.IResolutionListener
    • resolve

      public void resolve()
      Resolves the (initial) values of the configuration.
      See Also:
    • evaluateConstraintBase

      private void evaluateConstraintBase(long start, net.ssehub.easy.varModel.model.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

      private void evaluateConstraints(net.ssehub.easy.varModel.model.Project project)
      Evaluates and reschedules failed constraints.
      Parameters:
      project - the project to evaluate the constraints for
      See Also:
    • evaluateConstraint

      private void evaluateConstraint(net.ssehub.easy.varModel.model.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

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

      private void translateDerivedDatatypeConstraints(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.model.datatypes.IDatatype type, net.ssehub.easy.varModel.model.DecisionVariableDeclaration localDecl, net.ssehub.easy.varModel.model.IModelElement parent, int refCounter, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
      Extracts, translates and collects the internal constraints of type (if derived or, transitively, a reference datatype) and stores the constraints.
      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
    • translateAnnotationDeclarations

      private void translateAnnotationDeclarations(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc)
      Translates annotation declarations.
      Parameters:
      decl - AbstractVariable with annotations.
      variable - IDecisionVariable with annotations.
      cAcc - CompoundAccess null if variable is not nested, else accessor expression to variable.
    • translateAnnotationDeclaration

      private void translateAnnotationDeclaration(net.ssehub.easy.varModel.model.Attribute decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree defaultValue, Resolver.DefaultConstraints tmp, boolean enable, net.ssehub.easy.varModel.confModel.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).
    • transfer

      private net.ssehub.easy.reasoning.core.reasoner.DefaultConstraint transfer(net.ssehub.easy.reasoning.core.reasoner.DefaultConstraint constraint, Resolver.DefaultConstraints tmp, boolean enable)
      Temporarily transfers the default constraint lists between defaultConstraints and tmp. After transferring the lists to constraint (and defaultConstraints temporarily into tmp) default constraints to be registered afterwards will be collected and evaluated as a batch before constraint, e.g., in case of a (refined) compound. If constraint is null, defaultConstraints will set with the lists in tmp and become active again for collecting further default constraints. If enable is false, no transfer will happen at all.
      Parameters:
      constraint - the constraint to hold/holding the actual default constraints lists. If given, the transfer to tmp may happen (dependent on enable), if not, backward-transfer to defaultConstraints will happen if tmp is not null
      tmp - a temporary structure for storing defaultConstraints, may be null
      enable - generally enables or disable the transfer
      Returns:
      constraint
    • checkTypeCast

      private static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree checkTypeCast(net.ssehub.easy.varModel.model.datatypes.IDatatype declType, net.ssehub.easy.varModel.model.datatypes.IDatatype actType, net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.model.datatypes.IDatatype type, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.model.datatypes.IDatatype declaredContainedType, net.ssehub.easy.varModel.cst.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)
    • translateCompoundDeclaration

      private int translateCompoundDeclaration(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, net.ssehub.easy.varModel.model.datatypes.Compound type, int mode)
      Translates translating compound type declarations, but only if not ContextStack.alreadyProcessed(IDatatype) in nested collection/compound types.
      Parameters:
      decl - The AbstractVariable for which the default value should be resolved.
      variable - the instance of decl (may be null for based-type translation).
      cAcc - if variable is a nested compound, the access expression to decl/variable
      type - specific Compound type.
      mode - the processing mode, either MODE_COMPOUND_REGISTER for just registering the compound slot accessor expressions, which must either be followed with MODE_COMPOUND_TRANSLATE or ContextStack.popContext() on the same nesting level. Not processing a complete compound allows keeping the registered scope open for processing related (default) value expressions that may refer to compound slots. May also be MODE_COMPOUND_NONE for not processing anything.
      Returns:
      the next mode for calling this method again with the same parameters, typically MODE_COMPOUND_NONE or MODE_COMPOUND_TRANSLATE if mode was MODE_COMPOUND_REGISTER
    • registerCompoundMapping

      private void registerCompoundMapping(net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, net.ssehub.easy.varModel.cst.Variable declVar)
      Registers the mapping for a compound type.
      Parameters:
      type - the compound type
      cAcc - the accessor expression (may be null)
      declVar - the compound variable as expression
      See Also:
    • registerCompoundSlotMapping

      private void registerCompoundSlotMapping(net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.model.datatypes.Compound type, net.ssehub.easy.varModel.cst.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 net.ssehub.easy.varModel.cst.ConstraintSyntaxTree getNestedAccessor(net.ssehub.easy.varModel.model.AbstractVariable nestedDecl, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.datatypes.Compound cmpType, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.confModel.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(net.ssehub.easy.varModel.model.PartialEvaluationBlock evalBlock, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.confModel.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(net.ssehub.easy.varModel.model.values.ContainerValue val, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.model.IModelElement parent, net.ssehub.easy.varModel.confModel.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(net.ssehub.easy.varModel.model.AttributeAssignment assignment, net.ssehub.easy.varModel.confModel.IDecisionVariable var, List<net.ssehub.easy.varModel.model.AttributeAssignment.Assignment> effectiveAssignments, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.AttributeAssignment.Assignment assignment, net.ssehub.easy.varModel.model.DecisionVariableDeclaration element, net.ssehub.easy.varModel.cst.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(net.ssehub.easy.varModel.model.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:
    • addConstraint

      private void addConstraint(net.ssehub.easy.reasoning.core.reasoner.ConstraintList target, net.ssehub.easy.varModel.model.Constraint constraint, boolean checkForInitializers, net.ssehub.easy.varModel.confModel.IDecisionVariable variable, net.ssehub.easy.varModel.confModel.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
    • addConstraint

      public final void addConstraint(net.ssehub.easy.reasoning.core.reasoner.ConstraintList target, boolean first, net.ssehub.easy.varModel.model.Constraint constraint, net.ssehub.easy.varModel.confModel.IDecisionVariable register)
      Description copied from interface: TypeCache.IConstraintTarget
      Adds a constraint to the (preliminary) constraint base.
      Specified by:
      addConstraint in interface TypeCache.IConstraintTarget
      Parameters:
      target - the target constraint set
      first - at to front/end
      constraint - the constraint to be added
      register - register the constraint with VariablesMap for the given variable (ignored if null)
    • createConstraintVariableConstraint

      net.ssehub.easy.varModel.model.Constraint createConstraintVariableConstraint(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.model.IModelElement parent, net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
      Creates a constraint for a (nested) constraint variable. Performs initializers check upon adding if cst is not a ConstantValue.
      Parameters:
      cst - the constraint
      selfEx - the expression representing self in cst, both, self and selfEx must not be different from null at the same time (may be null for none)
      self - the declaration of the variable representing self in cst (may be null for none)
      parent - the parent for new constraints
      variable - the actually (nested) variable, used to relate the created constraint to, may be null
      Returns:
      the created constraint
      See Also:
    • createConstraintVariableConstraint

      net.ssehub.easy.varModel.model.Constraint createConstraintVariableConstraint(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.model.AbstractVariable self, boolean checkForInitializers, net.ssehub.easy.varModel.model.IModelElement parent, net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
      Creates a constraint for a (nested) constraint variable adding the result to otherConstraints. Registers the constraint if needed.
      Parameters:
      cst - the constraint
      self - the declaration of the variable representing self in cst (may be null for none), just used for logging
      checkForInitializers - whether initializers shall be checked (recursively) when adding a constraint
      parent - the parent for new constraints
      variable - the actually (nested) variable, used to relate the created constraint to, may be null
      Returns:
      the created constraint
      See Also:
    • analyzeEvaluationResult

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

      net.ssehub.easy.varModel.cst.ConstraintSyntaxTree substituteVariables(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree selfEx, net.ssehub.easy.varModel.model.AbstractVariable self, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc)
      Method for using SubstitutionVisitor for constraint transformation. Uses the actual variable mapping 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.
    • conflictingDefault

      private void conflictingDefault(net.ssehub.easy.varModel.model.AbstractVariable decl)
      Will be called after a failure was detected in a default constraint of an AbstractVariable.
      Parameters:
      decl - The conflicting declaration of an AbstractVariable. Call AbstractVariable.getDefaultValue() to retrieve the conflicting constraint.
    • getFailedConstraintPart

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

      net.ssehub.easy.varModel.confModel.IDecisionVariable getConstraintVariable(net.ssehub.easy.varModel.model.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.
    • getFailedElements

      FailedElements getFailedElements()
      Method for retrieving FailedElements with failed Constraints and IDecisionVariables.
      Returns:
      FailedElements
    • 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
    • createEvaluationVisitor

      protected net.ssehub.easy.varModel.cstEvaluation.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:
    • reInit

      void reInit()
      Re-initializes this resolver instance to allocated resources only if really needed.
      See Also:
    • 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(net.ssehub.easy.varModel.confModel.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(net.ssehub.easy.varModel.confModel.IDecisionVariable variable)
      Adds an assigned variable to the current scope.
      Parameters:
      variable - the variable to add to the scope
    • contextContainsMapping

      final boolean contextContainsMapping(net.ssehub.easy.varModel.model.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(net.ssehub.easy.varModel.model.AbstractVariable var, net.ssehub.easy.varModel.cst.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