-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: updating operations to adhere to new name
- Loading branch information
Showing
11 changed files
with
100 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
flamapy/metamodels/pysat_metamodel/operations/pysat_satisfiable_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from typing import cast | ||
|
||
from pysat.solvers import Solver | ||
|
||
from flamapy.core.models import VariabilityModel | ||
from flamapy.core.operations import SatisfiableConfiguration | ||
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration | ||
from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel | ||
|
||
|
||
class PySATSatisfiableConfiguration(SatisfiableConfiguration): | ||
|
||
def __init__(self) -> None: | ||
self.result = False | ||
self.configuration = Configuration(elements={}) | ||
self.solver = Solver(name='glucose3') | ||
self.is_full = False | ||
|
||
def is_satisfiable(self) -> bool: | ||
return self.result | ||
|
||
def get_result(self) -> bool: | ||
return self.is_satisfiable() | ||
|
||
def set_configuration(self, configuration: Configuration, is_full: bool) -> None: | ||
self.configuration = configuration | ||
self.is_full = is_full | ||
|
||
def execute(self, model: VariabilityModel) -> 'PySATSatisfiableConfiguration': | ||
sat_model = cast(PySATModel, model) | ||
|
||
for clause in sat_model.get_all_clauses(): # AC es conjunto de conjuntos | ||
self.solver.add_clause(clause) # añadimos la constraint | ||
|
||
if not self.is_full: | ||
assumptions = [] | ||
for feature, selected in self.configuration.elements.items(): | ||
if selected: | ||
assumptions.append(sat_model.variables[feature.name]) | ||
else: | ||
assumptions.append(-sat_model.variables[feature.name]) | ||
else: | ||
missing_features = [feature for feature in self.configuration.elements.keys() if feature.name not in sat_model.variables.keys()] | ||
|
||
if missing_features: | ||
print("The features that are missing are:", [feature.name for feature in missing_features]) | ||
print("The feature model contains the following features:", list(sat_model.variables.keys())) | ||
self.result = False | ||
return self | ||
|
||
print(self.configuration.elements.items()) | ||
assumptions = [] | ||
for feature in sat_model.features.values(): | ||
if self.configuration.has(feature): | ||
assumptions.append(sat_model.variables[feature]) | ||
else: | ||
assumptions.append(-sat_model.variables[feature]) | ||
|
||
self.result = self.solver.solve(assumptions=assumptions) | ||
self.solver.delete() | ||
return self |
42 changes: 0 additions & 42 deletions
42
flamapy/metamodels/pysat_metamodel/operations/pysat_valid_configuration.py
This file was deleted.
Oops, something went wrong.
47 changes: 0 additions & 47 deletions
47
flamapy/metamodels/pysat_metamodel/operations/pysat_valid_product.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters