From fdf376585c6648c56b6d887b4cb02e23e5259b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20A=2E=20Galindo?= Date: Tue, 23 Jul 2024 23:50:05 +0200 Subject: [PATCH] fix: solve issue with diag operations --- .../models/pysat_diagnosis_model.py | 4 ++-- .../transformations/fm_to_diag_pysat.py | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/flamapy/metamodels/pysat_diagnosis_metamodel/models/pysat_diagnosis_model.py b/flamapy/metamodels/pysat_diagnosis_metamodel/models/pysat_diagnosis_model.py index 07c38ee..ea89009 100644 --- a/flamapy/metamodels/pysat_diagnosis_metamodel/models/pysat_diagnosis_model.py +++ b/flamapy/metamodels/pysat_diagnosis_metamodel/models/pysat_diagnosis_model.py @@ -183,10 +183,10 @@ def _prepare_assumptions_for_configuration(self, assumption: List[int], if value: desc = f'{feat.name} = true' - clause = [self.variables[feat[0].name], -1 * id_assumption] + clause = [self.variables[feat.name], -1 * id_assumption] else: desc = f'{feat.name} = false' - clause = [-1 * self.variables[feat[0].name], -1 * id_assumption] + clause = [-1 * self.variables[feat.name], -1 * id_assumption] assumption.append(id_assumption) self.set_kb.append(clause) diff --git a/flamapy/metamodels/pysat_diagnosis_metamodel/transformations/fm_to_diag_pysat.py b/flamapy/metamodels/pysat_diagnosis_metamodel/transformations/fm_to_diag_pysat.py index c579893..0e11f7c 100644 --- a/flamapy/metamodels/pysat_diagnosis_metamodel/transformations/fm_to_diag_pysat.py +++ b/flamapy/metamodels/pysat_diagnosis_metamodel/transformations/fm_to_diag_pysat.py @@ -32,11 +32,25 @@ def add_root(self, feature: Feature) -> None: self.destination_model.add_clause([var]) self.destination_model.add_clause_to_map(str(feature), [[var]]) - def _store_constraint_relation(self, relation: Relation, clauses: List[List[int]]) -> None: - for clause in clauses: - self.destination_model.add_clause(clause) - self.destination_model.add_clause_to_map(str(relation), clauses) + #def _store_constraint_relation(self, relation: Relation, clauses: List[List[int]]) -> None: + # for clause in clauses: + # self.destination_model.add_clause(clause) + # self.destination_model.add_clause_to_map(str(relation), clauses) + def add_relation(self, relation: Relation) -> None: + if relation.is_mandatory(): + clauses = self._add_mandatory_relation(relation) + elif relation.is_optional(): + clauses = self._add_optional_relation(relation) + elif relation.is_or(): + clauses = self._add_or_relation(relation) + elif relation.is_alternative(): + clauses = self._add_alternative_relation(relation) + else: + clauses = self._add_constraint_relation(relation) + self._store_constraint_clauses(clauses) + self.destination_model.add_clause_to_map(str(relation), clauses) + def add_constraint(self, ctc: Constraint) -> None: def get_term_variable(term: Any) -> int: negated = False