Exemplo n.º 1
0
 def execute(self, model: FeatureModel) -> 'FMCountLeafs':
     number = 0
     for feat in model.get_features():
         if len(feat.get_relations()) == 0:
             number += 1
     self.number_of_leafs = number
     return self
Exemplo n.º 2
0
 def execute(self, model: FeatureModel) -> 'FMAverageBranchingFactor':
     features = model.get_features()
     childrens = 0
     for feat in features:
         for relation in feat.get_relations():
             childrens += len(relation.children)
     self.average_branching_factor = round(childrens / len(features))
     return self
def average_branching_factor(feature_model: FeatureModel,
                             precision: int = 2) -> float:
    nof_branches = 0
    nof_children = 0
    for feature in feature_model.get_features():
        if feature.get_relations():
            nof_branches += 1
            nof_children += sum(
                len(r.children) for r in feature.get_relations())
    return round(nof_children / nof_branches, precision)
def get_false_optional_features(sat_model: PySATModel, feature_model: FeatureModel) -> list[Any]:
    real_optional_features = [f for f in feature_model.get_features() 
                              if not f.is_root() and not f.is_mandatory()]

    result = []
    solver = Glucose3()
    for clause in sat_model.get_all_clauses():
        solver.add_clause(clause)

    for feature in real_optional_features:
        variable = sat_model.variables.get(feature.name)
        parent_variable = sat_model.variables.get(feature.get_parent().name)
        assert variable is not None
        satisfiable = solver.solve(assumptions=[parent_variable, -variable])
        if not satisfiable:
            result.append(feature.name)
    solver.delete()
    return result