Class ReasonerAdapter


  • public class ReasonerAdapter
    extends java.lang.Object
    Abstracts 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
    • 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 be ProgressObserver.NO_OBSERVER if unused
        reasonerConfiguration - 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.UNSUPPORTED if 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 be ProgressObserver.NO_OBSERVER if unused
        Returns:
        The result of this reasoning step. Can have the status Status.UNSUPPORTED if 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 be ProgressObserver.NO_OBSERVER if unused
        Returns:
        The result of this reasoning step. Can have the status Status.UNSUPPORTED if 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 be ProgressObserver.NO_OBSERVER if unused
        Returns:
        The result of this reasoning step. Can have the status Status.UNSUPPORTED if 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 if type is given, may imply additional constraints)
        type - the type to create the value for (may be null if var is 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 be ProgressObserver.NO_OBSERVER if 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 for config if 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) for config for 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