Skip to main content

BDD plugin for FaMaPy

Description

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

The plugin is based on FaMaPy 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 famapy famapy-fm famapy-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 and create the BDD

from famapy.metamodels.fm_metamodel.transformations.featureide_reader import FeatureIDEReader
from famapy.metamodels.bdd_metamodel.transformations.fm_to_bdd import FmToBDD

# Load the feature model from FeatureIDE
feature_model = FeatureIDEReader('input_fms/featureide_models/pizzas.xml').transform() 
# Create the BDD from the feature model
bdd_model = FmToBDD(feature_model).transform()

Save the BDD in a file

from famapy.metamodels.bdd_metamodel.transformations.bdd_writer import BDDWriter, BDDDumpFormat
# Save the BDD as an image in PNG
BDDWriter(path='my_bdd.png', 
          source_model=bdd_model, 
          roots=[bdd_model.root], 
          output_format=BDDDumpFormat.PNG).transform()

Formats supported: DDDMP_V3 ('dddmp'), DDDMP_V2 ('dddmp2'), PDF ('pdf'), PNG ('png'), SVG ('svg').

Analysis operations

  • Products number

    Return the number of products (configurations):

    from famapy.metamodels.bdd_metamodel.operations import BDDProductsNumber
    nof_products = BDDProductsNumber().execute(bdd_model).get_result()
    print(f'#Products: {nof_products}')
    

    or alternatively:

    from famapy.metamodels.bdd_metamodel.operations import products_number
    nof_products = products_number(bdd_model)
    print(f'#Products: {nof_products}')
    
  • Products

    Return the list of products (configurations):

    from famapy.metamodels.bdd_metamodel.operations import BDDProducts
    list_products = BDDProducts().execute(bdd_model).get_result()
    for i, prod in enumerate(list_products):
        print(f'Product {i}: {[feat for feat in prod.elements if prod.elements[feat]]}')
    

    or alternatively:

    from famapy.metamodels.bdd_metamodel.operations import products
    nof_products = products(bdd_model)
    for i, prod in enumerate(list_products):
        print(f'Product {i}: {[feat for feat in prod.elements if prod.elements[feat]]}')
    
  • Sampling

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

    from famapy.metamodels.bdd_metamodel.operations import BDDSampling
    list_sample = BDDSampling(size=5, with_replacement=False).execute(bdd_model).get_result()
    for i, prod in enumerate(list_sample):
        print(f'Product {i}: {[feat for feat in prod.elements if prod.elements[feat]]}')
    

    or alternatively:

    from famapy.metamodels.bdd_metamodel.operations import sample
    list_sample = sample(bdd_model, size=5, with_replacement=False)
    for i, prod in enumerate(list_sample):
        print(f'Product {i}: {[feat for feat in prod.elements if prod.elements[feat]]}')
    
  • Product Distribution

    Return the number of products having a given number of features:

    from famapy.metamodels.bdd_metamodel.operations import BDDProductDistributionBF
    dist = BDDProductDistributionBF().execute(bdd_model).get_result()
    print(f'Product Distribution: {dist}')
    

    or alternatively:

    from famapy.metamodels.bdd_metamodel.operations import product_distribution
    dist = product_distribution(bdd_model)
    print(f'Product Distribution: {dist}')
    
  • Feature Inclusion Probability

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

    from famapy.metamodels.bdd_metamodel.operations import BDDFeatureInclusionProbabilityBF
    prob = BDDFeatureInclusionProbabilityBF().execute(bdd_model).get_result()
    for feat in prob.keys():
        print(f'{feat}: {prob[feat]}')
    

    or alternatively:

    from famapy.metamodels.bdd_metamodel.operations import feature_inclusion_probability
    prob = feature_inclusion_probability(bdd_model)
    for feat in prob.keys():
        print(f'{feat}: {prob[feat]}')
    

All 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 famapy.core.models import Configuration
# Create a partial configuration
elements = {'Pizza': True, 'Big': True}
partial_config = Configuration(elements)
# Calculate the number of products from the partial configuration
nof_products = BDDProductsNumber(partial_config).execute(bdd_model).get_result()
print(f'#Products: {nof_products}')

or alternatively:

nof_products = products(bdd_model, partial_config)
print(f'#Products: {nof_products}')

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 famapy famapy-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

Metadata

Release files for famapy-bdd 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for famapy-bdd 1.0.0
File Size Uploaded Provenance
famapy-bdd-1.0.0.tar.gz 14.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for famapy-bdd 1.0.0
File Interpreter ABI Platform
famapy_bdd-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 32.9 kB

Release files / famapy-bdd-1.0.0.tar.gz

Download URL famapy-bdd-1.0.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4d5d6133809b9f8f871041075c025763c4a57deb47349728fe2de5ffa425fcd7
BLAKE2b-256 checksum
How to use checksums
d85341b521682b382a9cacaf2fb87e8d53f4f3420838874c753a64351c46c556
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Release files / famapy_bdd-1.0.0-py3-none-any.whl

Download URL famapy_bdd-1.0.0-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
79e7c5844089ffeb32c0fc5453a7a26013595fa14d332750ac40ce0a8430e8c8
BLAKE2b-256 checksum
How to use checksums
f8b26aed5c7c2bed0a4cc95b8410fafc1e6cc231aa649cbfacc512b0c95fbb2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.13

Security for famapy-bdd 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page