flamapy-bdd 2.1.0.dev1__tar.gz → 2.1.0.dev2__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_bdd-2.1.0.dev2/LICENSE +165 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/PKG-INFO +7 -18
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/models/bdd_model.py +172 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/models/utils/__init__.py +5 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/models/utils/pl_model.py +178 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/__init__.py +5 -1
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_configurations.py +7 -8
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_configurations_number.py +7 -3
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/operations/bdd_configurations_with_n_features.py +115 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/operations/bdd_false_optional_features.py +49 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/operations/bdd_feature_inclusion_probability.py +200 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_homogeneity.py +4 -4
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/operations/bdd_product_distribution.py +252 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/operations/bdd_sampling.py +202 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_satisfiable.py +3 -1
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_satisfiable_configuration.py +1 -1
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_unique_features.py +10 -7
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_variability.py +1 -1
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/transformations/__init__.py +0 -4
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/dddmp_reader.py +65 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/transformations/dddmp_writer.py +18 -18
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/fm_to_bdd.py +40 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/json_reader.py +14 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/json_writer.py +34 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/pdf_writer.py +19 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/png_writer.py +19 -0
- flamapy_bdd-2.1.0.dev2/flamapy/metamodels/bdd_metamodel/transformations/svg_writer.py +19 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy_bdd.egg-info/PKG-INFO +7 -18
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy_bdd.egg-info/SOURCES.txt +4 -3
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy_bdd.egg-info/requires.txt +1 -1
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/pyproject.toml +35 -1
- flamapy_bdd-2.1.0.dev2/setup.py +3 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/tests/test_bdd_metamodel.py +41 -6
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/models/bdd_model.py +0 -198
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/models/utils/__init__.py +0 -4
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/operations/bdd_feature_inclusion_probability.py +0 -215
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/operations/bdd_product_distribution.py +0 -208
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/operations/bdd_sampling.py +0 -113
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/_bdd_writer.py +0 -42
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/dddmp_reader.py +0 -48
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/fm_to_bdd.py +0 -215
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/json_reader.py +0 -34
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/json_writer.py +0 -29
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/pdf_writer.py +0 -7
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/pickle_reader.py +0 -21
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/pickle_writer.py +0 -22
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/png_writer.py +0 -7
- flamapy_bdd-2.1.0.dev1/flamapy/metamodels/bdd_metamodel/transformations/svg_writer.py +0 -7
- flamapy_bdd-2.1.0.dev1/setup.py +0 -37
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/README.md +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/__init__.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/models/__init__.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/models/utils/txtcnf.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_commonality_factor.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_core_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_dead_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_metrics.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_pure_optional_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/bdd_variant_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/__init__.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/commonality_factor.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/feature_inclusion_probability.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/homogeneity.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/product_distribution.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/pure_optional_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/unique_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/variability.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy/metamodels/bdd_metamodel/operations/interfaces/variant_features.py +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy_bdd.egg-info/dependency_links.txt +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/flamapy_bdd.egg-info/top_level.txt +0 -0
- {flamapy_bdd-2.1.0.dev1 → flamapy_bdd-2.1.0.dev2}/setup.cfg +0 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: flamapy-bdd
|
|
3
|
-
Version: 2.1.0.
|
|
3
|
+
Version: 2.1.0.dev2
|
|
4
4
|
Summary: bdd-plugin for the automated analysis of feature models
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
10
|
-
Classifier: Operating System :: OS Independent
|
|
5
|
+
Author-email: Flamapy <flamapy@us.es>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/flamapy/bdd_metamodel
|
|
11
8
|
Requires-Python: >=3.9
|
|
12
9
|
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
13
11
|
Requires-Dist: flamapy-fw~=2.1.0.dev1
|
|
14
12
|
Requires-Dist: flamapy-fm~=2.1.0.dev1
|
|
15
|
-
Requires-Dist: dd~=0.
|
|
13
|
+
Requires-Dist: dd~=0.6.0
|
|
16
14
|
Requires-Dist: graphviz~=0.20
|
|
17
15
|
Provides-Extra: dev
|
|
18
16
|
Requires-Dist: pytest; extra == "dev"
|
|
@@ -20,16 +18,7 @@ Requires-Dist: pytest-mock; extra == "dev"
|
|
|
20
18
|
Requires-Dist: prospector; extra == "dev"
|
|
21
19
|
Requires-Dist: mypy; extra == "dev"
|
|
22
20
|
Requires-Dist: coverage; extra == "dev"
|
|
23
|
-
Dynamic:
|
|
24
|
-
Dynamic: author-email
|
|
25
|
-
Dynamic: classifier
|
|
26
|
-
Dynamic: description
|
|
27
|
-
Dynamic: description-content-type
|
|
28
|
-
Dynamic: home-page
|
|
29
|
-
Dynamic: provides-extra
|
|
30
|
-
Dynamic: requires-dist
|
|
31
|
-
Dynamic: requires-python
|
|
32
|
-
Dynamic: summary
|
|
21
|
+
Dynamic: license-file
|
|
33
22
|
|
|
34
23
|
# BDD plugin for flamapy
|
|
35
24
|
- [BDD plugin for flamapy](#bdd-plugin-for-flamapy)
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Any, Optional
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from dd.cudd import BDD
|
|
7
|
+
except ImportError:
|
|
8
|
+
from dd.autoref import BDD
|
|
9
|
+
|
|
10
|
+
from flamapy.core.models import VariabilityModel
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class BDDModel(VariabilityModel):
|
|
16
|
+
"""A Binary Decision Diagram (BDD) representation of the feature model.
|
|
17
|
+
|
|
18
|
+
It relies on the dd library: https://pypi.org/project/dd/
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
class LogicConnective(Enum):
|
|
22
|
+
NOT = "!"
|
|
23
|
+
OR = "|"
|
|
24
|
+
AND = "&"
|
|
25
|
+
IMPLIES = "=>"
|
|
26
|
+
EQUIVALENCE = "<=>"
|
|
27
|
+
XOR = "^"
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def get_extension() -> str:
|
|
31
|
+
return "bdd"
|
|
32
|
+
|
|
33
|
+
def __init__(self) -> None:
|
|
34
|
+
self.bdd: BDD = BDD() # BDD manager
|
|
35
|
+
self.root: Any = None
|
|
36
|
+
self.features_vars: dict[str, str] = {} # Mapping feature name -> variable name
|
|
37
|
+
self.vars_features: dict[str, str] = {} # Mapping variable name -> feature name
|
|
38
|
+
self.vars_order: list[str] = [] # Ordered list of variables according to the BDD
|
|
39
|
+
|
|
40
|
+
def build_bdd(self, expression: str, variables: list[str]) -> None:
|
|
41
|
+
"""Built a BDD from an expression representing a logical formula."""
|
|
42
|
+
self.bdd.configure(reordering=False) # Disable dynamic reordering for consistency
|
|
43
|
+
for var in variables:
|
|
44
|
+
self.bdd.declare(var) # Declare variables in the BDD manager
|
|
45
|
+
self.vars_order = variables # The order is crucial to detect skipped variables
|
|
46
|
+
self.root = self.bdd.add_expr(expression) # Build the logical formula (root node)
|
|
47
|
+
|
|
48
|
+
def get_expression(self) -> str:
|
|
49
|
+
""" Converts the BDD to a readable Boolean expression string."""
|
|
50
|
+
return self.bdd.to_expr(self.root)
|
|
51
|
+
|
|
52
|
+
def get_all_paths(self) -> list[dict[str, bool]]:
|
|
53
|
+
"""Transverses the BDD to find all models (paths to True)."""
|
|
54
|
+
return list(self.bdd.pick_iter(self.root))
|
|
55
|
+
|
|
56
|
+
def count_solutions(self) -> int:
|
|
57
|
+
"""Count the number of valid configurations (SAT)."""
|
|
58
|
+
return self.bdd.count(self.root, len(self.vars)) # count(node, n_vars)
|
|
59
|
+
|
|
60
|
+
def dump_structure(self) -> None:
|
|
61
|
+
"""Prints the structure of the BDD for debugging purposes."""
|
|
62
|
+
if self.root is None:
|
|
63
|
+
logger.debug("Empty BDD.")
|
|
64
|
+
return
|
|
65
|
+
|
|
66
|
+
visited = set()
|
|
67
|
+
# In dd.autoref, bdd.true is the unique terminal.
|
|
68
|
+
# bdd.false is just ~bdd.true
|
|
69
|
+
|
|
70
|
+
def _dump(node: Any, indent: str = "") -> None:
|
|
71
|
+
if node == self.bdd.true:
|
|
72
|
+
logger.debug("%s leaf: TRUE", indent)
|
|
73
|
+
return
|
|
74
|
+
if node == self.bdd.false:
|
|
75
|
+
logger.debug("%s leaf: FALSE", indent)
|
|
76
|
+
return
|
|
77
|
+
|
|
78
|
+
# We use the node object for the visited set
|
|
79
|
+
if node in visited:
|
|
80
|
+
logger.debug("%s (Ref: %s)", indent, node.var)
|
|
81
|
+
return
|
|
82
|
+
visited.add(node)
|
|
83
|
+
|
|
84
|
+
logger.debug("%s Node [Var: %s]", indent, node.var)
|
|
85
|
+
# Safe access: only internal nodes have children
|
|
86
|
+
_dump(node.low, indent + " Low: ")
|
|
87
|
+
_dump(node.high, indent + " High: ")
|
|
88
|
+
|
|
89
|
+
logger.debug("Exploring BDD (Root: %s)", self.root)
|
|
90
|
+
_dump(self.root)
|
|
91
|
+
|
|
92
|
+
def save_bdd(self,
|
|
93
|
+
path: str,
|
|
94
|
+
roots: Optional[Any] = None,
|
|
95
|
+
filetype: Optional[str] = None) -> None:
|
|
96
|
+
if filetype is None:
|
|
97
|
+
filetype = self.bdd.dump(filename=path, roots=roots)
|
|
98
|
+
else:
|
|
99
|
+
self.bdd.dump(filename=path, roots=roots, filetype=filetype)
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
def load_bdd(path: str, vars: Optional[list[str]] = None) -> 'BDDModel':
|
|
103
|
+
bdd_model = BDDModel()
|
|
104
|
+
if vars is not None:
|
|
105
|
+
for var in vars:
|
|
106
|
+
bdd_model.bdd.declare(var)
|
|
107
|
+
roots = bdd_model.bdd.load(path)
|
|
108
|
+
if isinstance(roots, dict):
|
|
109
|
+
bdd_model.root = next(iter(roots.values()))
|
|
110
|
+
elif isinstance(roots, list):
|
|
111
|
+
bdd_model.root = roots[0]
|
|
112
|
+
else:
|
|
113
|
+
bdd_model.root = roots
|
|
114
|
+
all_vars = list(bdd_model.bdd.vars)
|
|
115
|
+
sorted_vars = sorted(all_vars, key=bdd_model.bdd.level_of_var)
|
|
116
|
+
bdd_model.vars_order = sorted_vars
|
|
117
|
+
bdd_model.vars_features = {var: var for var in bdd_model.vars_order}
|
|
118
|
+
bdd_model.features_vars = {var: var for var in bdd_model.vars_order}
|
|
119
|
+
return bdd_model
|
|
120
|
+
|
|
121
|
+
def __str__(self) -> str:
|
|
122
|
+
bdd = self.bdd
|
|
123
|
+
root = self.root
|
|
124
|
+
# Recolect reachable nodes from the root
|
|
125
|
+
# This avoids counting orphan nodes that are in the manager's memory
|
|
126
|
+
reachable_nodes = set()
|
|
127
|
+
to_visit = [root]
|
|
128
|
+
while to_visit:
|
|
129
|
+
u = to_visit.pop()
|
|
130
|
+
if u not in reachable_nodes:
|
|
131
|
+
reachable_nodes.add(u)
|
|
132
|
+
if u.var is not None:
|
|
133
|
+
to_visit.extend([u.low, u.high])
|
|
134
|
+
|
|
135
|
+
result = ""
|
|
136
|
+
result += f"Total nodes in manager: {len(self.bdd)}\n"
|
|
137
|
+
result += f"Nodes in this formula: {len(reachable_nodes)}\n"
|
|
138
|
+
|
|
139
|
+
root_var = root.var if root.var is not None else "Terminal"
|
|
140
|
+
result += f"Root node: {root} (Variable: {root_var}, Negated: {root.negated})\n"
|
|
141
|
+
|
|
142
|
+
# Group nodes by level
|
|
143
|
+
# In dd, level 0 is the top (root) and goes down
|
|
144
|
+
nodes_by_level: dict[int, list[Any]] = {}
|
|
145
|
+
terminals: list[Any] = []
|
|
146
|
+
for node in reachable_nodes:
|
|
147
|
+
if node.var is not None:
|
|
148
|
+
# Get the level of the variable
|
|
149
|
+
level = bdd.level_of_var(node.var)
|
|
150
|
+
if level not in nodes_by_level:
|
|
151
|
+
nodes_by_level[level] = []
|
|
152
|
+
nodes_by_level[level].append(node)
|
|
153
|
+
else:
|
|
154
|
+
terminals.append(node)
|
|
155
|
+
|
|
156
|
+
# Print levels in order
|
|
157
|
+
for level in sorted(nodes_by_level.keys()):
|
|
158
|
+
var_name = self.vars_order[level]
|
|
159
|
+
num_nodes = len(nodes_by_level[level])
|
|
160
|
+
result += f"Level {level:2} | Variable: {var_name:15} | Nodes: {num_nodes}"
|
|
161
|
+
# Optional: print IDs of nodes at this level
|
|
162
|
+
node_ids = [str(n) for n in nodes_by_level[level]]
|
|
163
|
+
result += f" IDs: {', '.join(node_ids)}\n"
|
|
164
|
+
|
|
165
|
+
# Terminal nodes
|
|
166
|
+
# IIn dd (CUDD), there is only one real terminal node (True)
|
|
167
|
+
# The value False is represented as a negated edge to True
|
|
168
|
+
for t in terminals:
|
|
169
|
+
val = "TRUE" if not t.negated else "FALSE"
|
|
170
|
+
result += f"Terminal Node ID: {t} (Semantic Value: {val})\n"
|
|
171
|
+
#result += f"Expression: {self.get_expression()}\n"
|
|
172
|
+
return result
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import itertools
|
|
3
|
+
|
|
4
|
+
from flamapy.core.models.ast import ASTOperation
|
|
5
|
+
from flamapy.metamodels.fm_metamodel.models import FeatureModel, Relation, Constraint
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class PLModel():
|
|
9
|
+
"""A model representing a Prepositional Logical Formula (PL)."""
|
|
10
|
+
|
|
11
|
+
LOGIC_CONNECTIVES = {
|
|
12
|
+
"NOT": "!",
|
|
13
|
+
"OR": "|",
|
|
14
|
+
"AND": "&",
|
|
15
|
+
"IMPLIES": "=>",
|
|
16
|
+
"EQUIVALENCE": "<=>",
|
|
17
|
+
"XOR": "^"}
|
|
18
|
+
|
|
19
|
+
def __init__(self, logic_connectives: dict[str, str] = LOGIC_CONNECTIVES) -> None:
|
|
20
|
+
self.formula: str = ""
|
|
21
|
+
self.variables: set[str] = set()
|
|
22
|
+
self.logic_connectives: dict[str, str] = logic_connectives
|
|
23
|
+
|
|
24
|
+
def build_from_feature_model(self, fm_model: FeatureModel) -> str:
|
|
25
|
+
"""Builds a PL formula from a feature model."""
|
|
26
|
+
self.variables = {feature.name for feature in fm_model.get_features()}
|
|
27
|
+
self.formula = self._traverse_feature_tree(fm_model)
|
|
28
|
+
return self.formula
|
|
29
|
+
|
|
30
|
+
def _traverse_feature_tree(self, feature_model: FeatureModel) -> str:
|
|
31
|
+
"""Traverse the feature tree from the root and return the propositional formula."""
|
|
32
|
+
if feature_model is None or feature_model.root is None:
|
|
33
|
+
return ""
|
|
34
|
+
# The root is always present
|
|
35
|
+
root_feature = feature_model.root
|
|
36
|
+
formula = [root_feature.name]
|
|
37
|
+
for feature in feature_model.get_features():
|
|
38
|
+
for relation in feature.get_relations():
|
|
39
|
+
formula.append(self._get_relation_formula(relation))
|
|
40
|
+
for constraint in feature_model.get_logical_constraints():
|
|
41
|
+
formula.append(self._get_constraint_formula(constraint))
|
|
42
|
+
propositional_formula = f" {self.logic_connectives['AND']} ".join(f"({f})" for f in formula)
|
|
43
|
+
return propositional_formula
|
|
44
|
+
|
|
45
|
+
def _get_relation_formula(self, relation: Relation) -> str:
|
|
46
|
+
result = ""
|
|
47
|
+
if relation.is_mandatory():
|
|
48
|
+
result = self._get_mandatory_formula(relation)
|
|
49
|
+
elif relation.is_optional():
|
|
50
|
+
result = self._get_optional_formula(relation)
|
|
51
|
+
elif relation.is_or():
|
|
52
|
+
result = self._get_or_formula(relation)
|
|
53
|
+
elif relation.is_alternative():
|
|
54
|
+
result = self._get_alternative_formula(relation)
|
|
55
|
+
elif relation.is_mutex():
|
|
56
|
+
result = self._get_mutex_formula(relation)
|
|
57
|
+
elif relation.is_cardinal():
|
|
58
|
+
result = self._get_cardinality_formula(relation)
|
|
59
|
+
return result
|
|
60
|
+
|
|
61
|
+
def _get_mandatory_formula(self, relation: Relation) -> str:
|
|
62
|
+
parent = relation.parent.name
|
|
63
|
+
child = relation.children[0].name
|
|
64
|
+
return f"{parent} {self.logic_connectives['EQUIVALENCE']} {child}"
|
|
65
|
+
|
|
66
|
+
def _get_optional_formula(self, relation: Relation) -> str:
|
|
67
|
+
parent = relation.parent.name
|
|
68
|
+
child = relation.children[0].name
|
|
69
|
+
return f"{child} {self.logic_connectives['IMPLIES']} {parent}"
|
|
70
|
+
|
|
71
|
+
def _get_or_formula(self, relation: Relation) -> str:
|
|
72
|
+
parent = relation.parent.name
|
|
73
|
+
children = f" {self.logic_connectives['OR']} ".join(
|
|
74
|
+
child.name for child in relation.children
|
|
75
|
+
)
|
|
76
|
+
return f"{parent} {self.logic_connectives['EQUIVALENCE']} ({children})"
|
|
77
|
+
|
|
78
|
+
def _get_alternative_formula(self, relation: Relation) -> str:
|
|
79
|
+
formula = []
|
|
80
|
+
parent = relation.parent.name
|
|
81
|
+
children = {child.name for child in relation.children}
|
|
82
|
+
equiv_str = self.logic_connectives['EQUIVALENCE']
|
|
83
|
+
and_str = self.logic_connectives['AND']
|
|
84
|
+
not_str = self.logic_connectives['NOT']
|
|
85
|
+
for child in children:
|
|
86
|
+
children_negatives = children - {child}
|
|
87
|
+
neg_children = f" {and_str} ".join(not_str + ch for ch in children_negatives)
|
|
88
|
+
formula.append(f"{child} {equiv_str} ({neg_children} {and_str} {parent})")
|
|
89
|
+
return f" {and_str} ".join(f"({f})" for f in formula)
|
|
90
|
+
|
|
91
|
+
def _get_mutex_formula(self, relation: Relation) -> str:
|
|
92
|
+
formula = []
|
|
93
|
+
parent = relation.parent.name
|
|
94
|
+
children = {child.name for child in relation.children}
|
|
95
|
+
equiv_str = self.logic_connectives['EQUIVALENCE']
|
|
96
|
+
and_str = self.logic_connectives['AND']
|
|
97
|
+
not_str = self.logic_connectives['NOT']
|
|
98
|
+
or_str = self.logic_connectives['OR']
|
|
99
|
+
for child in children:
|
|
100
|
+
children_negatives = children - {child}
|
|
101
|
+
neg_children = f" {and_str} ".join(not_str + cn for cn in children_negatives)
|
|
102
|
+
formula.append(f"{child} {equiv_str} ({neg_children} {and_str} {parent})")
|
|
103
|
+
formula_str = f" {and_str} ".join(f"({f})" for f in formula)
|
|
104
|
+
children_or = f" {or_str} ".join(child for child in children)
|
|
105
|
+
left = f"({parent} {equiv_str} {not_str} ({children_or}))"
|
|
106
|
+
return f"{left} {or_str} ({formula_str})"
|
|
107
|
+
|
|
108
|
+
def _get_cardinality_formula(self, relation: Relation) -> str:
|
|
109
|
+
parent = relation.parent.name
|
|
110
|
+
children = [child.name for child in relation.children]
|
|
111
|
+
not_str = self.logic_connectives['NOT']
|
|
112
|
+
and_str = self.logic_connectives['AND']
|
|
113
|
+
or_str = self.logic_connectives['OR']
|
|
114
|
+
|
|
115
|
+
all_clauses = []
|
|
116
|
+
|
|
117
|
+
# 1. If the parent is active, prohibit combinations outside the range [min..max]
|
|
118
|
+
for val in range(len(children) + 1):
|
|
119
|
+
if val < relation.card_min or val > relation.card_max:
|
|
120
|
+
for combination in itertools.combinations(children, val):
|
|
121
|
+
# To prohibit an exact combination: (NOT parent OR NOT child1 OR child2...)
|
|
122
|
+
clause_parts = [f"{not_str}{parent}"]
|
|
123
|
+
for child in children:
|
|
124
|
+
if child in combination:
|
|
125
|
+
clause_parts.append(f"{not_str}{child}")
|
|
126
|
+
else:
|
|
127
|
+
clause_parts.append(child)
|
|
128
|
+
all_clauses.append(f"({f' {or_str} '.join(clause_parts)})")
|
|
129
|
+
|
|
130
|
+
# 2. If the parent is inactive, NO child can be active (or combinations not allowed)
|
|
131
|
+
# Following the logic of the first script to maintain consistency:
|
|
132
|
+
for val in range(1, len(children) + 1):
|
|
133
|
+
for combination in itertools.combinations(children, val):
|
|
134
|
+
clause_parts = [parent]
|
|
135
|
+
for child in children:
|
|
136
|
+
if child in combination:
|
|
137
|
+
clause_parts.append(f"{not_str}{child}")
|
|
138
|
+
else:
|
|
139
|
+
clause_parts.append(child)
|
|
140
|
+
all_clauses.append(f"({f' {or_str} '.join(clause_parts)})")
|
|
141
|
+
|
|
142
|
+
return f" {and_str} ".join(all_clauses)
|
|
143
|
+
|
|
144
|
+
def _get_constraint_formula(self, ctc: Constraint) -> str:
|
|
145
|
+
constraint_str = ctc.ast.pretty_str()
|
|
146
|
+
constraint_str = re.sub(
|
|
147
|
+
rf"\b{ASTOperation.XOR.value}\b", self.logic_connectives['XOR'], constraint_str
|
|
148
|
+
)
|
|
149
|
+
constraint_str = re.sub(
|
|
150
|
+
rf"\b{ASTOperation.NOT.value}\b", self.logic_connectives['NOT'], constraint_str
|
|
151
|
+
)
|
|
152
|
+
constraint_str = re.sub(
|
|
153
|
+
rf"\b{ASTOperation.AND.value}\b", self.logic_connectives['AND'], constraint_str
|
|
154
|
+
)
|
|
155
|
+
constraint_str = re.sub(
|
|
156
|
+
rf"\b{ASTOperation.OR.value}\b", self.logic_connectives['OR'], constraint_str
|
|
157
|
+
)
|
|
158
|
+
constraint_str = re.sub(
|
|
159
|
+
rf"\b{ASTOperation.IMPLIES.value}\b",
|
|
160
|
+
self.logic_connectives['IMPLIES'],
|
|
161
|
+
constraint_str,
|
|
162
|
+
)
|
|
163
|
+
constraint_str = re.sub(
|
|
164
|
+
rf"\b{ASTOperation.EQUIVALENCE.value}\b",
|
|
165
|
+
self.logic_connectives['EQUIVALENCE'],
|
|
166
|
+
constraint_str,
|
|
167
|
+
)
|
|
168
|
+
constraint_str = re.sub(
|
|
169
|
+
rf"\b{ASTOperation.REQUIRES.value}\b",
|
|
170
|
+
self.logic_connectives['IMPLIES'],
|
|
171
|
+
constraint_str,
|
|
172
|
+
)
|
|
173
|
+
constraint_str = re.sub(
|
|
174
|
+
rf"\b{ASTOperation.EXCLUDES.value}\b",
|
|
175
|
+
f"{self.logic_connectives['IMPLIES']} {self.logic_connectives['NOT']}",
|
|
176
|
+
constraint_str,
|
|
177
|
+
)
|
|
178
|
+
return constraint_str
|
|
@@ -14,14 +14,18 @@ from .bdd_commonality_factor import BDDCommonalityFactor
|
|
|
14
14
|
from .bdd_homogeneity import BDDHomogeneity
|
|
15
15
|
from .bdd_metrics import BDDMetrics
|
|
16
16
|
from .bdd_satisfiable_configuration import BDDSatisfiableConfiguration
|
|
17
|
+
from .bdd_false_optional_features import BDDFalseOptionalFeatures
|
|
18
|
+
from .bdd_configurations_with_n_features import BDDConfigurationsWithNFeatures
|
|
17
19
|
|
|
18
20
|
|
|
19
21
|
__all__ = [
|
|
20
22
|
"BDDCommonalityFactor",
|
|
21
23
|
"BDDConfigurations",
|
|
22
24
|
"BDDConfigurationsNumber",
|
|
25
|
+
"BDDConfigurationsWithNFeatures",
|
|
23
26
|
"BDDCoreFeatures",
|
|
24
27
|
"BDDDeadFeatures",
|
|
28
|
+
"BDDFalseOptionalFeatures",
|
|
25
29
|
"BDDFeatureInclusionProbability",
|
|
26
30
|
"BDDHomogeneity",
|
|
27
31
|
"BDDMetrics",
|
|
@@ -32,5 +36,5 @@ __all__ = [
|
|
|
32
36
|
"BDDSatisfiableConfiguration",
|
|
33
37
|
"BDDUniqueFeatures",
|
|
34
38
|
"BDDVariability",
|
|
35
|
-
"BDDVariantFeatures"
|
|
39
|
+
"BDDVariantFeatures"
|
|
36
40
|
]
|
|
@@ -36,22 +36,21 @@ def configurations(
|
|
|
36
36
|
) -> list[Configuration]:
|
|
37
37
|
if partial_config is None:
|
|
38
38
|
u_func = bdd_model.root
|
|
39
|
-
care_vars = set(bdd_model.
|
|
39
|
+
care_vars = set(bdd_model.vars_order)
|
|
40
40
|
elements = {}
|
|
41
41
|
else:
|
|
42
|
-
values = {bdd_model.
|
|
42
|
+
values = {bdd_model.features_vars[f]: selected
|
|
43
43
|
for f, selected in partial_config.elements.items()}
|
|
44
44
|
u_func = bdd_model.bdd.let(values, bdd_model.root)
|
|
45
|
-
care_vars = set(bdd_model.
|
|
46
|
-
elements =
|
|
47
|
-
for f, selected in partial_config.elements.items()}
|
|
45
|
+
care_vars = set(bdd_model.vars_order) - set(values.keys())
|
|
46
|
+
elements = partial_config.elements.items()
|
|
48
47
|
|
|
49
48
|
configs = []
|
|
50
49
|
for assignment in bdd_model.bdd.pick_iter(u_func, care_vars=care_vars):
|
|
51
50
|
features = {
|
|
52
|
-
bdd_model.
|
|
51
|
+
bdd_model.vars_features[f]: True for f in assignment.keys() if assignment[f]
|
|
53
52
|
}
|
|
53
|
+
|
|
54
54
|
features = features | elements
|
|
55
|
-
|
|
56
|
-
configs.append(Configuration(new_features))
|
|
55
|
+
configs.append(Configuration(features))
|
|
57
56
|
return configs
|
|
@@ -36,12 +36,16 @@ def configurations_number(
|
|
|
36
36
|
) -> int:
|
|
37
37
|
if partial_configuration is None:
|
|
38
38
|
u_func = bdd_model.root
|
|
39
|
-
n_vars = len(bdd_model.
|
|
39
|
+
n_vars = len(bdd_model.vars_order)
|
|
40
40
|
else:
|
|
41
41
|
values = {
|
|
42
|
-
bdd_model.
|
|
42
|
+
bdd_model.features_vars[f]: selected
|
|
43
43
|
for f, selected in partial_configuration.elements.items()
|
|
44
44
|
}
|
|
45
|
+
if partial_configuration.is_full:
|
|
46
|
+
for feature, variable in bdd_model.features_vars.items():
|
|
47
|
+
if feature not in partial_configuration.elements:
|
|
48
|
+
values[variable] = False
|
|
45
49
|
u_func = bdd_model.bdd.let(values, bdd_model.root)
|
|
46
|
-
n_vars = len(bdd_model.
|
|
50
|
+
n_vars = len(bdd_model.vars_order) - len(values)
|
|
47
51
|
return int(bdd_model.bdd.count(u_func, nvars=n_vars))
|