flamapy-fw 2.6.0.dev4__tar.gz → 2.6.0.dev11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flamapy_fw-2.6.0.dev4/flamapy_fw.egg-info → flamapy_fw-2.6.0.dev11}/PKG-INFO +1 -1
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/discover.py +17 -7
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/models/ast.py +111 -7
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/__init__.py +10 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/attribute_optimization.py +68 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/configurations.py +29 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/configurations_number.py +30 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/core_features.py +29 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/dead_features.py +29 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/descriptor.py +61 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/false_optional_features.py +33 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/metrics_operation.py +1 -1
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/sampling.py +19 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/satisfiable.py +28 -0
- flamapy_fw-2.6.0.dev11/flamapy/core/operations/satisfiable_configuration.py +47 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/plugins.py +23 -33
- flamapy_fw-2.6.0.dev11/flamapy/core/utils.py +17 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/models/configuration.py +15 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11/flamapy_fw.egg-info}/PKG-INFO +1 -1
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy_fw.egg-info/SOURCES.txt +2 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/pyproject.toml +1 -1
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/configurations.py +0 -14
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/configurations_number.py +0 -13
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/core_features.py +0 -14
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/dead_features.py +0 -14
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/false_optional_features.py +0 -17
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/satisfiable.py +0 -13
- flamapy_fw-2.6.0.dev4/flamapy/core/operations/satisfiable_configuration.py +0 -18
- flamapy_fw-2.6.0.dev4/flamapy/core/utils.py +0 -9
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/LICENSE +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/README.md +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/__init__.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/config.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/exceptions.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/models/__init__.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/models/variability_model.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/abstract_operation.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/atomic_sets.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/average_branching_factor.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/commonality.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/count_leafs.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/error_detection.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/error_diagnosis.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/estimated_configurations_number.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/filter.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/variability.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/__init__.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/abstract_transformation.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/model_to_model.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/model_to_text.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/text_to_model.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/__init__.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/models/__init__.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/__init__.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/configuration_basic_reader.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/configuration_basic_writer.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/configuration_json_reader.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/configuration_json_writer.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/uvls_json_reader.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/metamodels/configuration_metamodel/transformations/uvls_json_writer.py +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy_fw.egg-info/dependency_links.txt +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy_fw.egg-info/entry_points.txt +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy_fw.egg-info/requires.txt +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy_fw.egg-info/top_level.txt +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/setup.cfg +0 -0
- {flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flamapy-fw
|
|
3
|
-
Version: 2.6.0.
|
|
3
|
+
Version: 2.6.0.dev11
|
|
4
4
|
Summary: Flamapy is a Python-based AAFM framework that takes into consideration previous AAFM tool designs and enables multi-solver and multi-metamodel support for the integration of AAFM tooling on the Python ecosystem.
|
|
5
5
|
Author-email: Flamapy <flamapy@us.es>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -11,10 +11,12 @@ from flamapy.core.exceptions import TransformationNotFound
|
|
|
11
11
|
from flamapy.core.exceptions import ConfigurationNotFound
|
|
12
12
|
from flamapy.core.models import VariabilityModel
|
|
13
13
|
from flamapy.core.operations import Operation
|
|
14
|
+
from flamapy.core.operations.descriptor import OperationDescriptor, collect_descriptors
|
|
14
15
|
from flamapy.core.plugins import Operations, Plugin, Plugins
|
|
15
16
|
from flamapy.core.transformations import Transformation
|
|
16
17
|
from flamapy.core.transformations.text_to_model import TextToModel
|
|
17
18
|
from flamapy.core.transformations.model_to_model import ModelToModel
|
|
19
|
+
from flamapy.core.utils import filename_matches_extension
|
|
18
20
|
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
|
|
19
21
|
|
|
20
22
|
|
|
@@ -103,6 +105,13 @@ class DiscoverMetamodels:
|
|
|
103
105
|
|
|
104
106
|
return operations
|
|
105
107
|
|
|
108
|
+
def available_operations(self) -> dict[str, OperationDescriptor]:
|
|
109
|
+
"""Facade descriptors of every discovered operation that declares one, keyed by public name.
|
|
110
|
+
|
|
111
|
+
This is the single source the facade, CLI and REST derive their operation surface from.
|
|
112
|
+
"""
|
|
113
|
+
return collect_descriptors(self.get_operations())
|
|
114
|
+
|
|
106
115
|
def get_transformations(self) -> list[Type[Transformation]]:
|
|
107
116
|
"""Get transformations for all modules"""
|
|
108
117
|
transformations: list[Type[Transformation]] = []
|
|
@@ -256,14 +265,15 @@ class DiscoverMetamodels:
|
|
|
256
265
|
|
|
257
266
|
def __transform_to_model_from_file(self, file: str) -> VariabilityModel:
|
|
258
267
|
t2m_transformations = self.get_transformations_t2m()
|
|
259
|
-
extension
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if
|
|
268
|
+
# Prefer the most specific matching extension (e.g. 'uvl.json' over 'json').
|
|
269
|
+
candidates = [
|
|
270
|
+
t2m
|
|
271
|
+
for t2m in t2m_transformations
|
|
272
|
+
if filename_matches_extension(file, t2m.get_source_extension())
|
|
273
|
+
]
|
|
274
|
+
if not candidates:
|
|
266
275
|
raise TransformationNotFound()
|
|
276
|
+
t2m = max(candidates, key=lambda t: len(t.get_source_extension()))
|
|
267
277
|
|
|
268
278
|
return t2m(file).transform()
|
|
269
279
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
from typing import Any, Optional
|
|
2
2
|
from enum import Enum
|
|
3
3
|
|
|
4
|
+
from flamapy.core.exceptions import FlamaException
|
|
5
|
+
|
|
4
6
|
|
|
5
7
|
class ASTOperation(Enum):
|
|
6
8
|
# logical operators
|
|
@@ -187,10 +189,31 @@ class AST:
|
|
|
187
189
|
def to_cnf(self) -> "AST":
|
|
188
190
|
return convert_into_cnf(self)
|
|
189
191
|
|
|
190
|
-
def get_clauses(self) -> list[list[Any]]:
|
|
192
|
+
def get_clauses(self, method: str = 'distributive') -> list[list[Any]]:
|
|
193
|
+
"""Return the CNF clauses of this AST.
|
|
194
|
+
|
|
195
|
+
``method='distributive'`` (default) uses the classic distributive expansion and
|
|
196
|
+
returns clauses over the formula's own variables. ``method='tseytin'`` uses the
|
|
197
|
+
Tseytin transformation; the returned clauses may contain fresh auxiliary
|
|
198
|
+
variables. Use :meth:`get_clauses_with_aux` when those auxiliary variable names
|
|
199
|
+
are needed (e.g. to register them as non-feature solver variables).
|
|
200
|
+
"""
|
|
201
|
+
if method == 'tseytin':
|
|
202
|
+
clauses, _ = tseytin_cnf(self)
|
|
203
|
+
return clauses
|
|
191
204
|
ast = self.to_cnf()
|
|
192
205
|
return get_clauses(ast)
|
|
193
206
|
|
|
207
|
+
def get_clauses_with_aux(self, method: str = 'tseytin') -> tuple[list[list[Any]], list[str]]:
|
|
208
|
+
"""Return ``(clauses, aux_names)`` for the given CNF ``method``.
|
|
209
|
+
|
|
210
|
+
For ``'tseytin'`` this exposes the auxiliary variable names introduced by the
|
|
211
|
+
encoding. For ``'distributive'`` the auxiliary list is always empty.
|
|
212
|
+
"""
|
|
213
|
+
if method == 'tseytin':
|
|
214
|
+
return tseytin_cnf(self)
|
|
215
|
+
return get_clauses(self.to_cnf()), []
|
|
216
|
+
|
|
194
217
|
def get_operators(self) -> list[ASTOperation]:
|
|
195
218
|
operators = []
|
|
196
219
|
stack = [self.root]
|
|
@@ -263,20 +286,22 @@ def simplify_formula(ast: AST) -> AST:
|
|
|
263
286
|
)
|
|
264
287
|
elif logic_op == ASTOperation.EQUIVALENCE:
|
|
265
288
|
# Replace P <=> Q with P => Q ∧ Q => P.
|
|
266
|
-
|
|
267
|
-
|
|
289
|
+
new_left = simplify_formula(
|
|
290
|
+
AST.create_binary_operation(ASTOperation.IMPLIES, left, right)
|
|
291
|
+
).root
|
|
292
|
+
new_right = simplify_formula(
|
|
268
293
|
AST.create_binary_operation(ASTOperation.IMPLIES, right, left)
|
|
269
294
|
).root
|
|
270
|
-
result = AST.create_binary_operation(ASTOperation.AND,
|
|
295
|
+
result = AST.create_binary_operation(ASTOperation.AND, new_left, new_right)
|
|
271
296
|
elif logic_op == ASTOperation.XOR:
|
|
272
297
|
# Replace P XOR Q with (P ∧ !Q) v (!P ∧ Q).
|
|
273
|
-
|
|
298
|
+
new_left = simplify_formula(
|
|
274
299
|
AST.create_binary_operation(ASTOperation.AND, left, Node(ASTOperation.NOT, right))
|
|
275
300
|
).root
|
|
276
|
-
|
|
301
|
+
new_right = simplify_formula(
|
|
277
302
|
AST.create_binary_operation(ASTOperation.AND, Node(ASTOperation.NOT, left), right)
|
|
278
303
|
).root
|
|
279
|
-
result = AST.create_binary_operation(ASTOperation.OR,
|
|
304
|
+
result = AST.create_binary_operation(ASTOperation.OR, new_left, new_right)
|
|
280
305
|
elif logic_op == ASTOperation.AND:
|
|
281
306
|
left = simplify_formula(AST(left)).root
|
|
282
307
|
right = simplify_formula(AST(right)).root
|
|
@@ -376,6 +401,85 @@ def propagate_negation(node: Node, negated: bool = False) -> AST:
|
|
|
376
401
|
return result
|
|
377
402
|
|
|
378
403
|
|
|
404
|
+
TSEYTIN_AUX_PREFIX = "__tseytin_"
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _negate_literal(literal: Any) -> Any:
|
|
408
|
+
"""Flip the sign of a CNF literal that uses the ``"-name"`` string convention."""
|
|
409
|
+
if isinstance(literal, str) and literal.startswith("-"):
|
|
410
|
+
return literal[1:]
|
|
411
|
+
return "-" + str(literal)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
def _tseytin_gate_clauses(op: ASTOperation, gate: Any, a: Any, b: Any) -> list[list[Any]]:
|
|
415
|
+
"""Biconditional clauses encoding ``gate <=> (a op b)`` for a binary logical ``op``.
|
|
416
|
+
|
|
417
|
+
``a`` and ``b`` are literals; ``gate`` is the fresh auxiliary literal. Encoding each
|
|
418
|
+
connective directly (rather than expanding it first) is what keeps the transformation
|
|
419
|
+
linear in the formula size.
|
|
420
|
+
"""
|
|
421
|
+
g, na, nb, ng = gate, _negate_literal(a), _negate_literal(b), _negate_literal(gate)
|
|
422
|
+
if op == ASTOperation.AND:
|
|
423
|
+
return [[ng, a], [ng, b], [g, na, nb]]
|
|
424
|
+
if op == ASTOperation.OR:
|
|
425
|
+
return [[g, na], [g, nb], [ng, a, b]]
|
|
426
|
+
if op in (ASTOperation.IMPLIES, ASTOperation.REQUIRES): # a -> b == (not a) or b
|
|
427
|
+
return [[g, a], [g, nb], [ng, na, b]]
|
|
428
|
+
if op == ASTOperation.EXCLUDES: # (not a) or (not b)
|
|
429
|
+
return [[g, a], [g, b], [ng, na, nb]]
|
|
430
|
+
if op == ASTOperation.EQUIVALENCE: # a <-> b
|
|
431
|
+
return [[ng, na, b], [ng, a, nb], [g, a, b], [g, na, nb]]
|
|
432
|
+
if op == ASTOperation.XOR: # a xor b
|
|
433
|
+
return [[ng, a, b], [ng, na, nb], [g, na, b], [g, a, nb]]
|
|
434
|
+
raise FlamaException(
|
|
435
|
+
f"Operation '{op}' is not a propositional connective supported by the Tseytin "
|
|
436
|
+
f"transformation."
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def tseytin_cnf(ast: AST) -> tuple[list[list[Any]], list[str]]:
|
|
441
|
+
"""Return an equisatisfiable CNF of ``ast`` using the Tseytin transformation.
|
|
442
|
+
|
|
443
|
+
Unlike the distributive :func:`to_cnf`, this produces a CNF whose size is linear
|
|
444
|
+
in the size of the formula by introducing one fresh auxiliary variable per gate.
|
|
445
|
+
Each logical connective is encoded directly (no distributive expansion), so formulas
|
|
446
|
+
that blow up under :func:`to_cnf` (XOR chains, wide equivalences) stay compact. Gates
|
|
447
|
+
are encoded as full biconditionals (``g <=> subformula``) so that every model of the
|
|
448
|
+
original formula extends to exactly one model of the encoding; this preserves model
|
|
449
|
+
counts and configuration enumeration (once auxiliary variables are projected out).
|
|
450
|
+
|
|
451
|
+
Returns a tuple ``(clauses, aux_names)`` where ``clauses`` is a list of clauses
|
|
452
|
+
(each a list of literals in the same ``"-name"`` string convention as
|
|
453
|
+
:func:`get_clauses`) and ``aux_names`` lists every auxiliary variable name
|
|
454
|
+
introduced (each prefixed with :data:`TSEYTIN_AUX_PREFIX`) so callers can register
|
|
455
|
+
them as solver variables that are not features.
|
|
456
|
+
|
|
457
|
+
Raises :class:`FlamaException` if the formula contains a non-propositional operator
|
|
458
|
+
(arithmetic, comparison or aggregation).
|
|
459
|
+
"""
|
|
460
|
+
clauses: list[list[Any]] = []
|
|
461
|
+
aux_names: list[str] = []
|
|
462
|
+
counter = [0]
|
|
463
|
+
|
|
464
|
+
def literal_of(node: Node) -> Any:
|
|
465
|
+
if node.is_term():
|
|
466
|
+
return node.data
|
|
467
|
+
if node.data == ASTOperation.NOT:
|
|
468
|
+
# Negation of a single literal is free; no gate needed.
|
|
469
|
+
return _negate_literal(literal_of(node.left))
|
|
470
|
+
left_lit = literal_of(node.left)
|
|
471
|
+
right_lit = literal_of(node.right)
|
|
472
|
+
counter[0] += 1
|
|
473
|
+
gate = f"{TSEYTIN_AUX_PREFIX}{counter[0]}"
|
|
474
|
+
aux_names.append(gate)
|
|
475
|
+
clauses.extend(_tseytin_gate_clauses(node.data, gate, left_lit, right_lit))
|
|
476
|
+
return gate
|
|
477
|
+
|
|
478
|
+
root_literal = literal_of(ast.root)
|
|
479
|
+
clauses.append([root_literal]) # assert the whole formula is true
|
|
480
|
+
return clauses, aux_names
|
|
481
|
+
|
|
482
|
+
|
|
379
483
|
def get_clauses(ast: AST) -> list[list[Any]]:
|
|
380
484
|
"""Return the list of clauses represented by the AST root node in conjunctive normal form."""
|
|
381
485
|
node = ast.root
|
|
@@ -17,9 +17,15 @@ from .variability import Variability # pylint: disable=cyclic-import
|
|
|
17
17
|
from .sampling import Sampling # pylint: disable=cyclic-import
|
|
18
18
|
from .atomic_sets import AtomicSets # pylint: disable=cyclic-import
|
|
19
19
|
from .metrics_operation import Metrics # pylint: disable=cyclic-import
|
|
20
|
+
from .attribute_optimization import ( # pylint: disable=cyclic-import
|
|
21
|
+
AttributeOptimization,
|
|
22
|
+
OptimizationGoal,
|
|
23
|
+
)
|
|
24
|
+
from .descriptor import Input, OperationDescriptor, collect_descriptors
|
|
20
25
|
|
|
21
26
|
__all__ = [
|
|
22
27
|
"AtomicSets",
|
|
28
|
+
"AttributeOptimization",
|
|
23
29
|
"AverageBranchingFactor",
|
|
24
30
|
"Commonality",
|
|
25
31
|
"Configurations",
|
|
@@ -32,10 +38,14 @@ __all__ = [
|
|
|
32
38
|
"EstimatedConfigurationsNumber",
|
|
33
39
|
"FalseOptionalFeatures",
|
|
34
40
|
"Filter",
|
|
41
|
+
"Input",
|
|
35
42
|
"Metrics",
|
|
36
43
|
"Operation",
|
|
44
|
+
"OperationDescriptor",
|
|
45
|
+
"OptimizationGoal",
|
|
37
46
|
"Sampling",
|
|
38
47
|
"Satisfiable",
|
|
39
48
|
"SatisfiableConfiguration",
|
|
40
49
|
"Variability",
|
|
50
|
+
"collect_descriptors",
|
|
41
51
|
]
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from flamapy.core.operations import Operation
|
|
6
|
+
from flamapy.core.operations.descriptor import OperationDescriptor, Input
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OptimizationGoal(Enum):
|
|
10
|
+
MAXIMIZE = 'Maximize'
|
|
11
|
+
MINIMIZE = 'Minimize'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _attribute_optimization_inputs(operation: Any, facade: Any, kwargs: dict[str, Any]) -> None:
|
|
15
|
+
objectives = kwargs['objectives']
|
|
16
|
+
if isinstance(objectives, str):
|
|
17
|
+
attributes = {objectives: OptimizationGoal.MINIMIZE}
|
|
18
|
+
else:
|
|
19
|
+
attributes = {
|
|
20
|
+
name: (OptimizationGoal.MINIMIZE if str(goal).lower().startswith('min')
|
|
21
|
+
else OptimizationGoal.MAXIMIZE)
|
|
22
|
+
for name, goal in dict(objectives).items()
|
|
23
|
+
}
|
|
24
|
+
operation.set_attributes(attributes)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _attribute_optimization_result(result: Any) -> Any:
|
|
28
|
+
# z3 returns (configuration, values) tuples; sat returns bare configurations.
|
|
29
|
+
return [item[0] if isinstance(item, tuple) else item for item in result]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AttributeOptimization(Operation):
|
|
33
|
+
"""Return the configuration(s) that optimize the given numeric feature attribute(s).
|
|
34
|
+
|
|
35
|
+
Attributes are identified by name and mapped to an :class:`OptimizationGoal`. The
|
|
36
|
+
objective for each attribute is the sum of its values over the selected features.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
facade = OperationDescriptor(
|
|
40
|
+
doc=(
|
|
41
|
+
'Returns the configuration(s) that optimize one or more numeric feature\n'
|
|
42
|
+
'attributes.\n'
|
|
43
|
+
'\n'
|
|
44
|
+
'``objectives`` is either a single attribute name (defaults to minimizing it)\n'
|
|
45
|
+
'or a mapping ``{attribute_name: "Minimize"|"Maximize"}``. ``backend`` selects\n'
|
|
46
|
+
'the plugin: "sat" performs single-objective MaxSAT optimization; "z3"\n'
|
|
47
|
+
'additionally supports typed attributes and multi-objective (Pareto)\n'
|
|
48
|
+
'optimization. Defaults to "sat".'
|
|
49
|
+
),
|
|
50
|
+
returns='Union[None, List[Configuration]]',
|
|
51
|
+
name='attribute_optimization', operation='AttributeOptimization', default_backend='sat',
|
|
52
|
+
selectable_backend=True,
|
|
53
|
+
inputs=(Input('objectives', Any, required=True),),
|
|
54
|
+
input_adapter=_attribute_optimization_inputs,
|
|
55
|
+
result_adapter=_attribute_optimization_result,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
@abstractmethod
|
|
59
|
+
def __init__(self) -> None:
|
|
60
|
+
pass
|
|
61
|
+
|
|
62
|
+
@abstractmethod
|
|
63
|
+
def set_attributes(self, attributes: dict[str, OptimizationGoal]) -> None:
|
|
64
|
+
"""Set the attributes to optimize as a mapping ``{attribute_name: OptimizationGoal}``."""
|
|
65
|
+
|
|
66
|
+
@abstractmethod
|
|
67
|
+
def optimize(self) -> list[Any]:
|
|
68
|
+
"""Return the optimal configuration(s)."""
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from flamapy.core.operations import Operation
|
|
4
|
+
from flamapy.core.operations.descriptor import OperationDescriptor
|
|
5
|
+
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Configurations(Operation):
|
|
9
|
+
facade = OperationDescriptor(
|
|
10
|
+
doc=(
|
|
11
|
+
'These are the individual outcomes that can be produced from a feature model.\n'
|
|
12
|
+
'Each product is a combination of features that satisfies all the constraints\n'
|
|
13
|
+
'and dependencies in the feature model.\n'
|
|
14
|
+
'\n'
|
|
15
|
+
'``backend`` selects the analysis plugin ("sat", "bdd" or "z3"); defaults to\n'
|
|
16
|
+
'bdd.'
|
|
17
|
+
),
|
|
18
|
+
returns='Union[None, List[Configuration]]',
|
|
19
|
+
name='configurations', operation='Configurations', default_backend='bdd',
|
|
20
|
+
selectable_backend=True,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def get_configurations(self) -> list[Configuration]:
|
|
29
|
+
pass
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from flamapy.core.operations import Operation
|
|
4
|
+
from flamapy.core.operations.descriptor import OperationDescriptor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ConfigurationsNumber(Operation):
|
|
8
|
+
facade = OperationDescriptor(
|
|
9
|
+
doc=(
|
|
10
|
+
'This is the total number of different full configurations that can be produced\n'
|
|
11
|
+
"from a feature model. It's calculated by considering all possible combinations\n"
|
|
12
|
+
'of features, taking into account the constraints and dependencies between\n'
|
|
13
|
+
'features.\n'
|
|
14
|
+
'\n'
|
|
15
|
+
'``backend`` selects the analysis plugin ("sat", "bdd", "z3", or "sharpsat" for\n'
|
|
16
|
+
'a scalable approximate count via the optional flamapy-sharpsat plugin);\n'
|
|
17
|
+
'defaults to bdd.'
|
|
18
|
+
),
|
|
19
|
+
returns='Union[None, int]',
|
|
20
|
+
name='configurations_number', operation='ConfigurationsNumber', default_backend='bdd',
|
|
21
|
+
selectable_backend=True,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
@abstractmethod
|
|
25
|
+
def __init__(self) -> None:
|
|
26
|
+
pass
|
|
27
|
+
|
|
28
|
+
@abstractmethod
|
|
29
|
+
def get_configurations_number(self) -> int:
|
|
30
|
+
pass
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from flamapy.core.operations import Operation
|
|
4
|
+
from flamapy.core.operations.descriptor import OperationDescriptor
|
|
5
|
+
from flamapy.core.models.variability_model import VariabilityElement
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class CoreFeatures(Operation):
|
|
9
|
+
facade = OperationDescriptor(
|
|
10
|
+
doc=(
|
|
11
|
+
'These are the features that are present in all products of a product line. In\n'
|
|
12
|
+
'a feature model, they are the features that are mandatory and not optional.\n'
|
|
13
|
+
'Core features define the commonality among all products in a product line.\n'
|
|
14
|
+
'\n'
|
|
15
|
+
'``backend`` selects the analysis plugin ("sat", "bdd" or "z3"); defaults to\n'
|
|
16
|
+
'sat.'
|
|
17
|
+
),
|
|
18
|
+
returns='Union[None, List[str]]',
|
|
19
|
+
name='core_features', operation='CoreFeatures', default_backend='sat',
|
|
20
|
+
selectable_backend=True,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def get_core_features(self) -> list[VariabilityElement]:
|
|
29
|
+
pass
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from flamapy.core.operations import Operation
|
|
4
|
+
from flamapy.core.operations.descriptor import OperationDescriptor
|
|
5
|
+
from flamapy.core.models.variability_model import VariabilityElement
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class DeadFeatures(Operation):
|
|
9
|
+
facade = OperationDescriptor(
|
|
10
|
+
doc=(
|
|
11
|
+
'These are features that, due to the constraints and dependencies in the\n'
|
|
12
|
+
'feature model, cannot be included in any valid product. Dead features are\n'
|
|
13
|
+
'usually a sign of an error in the feature model.\n'
|
|
14
|
+
'\n'
|
|
15
|
+
'``backend`` selects the analysis plugin ("sat", "bdd" or "z3"); defaults to\n'
|
|
16
|
+
'sat.'
|
|
17
|
+
),
|
|
18
|
+
returns='Union[None, List[str]]',
|
|
19
|
+
name='dead_features', operation='DeadFeatures', default_backend='sat',
|
|
20
|
+
selectable_backend=True,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
@abstractmethod
|
|
24
|
+
def __init__(self) -> None:
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def get_dead_features(self) -> list[VariabilityElement]:
|
|
29
|
+
pass
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Self-describing metadata for operations, so the facade/CLI/REST can be *derived* from the
|
|
2
|
+
installed operations instead of hand-written.
|
|
3
|
+
|
|
4
|
+
An operation interface (or a bespoke concrete operation) declares a class attribute ``facade`` of
|
|
5
|
+
type :class:`OperationDescriptor`. It states the operation's stable public name, which backend it
|
|
6
|
+
runs on, its inputs (and how to wire them), and optional input/result adapters for the few
|
|
7
|
+
operations whose facade method is not a plain ``set params -> execute``. Concrete backend
|
|
8
|
+
implementations inherit the descriptor from their interface, so there is exactly one descriptor
|
|
9
|
+
per *logical* operation.
|
|
10
|
+
"""
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
from typing import Any, Callable, Iterable, Optional
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class Input:
|
|
17
|
+
"""One input of a facade operation and how to feed it to the underlying operation."""
|
|
18
|
+
|
|
19
|
+
name: str
|
|
20
|
+
type: Any = str # a type or typing special form (e.g. Any), for CLI/REST
|
|
21
|
+
default: Any = None
|
|
22
|
+
required: bool = False
|
|
23
|
+
setter: Optional[str] = None # operation setter for the value, e.g. 'set_sample_size'
|
|
24
|
+
kind: str = 'scalar' # 'scalar' | 'configuration' | 'file' (CLI/REST marshalling)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@dataclass(frozen=True)
|
|
28
|
+
class OperationDescriptor:
|
|
29
|
+
"""Everything the facade/CLI/REST need to expose an operation without hand-written code."""
|
|
30
|
+
|
|
31
|
+
name: str # stable public (facade/CLI/REST) name
|
|
32
|
+
operation: str # name passed to DiscoverMetamodels.use_operation
|
|
33
|
+
kind: str = 'operation' # 'operation' | 'producer' | 'transformer'
|
|
34
|
+
default_backend: Optional[str] = None # None => runs directly on the feature model
|
|
35
|
+
backends: Optional[tuple[str, ...]] = None # allowed backends (None => any implementer)
|
|
36
|
+
selectable_backend: bool = False # facade exposes a backend= kwarg (else fixed)
|
|
37
|
+
inputs: tuple[Input, ...] = ()
|
|
38
|
+
# For the ~12 non-uniform methods: custom wiring / result reshaping. When absent, the generic
|
|
39
|
+
# "call each Input.setter, then execute, then get_result" path is used.
|
|
40
|
+
input_adapter: Optional[Callable[..., Any]] = None
|
|
41
|
+
result_adapter: Optional[Callable[[Any], Any]] = None
|
|
42
|
+
doc: str = ''
|
|
43
|
+
returns: str = 'Any' # return annotation (source text) for the stub
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def needs_backend(self) -> bool:
|
|
47
|
+
return self.default_backend is not None
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def collect_descriptors(operations: Iterable[type]) -> dict[str, OperationDescriptor]:
|
|
51
|
+
"""Collect the ``facade`` descriptors from a set of operation classes, keyed by public name.
|
|
52
|
+
|
|
53
|
+
Concrete backend operations inherit their interface's descriptor, so several classes may yield
|
|
54
|
+
the same descriptor; they are de-duplicated by ``descriptor.name`` (first one wins).
|
|
55
|
+
"""
|
|
56
|
+
descriptors: dict[str, OperationDescriptor] = {}
|
|
57
|
+
for operation in operations:
|
|
58
|
+
descriptor = getattr(operation, 'facade', None)
|
|
59
|
+
if isinstance(descriptor, OperationDescriptor):
|
|
60
|
+
descriptors.setdefault(descriptor.name, descriptor)
|
|
61
|
+
return descriptors
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from flamapy.core.operations import Operation
|
|
4
|
+
from flamapy.core.operations.descriptor import OperationDescriptor
|
|
5
|
+
from flamapy.core.models.variability_model import VariabilityElement
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FalseOptionalFeatures(Operation):
|
|
9
|
+
"""A feature is defined as `false optional` if the selection of its parent makes the feature
|
|
10
|
+
itself selected as well, although it is defined as optional and not mandatory.
|
|
11
|
+
|
|
12
|
+
A feature in a group can be also `false optional`.
|
|
13
|
+
In general, false optional features should be marked as mandatory for maintainability purposes.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
facade = OperationDescriptor(
|
|
17
|
+
doc=(
|
|
18
|
+
'These are features that appear to be optional in the feature model, but due to\n'
|
|
19
|
+
'the constraints and dependencies, must be included in every valid product.\n'
|
|
20
|
+
'Like dead features, false optional features are usually a sign of an error in\n'
|
|
21
|
+
'the feature model.\n'
|
|
22
|
+
'\n'
|
|
23
|
+
'``backend`` selects the analysis plugin ("sat", "bdd" or "z3"); defaults to\n'
|
|
24
|
+
'sat.'
|
|
25
|
+
),
|
|
26
|
+
returns='Union[None, List[str]]',
|
|
27
|
+
name='false_optional_features', operation='FalseOptionalFeatures', default_backend='sat',
|
|
28
|
+
selectable_backend=True,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@abstractmethod
|
|
32
|
+
def get_false_optional_features(self) -> list[VariabilityElement]:
|
|
33
|
+
pass
|
{flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/metrics_operation.py
RENAMED
|
@@ -19,10 +19,10 @@ class Metrics(Operation, metaclass=ABCMeta):
|
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
21
|
filter: Optional[list[str]] = None
|
|
22
|
-
result: list[dict[str, Any]] = []
|
|
23
22
|
|
|
24
23
|
def __init__(self) -> None:
|
|
25
24
|
self.model: Optional[VariabilityModel] = None
|
|
25
|
+
self.result: list[dict[str, Any]] = []
|
|
26
26
|
|
|
27
27
|
@abstractmethod
|
|
28
28
|
def calculate_metamodel_metrics(self, model: VariabilityModel) -> list[dict[str, Any]]:
|
|
@@ -2,6 +2,7 @@ from abc import abstractmethod
|
|
|
2
2
|
|
|
3
3
|
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
|
|
4
4
|
from flamapy.core.operations import Operation
|
|
5
|
+
from flamapy.core.operations.descriptor import OperationDescriptor, Input
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
class Sampling(Operation):
|
|
@@ -9,6 +10,24 @@ class Sampling(Operation):
|
|
|
9
10
|
(or configurations) from within a variability model.
|
|
10
11
|
"""
|
|
11
12
|
|
|
13
|
+
facade = OperationDescriptor(
|
|
14
|
+
doc=(
|
|
15
|
+
'Returns a random sample of valid configurations of the given size. When\n'
|
|
16
|
+
'with_replacement is True, the same configuration may appear more than once.\n'
|
|
17
|
+
'\n'
|
|
18
|
+
'``backend`` selects the analysis plugin; defaults to bdd. sat and bdd\n'
|
|
19
|
+
'implement (deterministic/enumerating) sampling; "sharpsat" provides almost-\n'
|
|
20
|
+
'uniform sampling via the optional flamapy-sharpsat plugin.'
|
|
21
|
+
),
|
|
22
|
+
returns='Union[None, List[Configuration]]',
|
|
23
|
+
name='sampling', operation='Sampling', default_backend='bdd',
|
|
24
|
+
selectable_backend=True,
|
|
25
|
+
inputs=(
|
|
26
|
+
Input('size', int, required=True, setter='set_sample_size'),
|
|
27
|
+
Input('with_replacement', bool, default=False, setter='set_with_replacement'),
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
|
|
12
31
|
@abstractmethod
|
|
13
32
|
def __init__(self) -> None:
|
|
14
33
|
pass
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from flamapy.core.operations import Operation
|
|
4
|
+
from flamapy.core.operations.descriptor import OperationDescriptor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Satisfiable(Operation):
|
|
8
|
+
facade = OperationDescriptor(
|
|
9
|
+
doc=(
|
|
10
|
+
'In the context of feature models, this usually refers to whether the feature\n'
|
|
11
|
+
'model itself satisfies all the constraints and dependencies. A a valid feature\n'
|
|
12
|
+
'model is one that does encodes at least a single valid product.\n'
|
|
13
|
+
'\n'
|
|
14
|
+
'``backend`` selects the analysis plugin ("sat", "bdd" or "z3"); defaults to\n'
|
|
15
|
+
'sat.'
|
|
16
|
+
),
|
|
17
|
+
returns='Union[None, bool]',
|
|
18
|
+
name='satisfiable', operation='Satisfiable', default_backend='sat',
|
|
19
|
+
selectable_backend=True,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
@abstractmethod
|
|
23
|
+
def __init__(self) -> None:
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
@abstractmethod
|
|
27
|
+
def is_satisfiable(self) -> bool:
|
|
28
|
+
pass
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
from typing import Any
|
|
3
|
+
|
|
4
|
+
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
|
|
5
|
+
from flamapy.core.operations import Operation
|
|
6
|
+
from flamapy.core.operations.descriptor import OperationDescriptor, Input
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _satisfiable_configuration_inputs(operation: Any, facade: Any, kwargs: dict[str, Any]) -> None:
|
|
10
|
+
configuration = facade._as_configuration(kwargs['configuration_path'])
|
|
11
|
+
configuration.is_full = bool(kwargs.get('full_configuration', False))
|
|
12
|
+
operation.set_configuration(configuration)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SatisfiableConfiguration(Operation):
|
|
16
|
+
facade = OperationDescriptor(
|
|
17
|
+
doc=(
|
|
18
|
+
'This is a product that is produced from a valid configuration of features. A\n'
|
|
19
|
+
'valid product satisfies all the constraints and dependencies in the feature\n'
|
|
20
|
+
'model.\n'
|
|
21
|
+
'\n'
|
|
22
|
+
'``configuration_path`` accepts a configuration file path, a ``{feature:\n'
|
|
23
|
+
'value}`` mapping, or a Configuration object. ``backend`` selects the analysis\n'
|
|
24
|
+
'plugin ("sat", "bdd" or "z3"); defaults to sat.'
|
|
25
|
+
),
|
|
26
|
+
returns='Union[None, bool]',
|
|
27
|
+
name='satisfiable_configuration', operation='SatisfiableConfiguration',
|
|
28
|
+
default_backend='sat', selectable_backend=True,
|
|
29
|
+
inputs=(
|
|
30
|
+
Input('configuration_path', str, required=True, kind='configuration',
|
|
31
|
+
setter='set_configuration'),
|
|
32
|
+
Input('full_configuration', bool, default=False),
|
|
33
|
+
),
|
|
34
|
+
input_adapter=_satisfiable_configuration_inputs,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@abstractmethod
|
|
38
|
+
def __init__(self) -> None:
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
@abstractmethod
|
|
42
|
+
def set_configuration(self, configuration: Configuration) -> None:
|
|
43
|
+
pass
|
|
44
|
+
|
|
45
|
+
@abstractmethod
|
|
46
|
+
def is_satisfiable(self) -> bool:
|
|
47
|
+
pass
|
|
@@ -15,7 +15,7 @@ from flamapy.core.transformations import (
|
|
|
15
15
|
ModelToText,
|
|
16
16
|
ModelToModel,
|
|
17
17
|
)
|
|
18
|
-
from flamapy.core.utils import
|
|
18
|
+
from flamapy.core.utils import filename_matches_extension
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class Transformations(UserList[Type[Transformation]]):
|
|
@@ -30,11 +30,7 @@ class Operations(UserList[Type[Operation]]):
|
|
|
30
30
|
lambda op: name in [op.__name__, op.__base__.__name__ if op.__base__ else ""], self.data
|
|
31
31
|
)
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
operation = next(candidates, None)
|
|
35
|
-
except StopIteration:
|
|
36
|
-
raise OperationNotFound(f"Operation '{name}' not found.") from StopIteration
|
|
37
|
-
|
|
33
|
+
operation = next(candidates, None)
|
|
38
34
|
if not operation:
|
|
39
35
|
raise OperationNotFound(f"Operation '{name}' not found.")
|
|
40
36
|
return operation
|
|
@@ -51,11 +47,7 @@ class Plugin:
|
|
|
51
47
|
self, filter_transformation: Callable[..., bool]
|
|
52
48
|
) -> Type[Transformation]:
|
|
53
49
|
candidates = filter(filter_transformation, self.transformations)
|
|
54
|
-
|
|
55
|
-
transformation = next(candidates, None)
|
|
56
|
-
except StopIteration:
|
|
57
|
-
raise TransformationNotFound from StopIteration
|
|
58
|
-
|
|
50
|
+
transformation = next(candidates, None)
|
|
59
51
|
if not transformation:
|
|
60
52
|
raise TransformationNotFound
|
|
61
53
|
return transformation
|
|
@@ -74,32 +66,30 @@ class Plugin:
|
|
|
74
66
|
return operation.execute(model=src)
|
|
75
67
|
|
|
76
68
|
def use_transformation_t2m(self, src: str) -> VariabilityModel:
|
|
77
|
-
extension
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
69
|
+
# Prefer the most specific matching extension (e.g. 'uvl.json' over 'json').
|
|
70
|
+
candidates = [
|
|
71
|
+
transformation
|
|
72
|
+
for transformation in self.transformations
|
|
73
|
+
if issubclass(transformation, TextToModel)
|
|
74
|
+
and filename_matches_extension(src, transformation.get_source_extension())
|
|
75
|
+
]
|
|
76
|
+
if not candidates:
|
|
77
|
+
raise TransformationNotFound
|
|
78
|
+
transformation = max(candidates, key=lambda t: len(t.get_source_extension()))
|
|
88
79
|
result = transformation(src)
|
|
89
80
|
return result.transform()
|
|
90
81
|
|
|
91
82
|
def use_transformation_m2t(self, src: VariabilityModel, dst: str) -> str:
|
|
92
|
-
extension
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
)
|
|
83
|
+
# Prefer the most specific matching extension (e.g. 'uvl.json' over 'json').
|
|
84
|
+
candidates = [
|
|
85
|
+
transformation
|
|
86
|
+
for transformation in self.transformations
|
|
87
|
+
if issubclass(transformation, ModelToText)
|
|
88
|
+
and filename_matches_extension(dst, transformation.get_destination_extension())
|
|
89
|
+
]
|
|
90
|
+
if not candidates:
|
|
91
|
+
raise TransformationNotFound
|
|
92
|
+
transformation = max(candidates, key=lambda t: len(t.get_destination_extension()))
|
|
103
93
|
result = transformation(path=dst, source_model=src)
|
|
104
94
|
return result.transform()
|
|
105
95
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def extract_filename_extension(filename: str) -> str:
|
|
5
|
+
return filename.rsplit(".", maxsplit=1)[-1]
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def filename_matches_extension(filename: str, extension: str) -> bool:
|
|
9
|
+
"""Whether the filename ends with the given extension.
|
|
10
|
+
|
|
11
|
+
Supports compound extensions such as 'uvl.json'.
|
|
12
|
+
"""
|
|
13
|
+
return filename.endswith(f".{extension}")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def file_exists(filepath: str) -> bool:
|
|
17
|
+
return os.path.isfile(filepath)
|
|
@@ -30,10 +30,25 @@ class Configuration(VariabilityModel):
|
|
|
30
30
|
def __init__(self, elements: dict[Any, Any]) -> None:
|
|
31
31
|
self.elements: dict[Any, Any] = elements
|
|
32
32
|
self.is_full: bool = False
|
|
33
|
+
# Optional decision provenance: element -> 'user' or 'propagated'. Empty by default
|
|
34
|
+
# and not part of the configuration's identity (equality/hash ignore it). Useful for
|
|
35
|
+
# interactive configurators that distinguish user choices from implied decisions.
|
|
36
|
+
self.provenance: dict[Any, str] = {}
|
|
33
37
|
|
|
34
38
|
def set_full(self, is_full: bool) -> None:
|
|
35
39
|
self.is_full = is_full
|
|
36
40
|
|
|
41
|
+
def set_provenance(self, element: Any, source: str) -> None:
|
|
42
|
+
"""Record whether an element's value came from the user or from propagation."""
|
|
43
|
+
self.provenance[element] = source
|
|
44
|
+
|
|
45
|
+
def get_provenance(self, element: Any) -> str:
|
|
46
|
+
"""Return 'user', 'propagated', or 'unknown' if not recorded."""
|
|
47
|
+
return self.provenance.get(element, 'unknown')
|
|
48
|
+
|
|
49
|
+
def is_user_decision(self, element: Any) -> bool:
|
|
50
|
+
return self.provenance.get(element) == 'user'
|
|
51
|
+
|
|
37
52
|
def get_selected_elements(self) -> list[Any]:
|
|
38
53
|
"""Get the list of selected elements in the configuration."""
|
|
39
54
|
return [e for e in self.elements if self.is_selected(e)]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flamapy-fw
|
|
3
|
-
Version: 2.6.0.
|
|
3
|
+
Version: 2.6.0.dev11
|
|
4
4
|
Summary: Flamapy is a Python-based AAFM framework that takes into consideration previous AAFM tool designs and enables multi-solver and multi-metamodel support for the integration of AAFM tooling on the Python ecosystem.
|
|
5
5
|
Author-email: Flamapy <flamapy@us.es>
|
|
6
6
|
License-Expression: GPL-3.0-or-later
|
|
@@ -14,6 +14,7 @@ flamapy/core/models/variability_model.py
|
|
|
14
14
|
flamapy/core/operations/__init__.py
|
|
15
15
|
flamapy/core/operations/abstract_operation.py
|
|
16
16
|
flamapy/core/operations/atomic_sets.py
|
|
17
|
+
flamapy/core/operations/attribute_optimization.py
|
|
17
18
|
flamapy/core/operations/average_branching_factor.py
|
|
18
19
|
flamapy/core/operations/commonality.py
|
|
19
20
|
flamapy/core/operations/configurations.py
|
|
@@ -21,6 +22,7 @@ flamapy/core/operations/configurations_number.py
|
|
|
21
22
|
flamapy/core/operations/core_features.py
|
|
22
23
|
flamapy/core/operations/count_leafs.py
|
|
23
24
|
flamapy/core/operations/dead_features.py
|
|
25
|
+
flamapy/core/operations/descriptor.py
|
|
24
26
|
flamapy/core/operations/error_detection.py
|
|
25
27
|
flamapy/core/operations/error_diagnosis.py
|
|
26
28
|
flamapy/core/operations/estimated_configurations_number.py
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "flamapy-fw"
|
|
7
|
-
version = "2.6.0.
|
|
7
|
+
version = "2.6.0.dev11"
|
|
8
8
|
description = "Flamapy is a Python-based AAFM framework that takes into consideration previous AAFM tool designs and enables multi-solver and multi-metamodel support for the integration of AAFM tooling on the Python ecosystem."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "GPL-3.0-or-later"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
|
|
3
|
-
from flamapy.core.operations import Operation
|
|
4
|
-
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class Configurations(Operation):
|
|
8
|
-
@abstractmethod
|
|
9
|
-
def __init__(self) -> None:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
@abstractmethod
|
|
13
|
-
def get_configurations(self) -> list[Configuration]:
|
|
14
|
-
pass
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
|
|
3
|
-
from flamapy.core.operations import Operation
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ConfigurationsNumber(Operation):
|
|
7
|
-
@abstractmethod
|
|
8
|
-
def __init__(self) -> None:
|
|
9
|
-
pass
|
|
10
|
-
|
|
11
|
-
@abstractmethod
|
|
12
|
-
def get_configurations_number(self) -> int:
|
|
13
|
-
pass
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
|
|
3
|
-
from flamapy.core.operations import Operation
|
|
4
|
-
from flamapy.core.models.variability_model import VariabilityElement
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class CoreFeatures(Operation):
|
|
8
|
-
@abstractmethod
|
|
9
|
-
def __init__(self) -> None:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
@abstractmethod
|
|
13
|
-
def get_core_features(self) -> list[VariabilityElement]:
|
|
14
|
-
pass
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
|
|
3
|
-
from flamapy.core.operations import Operation
|
|
4
|
-
from flamapy.core.models.variability_model import VariabilityElement
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class DeadFeatures(Operation):
|
|
8
|
-
@abstractmethod
|
|
9
|
-
def __init__(self) -> None:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
@abstractmethod
|
|
13
|
-
def get_dead_features(self) -> list[VariabilityElement]:
|
|
14
|
-
pass
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
|
|
3
|
-
from flamapy.core.operations import Operation
|
|
4
|
-
from flamapy.core.models.variability_model import VariabilityElement
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class FalseOptionalFeatures(Operation):
|
|
8
|
-
"""A feature is defined as `false optional` if the selection of its parent makes the feature
|
|
9
|
-
itself selected as well, although it is defined as optional and not mandatory.
|
|
10
|
-
|
|
11
|
-
A feature in a group can be also `false optional`.
|
|
12
|
-
In general, false optional features should be marked as mandatory for maintainability purposes.
|
|
13
|
-
"""
|
|
14
|
-
|
|
15
|
-
@abstractmethod
|
|
16
|
-
def get_false_optional_features(self) -> list[VariabilityElement]:
|
|
17
|
-
pass
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
from abc import abstractmethod
|
|
2
|
-
|
|
3
|
-
from flamapy.metamodels.configuration_metamodel.models.configuration import Configuration
|
|
4
|
-
from flamapy.core.operations import Operation
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class SatisfiableConfiguration(Operation):
|
|
8
|
-
@abstractmethod
|
|
9
|
-
def __init__(self) -> None:
|
|
10
|
-
pass
|
|
11
|
-
|
|
12
|
-
@abstractmethod
|
|
13
|
-
def set_configuration(self, configuration: Configuration) -> None:
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
@abstractmethod
|
|
17
|
-
def is_satisfiable(self) -> bool:
|
|
18
|
-
pass
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/abstract_operation.py
RENAMED
|
File without changes
|
|
File without changes
|
{flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/operations/average_branching_factor.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/model_to_model.py
RENAMED
|
File without changes
|
{flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/model_to_text.py
RENAMED
|
File without changes
|
{flamapy_fw-2.6.0.dev4 → flamapy_fw-2.6.0.dev11}/flamapy/core/transformations/text_to_model.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|