Class AssignmentResolver
- java.lang.Object
-
- net.ssehub.easy.varModel.confModel.AssignmentResolver
-
public class AssignmentResolver extends java.lang.ObjectResolves 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
- Starts resolving of values inside the inner most imported
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAssignmentResolver.AssignBlockVisitorPart of theAssignmentResolver#resolveAnnotationAssignments(AttributeAssignment, Map)for recursive resolving assignment values of annotation assignment blocks.
-
Field Summary
Fields Modifier and Type Field Description protected Configurationconfigprotected EvaluationVisitorevaluatorprivate java.util.Map<IDatatype,java.util.List<IDecisionVariable>>instancesPerTypeTemporary list of all instances per data type.private intiterationLoopsSpecification of max evaluation loops should be done perProject.
-
Constructor Summary
Constructors Constructor Description AssignmentResolver(Configuration config)Sole constructor for this class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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 voidconflictingDefault(AbstractVariable decl)Will be called after a failure was detected in a default constraint of anAbstractVariable.protected EvaluationVisitorcreateEvaluationVisitor()Factory method for creating the evaluation visitor.private voidfindImportedProjects(java.util.List<Project> projects)Fills the stack of importedProjects.private voidfindImportedProjects(Project project, java.util.List<Project> projects, java.util.Set<Project> done)Fills the stack of importedProjects recursively.private voidfindInstancesOfNestedVariavbles(IDecisionVariable variable)Recursive method to collect all nestedIDecisionVariable.protected java.util.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, java.util.Map<java.lang.String,Value> annotationAssignments, java.util.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 Detail
-
config
protected Configuration config
-
evaluator
protected EvaluationVisitor evaluator
-
iterationLoops
private int iterationLoops
Specification of max evaluation loops should be done perProject. If 0 or less, thisAssignmentResolverwill reason until the end (endless).
-
instancesPerType
private java.util.Map<IDatatype,java.util.List<IDecisionVariable>> 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 Detail
-
AssignmentResolver
public AssignmentResolver(Configuration config)
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 Detail
-
findInstancesOfNestedVariavbles
private void findInstancesOfNestedVariavbles(IDecisionVariable variable)
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
protected java.util.List<IDecisionVariable> getInstancesForType(IDatatype type)
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
protected EvaluationVisitor createEvaluationVisitor()
Factory method for creating the evaluation visitor.- Returns:
- the evaluation visitor
-
resolve
public void resolve()
Resolves the (initial) values of the configuration. This is done as follows:- Resolve default values of variable declarations
- Resolve values of assignments
-
resolveAnnotationAssignments
private void resolveAnnotationAssignments(Project project)
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, java.util.Map<java.lang.String,Value> annotationAssignments, java.util.List<IDecisionVariable> parents)
Recursive method for resolving annotation assignments (part ofresolveAnnotationAssignments(Project).- Parameters:
assignBlock- The current visited assignment block.annotationAssignments- A tuple of (, ) for the current annotation block. If a nested block is found, these values must be copied into a new map as nested blocks can have other values and also further elements can be found after a block was visited. parents- A list 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
protected void resolveDefaultValues(Project project)
Part of theresolve()method. Resolves default values of variable declarations.- Parameters:
project- The current project for which assignments shall be resolved.
-
resolveDefaultValue
public static boolean resolveDefaultValue(IDecisionVariable variable, EvaluationVisitor evaluator)
Resolves default values of a particular variable. No conflict handler is used.- Parameters:
variable- the instance to resolve the default values for.evaluator- the (re-usable) expression evaluator to utilize, may be null then a temporary one is created- Returns:
- true if a default value could be resolved and assigned to variable, false otherwise.
- See Also:
resolveDefaultValueForDeclaration(AbstractVariable, IDecisionVariable)
-
resolveDefaultValue
public static boolean resolveDefaultValue(IDecisionVariable variable)
Resolves default values of a particular variable. The evaluator is created on demand, no conflict handler is used.- Parameters:
variable- the instance to resolve the default values for.- Returns:
- true if a default value could be resolved and assigned to variable, false otherwise.
- See Also:
resolveDefaultValue(IDecisionVariable, EvaluationVisitor)
-
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 of decl.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:
- true if a default value could be resolved and assigned to variable, false otherwise.
- See Also:
resolveDefaultValues(Project)
-
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 of decl.- Returns:
- true if a default value could be resolved and assigned to variable, false otherwise.
- See Also:
resolveDefaultValues(Project)
-
resolveAssignments
protected void resolveAssignments(Project project)
Part of theresolve()method. Resolves assignments.- Parameters:
project- Project The current project for which assignments shall be resolved.
-
conflictingConstraint
protected void conflictingConstraint(Constraint constraint)
Will be called after a failure was detected in aConstraint.- Parameters:
constraint- The violatedConstraint.
-
conflictingDefault
protected void conflictingDefault(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.
-
findImportedProjects
private void findImportedProjects(java.util.List<Project> projects)
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
private void findImportedProjects(Project project, java.util.List<Project> projects, java.util.Set<Project> done)
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
-
-