flamapy / bdd_metamodel

BDD plugin for the automated analysis of feature models using a BDD.
1 stars 2 forks source link

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

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: