Class ReasonerAdapter
- java.lang.Object
-
- net.ssehub.easy.reasoning.core.frontend.ReasonerAdapter
-
public class ReasonerAdapter extends java.lang.ObjectAbstracts over instance-based and full reasoning. Configuration instances registered with this adaptor/cache lead to instance-based reasoning, others are subject to full reasoning.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classReasonerAdapter.FrontendReasonerAdapterImplements a full/fallback reasoner adapter.private classReasonerAdapter.InstanceReasonerAdapterImplements an instance-based reasoner adapter.private static interfaceReasonerAdapter.IReasonerAdapterDefines the interface of an abstracting reasoner adapter.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<Configuration,ReasonerAdapter.IReasonerAdapter>cacheprivate ReasonerAdapter.IReasonerAdapterdefltprivate booleanenableInstanceBasedReasoningprivate static java.util.Map<java.lang.Thread,ReasonerAdapter>instances
-
Constructor Summary
Constructors Constructor Description ReasonerAdapter()Creates a reasoning adapter cache with instance-based reasoning allowed as default.ReasonerAdapter(boolean enableInstanceBasedReasoning)Creates a reasoning adapter cache.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ReasoningResultcheck(Configuration cfg, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)Checks the configuration according to the given project structure and does not affect the configuration.voidclear()Clears all cache entries.voidclear(Configuration config)Clears the cache entry forconfigif one was registered.ValueCreationResultcreateValue(Configuration cfg, AbstractVariable var, IDatatype type, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)Creates the value for a certain IVML type/variable.EvaluationResultevaluate(Configuration cfg, java.util.List<Constraint> constraints, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)Evaluates a given list of constraints (in the sense of boolean conditions) which are related to and valid in the context of the given project and configuration.private ReasonerAdapter.IReasonerAdaptergetAdapter(Configuration cfg, ReasonerConfiguration reasonerConfiguration)Returns the adapter for the given configuration.static ReasonerAdaptergetInstance()Returns the registered instance for the current thread.static ReasonerAdaptergetInstanceSafe()Returns the registered instance for the current thread.ReasoningResultisConsistent(Configuration cfg, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)Checks whether a given variability model (project) is satisfiable.ReasoningResultpropagate(Configuration cfg, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)Checks the configuration according to the given model and propagates values, if possible.voidregister(Configuration config)Registers for a reasoning adapter (cache entry) forconfigfor instance-based reasoning.static voidregisterInstance(ReasonerAdapter adapter)Registers an instance for the current thread.voidsetEnableInstanceBasedReasoning(boolean enableInstanceBasedReasoning)Defines whether instance-based reasoning shall be allowed/supported.static voidunregisterInstance()Unregisters an instance for the current thread.
-
-
-
Field Detail
-
instances
private static java.util.Map<java.lang.Thread,ReasonerAdapter> instances
-
cache
private java.util.Map<Configuration,ReasonerAdapter.IReasonerAdapter> cache
-
deflt
private ReasonerAdapter.IReasonerAdapter deflt
-
enableInstanceBasedReasoning
private boolean enableInstanceBasedReasoning
-
-
Constructor Detail
-
ReasonerAdapter
public ReasonerAdapter()
Creates a reasoning adapter cache with instance-based reasoning allowed as default.
-
ReasonerAdapter
public ReasonerAdapter(boolean enableInstanceBasedReasoning)
Creates a reasoning adapter cache.- Parameters:
enableInstanceBasedReasoning- whether instance-based reasoning shall be allowed
-
-
Method Detail
-
getAdapter
private ReasonerAdapter.IReasonerAdapter getAdapter(Configuration cfg, ReasonerConfiguration reasonerConfiguration)
Returns the adapter for the given configuration.- Parameters:
cfg- The configuration to reason on.reasonerConfiguration- the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)- Returns:
- the adapter instance
-
isConsistent
public ReasoningResult isConsistent(Configuration cfg, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)
Checks whether a given variability model (project) is satisfiable.- Parameters:
cfg- The configuration to reason on.observer- an optional progress observer, shall beProgressObserver.NO_OBSERVERif unusedreasonerConfiguration- the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)- Returns:
- The result of this reasoning step. Can have the status
Status.UNSUPPORTEDif the concrete reasoner does not support this operation.
-
check
public ReasoningResult check(Configuration cfg, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)
Checks the configuration according to the given project structure and does not affect the configuration.- Parameters:
cfg- The configuration to reason on.reasonerConfiguration- the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)observer- an optional progress observer, shall beProgressObserver.NO_OBSERVERif unused- Returns:
- The result of this reasoning step. Can have the status
Status.UNSUPPORTEDif the concrete reasoner does not support this operation.
-
propagate
public ReasoningResult propagate(Configuration cfg, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)
Checks the configuration according to the given model and propagates values, if possible.- Parameters:
cfg- The configuration to reason on (may be modified as a side effect of value propagation)reasonerConfiguration- the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)observer- an optional progress observer, shall beProgressObserver.NO_OBSERVERif unused- Returns:
- The result of this reasoning step. Can have the status
Status.UNSUPPORTEDif the concrete reasoner does not support this operation.
-
evaluate
public EvaluationResult evaluate(Configuration cfg, java.util.List<Constraint> constraints, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)
Evaluates a given list of constraints (in the sense of boolean conditions) which are related to and valid in the context of the given project and configuration.- Parameters:
cfg- The configuration to reason on.constraints- the constraints (expressions which evaluate to a boolean value)reasonerConfiguration- the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)observer- an optional progress observer, shall beProgressObserver.NO_OBSERVERif unused- Returns:
- The result of this reasoning step. Can have the status
Status.UNSUPPORTEDif the concrete reasoner does not support this operation.
-
createValue
public ValueCreationResult createValue(Configuration cfg, AbstractVariable var, IDatatype type, ReasonerConfiguration reasonerConfiguration, ProgressObserver observer)
Creates the value for a certain IVML type/variable.- Parameters:
cfg- the configuration to operate on (will not be modified)var- the variable to create the value for (may be null iftypeis given, may imply additional constraints)type- the type to create the value for (may be null ifvaris given)reasonerConfiguration- the reasoner configuration to be used for reasoning (e.g. taken from the UI, may be null)observer- an optional progress observer, shall beProgressObserver.NO_OBSERVERif unused- Returns:
- the value creation result
-
setEnableInstanceBasedReasoning
public void setEnableInstanceBasedReasoning(boolean enableInstanceBasedReasoning)
Defines whether instance-based reasoning shall be allowed/supported. Please reset already registered configurations if needed.- Parameters:
enableInstanceBasedReasoning- whether instance-based reasoning shall be allowed
-
clear
public void clear()
Clears all cache entries.
-
clear
public void clear(Configuration config)
Clears the cache entry forconfigif one was registered.- Parameters:
config- the configuration to prepare for (ignored if null)
-
register
public void register(Configuration config)
Registers for a reasoning adapter (cache entry) forconfigfor instance-based reasoning. Already registered configurations are not re-registered.- Parameters:
config- the configuration to prepare for (ignored if null)
-
registerInstance
public static void registerInstance(ReasonerAdapter adapter)
Registers an instance for the current thread.- Parameters:
adapter- the adapter instance to register
-
unregisterInstance
public static void unregisterInstance()
Unregisters an instance for the current thread.
-
getInstance
public static ReasonerAdapter getInstance()
Returns the registered instance for the current thread.- Returns:
- the registered instance, null for none
-
getInstanceSafe
public static ReasonerAdapter getInstanceSafe()
Returns the registered instance for the current thread.- Returns:
- the registered instance, null for none
-
-