flamapy-sdd 2.6.0__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_sdd-2.6.0/LICENSE +165 -0
- flamapy_sdd-2.6.0/PKG-INFO +66 -0
- flamapy_sdd-2.6.0/README.md +45 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/__init__.py +0 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/models/__init__.py +4 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/models/sdd_model.py +27 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/operations/__init__.py +12 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/operations/sdd_configurations_number.py +29 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/operations/sdd_core_features.py +32 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/operations/sdd_dead_features.py +32 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/operations/sdd_satisfiable.py +23 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/transformations/__init__.py +4 -0
- flamapy_sdd-2.6.0/flamapy/metamodels/sdd_metamodel/transformations/fm_to_sdd.py +48 -0
- flamapy_sdd-2.6.0/flamapy_sdd.egg-info/PKG-INFO +66 -0
- flamapy_sdd-2.6.0/flamapy_sdd.egg-info/SOURCES.txt +20 -0
- flamapy_sdd-2.6.0/flamapy_sdd.egg-info/dependency_links.txt +1 -0
- flamapy_sdd-2.6.0/flamapy_sdd.egg-info/requires.txt +10 -0
- flamapy_sdd-2.6.0/flamapy_sdd.egg-info/top_level.txt +1 -0
- flamapy_sdd-2.6.0/pyproject.toml +76 -0
- flamapy_sdd-2.6.0/setup.cfg +4 -0
- flamapy_sdd-2.6.0/setup.py +3 -0
- flamapy_sdd-2.6.0/tests/test_sdd.py +108 -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.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flamapy-sdd
|
|
3
|
+
Version: 2.6.0
|
|
4
|
+
Summary: flamapy-sdd is a plugin to flamapy providing Sentential Decision Diagram (SDD) knowledge compilation for exact analysis of feature models
|
|
5
|
+
Author-email: Flamapy <flamapy@us.es>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/flamapy/sdd_metamodel
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: flamapy-fw~=2.6.0
|
|
12
|
+
Requires-Dist: flamapy-fm~=2.6.0
|
|
13
|
+
Requires-Dist: PySDD~=1.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
17
|
+
Requires-Dist: prospector; extra == "dev"
|
|
18
|
+
Requires-Dist: mypy; extra == "dev"
|
|
19
|
+
Requires-Dist: coverage; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# flamapy-sdd
|
|
23
|
+
|
|
24
|
+
`flamapy-sdd` is a [flamapy](https://flamapy.github.io) plugin that compiles a feature model
|
|
25
|
+
into a **Sentential Decision Diagram (SDD)** for exact analysis.
|
|
26
|
+
|
|
27
|
+
SDD is a knowledge-compilation language (a subset of d-DNNF, strictly more succinct than OBDD
|
|
28
|
+
in cases), so it supports exact, polytime queries — model counting, consistency, conditioning —
|
|
29
|
+
and can stay compact on models where a BDD blows up. It complements the ecosystem:
|
|
30
|
+
|
|
31
|
+
- `flamapy-bdd` compiles to OBDD (exact, but can explode on large models).
|
|
32
|
+
- `flamapy-sharpsat` gives an *approximate* count (ApproxMC) for very large models.
|
|
33
|
+
- `flamapy-sdd` gives an **exact** count via a more succinct compilation, on top of the SAT CNF.
|
|
34
|
+
|
|
35
|
+
It uses [PySDD](https://github.com/wannesm/PySDD).
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
pip install flamapy-sdd
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Operations
|
|
44
|
+
|
|
45
|
+
| Operation | Class |
|
|
46
|
+
|---|---|
|
|
47
|
+
| Exact number of configurations | `SDDConfigurationsNumber` |
|
|
48
|
+
| Satisfiable (non-void) | `SDDSatisfiable` |
|
|
49
|
+
| Core features | `SDDCoreFeatures` |
|
|
50
|
+
| Dead features | `SDDDeadFeatures` |
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from flamapy.metamodels.fm_metamodel.transformations import UVLReader
|
|
56
|
+
from flamapy.metamodels.sdd_metamodel.transformations import FmToSDD
|
|
57
|
+
from flamapy.metamodels.sdd_metamodel.operations import SDDConfigurationsNumber
|
|
58
|
+
|
|
59
|
+
fm = UVLReader('model.uvl').transform()
|
|
60
|
+
sdd_model = FmToSDD(fm).transform()
|
|
61
|
+
count = SDDConfigurationsNumber().execute(sdd_model).get_result()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
GPL-3.0-or-later.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# flamapy-sdd
|
|
2
|
+
|
|
3
|
+
`flamapy-sdd` is a [flamapy](https://flamapy.github.io) plugin that compiles a feature model
|
|
4
|
+
into a **Sentential Decision Diagram (SDD)** for exact analysis.
|
|
5
|
+
|
|
6
|
+
SDD is a knowledge-compilation language (a subset of d-DNNF, strictly more succinct than OBDD
|
|
7
|
+
in cases), so it supports exact, polytime queries — model counting, consistency, conditioning —
|
|
8
|
+
and can stay compact on models where a BDD blows up. It complements the ecosystem:
|
|
9
|
+
|
|
10
|
+
- `flamapy-bdd` compiles to OBDD (exact, but can explode on large models).
|
|
11
|
+
- `flamapy-sharpsat` gives an *approximate* count (ApproxMC) for very large models.
|
|
12
|
+
- `flamapy-sdd` gives an **exact** count via a more succinct compilation, on top of the SAT CNF.
|
|
13
|
+
|
|
14
|
+
It uses [PySDD](https://github.com/wannesm/PySDD).
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
pip install flamapy-sdd
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Operations
|
|
23
|
+
|
|
24
|
+
| Operation | Class |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Exact number of configurations | `SDDConfigurationsNumber` |
|
|
27
|
+
| Satisfiable (non-void) | `SDDSatisfiable` |
|
|
28
|
+
| Core features | `SDDCoreFeatures` |
|
|
29
|
+
| Dead features | `SDDDeadFeatures` |
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from flamapy.metamodels.fm_metamodel.transformations import UVLReader
|
|
35
|
+
from flamapy.metamodels.sdd_metamodel.transformations import FmToSDD
|
|
36
|
+
from flamapy.metamodels.sdd_metamodel.operations import SDDConfigurationsNumber
|
|
37
|
+
|
|
38
|
+
fm = UVLReader('model.uvl').transform()
|
|
39
|
+
sdd_model = FmToSDD(fm).transform()
|
|
40
|
+
count = SDDConfigurationsNumber().execute(sdd_model).get_result()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
GPL-3.0-or-later.
|
|
File without changes
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from typing import Any, Optional
|
|
2
|
+
|
|
3
|
+
from flamapy.core.models import VariabilityModel
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class SDDModel(VariabilityModel):
|
|
7
|
+
"""A Sentential Decision Diagram (SDD) representation of a feature model.
|
|
8
|
+
|
|
9
|
+
An SDD is a knowledge-compilation form (a subset of d-DNNF, strictly more succinct than
|
|
10
|
+
OBDD in cases) that supports exact, polytime queries: model counting, consistency and
|
|
11
|
+
conditioning. It is built by compiling the feature model's CNF with the ``PySDD`` library.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
@staticmethod
|
|
15
|
+
def get_extension() -> str:
|
|
16
|
+
return 'sdd'
|
|
17
|
+
|
|
18
|
+
def __init__(self) -> None:
|
|
19
|
+
self.manager: Any = None # pysdd SddManager
|
|
20
|
+
self.root: Any = None # pysdd SddNode (the compiled formula)
|
|
21
|
+
self.variables: dict[str, int] = {} # feature name -> SDD variable index (1-based)
|
|
22
|
+
self.features: dict[int, str] = {} # SDD variable index -> feature name
|
|
23
|
+
self.original_model: Optional[VariabilityModel] = None
|
|
24
|
+
|
|
25
|
+
def feature_variables(self) -> list[int]:
|
|
26
|
+
"""SDD variable indices that correspond to features."""
|
|
27
|
+
return list(self.features.keys())
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .sdd_configurations_number import SDDConfigurationsNumber
|
|
2
|
+
from .sdd_satisfiable import SDDSatisfiable
|
|
3
|
+
from .sdd_core_features import SDDCoreFeatures
|
|
4
|
+
from .sdd_dead_features import SDDDeadFeatures
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
'SDDConfigurationsNumber',
|
|
9
|
+
'SDDCoreFeatures',
|
|
10
|
+
'SDDDeadFeatures',
|
|
11
|
+
'SDDSatisfiable',
|
|
12
|
+
]
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
from typing import cast
|
|
2
|
+
|
|
3
|
+
from flamapy.core.models import VariabilityModel
|
|
4
|
+
from flamapy.core.operations import ConfigurationsNumber
|
|
5
|
+
from flamapy.metamodels.sdd_metamodel.models import SDDModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SDDConfigurationsNumber(ConfigurationsNumber):
|
|
9
|
+
"""Exact number of valid configurations, via SDD model counting.
|
|
10
|
+
|
|
11
|
+
Model counting is a polytime query on the compiled SDD, so this is exact and — for models
|
|
12
|
+
whose SDD stays compact — scales to cases where explicit enumeration does not.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self._result = 0
|
|
17
|
+
|
|
18
|
+
def get_configurations_number(self) -> int:
|
|
19
|
+
return self._result
|
|
20
|
+
|
|
21
|
+
def get_result(self) -> int:
|
|
22
|
+
return self._result
|
|
23
|
+
|
|
24
|
+
def execute(self, model: VariabilityModel) -> 'SDDConfigurationsNumber':
|
|
25
|
+
sdd_model = cast(SDDModel, model)
|
|
26
|
+
# global_model_count counts over every declared variable; SddNode.model_count only
|
|
27
|
+
# counts over the variables the node locally depends on (its own vtree context).
|
|
28
|
+
self._result = int(sdd_model.manager.global_model_count(sdd_model.root))
|
|
29
|
+
return self
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Any, cast
|
|
2
|
+
|
|
3
|
+
from flamapy.core.models import VariabilityModel
|
|
4
|
+
from flamapy.core.operations import CoreFeatures
|
|
5
|
+
from flamapy.metamodels.sdd_metamodel.models import SDDModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SDDCoreFeatures(CoreFeatures):
|
|
9
|
+
"""Core features: present in every valid configuration.
|
|
10
|
+
|
|
11
|
+
A feature is core iff no model selects it as false, i.e. conjoining its negative literal
|
|
12
|
+
with the compiled SDD yields the false node.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self._result: list[Any] = []
|
|
17
|
+
|
|
18
|
+
def get_core_features(self) -> list[Any]:
|
|
19
|
+
return self._result
|
|
20
|
+
|
|
21
|
+
def get_result(self) -> list[Any]:
|
|
22
|
+
return self._result
|
|
23
|
+
|
|
24
|
+
def execute(self, model: VariabilityModel) -> 'SDDCoreFeatures':
|
|
25
|
+
sdd_model = cast(SDDModel, model)
|
|
26
|
+
manager = sdd_model.manager
|
|
27
|
+
core = []
|
|
28
|
+
for variable, name in sdd_model.features.items():
|
|
29
|
+
if (sdd_model.root & manager.literal(-variable)).is_false():
|
|
30
|
+
core.append(name)
|
|
31
|
+
self._result = core
|
|
32
|
+
return self
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from typing import Any, cast
|
|
2
|
+
|
|
3
|
+
from flamapy.core.models import VariabilityModel
|
|
4
|
+
from flamapy.core.operations import DeadFeatures
|
|
5
|
+
from flamapy.metamodels.sdd_metamodel.models import SDDModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SDDDeadFeatures(DeadFeatures):
|
|
9
|
+
"""Dead features: present in no valid configuration.
|
|
10
|
+
|
|
11
|
+
A feature is dead iff no model selects it as true, i.e. conjoining its positive literal
|
|
12
|
+
with the compiled SDD yields the false node.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def __init__(self) -> None:
|
|
16
|
+
self._result: list[Any] = []
|
|
17
|
+
|
|
18
|
+
def get_dead_features(self) -> list[Any]:
|
|
19
|
+
return self._result
|
|
20
|
+
|
|
21
|
+
def get_result(self) -> list[Any]:
|
|
22
|
+
return self._result
|
|
23
|
+
|
|
24
|
+
def execute(self, model: VariabilityModel) -> 'SDDDeadFeatures':
|
|
25
|
+
sdd_model = cast(SDDModel, model)
|
|
26
|
+
manager = sdd_model.manager
|
|
27
|
+
dead = []
|
|
28
|
+
for variable, name in sdd_model.features.items():
|
|
29
|
+
if (sdd_model.root & manager.literal(variable)).is_false():
|
|
30
|
+
dead.append(name)
|
|
31
|
+
self._result = dead
|
|
32
|
+
return self
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from typing import cast
|
|
2
|
+
|
|
3
|
+
from flamapy.core.models import VariabilityModel
|
|
4
|
+
from flamapy.core.operations import Satisfiable
|
|
5
|
+
from flamapy.metamodels.sdd_metamodel.models import SDDModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SDDSatisfiable(Satisfiable):
|
|
9
|
+
"""Whether the feature model is satisfiable (non-void): the SDD is not the false node."""
|
|
10
|
+
|
|
11
|
+
def __init__(self) -> None:
|
|
12
|
+
self._result = False
|
|
13
|
+
|
|
14
|
+
def is_satisfiable(self) -> bool:
|
|
15
|
+
return self._result
|
|
16
|
+
|
|
17
|
+
def get_result(self) -> bool:
|
|
18
|
+
return self._result
|
|
19
|
+
|
|
20
|
+
def execute(self, model: VariabilityModel) -> 'SDDSatisfiable':
|
|
21
|
+
sdd_model = cast(SDDModel, model)
|
|
22
|
+
self._result = not sdd_model.root.is_false()
|
|
23
|
+
return self
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from pysdd.sdd import SddManager, Vtree
|
|
2
|
+
|
|
3
|
+
from flamapy.core.transformations import ModelToModel
|
|
4
|
+
from flamapy.metamodels.fm_metamodel.models import FeatureModel, ClauseSet
|
|
5
|
+
from flamapy.metamodels.sdd_metamodel.models import SDDModel
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class FmToSDD(ModelToModel):
|
|
9
|
+
"""Transform a feature model into an SDD by compiling its CNF with PySDD.
|
|
10
|
+
|
|
11
|
+
The CNF is produced by the feature-model ``ClauseSet`` (no SAT-solver dependency), then
|
|
12
|
+
conjoined clause by clause into an SDD over a balanced vtree.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
@staticmethod
|
|
16
|
+
def get_source_extension() -> str:
|
|
17
|
+
return 'fm'
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def get_destination_extension() -> str:
|
|
21
|
+
return 'sdd'
|
|
22
|
+
|
|
23
|
+
def __init__(self, source_model: FeatureModel, cnf_method: str = 'distributive') -> None:
|
|
24
|
+
self.source_model = source_model
|
|
25
|
+
self.cnf_method = cnf_method
|
|
26
|
+
self.destination_model = SDDModel()
|
|
27
|
+
|
|
28
|
+
def transform(self) -> SDDModel:
|
|
29
|
+
clause_set = ClauseSet.from_feature_model(self.source_model, cnf_method=self.cnf_method)
|
|
30
|
+
clauses = [list(clause) for clause in clause_set.clauses]
|
|
31
|
+
var_count = max((abs(literal) for clause in clauses for literal in clause), default=1)
|
|
32
|
+
|
|
33
|
+
vtree = Vtree(var_count=var_count, vtree_type='balanced')
|
|
34
|
+
manager = SddManager.from_vtree(vtree)
|
|
35
|
+
root = manager.true()
|
|
36
|
+
for clause in clauses:
|
|
37
|
+
clause_node = manager.false()
|
|
38
|
+
for literal in clause:
|
|
39
|
+
clause_node = clause_node | manager.literal(literal)
|
|
40
|
+
root = root & clause_node
|
|
41
|
+
|
|
42
|
+
model = self.destination_model
|
|
43
|
+
model.manager = manager
|
|
44
|
+
model.root = root
|
|
45
|
+
model.variables = dict(clause_set.variables)
|
|
46
|
+
model.features = dict(clause_set.features)
|
|
47
|
+
model.original_model = self.source_model
|
|
48
|
+
return model
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: flamapy-sdd
|
|
3
|
+
Version: 2.6.0
|
|
4
|
+
Summary: flamapy-sdd is a plugin to flamapy providing Sentential Decision Diagram (SDD) knowledge compilation for exact analysis of feature models
|
|
5
|
+
Author-email: Flamapy <flamapy@us.es>
|
|
6
|
+
License-Expression: GPL-3.0-or-later
|
|
7
|
+
Project-URL: Homepage, https://github.com/flamapy/sdd_metamodel
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: flamapy-fw~=2.6.0
|
|
12
|
+
Requires-Dist: flamapy-fm~=2.6.0
|
|
13
|
+
Requires-Dist: PySDD~=1.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest; extra == "dev"
|
|
16
|
+
Requires-Dist: pytest-mock; extra == "dev"
|
|
17
|
+
Requires-Dist: prospector; extra == "dev"
|
|
18
|
+
Requires-Dist: mypy; extra == "dev"
|
|
19
|
+
Requires-Dist: coverage; extra == "dev"
|
|
20
|
+
Dynamic: license-file
|
|
21
|
+
|
|
22
|
+
# flamapy-sdd
|
|
23
|
+
|
|
24
|
+
`flamapy-sdd` is a [flamapy](https://flamapy.github.io) plugin that compiles a feature model
|
|
25
|
+
into a **Sentential Decision Diagram (SDD)** for exact analysis.
|
|
26
|
+
|
|
27
|
+
SDD is a knowledge-compilation language (a subset of d-DNNF, strictly more succinct than OBDD
|
|
28
|
+
in cases), so it supports exact, polytime queries — model counting, consistency, conditioning —
|
|
29
|
+
and can stay compact on models where a BDD blows up. It complements the ecosystem:
|
|
30
|
+
|
|
31
|
+
- `flamapy-bdd` compiles to OBDD (exact, but can explode on large models).
|
|
32
|
+
- `flamapy-sharpsat` gives an *approximate* count (ApproxMC) for very large models.
|
|
33
|
+
- `flamapy-sdd` gives an **exact** count via a more succinct compilation, on top of the SAT CNF.
|
|
34
|
+
|
|
35
|
+
It uses [PySDD](https://github.com/wannesm/PySDD).
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
pip install flamapy-sdd
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Operations
|
|
44
|
+
|
|
45
|
+
| Operation | Class |
|
|
46
|
+
|---|---|
|
|
47
|
+
| Exact number of configurations | `SDDConfigurationsNumber` |
|
|
48
|
+
| Satisfiable (non-void) | `SDDSatisfiable` |
|
|
49
|
+
| Core features | `SDDCoreFeatures` |
|
|
50
|
+
| Dead features | `SDDDeadFeatures` |
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from flamapy.metamodels.fm_metamodel.transformations import UVLReader
|
|
56
|
+
from flamapy.metamodels.sdd_metamodel.transformations import FmToSDD
|
|
57
|
+
from flamapy.metamodels.sdd_metamodel.operations import SDDConfigurationsNumber
|
|
58
|
+
|
|
59
|
+
fm = UVLReader('model.uvl').transform()
|
|
60
|
+
sdd_model = FmToSDD(fm).transform()
|
|
61
|
+
count = SDDConfigurationsNumber().execute(sdd_model).get_result()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## License
|
|
65
|
+
|
|
66
|
+
GPL-3.0-or-later.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
flamapy/metamodels/sdd_metamodel/__init__.py
|
|
6
|
+
flamapy/metamodels/sdd_metamodel/models/__init__.py
|
|
7
|
+
flamapy/metamodels/sdd_metamodel/models/sdd_model.py
|
|
8
|
+
flamapy/metamodels/sdd_metamodel/operations/__init__.py
|
|
9
|
+
flamapy/metamodels/sdd_metamodel/operations/sdd_configurations_number.py
|
|
10
|
+
flamapy/metamodels/sdd_metamodel/operations/sdd_core_features.py
|
|
11
|
+
flamapy/metamodels/sdd_metamodel/operations/sdd_dead_features.py
|
|
12
|
+
flamapy/metamodels/sdd_metamodel/operations/sdd_satisfiable.py
|
|
13
|
+
flamapy/metamodels/sdd_metamodel/transformations/__init__.py
|
|
14
|
+
flamapy/metamodels/sdd_metamodel/transformations/fm_to_sdd.py
|
|
15
|
+
flamapy_sdd.egg-info/PKG-INFO
|
|
16
|
+
flamapy_sdd.egg-info/SOURCES.txt
|
|
17
|
+
flamapy_sdd.egg-info/dependency_links.txt
|
|
18
|
+
flamapy_sdd.egg-info/requires.txt
|
|
19
|
+
flamapy_sdd.egg-info/top_level.txt
|
|
20
|
+
tests/test_sdd.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
flamapy
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "flamapy-sdd"
|
|
7
|
+
version = "2.6.0"
|
|
8
|
+
description = "flamapy-sdd is a plugin to flamapy providing Sentential Decision Diagram (SDD) knowledge compilation for exact analysis of feature models"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "GPL-3.0-or-later"
|
|
11
|
+
authors = [{ name = "Flamapy", email = "flamapy@us.es" }]
|
|
12
|
+
requires-python = ">=3.11"
|
|
13
|
+
dependencies = [
|
|
14
|
+
"flamapy-fw~=2.6.0",
|
|
15
|
+
"flamapy-fm~=2.6.0",
|
|
16
|
+
"PySDD~=1.0",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
[project.optional-dependencies]
|
|
20
|
+
dev = [
|
|
21
|
+
"pytest",
|
|
22
|
+
"pytest-mock",
|
|
23
|
+
"prospector",
|
|
24
|
+
"mypy",
|
|
25
|
+
"coverage",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/flamapy/sdd_metamodel"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
include = ["flamapy.*"]
|
|
33
|
+
|
|
34
|
+
[tool.ruff]
|
|
35
|
+
line-length = 100
|
|
36
|
+
target-version = "py311"
|
|
37
|
+
|
|
38
|
+
[tool.ruff.lint]
|
|
39
|
+
select = ["E", "W", "F", "C", "PL", "RUF"]
|
|
40
|
+
ignore = [
|
|
41
|
+
"RUF012",
|
|
42
|
+
"RUF002",
|
|
43
|
+
"RUF001",
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
[tool.ruff.lint.mccabe]
|
|
47
|
+
max-complexity = 10
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint.per-file-ignores]
|
|
50
|
+
"tests/*" = ["ALL"]
|
|
51
|
+
"build/*" = ["ALL"]
|
|
52
|
+
"resources/*" = ["ALL"]
|
|
53
|
+
".mypy_cache/*" = ["ALL"]
|
|
54
|
+
"venv/*" = ["ALL"]
|
|
55
|
+
".venv/*" = ["ALL"]
|
|
56
|
+
"env/*" = ["ALL"]
|
|
57
|
+
"flamapy_sdd.egg-info/*" = ["ALL"]
|
|
58
|
+
"__pycache__/*" = ["ALL"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff.lint.pycodestyle]
|
|
61
|
+
max-line-length = 100
|
|
62
|
+
|
|
63
|
+
[tool.mypy]
|
|
64
|
+
scripts_are_modules = true
|
|
65
|
+
show_traceback = true
|
|
66
|
+
check_untyped_defs = true
|
|
67
|
+
disallow_untyped_defs = true
|
|
68
|
+
disallow_any_generics = true
|
|
69
|
+
warn_no_return = true
|
|
70
|
+
strict_optional = true
|
|
71
|
+
no_implicit_optional = true
|
|
72
|
+
warn_redundant_casts = true
|
|
73
|
+
warn_unused_ignores = true
|
|
74
|
+
show_error_codes = true
|
|
75
|
+
ignore_missing_imports = true
|
|
76
|
+
warn_unreachable = true
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Tests for the SDD metamodel: exact counting, satisfiability, core/dead features.
|
|
2
|
+
|
|
3
|
+
Oracles are computed by brute-forcing the CNF from fm_metamodel's solver-agnostic ClauseSet,
|
|
4
|
+
so CI needs no SAT plugin — only flamapy-fm, which is already a declared dependency.
|
|
5
|
+
"""
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from itertools import product
|
|
9
|
+
|
|
10
|
+
from flamapy.metamodels.fm_metamodel.transformations import UVLReader
|
|
11
|
+
from flamapy.metamodels.fm_metamodel.models import FeatureModel, ClauseSet
|
|
12
|
+
from flamapy.metamodels.sdd_metamodel.transformations import FmToSDD
|
|
13
|
+
from flamapy.metamodels.sdd_metamodel.operations import (
|
|
14
|
+
SDDConfigurationsNumber,
|
|
15
|
+
SDDSatisfiable,
|
|
16
|
+
SDDCoreFeatures,
|
|
17
|
+
SDDDeadFeatures,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _valid_configs(fm: FeatureModel) -> tuple:
|
|
22
|
+
"""(valid configurations as frozensets of selected names, all feature names)."""
|
|
23
|
+
clause_set = ClauseSet.from_feature_model(fm)
|
|
24
|
+
name_of = {vid: name for name, vid in clause_set.variables.items()}
|
|
25
|
+
var_ids = sorted({abs(lit) for clause in clause_set.clauses for lit in clause}
|
|
26
|
+
| set(clause_set.variables.values()))
|
|
27
|
+
configs = set()
|
|
28
|
+
for bits in product((False, True), repeat=len(var_ids)):
|
|
29
|
+
assignment = dict(zip(var_ids, bits))
|
|
30
|
+
if all(any((lit > 0) == assignment[abs(lit)] for lit in clause)
|
|
31
|
+
for clause in clause_set.clauses):
|
|
32
|
+
configs.add(frozenset(name_of[v] for v in var_ids if assignment[v] and v in name_of))
|
|
33
|
+
return configs, set(clause_set.variables)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _exact_count(fm: FeatureModel) -> int:
|
|
37
|
+
return len(_valid_configs(fm)[0])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _core_features(fm: FeatureModel) -> set:
|
|
41
|
+
configs, names = _valid_configs(fm)
|
|
42
|
+
return {name for name in names if configs and all(name in cfg for cfg in configs)}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _dead_features(fm: FeatureModel) -> set:
|
|
46
|
+
configs, names = _valid_configs(fm)
|
|
47
|
+
return names - (set().union(*configs) if configs else set())
|
|
48
|
+
|
|
49
|
+
_UVL = """features
|
|
50
|
+
Root {abstract}
|
|
51
|
+
mandatory
|
|
52
|
+
Base
|
|
53
|
+
optional
|
|
54
|
+
A
|
|
55
|
+
B
|
|
56
|
+
C
|
|
57
|
+
constraints
|
|
58
|
+
A => B
|
|
59
|
+
A | B
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
_UNSAT_UVL = """features
|
|
63
|
+
Root {abstract}
|
|
64
|
+
mandatory
|
|
65
|
+
A
|
|
66
|
+
constraints
|
|
67
|
+
!A
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _fm(uvl):
|
|
72
|
+
handle, path = tempfile.mkstemp(suffix='.uvl')
|
|
73
|
+
try:
|
|
74
|
+
with os.fdopen(handle, 'w') as file:
|
|
75
|
+
file.write(uvl)
|
|
76
|
+
return UVLReader(path).transform()
|
|
77
|
+
finally:
|
|
78
|
+
os.remove(path)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_count_matches_sat_enumeration():
|
|
82
|
+
fm = _fm(_UVL)
|
|
83
|
+
exact = _exact_count(fm)
|
|
84
|
+
sdd = SDDConfigurationsNumber().execute(FmToSDD(fm).transform()).get_result()
|
|
85
|
+
assert sdd == exact
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def test_satisfiable():
|
|
89
|
+
assert SDDSatisfiable().execute(FmToSDD(_fm(_UVL)).transform()).get_result() is True
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_unsatisfiable_model():
|
|
93
|
+
assert SDDSatisfiable().execute(FmToSDD(_fm(_UNSAT_UVL)).transform()).get_result() is False
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_core_features_match_sat():
|
|
97
|
+
fm = _fm(_UVL)
|
|
98
|
+
expected = _core_features(fm)
|
|
99
|
+
sdd = set(SDDCoreFeatures().execute(FmToSDD(fm).transform()).get_result())
|
|
100
|
+
assert sdd == expected
|
|
101
|
+
assert 'Base' in sdd and 'Root' in sdd # mandatory chain is core
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def test_dead_features_match_sat():
|
|
105
|
+
fm = _fm(_UVL)
|
|
106
|
+
expected = _dead_features(fm)
|
|
107
|
+
sdd = set(SDDDeadFeatures().execute(FmToSDD(fm).transform()).get_result())
|
|
108
|
+
assert sdd == expected # no dead features in this model
|