Package: famapy-bdd
BDD plugin for FaMaPyBDD plugin for FaMaPyDescriptionRequirements and InstallationFunctionality and usageLoad a feature model and create the BDDSave the BDD in a fileAnalysis operationsContributing to the BDD pluginDescriptionThis plugin supports Binary Decision Diagrams (BDDs) representations for feature models.The plugin is based onFaMaPyand thus, it follows the same architecture:The BDD plugin relies on theddlibrary to manipulate BDDs.
The complete documentation of such library is availablehere.The following is an example of feature model and its BDD using complemented arcs.Requirements and InstallationPython 3.9+This plugin depends on theFaMaPy coreand on theFeature Model plugin.pip install famapy famapy-fm famapy-bddWe have tested the plugin on Linux, but Windows is also supported.Functionality and usageThe executable scripttest_bdd_metamodel.pyserves as an entry point to show the plugin in action.The following functionality is provided:Load a feature model and create the BDDfromfamapy.metamodels.fm_metamodel.transformations.featureide_readerimportFeatureIDEReaderfromfamapy.metamodels.bdd_metamodel.transformations.fm_to_bddimportFmToBDD# Load the feature model from FeatureIDEfeature_model=FeatureIDEReader('input_fms/featureide_models/pizzas.xml').transform()# Create the BDD from the feature modelbdd_model=FmToBDD(feature_model).transform()Save the BDD in a filefromfamapy.metamodels.bdd_metamodel.transformations.bdd_writerimportBDDWriter,BDDDumpFormat# Save the BDD as an image in PNGBDDWriter(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 operationsProducts numberReturn the number of products (configurations):fromfamapy.metamodels.bdd_metamodel.operationsimportBDDProductsNumbernof_products=BDDProductsNumber().execute(bdd_model).get_result()print(f'#Products:{nof_products}')or alternatively:fromfamapy.metamodels.bdd_metamodel.operationsimportproducts_numbernof_products=products_number(bdd_model)print(f'#Products:{nof_products}')ProductsReturn the list of products (configurations):fromfamapy.metamodels.bdd_metamodel.operationsimportBDDProductslist_products=BDDProducts().execute(bdd_model).get_result()fori,prodinenumerate(list_products):print(f'Product{i}:{[featforfeatinprod.elementsifprod.elements[feat]]}')or alternatively:fromfamapy.metamodels.bdd_metamodel.operationsimportproductsnof_products=products(bdd_model)fori,prodinenumerate(list_products):print(f'Product{i}:{[featforfeatinprod.elementsifprod.elements[feat]]}')SamplingReturn a sample of the given size of uniform random products (configurations) with or without replacement:fromfamapy.metamodels.bdd_metamodel.operationsimportBDDSamplinglist_sample=BDDSampling(size=5,with_replacement=False).execute(bdd_model).get_result()fori,prodinenumerate(list_sample):print(f'Product{i}:{[featforfeatinprod.elementsifprod.elements[feat]]}')or alternatively:fromfamapy.metamodels.bdd_metamodel.operationsimportsamplelist_sample=sample(bdd_model,size=5,with_replacement=False)fori,prodinenumerate(list_sample):print(f'Product{i}:{[featforfeatinprod.elementsifprod.elements[feat]]}')Product DistributionReturn the number of products having a given number of features:fromfamapy.metamodels.bdd_metamodel.operationsimportBDDProductDistributionBFdist=BDDProductDistributionBF().execute(bdd_model).get_result()print(f'Product Distribution:{dist}')or alternatively:fromfamapy.metamodels.bdd_metamodel.operationsimportproduct_distributiondist=product_distribution(bdd_model)print(f'Product Distribution:{dist}')Feature Inclusion ProbabilityReturn the probability for a feature to be included in a valid product:fromfamapy.metamodels.bdd_metamodel.operationsimportBDDFeatureInclusionProbabilityBFprob=BDDFeatureInclusionProbabilityBF().execute(bdd_model).get_result()forfeatinprob.keys():print(f'{feat}:{prob[feat]}')or alternatively:fromfamapy.metamodels.bdd_metamodel.operationsimportfeature_inclusion_probabilityprob=feature_inclusion_probability(bdd_model)forfeatinprob.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:fromfamapy.core.modelsimportConfiguration# Create a partial configurationelements={'Pizza':True,'Big':True}partial_config=Configuration(elements)# Calculate the number of products from the partial configurationnof_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 pluginTo contribute in the development of this plugin:Fork the repository into your GitHub account.Clone the repository:git@github.com:<<username>>/bdd_metamodel.gitCreate a virtual environment:python -m venv envActivate the virtual environment:source env/bin/activateInstall the plugin dependencies:pip install famapy famapy-fmInstall the BDD plugin from the source code:pip install -e bdd_metamodelPlease 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 lintTo analyze the static type checker for Python and find bugs, pass the Mypy:make mypy