Skip to main content

bdd-plugin for the automated analysis of feature models

Project description

BDD plugin for flamapy

Description

This plugin supports Binary Decision Diagrams (BDDs) representations for feature models.

The plugin is based on flamapy and thus, it follows the same architecture:

The BDD plugin relies on the dd library to manipulate BDDs. The complete documentation of such library is available here.

The following is an example of feature model and its BDD using complemented arcs.

Requirements and Installation

pip install flamapy flamapy-fm flamapy-bdd

We have tested the plugin on Linux, but Windows is also supported.

Functionality and usage

The executable script test_bdd_metamodel.py serves as an entry point to show the plugin in action.

The following functionality is provided:

Load a feature model in UVL and create the BDD

from flamapy.metamodels.fm_metamodel.transformations import UVLReader
from flamapy.metamodels.bdd_metamodel.transformations import FmToBDD

# Load the feature model from UVL
feature_model = UVLReader('models/uvl_models/pizzas.uvl').transform()
# Create the BDD from the feature model
bdd_model = FmToBDD(feature_model).transform()

Save the BDD in a file

from flamapy.metamodels.bdd_metamodel.transformations import PNGWriter, DDDMPv3Writer
# Save the BDD as an image in PNG
PNGWriter(path='my_bdd.png', bdd_model).transform()
# Save the BDD in a .dddmp file
DDDMPv3Writer(f'my_bdd.dddmp', bdd_model).transform()

Writers available: DDDMPv3 ('dddmp'), DDDMPv2 ('dddmp'), JSON ('json'), Pickle ('p'), PDF ('pdf'), PNG ('png'), SVG ('svg').

Load the BDD from a file

from flamapy.metamodels.bdd_metamodel.transformations import JSONReader
# Load the BDD from a .json file
bdd_model = JSONReader(path='path/to/my_bdd.json').transform()

Readers available: JSON ('json'), DDDMP ('dddmp'), Pickle ('p').

NOTE: DDDMP and Pickle readers are not fully supported yet.

Analysis operations

  • Satisfiable

    Return whether the model is satisfiable (valid):

    from flamapy.metamodels.bdd_metamodel.operations import BDDSatisfiable
    satisfiable = BDDSatisfiable().execute(bdd_model).get_result()
    print(f'Satisfiable? (valid?): {satisfiable}')
    
  • Configurations number

    Return the number of configurations:

    from flamapy.metamodels.bdd_metamodel.operations import BDDConfigurationsNumber
    n_configs = BDDConfigurationsNumber().execute(bdd_model).get_result()
    print(f'#Configurations: {n_configs}')
    
  • Configurations

    Enumerate the configurations of the model:

    from flamapy.metamodels.bdd_metamodel.operations import BDDConfigurations
    configurations = BDDConfigurations().execute(bdd_model).get_result()
    for i, config in enumerate(configurations, 1):
        print(f'Config {i}: {[feat for feat in config.elements if config.elements[feat]]}')
    
  • Sampling

    Return a sample of the given size of uniform random configurations with or without replacement:

    from flamapy.metamodels.bdd_metamodel.operations import BDDSampling
    sampling_op = BDDSampling()
    sampling_op.set_sample_size(5)
    sampling_op.set_with_replacement(False)  # Default False
    sample = sampling_op.execute(bdd_model).get_result()
    for i, config in enumerate(sample, 1):
        print(f'Config {i}: {[feat for feat in config.elements if config.elements[feat]]}')
    
  • Product Distribution

    Return the number of products (configurations) having a given number of features:

    from flamapy.metamodels.bdd_metamodel.operations import BDDProductDistribution
    dist = BDDProductDistribution().execute(bdd_model).get_result()
    print(f'Product Distribution: {dist}')
    
  • Feature Inclusion Probability

    Return the probability for a feature to be included in a valid configuration:

    from flamapy.metamodels.bdd_metamodel.operations import BDDFeatureInclusionProbability
    prob = BDDFeatureInclusionProbability().execute(bdd_model).get_result()
    for feat in prob.keys():
        print(f'{feat}: {prob[feat]}')
    
  • Core features

    Return the core features (those features that are present in all the configurations):

    from flamapy.metamodels.bdd_metamodel.operations import BDDCoreFeatures
    core_features = BDDCoreFeatures().execute(bdd_model).get_result()
    print(f'Core features: {core_features}')
    
  • Dead features

    Return the dead features (those features that are not present in any configuration):

    from flamapy.metamodels.bdd_metamodel.operations import BDDDeadFeatures
    dead_features = BDDDeadFeatures().execute(bdd_model).get_result()
    print(f'Dead features: {dead_features}')
    

Most analysis operations support also a partial configuration as an additional argument, so the operation will return the result taking into account the given partial configuration. For example:

from flamapy.core.models import Configuration
# Create a partial configuration
elements = {'Pizza': True, 'Big': True}
partial_config = Configuration(elements)
# Calculate the number of configuration from the partial configuration
configs_number_op = BDDConfigurationsNumber()
configs_number_op.set_partial_configuration(partial_config)
n_configs = configs_number_op.execute(bdd_model).get_result()
print(f'#Configurations: {n_configs}')

Contributing to the BDD plugin

To contribute in the development of this plugin:

  1. Fork the repository into your GitHub account.
  2. Clone the repository: git@github.com:<<username>>/bdd_metamodel.git
  3. Create a virtual environment: python -m venv env
  4. Activate the virtual environment: source env/bin/activate
  5. Install the plugin dependencies: pip install flamapy flamapy-fm
  6. Install the BDD plugin from the source code: pip install -e bdd_metamodel

Please try to follow the standards code quality to contribute to this plugin before creating a Pull Request:

  • To analyze your Python code and output information about errors, potential problems, convention violations and complexity, pass the prospector with:

    make lint

  • To analyze the static type checker for Python and find bugs, pass the Mypy:

    make mypy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flamapy-bdd-2.0.1.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

flamapy_bdd-2.0.1-py3-none-any.whl (45.5 kB view details)

Uploaded Python 3

File details

Details for the file flamapy-bdd-2.0.1.tar.gz.

File metadata

  • Download URL: flamapy-bdd-2.0.1.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for flamapy-bdd-2.0.1.tar.gz
Algorithm Hash digest
SHA256 4debb3edacd7c98f33ed0488885a4c4ed1452fb5a0c030f33c15437cc68da9a2
MD5 2cd44b15b1a03765257bc85f89ceb973
BLAKE2b-256 a85edb5dda2fed43439a228970aeac663a58987b0484ff8edb5a03b3353f253a

See more details on using hashes here.

File details

Details for the file flamapy_bdd-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: flamapy_bdd-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 45.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for flamapy_bdd-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a42815a77c2794871dab8e1dd97c2f644c338341fb8b9d81ecdf3b3c4e3b2137
MD5 4519b0acfa94b85ea0c2acb7d56eecd6
BLAKE2b-256 02314b882aef97a22224e62a87301bc8b6a18c217412be0ddb2bccce62be0c08

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page