Class ReasoningUtils
java.lang.Object
net.ssehub.easy.reasoning.sseReasoner.model.ReasoningUtils
Utility methods for reasoning/constraint resolution.
- Author:
- Holger Eichelberger
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final booleanprivate static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLoggerstatic final net.ssehub.easy.basics.pool.Pool<Set<net.ssehub.easy.varModel.model.datatypes.Compound>> A set pool for instances ofSet<Compound>. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,S extends T>
voidaddAll(Collection<T> target, S[] source) Adds all elements fromsourcetotarget.static voidaddRefines(net.ssehub.easy.varModel.model.datatypes.Compound cmp, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Adds all refines ofcmptoresult.private static voidcollectRefines(net.ssehub.easy.varModel.model.datatypes.Compound cmp, net.ssehub.easy.varModel.model.datatypes.IDatatype exclude, boolean add, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Collects all refines fromcmpexcluding all originating atexclude, adding or removing following compounds based onaddstoring the results inresult.static Set<net.ssehub.easy.varModel.model.datatypes.Compound> collectRefines(net.ssehub.easy.varModel.model.datatypes.IDatatype start, net.ssehub.easy.varModel.model.datatypes.IDatatype exclude) Collects all refines fromstartexcluding all originating atexclude.static <K,V> Map <K, V> copyMapNull(Map<K, V> source) Returns a copy of thesourcemap.static intcountSlots(net.ssehub.easy.varModel.model.datatypes.Compound cmp, String name, boolean stopGreater1) Counts the number of slots with givennamein the refines hierarchy ofcmp.static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecreateAsTypeCast(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree exp, net.ssehub.easy.varModel.model.datatypes.IDatatype targetType) Creates a type cast ("asType" operation, if needed) from the type ofexptotargetTypeapplied toexp.static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecreateAsTypeCast(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree exp, net.ssehub.easy.varModel.model.datatypes.IDatatype sourceType, net.ssehub.easy.varModel.model.datatypes.IDatatype targetType) Creates a type cast ("asType" operation, if needed) fromsourceTypetotargetTypeapplied toexp.static net.ssehub.easy.varModel.cst.ContainerOperationCallcreateContainerCall(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree container, net.ssehub.easy.varModel.model.datatypes.Operation op, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree iterEx, net.ssehub.easy.varModel.model.DecisionVariableDeclaration... decl) Creates a container operation call ("shortcut").static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecreateParentExpression(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Creates an expression representing the parent ofvariable.static net.ssehub.easy.varModel.model.values.ValuecreateTypeValue(net.ssehub.easy.varModel.model.datatypes.IDatatype type) Creates a type value.static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecreateTypeValueConstant(net.ssehub.easy.varModel.model.datatypes.IDatatype type) Creates a type value constraint tree node.static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreecreateTypeValueConstantSafe(net.ssehub.easy.varModel.model.datatypes.IDatatype type) Creates a type value constraint tree node and logs occurring exceptions.static net.ssehub.easy.varModel.cst.ConstraintSyntaxTreegetConstraintValueExpression(net.ssehub.easy.varModel.model.values.Value value) Returns the expression for a constraint to be created for a constraint variable.static net.ssehub.easy.varModel.model.datatypes.IDatatypegetDeepestContainedType(net.ssehub.easy.varModel.model.datatypes.Container cnt) Returns the deepest contained type, i.e., for a nested container the deeply nested (base) type.static net.ssehub.easy.varModel.model.values.ValuegetRelevantValue(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, boolean incremental) Returns the relevant value for reasoning.static <D extends net.ssehub.easy.varModel.model.values.Value>
DgetRelevantValue(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, boolean incremental, Class<D> filter) Returns the relevant value for reasoning.static booleangetUsedCompoundTypes(net.ssehub.easy.varModel.model.values.Value val, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Returns the used types ifvalueis a container value.static net.ssehub.easy.varModel.model.datatypes.IDatatypeinferTypeSafe(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.model.datatypes.IDatatype dflt) Infers the type ofcstusingdfltas fallback.static booleanisNestedContainer(net.ssehub.easy.varModel.model.datatypes.IDatatype type) Returns whethertypeis a type-nested container.static booleanisOverriddenSlot(net.ssehub.easy.varModel.model.AbstractVariable decl) Returns whetherdeclis an overridden slot.static voidprintConstraintEvaluationResult(net.ssehub.easy.varModel.model.Constraint constraint, net.ssehub.easy.varModel.cstEvaluation.EvaluationVisitor evaluator) Prints a constraint evaluation result (for debugging).static voidprintConstraints(String text, Iterable<net.ssehub.easy.varModel.model.Constraint> constraints) Prints a constraints collection, each constraint including top-levle parent and system identity hashcodes [DEBUGGING].static voidprintFailedElements(FailedElements failedElements) Method for displaying failed constraints and assignments.static voidprintModelElement(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Method for printing info aboutIDecisionVariable.static voidprintModelElements(net.ssehub.easy.varModel.confModel.Configuration config, String comment) Method for printing all variables, their states and values.static voidprintProblemPoints(Set<net.ssehub.easy.varModel.confModel.IDecisionVariable> problemVariables) Method for printing all problem points.static voidpurgeRefines(Set<net.ssehub.easy.varModel.model.datatypes.Compound> compounds, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Purges all refined compounds mentioned incompounds.private static voidpurgeRefines(net.ssehub.easy.varModel.model.datatypes.Compound comp, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Purges all refined compounds ofcompfromresult.static voidremoveAll(Collection<net.ssehub.easy.varModel.model.Constraint> collection, Collection<net.ssehub.easy.varModel.model.Constraint> remove) Removes constraints from a constraints collection printing those constraints that have been removed.static <K> voidremoveAll(Map<K, ?> map, Collection<K> remove) Removes all elements inremoveas keys frommap.static voidsetValue(net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.model.Constraint value) Sets a constraint value.static StringtoIvmlString(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst) Turns a constraint syntax tree into a string.static StringtoIvmlString(net.ssehub.easy.varModel.model.Constraint constraint) Turns a constraint into a string.static StringtoStringAttributes(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Method for displaying all variable attributes.
-
Field Details
-
DEBUG
public static final boolean DEBUG- See Also:
-
SET_COMPOUND_POOL
public static final net.ssehub.easy.basics.pool.Pool<Set<net.ssehub.easy.varModel.model.datatypes.Compound>> SET_COMPOUND_POOLA set pool for instances ofSet<Compound>. -
LOGGER
private static final net.ssehub.easy.basics.logger.EASyLoggerFactory.EASyLogger LOGGER
-
-
Constructor Details
-
ReasoningUtils
public ReasoningUtils()
-
-
Method Details
-
inferTypeSafe
public static net.ssehub.easy.varModel.model.datatypes.IDatatype inferTypeSafe(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree cst, net.ssehub.easy.varModel.model.datatypes.IDatatype dflt) Infers the type ofcstusingdfltas fallback.- Parameters:
cst- the expression to infer the type fordflt- the default- Returns:
- the type of the expression or
dfltin case of failures
-
createTypeValue
public static net.ssehub.easy.varModel.model.values.Value createTypeValue(net.ssehub.easy.varModel.model.datatypes.IDatatype type) throws net.ssehub.easy.varModel.model.values.ValueDoesNotMatchTypeException Creates a type value.- Parameters:
type- the datatype- Returns:
- the constant value
- Throws:
net.ssehub.easy.varModel.model.values.ValueDoesNotMatchTypeException- if the value cannot be created
-
createTypeValueConstant
public static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createTypeValueConstant(net.ssehub.easy.varModel.model.datatypes.IDatatype type) throws net.ssehub.easy.varModel.model.values.ValueDoesNotMatchTypeException Creates a type value constraint tree node.- Parameters:
type- the datatype- Returns:
- the constant value constraint tree node
- Throws:
net.ssehub.easy.varModel.model.values.ValueDoesNotMatchTypeException- if the value cannot be created
-
setValue
public static void setValue(net.ssehub.easy.varModel.confModel.IDecisionVariable var, net.ssehub.easy.varModel.model.Constraint value) Sets a constraint value.- Parameters:
var- the variable to set the value on.value- the value to set
-
createTypeValueConstantSafe
public static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createTypeValueConstantSafe(net.ssehub.easy.varModel.model.datatypes.IDatatype type) Creates a type value constraint tree node and logs occurring exceptions.- Parameters:
type- the datatype- Returns:
- the constant value constraint tree node
-
createAsTypeCast
public static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createAsTypeCast(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree exp, net.ssehub.easy.varModel.model.datatypes.IDatatype targetType) Creates a type cast ("asType" operation, if needed) from the type ofexptotargetTypeapplied toexp.- Parameters:
exp- the expression to apply the type cast operation totargetType- the target type- Returns:
- the resulting expression
-
createAsTypeCast
public static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createAsTypeCast(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree exp, net.ssehub.easy.varModel.model.datatypes.IDatatype sourceType, net.ssehub.easy.varModel.model.datatypes.IDatatype targetType) Creates a type cast ("asType" operation, if needed) fromsourceTypetotargetTypeapplied toexp.- Parameters:
exp- the expression to apply the type cast operation tosourceType- the source typetargetType- the target type (nothing happens iftargetTypeis null orsourceTypeis identical totargetType)- Returns:
- the resulting expression
-
printProblemPoints
public static void printProblemPoints(Set<net.ssehub.easy.varModel.confModel.IDecisionVariable> problemVariables) Method for printing all problem points.- Parameters:
problemVariables- the variables to print
-
toStringAttributes
public static String toStringAttributes(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Method for displaying all variable attributes.- Parameters:
variable- variable- Returns:
- String of all attributes of the variable.
-
printModelElement
public static void printModelElement(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Method for printing info aboutIDecisionVariable.- Parameters:
variable- Variable to be printed out.
-
toIvmlString
Turns a constraint into a string.- Parameters:
constraint- the constraint- Returns:
- the representing string
-
toIvmlString
Turns a constraint syntax tree into a string.- Parameters:
cst- may be null, print "-" then- Returns:
- the string representation
-
printModelElements
public static void printModelElements(net.ssehub.easy.varModel.confModel.Configuration config, String comment) Method for printing all variables, their states and values.- Parameters:
config- Configuration to work with.comment- Comment for printing.
-
printConstraints
public static void printConstraints(String text, Iterable<net.ssehub.easy.varModel.model.Constraint> constraints) Prints a constraints collection, each constraint including top-levle parent and system identity hashcodes [DEBUGGING].- Parameters:
text- text to be printed before (may be null, ignored then)constraints- the constraints to be printed
-
printFailedElements
Method for displaying failed constraints and assignments.- Parameters:
failedElements- the failed elements
-
createContainerCall
public static net.ssehub.easy.varModel.cst.ContainerOperationCall createContainerCall(net.ssehub.easy.varModel.cst.ConstraintSyntaxTree container, net.ssehub.easy.varModel.model.datatypes.Operation op, net.ssehub.easy.varModel.cst.ConstraintSyntaxTree iterEx, net.ssehub.easy.varModel.model.DecisionVariableDeclaration... decl) Creates a container operation call ("shortcut").- Parameters:
container- the container to operate onop- the operationiterEx- the iterator expressiondecl- the declarators- Returns:
- the created call
-
isOverriddenSlot
public static boolean isOverriddenSlot(net.ssehub.easy.varModel.model.AbstractVariable decl) Returns whetherdeclis an overridden slot.- Parameters:
decl- the declaration of the slot to search for- Returns:
trueif overridden,falseelse
-
countSlots
public static int countSlots(net.ssehub.easy.varModel.model.datatypes.Compound cmp, String name, boolean stopGreater1) Counts the number of slots with givennamein the refines hierarchy ofcmp.- Parameters:
cmp- the compound to start searchingname- the name of the slot to search forstopGreater1- stop searching if we have more than one matching slot- Returns:
- the number of slots
-
isNestedContainer
public static boolean isNestedContainer(net.ssehub.easy.varModel.model.datatypes.IDatatype type) Returns whethertypeis a type-nested container.- Parameters:
type- the type- Returns:
truefor a nested collection,false else
-
getRelevantValue
public static net.ssehub.easy.varModel.model.values.Value getRelevantValue(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, boolean incremental) Returns the relevant value for reasoning.- Parameters:
decl- the declarationvar- the decision variableincremental- are we in incremental mode- Returns:
- the value, may be null
-
getRelevantValue
public static <D extends net.ssehub.easy.varModel.model.values.Value> D getRelevantValue(net.ssehub.easy.varModel.model.AbstractVariable decl, net.ssehub.easy.varModel.confModel.IDecisionVariable var, boolean incremental, Class<D> filter) Returns the relevant value for reasoning.- Type Parameters:
D- the value type- Parameters:
decl- the declarationvar- the decision variableincremental- are we in incremental modefilter- in case that only a value of the specific type shall be returned- Returns:
- the value, may be null
-
addRefines
public static void addRefines(net.ssehub.easy.varModel.model.datatypes.Compound cmp, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Adds all refines ofcmptoresult.- Parameters:
cmp- the compound to derive the refined compound hierarchy fromresult- the set of refined compounds
-
getUsedCompoundTypes
public static boolean getUsedCompoundTypes(net.ssehub.easy.varModel.model.values.Value val, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Returns the used types ifvalueis a container value.- Parameters:
val- the valueresult- the result set to be modified as a side effect- Returns:
trueifvalis a container value,falseelse
-
purgeRefines
public static void purgeRefines(Set<net.ssehub.easy.varModel.model.datatypes.Compound> compounds, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Purges all refined compounds mentioned incompounds.- Parameters:
compounds- the compounds to purgeresult- the purged compounds (to be modified as a side effect)
-
purgeRefines
private static void purgeRefines(net.ssehub.easy.varModel.model.datatypes.Compound comp, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Purges all refined compounds ofcompfromresult.- Parameters:
comp- the compound to purge the refined ones forresult- modified as a side effect
-
addAll
Adds all elements fromsourcetotarget.- Type Parameters:
T- the target typeS- the source type, a subtype of<T>- Parameters:
target- the target collectionsource- the source array (may be null, then nothing happens)
-
getDeepestContainedType
public static net.ssehub.easy.varModel.model.datatypes.IDatatype getDeepestContainedType(net.ssehub.easy.varModel.model.datatypes.Container cnt) Returns the deepest contained type, i.e., for a nested container the deeply nested (base) type.- Parameters:
cnt- the container type- Returns:
- the deeply nested type
-
printConstraintEvaluationResult
public static void printConstraintEvaluationResult(net.ssehub.easy.varModel.model.Constraint constraint, net.ssehub.easy.varModel.cstEvaluation.EvaluationVisitor evaluator) Prints a constraint evaluation result (for debugging).- Parameters:
constraint- the constraintevaluator- the evaluator
-
getConstraintValueExpression
public static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree getConstraintValueExpression(net.ssehub.easy.varModel.model.values.Value value) Returns the expression for a constraint to be created for a constraint variable.- Parameters:
value- the value to create the constraint for- Returns:
- the constraint expression, may be null
-
removeAll
public static void removeAll(Collection<net.ssehub.easy.varModel.model.Constraint> collection, Collection<net.ssehub.easy.varModel.model.Constraint> remove) Removes constraints from a constraints collection printing those constraints that have been removed. [debugging]- Parameters:
collection- the collections to remove the constraints fromremove- the constraints to remove
-
removeAll
Removes all elements inremoveas keys frommap.- Type Parameters:
K- the key type- Parameters:
map- the map to remove fromremove- the elements to remove
-
collectRefines
public static Set<net.ssehub.easy.varModel.model.datatypes.Compound> collectRefines(net.ssehub.easy.varModel.model.datatypes.IDatatype start, net.ssehub.easy.varModel.model.datatypes.IDatatype exclude) Collects all refines fromstartexcluding all originating atexclude.- Parameters:
start- the start type (an empty set will be returned ifstartis not aCompound)exclude- an optional type excluding the entire refinement hierarchy originating atexcludeifexcludeis a compound, ignored if null- Returns:
- the set of refined compounds, must be released via
SET_COMPOUND_POOL
-
collectRefines
private static void collectRefines(net.ssehub.easy.varModel.model.datatypes.Compound cmp, net.ssehub.easy.varModel.model.datatypes.IDatatype exclude, boolean add, Set<net.ssehub.easy.varModel.model.datatypes.Compound> result) Collects all refines fromcmpexcluding all originating atexclude, adding or removing following compounds based onaddstoring the results inresult.- Parameters:
cmp- the type to collect forexclude- an optional type excluding the entire refinement hierarchy originating atexcludeifexcludeis a compound, ignored if nulladd- whether datatypes shall be added or removed fromresult.result- incrementally built up result, may be modified as a side effect
-
createParentExpression
public static net.ssehub.easy.varModel.cst.ConstraintSyntaxTree createParentExpression(net.ssehub.easy.varModel.confModel.IDecisionVariable variable) Creates an expression representing the parent ofvariable.- Parameters:
variable- the variable- Returns:
- the expression, null if no expression can be constructed
-
copyMapNull
Returns a copy of thesourcemap. Turns an empty map intonull.- Type Parameters:
K- the keyV- the value- Parameters:
source- the source map, may be null- Returns:
- the copy or null if there was no or just an empty
source
-