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 ClassesModifier and TypeClassDescriptionprivate classImplements a compound annotation mapper.private classVisits the contents of a project for translation.private static classStorage 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 classImplements a processor for constraints, for which variables (including the variable mapping) shall be substituted and the result shall be added tootherConstraints.private static classRepresents the state of the resolver/reasoner to be kept in case of incremental reasoning. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate net.ssehub.easy.varModel.confModel.IAssignmentStateprivate net.ssehub.easy.varModel.confModel.Configurationprivate net.ssehub.easy.reasoning.core.reasoner.ConstraintBaseprivate intprivate ContextStackprivate Resolver.ReasonerStateprivate Resolver.DefaultConstraintsprivate Set<net.ssehub.easy.varModel.model.Project> private longprivate longprivate EvalVisitorprivate FailedElementsprivate booleanprivate booleanprivate CheckInitializerVisitorprivate booleanprivate booleanprivate booleanprivate static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLoggerprivate static final intprivate static final intprivate static final intprivate net.ssehub.easy.reasoning.core.reasoner.ConstraintListprivate net.ssehub.easy.varModel.model.Projectprivate List<net.ssehub.easy.varModel.model.Project> private net.ssehub.easy.reasoning.core.reasoner.ReasonerConfigurationprivate intprivate RescheduleValueChangeVisitorprivate booleanprivate ScopeAssignmentsprivate SubstitutionVisitorprivate Stack<net.ssehub.easy.reasoning.core.reasoner.ConstraintBase> private net.ssehub.easy.reasoning.core.reasoner.ConstraintListprivate longprivate Set<net.ssehub.easy.varModel.confModel.IDecisionVariable> private intprivate VariablesInConstraintFinderprivate intprivate VariablesMapprivate boolean -
Constructor Summary
ConstructorsConstructorDescriptionResolver(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 TypeMethodDescription(package private) final voidaddAssignedVariableToScope(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Adds an assigned variable to the current scope.final voidaddConstraint(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 voidaddConstraint(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 voidaddDefaultConstraint(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 voidanalyzeEvaluationResult(net.ssehub.easy.varModel.model.Constraint constraint) Records information about the evaluation result, failed evaluation messages.private static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecheckTypeCast(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) voidclear()Clears this instance for reuse to free most of the resources.private voidconflictingDefault(net.ssehub.easy.varModel.model.AbstractVariable decl) Will be called after a failure was detected in a default constraint of anAbstractVariable.(package private) intMethod for returning the overall count of evaluated constraints in the model.(package private) final booleancontextContainsMapping(net.ssehub.easy.varModel.model.AbstractVariable var) Returns whether the current context contains a mapping forvar.(package private) final voidcontextRegisterMapping(net.ssehub.easy.varModel.model.AbstractVariable var, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc) Registers a mapping between the variablevarand its actual access expressionaccinto the current top-most context.(package private) net.ssehub.easy.varModel.model.ConstraintcreateConstraintVariableConstraint(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.ConstraintcreateConstraintVariableConstraint(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 tootherConstraints.(package private) voidcreateContainerConstraintValueConstraints(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.EvaluationVisitorFactory method for creating the evaluation visitor.private voidevaluateConstraint(net.ssehub.easy.varModel.model.Constraint constraint, boolean top) Evaluatesconstraintand if available, in case of default constraints, also all related initializing default constraints as one block.private voidevaluateConstraint(net.ssehub.easy.varModel.model.Constraint constraint, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) Evaluates a single constraint.private voidevaluateConstraintBase(long start, net.ssehub.easy.varModel.model.Project project) Evaluates all constraints in the constraint base.private voidevaluateConstraints(net.ssehub.easy.varModel.model.Project project) Evaluates and reschedules failed constraints.(package private) net.ssehub.easy.varModel.confModel.IDecisionVariablegetConstraintVariable(net.ssehub.easy.varModel.model.Constraint constraint) Returns the variable currently assigned toconstraint.(package private) longReturns the time used for evaluation.private net.ssehub.easy.varModel.cst.ConstraintSyntaxTreeMethod for checking part of a failed constraints against null.(package private) FailedElementsprivate net.ssehub.easy.varModel.cst.ConstraintSyntaxTreegetNestedAccessor(net.ssehub.easy.varModel.model.AbstractVariable nestedDecl, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cAcc) Returns the accessor for a nested variable declaration.(package private) longReturns the time used for translation.(package private) booleanReturns whether reasoning stopped due to a timeout.booleanReturns whether the constraint target is currently in re-scheduling and, thus, e.g., default constraints shall not be added.(package private) booleanReturns whether the reasoner is (still) operating.voidlocalVariableCreated(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var) voidlocalVariableDisposed(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var) (package private) voidMarks this instance for re-use.(package private) voidmoveOtherConstraintsToConstraintBase(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Moves (temporary) constraints inotherConstraintsas created by constraint translation to the constraint base.(package private) final voidnotifyRescheduling(boolean inRescheduling) Notifies the resolver that following translations happen as part of constraint re-scheduling (or not).voidnotifyResolved(net.ssehub.easy.varModel.confModel.IDecisionVariable compound, String slotName, net.ssehub.easy.varModel.confModel.IDecisionVariable resolved) voidnotifyResolved(net.ssehub.easy.varModel.model.AbstractVariable declaration, net.ssehub.easy.varModel.confModel.IDecisionVariable resolved) private voidprocessCompoundEvals(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 voidprocessEvalConstraints(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) intMethod for returning the overall number of reevaluations in the model.private voidregisterCompoundMapping(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 voidregisterCompoundSlotMapping(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 oftype.(package private) voidreInit()Re-initializes this resolver instance to allocated resources only if really needed.private voidreschedule(Collection<net.ssehub.easy.varModel.model.Constraint> constraints) Tries rescheduling the given constraints.(package private) voidreschedule(net.ssehub.easy.varModel.confModel.IDecisionVariable var) Tries rescheduling the given constraints.(package private) voidreschedule(net.ssehub.easy.varModel.model.AbstractVariable declaration) Tries rescheduling the given constraints.voidresolve()Resolves the (initial) values of the configuration.(package private) voidsetAssignmentState(net.ssehub.easy.varModel.confModel.IAssignmentState state) Sets the desired assignment state.(package private) booleansetIncremental(boolean incremental) Sets whether reasoning shall happen incrementally.(package private) booleanstop()Stops/terminates reasoning.(package private) net.ssehub.easy.varModel.cst.ConstraintSyntaxTreesubstituteVariables(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 usingSubstitutionVisitorfor constraint transformation.private net.ssehub.easy.reasoning.core.reasoner.DefaultConstrainttransfer(net.ssehub.easy.reasoning.core.reasoner.DefaultConstraint constraint, Resolver.DefaultConstraints tmp, boolean enable) Temporarily transfers the default constraint lists betweendefaultConstraintsandtmp.private voidtranslateAnnotationAssignment(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 voidtranslateAnnotationAssignments(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 voidtranslateAnnotationDeclaration(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 voidtranslateAnnotationDeclarations(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 voidtranslateCompoundContainer(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 containerdeclincluding defaults and constraints for the specific typecmpType(iterate through all relevant types).private voidtranslateCompoundContent(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 inttranslateCompoundDeclaration(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 notContextStack.alreadyProcessed(IDatatype)in nested collection/compound types.private voidtranslateConstraints(net.ssehub.easy.varModel.model.Project project) Translates and collects all constraints inprojectby adding the collected constraints to theconstraintBase.private voidtranslateContainerDeclaration(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 voidtranslateDeclaration(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 voidtranslateDerivedDatatypeConstraints(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 oftype(if derived or, transitively, a reference datatype) and stores the constraints.(package private) voidtranslateValueTypeChange(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) intMethod for returning the overall number of variables in the model.(package private) intMethod for returning the number of variables involved in constraints.(package private) booleanReturns whether reasoning was stopped due to a user-request.
-
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
-
failedElements
-
scopeAssignments
-
variablesMap
-
copiedState
-
tmpBase
-
constraintBase
private net.ssehub.easy.reasoning.core.reasoner.ConstraintBase constraintBase -
defaultConstraints
-
topLevelConstraints
private net.ssehub.easy.reasoning.core.reasoner.ConstraintList topLevelConstraints -
otherConstraints
private net.ssehub.easy.reasoning.core.reasoner.ConstraintList otherConstraints -
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
-
usedVariables
-
substVisitor
-
contexts
-
simpleAssignmentFinder
-
projectVisitor
-
variablesFinder
-
otherConstraintsProc
-
annotationMapper
-
rescheduler
-
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:
localVariableCreatedin interfacenet.ssehub.easy.varModel.cstEvaluation.IResolutionListener
-
localVariableDisposed
public void localVariableDisposed(net.ssehub.easy.varModel.cstEvaluation.LocalDecisionVariable var) - Specified by:
localVariableDisposedin interfacenet.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 != newValueand both,oldValueandnewValueare not null.- Parameters:
variable- the variablenewValue- the new value (invariableoldValue- 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 forclear-truefor clear variables,falsefor leave them as they aredeleteFilter- 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 ifclearistrue.- Returns:
- the constraints stored for
variable, may be null
-
moveOtherConstraintsToConstraintBase
void moveOtherConstraintsToConstraintBase(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Moves (temporary) constraints inotherConstraintsas 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
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:
notifyResolvedin interfacenet.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:
notifyResolvedin interfacenet.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 statisticsproject- 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) Evaluatesconstraintand 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 evaluatedtop- 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 constraintcst- the constraint syntax tree already extracted fromconstraint
-
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 oftype(if derived or, transitively, a reference datatype) and stores the constraints.- Parameters:
decl- VariableDeclaration ofDerivedDatatypetype- the type to translatelocalDecl- the declaration of an iterator variable if quantified constraints shall be created, null for normal constraintsparent- the parent model element for creating constraint instancesrefCounter- the number of intermediary reference types on the path from the top-most call (call with0)cAcc- compound access to be used instead ofdecl, 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-AbstractVariablewith annotations.variable-IDecisionVariablewith annotations.cAcc-CompoundAccessnull if variable is not nested, else accessor expression tovariable.
-
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-AbstractVariablewith annotations.variable-IDecisionVariablewith annotations.cAcc-CompoundAccessnull if variable is not nested, else accessor expression tovariable.qualifyAttribute- whether the attribute must be explicitly qualified viacAcc
-
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- TheAbstractVariablefor which the default value should be resolved.var- the instance ofdecl(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- TheAbstractVariablefor which the default value should be resolved.defaultValue- the default value expressiontmp- temporary storage structure for default value constraints (usually given, may be null) if no transfer (default constraints to block evaluation) shall happenenable- whether transfer (default constraints to block evaluation) shall happen at allvar- the instance ofdecl(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 betweendefaultConstraintsandtmp. After transferring the lists toconstraint(anddefaultConstraintstemporarily intotmp) default constraints to be registered afterwards will be collected and evaluated as a batch beforeconstraint, e.g., in case of a (refined) compound. Ifconstraintis null,defaultConstraintswill set with the lists intmpand become active again for collecting further default constraints. Ifenableis false, no transfer will happen at all.- Parameters:
constraint- the constraint to hold/holding the actual default constraints lists. If given, the transfer totmpmay happen (dependent onenable), if not, backward-transfer todefaultConstraintswill happen iftmpis not nulltmp- a temporary structure for storingdefaultConstraints, may be nullenable- 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 typeactType- the actual typedecl- the variable declaration (for the access ifcAccis null)cAcc- the actual access expression- Returns:
cAccif no cast is needed, a cast toactTypebased oncAccordeclifcAccis 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- TheAbstractVariablefor which the default value should be resolved.var- the instance ofdecl(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 containerdeclincluding defaults and constraints for the specific typecmpType(iterate through all relevant types).- Parameters:
decl- the declarationtype- the compound type to translate fordeclaredContainedType- the declared contained type ofdeclcAcc- compound access todeclif 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 notContextStack.alreadyProcessed(IDatatype)in nested collection/compound types.- Parameters:
decl- TheAbstractVariablefor which the default value should be resolved.variable- the instance ofdecl(may be null for based-type translation).cAcc- if variable is a nested compound, the access expression todecl/variabletype- specificCompoundtype.mode- the processing mode, eitherMODE_COMPOUND_REGISTERfor just registering the compound slot accessor expressions, which must either be followed withMODE_COMPOUND_TRANSLATEorContextStack.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 beMODE_COMPOUND_NONEfor not processing anything.- Returns:
- the next mode for calling this method again with the same parameters, typically
MODE_COMPOUND_NONEorMODE_COMPOUND_TRANSLATEifmodewasMODE_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 typecAcc- 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 oftype. Considers shadowed slots and maps them to the most specific (non-shadowed) slot.- Parameters:
type- the compound typecAcc- 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 ofcAcc)variable- the decision variable holdingdecl, may be null - ignored thentype- the (specific) compound typecAcc- 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 acAccbased accessor if given, else use a cached one fromcontexts. In particular, this is required to have type cast in the accessor if given from outside.- Parameters:
nestedDecl- the nested declarationcAcc- 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 analyzedselfEx- an expression representing self (ignored if null,selfandselfExshall 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,selfandselfExshall 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 valueselfEx- expression representing self, must never be not null in conjunction withselfself- the variable declaration representing self, must never be not null in conjunction withselfparent- the parent for new constraintsnestedVariable- 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 typeseffectiveAssignments- the list of effective current assignments, use null if not recursive.compound- ParentCompoundAccess.
-
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 inprojectby adding the collected constraints to theconstraintBase.- 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.IConstraintTargetAdds a constraint to the (preliminary) constraint base.- Specified by:
addConstraintin interfaceTypeCache.IConstraintTarget- Parameters:
target- the target constraint setfirst- at to front/endconstraint- the constraint to be addedregister- register the constraint withVariablesMapfor 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 ifcstis not aConstantValue.- Parameters:
cst- the constraintselfEx- the expression representing self incst, both,selfandselfExmust not be different from null at the same time (may be null for none)self- the declaration of the variable representing self incst(may be null for none)parent- the parent for new constraintsvariable- 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 tootherConstraints. Registers the constraint if needed.- Parameters:
cst- the constraintself- the declaration of the variable representing self incst(may be null for none), just used for loggingcheckForInitializers- whether initializers shall be checked (recursively) when adding a constraintparent- the parent for new constraintsvariable- 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 usingSubstitutionVisitorfor constraint transformation. Uses the actual variable mapping and may consider a mapping forself.- Parameters:
cst- Constraint to be transformed.selfEx- an expression representing self (ignored if null,selfandselfExshall 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 anAbstractVariable.- Parameters:
decl- The conflicting declaration of anAbstractVariable. CallAbstractVariable.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 toconstraint.- 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()- 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:
truefor timeout,falseelse
-
wasStopped
boolean wasStopped()Returns whether reasoning was stopped due to a user-request.- Returns:
truefor stopped,falseelse
-
isRunning
boolean isRunning()Returns whether the reasoner is (still) operating.- Returns:
truefor operating,falseelse
-
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:
trueif the reasoner tries to stop,falseelse (operation not implemented)
-
markForReuse
void markForReuse()Marks this instance for re-use. Must be called before the first call toresolve(). 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 isAssignmentState.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 forvar.- Parameters:
var- the variable to look for- Returns:
trueif there is a mapping,falseelse
-
contextRegisterMapping
final void contextRegisterMapping(net.ssehub.easy.varModel.model.AbstractVariable var, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree acc) Registers a mapping between the variablevarand its actual access expressionaccinto 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 variableacc- 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.IConstraintTargetReturns whether the constraint target is currently in re-scheduling and, thus, e.g., default constraints shall not be added.- Specified by:
inReschedulingin interfaceTypeCache.IConstraintTarget- Returns:
truefor re-scheduling,falseelse
-