Class AssignmentResolver
java.lang.Object
net.ssehub.easy.varModel.confModel.AssignmentResolver
Resolves the initial assignment settings for a configuration.
- Starts resolving of values inside the inner most imported
Projectand continues until it arrives at the main project of theConfiguration. Thus, interim assignments shall be considered correctly. - This "simple Reasoner" is not intended to find inconsistencies/errors inside the model. If multiple constraints lead to different value assignments for the same variable, one of these values will be randomly assigned.
- Does not consider
Constraints ofCompounds andDerivedDatatypes. DecisionVariableDeclarationof typeConstraintTypeare also not used for value assignments
- Author:
- El-Sharkawy
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classPart of theresolveAnnotationAssignments(AttributeAssignment, Map, List)for recursive resolving assignment values of annotation assignment blocks. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Configurationprotected EvaluationVisitorprivate Map<IDatatype, List<IDecisionVariable>> Temporary list of all instances per data type.private intSpecification of max evaluation loops should be done perProject. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static ValueaugmentValue(Value value, IDecisionVariable variable, EvaluationVisitor evaluator, IConfiguration config, AssignmentResolver conflictHandler) If a value of a refined compound shall the first time be assigned to a variable of a super compound (polymorphic values), then also the default values of the refined compounds shall be taken into account and augment the value.protected voidconflictingConstraint(Constraint constraint) Will be called after a failure was detected in aConstraint.protected voidWill be called after a failure was detected in a default constraint of anAbstractVariable.protected EvaluationVisitorFactory method for creating the evaluation visitor.private voidfindImportedProjects(List<Project> projects) Fills the stack of importedProjects.private voidFills the stack of importedProjects recursively.private voidRecursive method to collect all nestedIDecisionVariable.protected List<IDecisionVariable> getInstancesForType(IDatatype type) Returns a list of all (nested)IDecisionVariables for the given type.voidresolve()Resolves the (initial) values of the configuration.private voidresolveAnnotationAssignments(AttributeAssignment assignBlock, Map<String, Value> annotationAssignments, List<IDecisionVariable> parents) Recursive method for resolving annotation assignments (part ofresolveAnnotationAssignments(Project).private voidresolveAnnotationAssignments(Project project) Sets the (re-)assigned annotation values for all annotation of all variables for the currentProject.protected voidresolveAssignments(Project project) Part of theresolve()method.static booleanresolveDefaultValue(IDecisionVariable variable) Resolves default values of a particular variable.static booleanresolveDefaultValue(IDecisionVariable variable, EvaluationVisitor evaluator) Resolves default values of a particular variable.protected booleanresolveDefaultValueForDeclaration(AbstractVariable decl, IDecisionVariable variable) Resolves default values of a particular declaration.protected static booleanresolveDefaultValueForDeclaration(AbstractVariable decl, IDecisionVariable variable, EvaluationVisitor evaluator, IConfiguration config, AssignmentResolver conflictHandler) Resolves default values of a particular declaration.protected voidresolveDefaultValues(Project project) Part of theresolve()method.
-
Field Details
-
config
-
evaluator
-
iterationLoops
private int iterationLoopsSpecification of max evaluation loops should be done perProject. If 0 or less, thisAssignmentResolverwill reason until the end (endless). -
instancesPerType
Temporary list of all instances per data type. Should reduce retrieval if nestedIDecisionVariables for aIDatatype(e.g. aCompound) shall be found. Needed for resolving values for nested elements.
-
-
Constructor Details
-
AssignmentResolver
Sole constructor for this class. Will not start resolving values, this must be done via calling theresolve()method.- Parameters:
config- The configuration for which assignments shall be resolved.
-
-
Method Details
-
findInstancesOfNestedVariavbles
Recursive method to collect all nestedIDecisionVariable. Part of the constructor.- Parameters:
variable- A already collected variable, may containing nested variables (must not be null.
-
getInstancesForType
Returns a list of all (nested)IDecisionVariables for the given type.- Parameters:
type- The type for which theIDecisionVariables shall be returned. Will not considerIDatatype.isAssignableFrom(IDatatype).- Returns:
- The list of instances or null if no instance exist for the specified type.
-
createEvaluationVisitor
Factory method for creating the evaluation visitor.- Returns:
- the evaluation visitor
-
resolve
public void resolve()Resolves the (initial) values of the configuration. This is done as follows:- Resolve default values of variable declarations
- Resolve values of assignments
-
resolveAnnotationAssignments
Sets the (re-)assigned annotation values for all annotation of all variables for the currentProject.- Parameters:
project- The current project for which annotation assignments shall be resolved.
-
resolveAnnotationAssignments
private void resolveAnnotationAssignments(AttributeAssignment assignBlock, Map<String, Value> annotationAssignments, List<IDecisionVariable> parents) Recursive method for resolving annotation assignments (part ofresolveAnnotationAssignments(Project).- Parameters:
assignBlock- The current visited assignment block.annotationAssignments- A tuple of (<annotation name>, <value>) for the current annotation block. If a nested block is found, these values must be copied into a new map as nested blocks can have other values and also further elements can be found after a block was visited.parents- A list ofIDecisionVariables which shall currently be treated as parents for retrieving (nested)IDecisionVariables during visitation. Can be empty or null if the current parent is the whole project.
-
resolveDefaultValues
Part of theresolve()method. Resolves default values of variable declarations.- Parameters:
project- The current project for which assignments shall be resolved.
-
resolveDefaultValue
Resolves default values of a particular variable. No conflict handler is used.- Parameters:
variable- the instance to resolve the default values for.evaluator- the (re-usable) expression evaluator to utilize, may be null then a temporary one is created- Returns:
trueif a default value could be resolved and assigned tovariable,falseotherwise.- See Also:
-
resolveDefaultValue
Resolves default values of a particular variable. The evaluator is created on demand, no conflict handler is used.- Parameters:
variable- the instance to resolve the default values for.- Returns:
trueif a default value could be resolved and assigned tovariable,falseotherwise.- See Also:
-
resolveDefaultValueForDeclaration
protected static boolean resolveDefaultValueForDeclaration(AbstractVariable decl, IDecisionVariable variable, EvaluationVisitor evaluator, IConfiguration config, AssignmentResolver conflictHandler) Resolves default values of a particular declaration.- Parameters:
decl- TheAbstractVariablefor which the default value should be resolved.variable- the instance ofdecl.evaluator- the (re-usable) expression evaluator to utilizeconfig- the configuration to rely on (shall be consistent withvariable)conflictHandler- optional instance to callconflictingDefault(AbstractVariable)on, may be null- Returns:
trueif a default value could be resolved and assigned tovariable,falseotherwise.- See Also:
-
augmentValue
private static Value augmentValue(Value value, IDecisionVariable variable, EvaluationVisitor evaluator, IConfiguration config, AssignmentResolver conflictHandler) If a value of a refined compound shall the first time be assigned to a variable of a super compound (polymorphic values), then also the default values of the refined compounds shall be taken into account and augment the value. Otherwise, an inconsistent configuration structure may later lead to invalid values.- Parameters:
value- the value to be checkedvariable- the variable to assign the value toevaluator- the (re-usable) expression evaluator to utilizeconfig- the configuration to rely on (shall be consistent withvariable)conflictHandler- optional instance to callconflictingDefault(AbstractVariable)on, may be null- Returns:
- the (augmented)
value
-
resolveDefaultValueForDeclaration
protected boolean resolveDefaultValueForDeclaration(AbstractVariable decl, IDecisionVariable variable) Resolves default values of a particular declaration.- Parameters:
decl- TheAbstractVariablefor which the default value should be resolved.variable- the instance ofdecl.- Returns:
trueif a default value could be resolved and assigned tovariable,falseotherwise.- See Also:
-
resolveAssignments
Part of theresolve()method. Resolves assignments.- Parameters:
project- Project The current project for which assignments shall be resolved.
-
conflictingConstraint
Will be called after a failure was detected in aConstraint.- Parameters:
constraint- The violatedConstraint.
-
conflictingDefault
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.
-
findImportedProjects
Fills the stack of importedProjects. The innermost import will be on top of the stack (List). The mainProjectof theConfigurationwill be on bottom. No project will be listed multiple times.- Parameters:
projects- The list of all included projects, which are used inside the configuration.
-
findImportedProjects
Fills the stack of importedProjects recursively.- Parameters:
project- the project to be consideredprojects- the list of all included projects (modified as a side effect)done- already considered projects
-