Skip to content

Commit

Permalink
fix: updating operations to adhere to new name
Browse files Browse the repository at this point in the history
  • Loading branch information
jagalindo committed May 27, 2024
1 parent 5dccbb6 commit 363c395
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 130 deletions.
18 changes: 8 additions & 10 deletions flamapy/metamodels/pysat_metamodel/operations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .pysat_valid import PySATValid
from .pysat_valid_configuration import PySATValidConfiguration
from .pysat_valid_product import PySATValidProduct
from .pysat_products import PySATProducts
from .pysat_products_number import PySATProductsNumber
from .pysat_satisfiable import PySATSatisfiable
from .pysat_satisfiable_configuration import PySATSatisfiableConfiguration
from .pysat_configurations import PySATConfigurations
from .pysat_configurations_number import PySATConfigurationsNumber
from .pysat_commonality import PySATCommonality
from .pysat_filter import PySATFilter
from .pysat_core_features import PySATCoreFeatures
Expand All @@ -12,11 +11,10 @@


__all__ = [
'PySATValid',
'PySATValidConfiguration',
'PySATValidProduct',
'PySATProducts',
'PySATProductsNumber',
'PySATSatisfiable',
'PySATSatisfiableConfiguration',
'PySATConfigurations',
'PySATConfigurationsNumber',
'PySATCommonality',
'PySATFilter',
'PySATCoreFeatures',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from flamapy.core.operations import Commonality
from flamapy.core.models import VariabilityModel
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
from flamapy.metamodels.pysat_metamodel.operations.pysat_products import PySATProducts
from .pysat_configurations import PySATConfigurations


class PySATCommonality(Commonality):
Expand All @@ -20,7 +20,7 @@ def get_result(self) -> float:
return self.result

def execute(self, model: VariabilityModel) -> 'PySATCommonality':
pysat_products_op = PySATProducts()
pysat_products_op = PySATConfigurations()
pysat_products_op.execute(model)
products = pysat_products_op.get_result()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

from pysat.solvers import Solver

from flamapy.core.operations import Products
from flamapy.core.operations import Configurations
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel
from flamapy.core.models import VariabilityModel


class PySATProducts(Products):
class PySATConfigurations(Configurations):

def __init__(self) -> None:
self.result: list[Configuration] = []
self.solver = Solver(name='glucose3')

def get_products(self) -> list[Configuration]:
def get_configurations(self) -> list[Configuration]:
return self.get_result()

def get_result(self) -> list[Configuration]:
return self.result

def execute(self, model: VariabilityModel) -> 'PySATProducts':
def execute(self, model: VariabilityModel) -> 'PySATConfigurations':
sat_model = cast(PySATModel, model)
self.result = products(self.solver, sat_model)
self.result = configurations(self.solver, sat_model)
return self


def products(solver: Solver, model: PySATModel) -> list[Configuration]:
def configurations(solver: Solver, model: PySATModel) -> list[Configuration]:
for clause in model.get_all_clauses():
solver.add_clause(clause)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

from pysat.solvers import Solver

from flamapy.core.operations import ProductsNumber
from flamapy.core.operations import ConfigurationsNumber
from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel
from flamapy.core.models import VariabilityModel


class PySATProductsNumber(ProductsNumber):
class PySATConfigurationsNumber(ConfigurationsNumber):

def __init__(self) -> None:
self.products_number = 0
self.solver = Solver(name='glucose3')

def get_products_number(self) -> int:
def get_configurations_number(self) -> int:
return self.products_number

def get_result(self) -> int:
return self.get_products_number()
return self.get_configurations_number()

def execute(self, model: VariabilityModel) -> 'PySATProductsNumber':
def execute(self, model: VariabilityModel) -> 'PySATConfigurationsNumber':
model = cast(PySATModel, model)

for clause in model.get_all_clauses(): # AC es conjunto de conjuntos
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flamapy.core.operations import FalseOptionalFeatures
from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel
from flamapy.metamodels.fm_metamodel.models.feature_model import FeatureModel
from flamapy.core.models import VariabilityModel
from flamapy.core.models import VariabilityModel, VariabilityElement
from flamapy.core.exceptions import FlamaException


Expand All @@ -24,7 +24,7 @@ def execute(self, model: VariabilityModel) -> 'PySATFalseOptionalFeatures':
self.result = self._get_false_optional_features(sat_model)
return self

def get_false_optional_features(self) -> list[Any]:
def get_false_optional_features(self) -> list[VariabilityElement]:
return self.get_result()

def get_result(self) -> list[Any]:
Expand All @@ -37,7 +37,7 @@ def _get_false_optional_features(self, sat_model: PySATModel) -> list[Any]:
LOGGER.exception("The transformation didn't attach the source model, "
"which is required for this operation.")

real_optional_features = [f.name for f in feature_model.get_features()
real_optional_features = [f for f in feature_model.get_features()
if not f.is_root() and not f.is_mandatory()]

result = []
Expand All @@ -52,6 +52,6 @@ def _get_false_optional_features(self, sat_model: PySATModel) -> list[Any]:
assert variable is not None
satisfiable = self.solver.solve(assumptions=[parent_variable, -variable])
if not satisfiable:
result.append(feature.name)
result.append(feature)
self.solver.delete()
return result
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

from pysat.solvers import Solver

from flamapy.core.operations import Valid
from flamapy.core.operations import Satisfiable

from flamapy.metamodels.pysat_metamodel.models.pysat_model import PySATModel
from flamapy.core.models import VariabilityModel


class PySATValid(Valid):
class PySATSatisfiable(Satisfiable):

def __init__(self) -> None:
self.result = False
self.solver = Solver(name='glucose3')

def is_valid(self) -> bool:
def is_satisfiable(self) -> bool:
return self.get_result()

def get_result(self) -> bool:
return self.result

def execute(self, model: VariabilityModel) -> 'PySATValid':
def execute(self, model: VariabilityModel) -> 'PySATSatisfiable':
sat_model = cast(PySATModel, model)
self.result = valid(self.solver, sat_model)
return self
Expand Down
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

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="flamapy-sat",
version="1.6.0.dev0",
version="2.0.0.dev0",
author="Flamapy",
author_email="flamapy@us.es",
description="flamapy-sat is a plugin to flamapy module",
Expand All @@ -22,8 +22,8 @@
],
python_requires='>=3.9',
install_requires=[
'flamapy~=1.6.0.dev0',
'flamapy-fm~=1.6.0.dev0',
'flamapy-fw~=2.0.0.dev0',
'flamapy-fm~=2.0.0.dev0',
'python-sat>=0.1.7.dev6'
],
extras_require={
Expand Down
14 changes: 7 additions & 7 deletions tests/operations/operations_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from flamapy.metamodels.pysat_metamodel.operations.pysat_false_optional_features import (
PySATFalseOptionalFeatures,
)
from flamapy.metamodels.pysat_metamodel.operations.pysat_products import (
PySATProducts,
from pysat_metamodel.flamapy.metamodels.pysat_metamodel.operations.pysat_configurations import (
PySATConfigurations,
)
from flamapy.metamodels.pysat_metamodel.operations.pysat_products_number import (
PySATProductsNumber,
from pysat_metamodel.flamapy.metamodels.pysat_metamodel.operations.pysat_configurations_number import (
PySATConfigurationsNumber,
)
from flamapy.metamodels.pysat_metamodel.operations.pysat_valid import PySATValid
from flamapy.metamodels.pysat_metamodel.operations.pysat_valid_product import (
PySATValidProduct,
from flamapy.metamodels.pysat_metamodel.operations.pysat_satisfiabjle import PySATSatisfiable
from flamapy.metamodels.pysat_metamodel.operations.pysat_satisfiable_configuraiton import (
PySATSatisfiableConfiguration,
)


Expand Down

0 comments on commit 363c395

Please sign in to comment.