Skip to content

Commit

Permalink
fix: issue solved in the configurations op
Browse files Browse the repository at this point in the history
  • Loading branch information
jagalindo committed Aug 22, 2024
1 parent 2b4fede commit d77446e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
16 changes: 5 additions & 11 deletions flamapy/metamodels/pysat_metamodel/operations/pysat_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def get_result(self) -> list[list[Any]]:
def set_configuration(self, configuration: Configuration) -> None:
self.configuration = configuration

def execute(self, model: VariabilityModel) -> 'PySATFilter':
def execute(self, model: VariabilityModel) -> 'PySATFilter': # noqa: MC0001
model = cast(PySATModel, model)

for clause in model.get_all_clauses(): # AC es conjunto de conjuntos
Expand All @@ -40,28 +40,22 @@ def execute(self, model: VariabilityModel) -> 'PySATFilter':
else:
missing_features = [feature for feature in self.configuration.elements.keys()
if feature not in model.variables.keys()]

if missing_features:
print("The features that are missing are:", list(missing_features))
print("The feature model contains the following features:",
list(model.variables.keys()))
self.result = False
return self

raise ValueError("The configuration contains features that are \
not present in the feature model.",
list(missing_features))
assumptions = []
for feature in model.features.values():

if self.configuration.elements.get(feature, False):
assumptions.append(model.variables[feature])
else:
assumptions.append(-model.variables[feature])


for solution in self.solver.enum_models(assumptions=assumptions):
product = []
for variable in solution:
if variable is not None and variable > 0:
product.append(model.features.get(variable))
self.filter_products.append(product)
self.solver.delete()
return self
return self
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self) -> None:
@property
def model_type_extension(self) -> str:
return self._model_type_extension

@model_type_extension.setter
def model_type_extension(self, ext: str) -> None:
self._model_type_extension = ext
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flamapy-fw~=2.0.0
flamapy-fw~=2.0.1
flamapy-fm~=2.0.0
python-sat~=0.1.7.dev1
6 changes: 4 additions & 2 deletions tests/operations/operations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ def run(
if expected_valid_product_list is not None:
for product in expected_valid_product_list:
valid_product = PySATSatisfiableConfiguration()
valid_product.set_configuration(configuration = product, is_full = True)
product.is_full = True
valid_product.set_configuration(configuration = product)
valid_product.execute(model)
assert valid_product.is_satisfiable()

if expected_non_valid_product_list is not None:
for product in expected_non_valid_product_list:
valid_product = PySATSatisfiableConfiguration()
valid_product.set_configuration(configuration = product, is_full = True)
product.is_full = True
valid_product.set_configuration(configuration = product)
valid_product.execute(model)
assert not valid_product.is_satisfiable()

Expand Down

0 comments on commit d77446e

Please sign in to comment.