-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
479 additions
and
32 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
36 changes: 36 additions & 0 deletions
36
flamapy/metamodels/bdd_metamodel/operations/bdd_commonality_factor.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,36 @@ | ||
from typing import cast | ||
|
||
from flamapy.core.models import VariabilityModel | ||
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration | ||
from flamapy.metamodels.bdd_metamodel.models import BDDModel | ||
from flamapy.metamodels.bdd_metamodel.operations.interfaces import CommonalityFactor | ||
from flamapy.metamodels.bdd_metamodel.operations import BDDConfigurationsNumber | ||
|
||
|
||
class BDDCommonalityFactor(CommonalityFactor): | ||
|
||
def __init__(self) -> None: | ||
self._result: float = 0.0 | ||
self._configuration: Configuration = Configuration(elements={}) | ||
|
||
def set_configuration(self, configuration: Configuration) -> None: | ||
self._configuration = configuration | ||
|
||
def execute(self, model: VariabilityModel) -> 'BDDCommonalityFactor': | ||
bdd_model = cast(BDDModel, model) | ||
self._result = commonality_factor(bdd_model, self._configuration) | ||
return self | ||
|
||
def get_result(self) -> float: | ||
return self._result | ||
|
||
def commonality_factor(self) -> float: | ||
return self.get_result() | ||
|
||
|
||
def commonality_factor(bdd_model: BDDModel, config: Configuration) -> float: | ||
configs_number_op = BDDConfigurationsNumber() | ||
total_configs = configs_number_op.execute(bdd_model).get_result() | ||
configs_number_op.set_partial_configuration(config) | ||
n_configs = configs_number_op.execute(bdd_model).get_result() | ||
return n_configs / total_configs |
35 changes: 35 additions & 0 deletions
35
flamapy/metamodels/bdd_metamodel/operations/bdd_homogeneity.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,35 @@ | ||
from typing import cast | ||
|
||
from flamapy.core.models import VariabilityModel | ||
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration | ||
from flamapy.metamodels.bdd_metamodel.models import BDDModel | ||
from flamapy.metamodels.bdd_metamodel.operations.interfaces import Homogeneity | ||
from flamapy.metamodels.bdd_metamodel.operations import BDDCommonalityFactor | ||
|
||
|
||
class BDDHomogeneity(Homogeneity): | ||
|
||
def __init__(self) -> None: | ||
self._result: float = 0.0 | ||
|
||
def execute(self, model: VariabilityModel) -> 'BDDHomogeneity': | ||
bdd_model = cast(BDDModel, model) | ||
self._result = homogeneity(bdd_model) | ||
return self | ||
|
||
def get_result(self) -> float: | ||
return self._result | ||
|
||
def homogeneity(self) -> float: | ||
return self.get_result() | ||
|
||
|
||
def homogeneity(bdd_model: BDDModel) -> float: | ||
commonality_sum = 0.0 | ||
commonality_op = BDDCommonalityFactor() | ||
|
||
for feature in bdd_model.variables: | ||
config = Configuration(elements={feature: True}) | ||
commonality_op.set_configuration(config) | ||
commonality_sum += commonality_op.execute(bdd_model).get_result() | ||
return commonality_sum / len(bdd_model.variables) |
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
56 changes: 56 additions & 0 deletions
56
flamapy/metamodels/bdd_metamodel/operations/bdd_unique_features.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,56 @@ | ||
from typing import Any, Optional, cast | ||
|
||
from flamapy.core.models import VariabilityModel | ||
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration | ||
from flamapy.metamodels.bdd_metamodel.models import BDDModel | ||
from flamapy.metamodels.bdd_metamodel.operations.interfaces import UniqueFeatures | ||
|
||
|
||
class BDDUniqueFeatures(UniqueFeatures): | ||
|
||
def __init__(self) -> None: | ||
self._result: list[Any] = [] | ||
self._partial_configuration: Optional[Configuration] = None | ||
|
||
def set_partial_configuration(self, partial_configuration: Optional[Configuration]) -> None: | ||
self._partial_configuration = partial_configuration | ||
|
||
def execute(self, model: VariabilityModel) -> 'BDDUniqueFeatures': | ||
bdd_model = cast(BDDModel, model) | ||
self._result = unique_features(bdd_model, self._partial_configuration) | ||
return self | ||
|
||
def get_result(self) -> list[Any]: | ||
return self._result | ||
|
||
def unique_features(self) -> list[Any]: | ||
return self.get_result() | ||
|
||
|
||
def unique_features(bdd_model: BDDModel, | ||
config: Optional[Configuration] = None) -> list[Any]: | ||
unique_features_list = [] | ||
if config is None: | ||
for feature in bdd_model.variables: | ||
values = {feature: True} | ||
u_func = bdd_model.bdd.let(values, bdd_model.root) | ||
n_vars = len(bdd_model.variables) - len(values) | ||
n_configs = bdd_model.bdd.count(u_func, nvars=n_vars) | ||
if n_configs == 1: | ||
unique_features_list.append(feature) | ||
else: | ||
values = dict(config.elements.items()) | ||
for feature in bdd_model.variables: | ||
feature_selected = values.get(feature, None) | ||
values = {feature: True} | ||
u_func = bdd_model.bdd.let(values, bdd_model.root) | ||
n_vars = len(bdd_model.variables) - len(values) | ||
n_configs = bdd_model.bdd.count(u_func, nvars=n_vars) | ||
if n_configs == 1: | ||
unique_features_list.append(feature) | ||
|
||
if feature_selected is None: | ||
values.pop(feature) | ||
else: | ||
values[feature] = feature_selected | ||
return unique_features_list |
37 changes: 37 additions & 0 deletions
37
flamapy/metamodels/bdd_metamodel/operations/bdd_variability.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,37 @@ | ||
from typing import cast | ||
|
||
from flamapy.core.models import VariabilityModel | ||
from flamapy.metamodels.bdd_metamodel.models import BDDModel | ||
from flamapy.metamodels.bdd_metamodel.operations.interfaces import Variability | ||
from flamapy.metamodels.bdd_metamodel.operations import ( | ||
BDDConfigurationsNumber, | ||
BDDVariantFeatures | ||
) | ||
|
||
|
||
class BDDVariability(Variability): | ||
|
||
def __init__(self) -> None: | ||
self._result: tuple[float, float] = (0.0, 0.0) | ||
|
||
def execute(self, model: VariabilityModel) -> 'BDDVariability': | ||
bdd_model = cast(BDDModel, model) | ||
self._result = variability(bdd_model) | ||
return self | ||
|
||
def get_result(self) -> tuple[float, float]: | ||
return self._result | ||
|
||
def total_variability(self) -> float: | ||
return self.get_result()[0] | ||
|
||
def partial_variability(self) -> float: | ||
return self.get_result()[1] | ||
|
||
|
||
def variability(bdd_model: BDDModel) -> tuple[float, float]: | ||
n_configs = BDDConfigurationsNumber().execute(bdd_model).get_result() | ||
total_variability = n_configs / (2**len(bdd_model.variables) - 1) | ||
variant_features = BDDVariantFeatures().execute(bdd_model).get_result() | ||
partial_variability = n_configs / (2**len(variant_features) - 1) | ||
return (total_variability, partial_variability) |
36 changes: 36 additions & 0 deletions
36
flamapy/metamodels/bdd_metamodel/operations/bdd_variant_features.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,36 @@ | ||
from typing import Any, Optional, cast | ||
|
||
from flamapy.core.models import VariabilityModel | ||
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration | ||
from flamapy.metamodels.bdd_metamodel.models import BDDModel | ||
from flamapy.metamodels.bdd_metamodel.operations.interfaces import VariantFeatures | ||
from flamapy.metamodels.bdd_metamodel.operations import BDDFeatureInclusionProbability | ||
|
||
|
||
class BDDVariantFeatures(VariantFeatures): | ||
|
||
def __init__(self) -> None: | ||
self._result: list[Any] = [] | ||
self._partial_configuration: Optional[Configuration] = None | ||
|
||
def set_partial_configuration(self, partial_configuration: Optional[Configuration]) -> None: | ||
self._partial_configuration = partial_configuration | ||
|
||
def execute(self, model: VariabilityModel) -> 'BDDVariantFeatures': | ||
bdd_model = cast(BDDModel, model) | ||
self._result = variant_features(bdd_model, self._partial_configuration) | ||
return self | ||
|
||
def get_result(self) -> list[Any]: | ||
return self._result | ||
|
||
def variant_features(self) -> list[Any]: | ||
return self.get_result() | ||
|
||
|
||
def variant_features(bdd_model: BDDModel, | ||
config: Optional[Configuration] = None) -> list[Any]: | ||
fip_op = BDDFeatureInclusionProbability() | ||
fip_op.set_partial_configuration(config) | ||
probs = fip_op.execute(bdd_model).get_result() | ||
return [feat for feat, prob, in probs.items() if 0.0 < prob < 1.0] |
12 changes: 11 additions & 1 deletion
12
flamapy/metamodels/bdd_metamodel/operations/interfaces/__init__.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 |
---|---|---|
@@ -1,8 +1,18 @@ | ||
from .product_distribution import ProductDistribution | ||
from .feature_inclusion_probability import FeatureInclusionProbability | ||
from .pure_optional_features import PureOptionalFeatures | ||
from .unique_features import UniqueFeatures | ||
from .variant_features import VariantFeatures | ||
from .commonality_factor import CommonalityFactor | ||
from .homogeneity import Homogeneity | ||
from .variability import Variability | ||
|
||
|
||
__all__ = ['ProductDistribution', | ||
'FeatureInclusionProbability', | ||
'PureOptionalFeatures'] | ||
'PureOptionalFeatures', | ||
'UniqueFeatures', | ||
'VariantFeatures', | ||
'CommonalityFactor', | ||
'Homogeneity', | ||
'Variability'] |
26 changes: 26 additions & 0 deletions
26
flamapy/metamodels/bdd_metamodel/operations/interfaces/commonality_factor.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,26 @@ | ||
from abc import abstractmethod | ||
|
||
from flamapy.core.operations import Operation | ||
from flamapy.metamodels.configuration_metamodel.models import Configuration | ||
|
||
|
||
class CommonalityFactor(Operation): | ||
"""The commonality factor of a configuration in an SPL is the percentage of products | ||
of the SPL including the given configuration (0 if the SPL is void). | ||
Ref.: [Duran et al. 2017. FLAME: a formal framework for the automated analysis of software | ||
product lines validated by automated specification testing. | ||
(https://doi.org/10.1007/s10270-015-0503-z)] | ||
""" | ||
|
||
@abstractmethod | ||
def __init__(self) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def set_configuration(self, configuration: Configuration) -> None: | ||
pass | ||
|
||
@abstractmethod | ||
def commonality_factor(self) -> float: | ||
pass |
Oops, something went wrong.