Generate Random Attribute

This operation augments a feature model with a randomly generated numeric attribute attached to its features. It is useful for creating attributed feature models on which to exercise attribute-based analyses (for example optimization or feature bounds) when the original model has no attributes.


Code Examples

from flamapy.metamodels.fm_metamodel.models import Domain, Range
from flamapy.metamodels.fm_metamodel.transformations import UVLReader
from flamapy.metamodels.fm_metamodel.operations import GenerateRandomAttribute

feature_model = UVLReader('model.uvl').transform()
operation = GenerateRandomAttribute()
# The attribute name and the range its values are drawn from are required
operation.set_name('cost')
operation.set_domain(Domain([Range(0, 100)], None))
# Optionally, only add the attribute to leaf features
operation.set_only_leaf_features(False)
model_with_attribute = operation.execute(feature_model).get_result()
print(model_with_attribute)

Or, more simply, through the facade (values are drawn from the [min_value, max_value] range):

from flamapy.interfaces.python.flamapy_feature_model import FLAMAFeatureModel

fm = FLAMAFeatureModel('model.uvl')
model_with_attribute = fm.generate_random_attribute('cost', min_value=0, max_value=100)
print(model_with_attribute)

Facade signature: generate_random_attribute(self, name: str, min_value: int = 0, max_value: int = 100, only_leaf_features: bool = False)

Inputs:

name type required default
name str yes —
min_value int no 0
max_value int no 100
only_leaf_features bool no False

Default backend: none (runs on the feature model)

Implemented by:

plugin exact scale limit
fm_metamodel yes —