From 619e7ba2eb88ad991d9724ee2fae0189b31598fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20A=2E?= Date: Tue, 7 Nov 2023 15:20:00 +0000 Subject: [PATCH] fix: integrating diagnosis tasks and removing error detection so it is not duplicating code --- .../operations/__init__.py | 12 ++--- ...tifier.py => pysat_abstract_identifier.py} | 4 +- ...glucose3_conflict.py => pysat_conflict.py} | 4 +- ...ucose3_diagnosis.py => pysat_diagnosis.py} | 9 +--- .../pysat_metamodel/operations/__init__.py | 2 - .../operations/pysat_error_detection.py | 53 ------------------- 6 files changed, 12 insertions(+), 72 deletions(-) rename flamapy/metamodels/pysat_diagnosis_metamodel/operations/{glucose3_abstract_identifier.py => pysat_abstract_identifier.py} (95%) rename flamapy/metamodels/pysat_diagnosis_metamodel/operations/{glucose3_conflict.py => pysat_conflict.py} (95%) rename flamapy/metamodels/pysat_diagnosis_metamodel/operations/{glucose3_diagnosis.py => pysat_diagnosis.py} (85%) delete mode 100644 flamapy/metamodels/pysat_metamodel/operations/pysat_error_detection.py diff --git a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/__init__.py b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/__init__.py index bb7e2d0..556095f 100644 --- a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/__init__.py +++ b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/__init__.py @@ -1,10 +1,10 @@ -from .glucose3_abstract_identifier import Glucose3AbstractIdentifier -from .glucose3_conflict import Glucose3Conflict -from .glucose3_diagnosis import Glucose3Diagnosis +from .pysat_abstract_identifier import PySATAbstractIdentifier +from .pysat_conflict import PySATConflict +from .pysat_diagnosis import PySATDiagnosis __all__ = [ - 'Glucose3AbstractIdentifier', - 'Glucose3Diagnosis', - 'Glucose3Conflict' + 'PySATAbstractIdentifier', + 'PySATDiagnosis', + 'PySATConflict' ] diff --git a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_abstract_identifier.py b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_abstract_identifier.py similarity index 95% rename from flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_abstract_identifier.py rename to flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_abstract_identifier.py index cc797aa..4cf20c1 100644 --- a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_abstract_identifier.py +++ b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_abstract_identifier.py @@ -35,7 +35,7 @@ def _execute_hsdag(model: DiagnosisModel, hsdag: HSDAG) -> Tuple[str, str]: return cs_mess, diag_mess -class Glucose3AbstractIdentifier(Operation): +class PySATAbstractIdentifier(Operation): """ An abstract operation for computes conflicts or diagnoses. Four optional inputs: @@ -66,7 +66,7 @@ def set_test_case(self, test_case: Configuration) -> None: def get_result(self) -> List[str]: return self.result_messages - def execute(self, model: VariabilityModel) -> 'Glucose3AbstractIdentifier': + def execute(self, model: VariabilityModel) -> 'PySATAbstractIdentifier': model = cast(DiagnosisModel, model) checker, labeler = self.prepare_hsdag(model) diff --git a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_conflict.py b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_conflict.py similarity index 95% rename from flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_conflict.py rename to flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_conflict.py index ba52ba6..b2c6e9f 100644 --- a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_conflict.py +++ b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_conflict.py @@ -1,13 +1,13 @@ from typing import Tuple from flamapy.metamodels.pysat_diagnosis_metamodel.models import DiagnosisModel -from . import Glucose3AbstractIdentifier +from . import PySATAbstractIdentifier from .diagnosis.checker import ConsistencyChecker from .diagnosis.hsdag.hsdag import HSDAG from .diagnosis.hsdag.labeler.quickxplain_labeler import QuickXPlainParameters, QuickXPlainLabeler -class Glucose3Conflict(Glucose3AbstractIdentifier): +class PySATConflict(PySATAbstractIdentifier): """ An operation that computes conflicts and diagnoses using the combination of HSDAG and QuickXPlain algorithms. diff --git a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_diagnosis.py b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_diagnosis.py similarity index 85% rename from flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_diagnosis.py rename to flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_diagnosis.py index 160d4bd..fede50e 100644 --- a/flamapy/metamodels/pysat_diagnosis_metamodel/operations/glucose3_diagnosis.py +++ b/flamapy/metamodels/pysat_diagnosis_metamodel/operations/pysat_diagnosis.py @@ -1,13 +1,13 @@ from typing import Tuple from flamapy.metamodels.pysat_diagnosis_metamodel.models import DiagnosisModel -from . import Glucose3AbstractIdentifier +from . import PySATAbstractIdentifier from .diagnosis.checker import ConsistencyChecker from .diagnosis.hsdag.hsdag import HSDAG from .diagnosis.hsdag.labeler.fastdiag_labeler import FastDiagParameters, FastDiagLabeler -class Glucose3Diagnosis(Glucose3AbstractIdentifier): +class PySAT3Diagnosis(PySATAbstractIdentifier): """ An operation that computes diagnoses and conflict sets using the combination of HSDAG and FastDiag algorithms. @@ -29,12 +29,7 @@ def prepare_hsdag(self, model: DiagnosisModel) -> Tuple[ConsistencyChecker, HSDA # transform model to diagnosis model model.prepare_diagnosis_task(configuration=self.configuration, test_case=self.test_case) - # print(f'C: {model.get_c()}') - # print(f'B: {model.get_b()}') - set_c = model.get_c() - # if self.configuration is None: - # C.reverse() # reverse the list to get the correct order of diagnosis checker = ConsistencyChecker(self.solver_name, model.get_kb()) parameters = FastDiagParameters(set_c, [], model.get_b()) diff --git a/flamapy/metamodels/pysat_metamodel/operations/__init__.py b/flamapy/metamodels/pysat_metamodel/operations/__init__.py index 1e5dc3f..38374f0 100644 --- a/flamapy/metamodels/pysat_metamodel/operations/__init__.py +++ b/flamapy/metamodels/pysat_metamodel/operations/__init__.py @@ -8,7 +8,6 @@ from .pysat_core_features import PySATCoreFeatures from .pysat_dead_features import PySATDeadFeatures from .pysat_false_optional_features import PySATFalseOptionalFeatures -from .pysat_error_detection import PySATErrorDetection from .pysat_metrics import PySATMetrics __all__ = [ @@ -22,5 +21,4 @@ 'PySATCoreFeatures', 'PySATDeadFeatures', 'PySATFalseOptionalFeatures', - 'PySATErrorDetection', ] diff --git a/flamapy/metamodels/pysat_metamodel/operations/pysat_error_detection.py b/flamapy/metamodels/pysat_metamodel/operations/pysat_error_detection.py deleted file mode 100644 index 42b2162..0000000 --- a/flamapy/metamodels/pysat_metamodel/operations/pysat_error_detection.py +++ /dev/null @@ -1,53 +0,0 @@ -from typing import Optional, cast - -from flamapy.core.operations import ErrorDetection -from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel -from flamapy.metamodels.pysat_metamodel.operations.pysat_dead_features import ( - PySATDeadFeatures -) -from flamapy.metamodels.pysat_metamodel.operations.pysat_false_optional_features import ( - PySATFalseOptionalFeatures -) -from flamapy.core.models import VariabilityModel -from flamapy.core.exceptions import FlamaException -from flamapy.metamodels.fm_metamodel.models.feature_model import FeatureModel -from flamapy.metamodels.pysat_metamodel.operations.pysat_valid import PySATValid - - -class PySATErrorDetection(ErrorDetection): - - def __init__(self) -> None: - self.feature_model: Optional[FeatureModel] = None - self.errors_messages: list[str] = [] - - def get_errors_messages(self) -> list[str]: - return self.get_result() - - def get_result(self) -> list[str]: - return self.errors_messages - - def execute(self, model: VariabilityModel) -> 'PySATErrorDetection': - if self.feature_model is None: - raise FlamaException('The feature model is not setted') - - cast_model = cast(PySATModel, model) - - # Valid feature model check - valid = PySATValid().execute(cast_model).get_result() - if not valid: - self.errors_messages.append('The model is not valid (it is void), \ - so it has not any product.') - - # Dead features detection - dead_features = PySATDeadFeatures().execute(cast_model).get_result() - if dead_features: - self.errors_messages.append(f'Dead features: {dead_features}') - - # False optional detection - fof_op = PySATFalseOptionalFeatures() - fof_op.feature_model = self.feature_model - false_optional_features = fof_op.execute(cast_model).get_result() - if false_optional_features: - self.errors_messages.append(f'False optional features: {false_optional_features}') - - return self