flamapy-dnnf 2.6.0.dev6__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.
@@ -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,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: flamapy-dnnf
3
+ Version: 2.6.0.dev6
4
+ Summary: flamapy-dnnf is a plugin to flamapy providing exact analysis of feature models via d-DNNF knowledge compilation with the d4 compiler
5
+ Author-email: Flamapy <flamapy@us.es>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/flamapy/dnnf_metamodel
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: flamapy-fw~=2.6.0.dev5
12
+ Requires-Dist: flamapy-fm~=2.6.0.dev5
13
+ Requires-Dist: flamapy-sat~=2.6.0.dev5
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-dnnf
23
+
24
+ `flamapy-dnnf` is a [flamapy](https://flamapy.github.io) plugin for **exact** analysis of feature
25
+ models via **d-DNNF knowledge compilation**, using the [d4](https://github.com/crillab/d4) compiler.
26
+
27
+ d-DNNF (deterministic Decomposable Negation Normal Form) is a highly succinct compilation target
28
+ that supports exact, polytime model counting. It complements the ecosystem:
29
+
30
+ - `flamapy-bdd` — OBDD; exact, but can blow up on large models.
31
+ - `flamapy-sdd` — SDD; exact, more succinct than OBDD, pure-Python (PySDD).
32
+ - `flamapy-sharpsat` — ApproxMC; **approximate** count for very large models.
33
+ - `flamapy-dnnf` — d4/d-DNNF; **exact** count that scales to large industrial models.
34
+
35
+ ## Requirements
36
+
37
+ d4 is a native C++ binary with **no PyPI package**. Install it from
38
+ <https://github.com/crillab/d4> and either put it on your `PATH` as `d4` or point
39
+ `FLAMAPY_D4_PATH` at the binary.
40
+
41
+ ```
42
+ pip install flamapy-dnnf
43
+ export FLAMAPY_D4_PATH=/path/to/d4 # or have `d4` on PATH
44
+ ```
45
+
46
+ ## Operations
47
+
48
+ | Operation | Class |
49
+ |---|---|
50
+ | Exact number of configurations | `DDNNFConfigurationsNumber` |
51
+ | Satisfiable (non-void) | `DDNNFSatisfiable` |
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+ from flamapy.metamodels.fm_metamodel.transformations import UVLReader
57
+ from flamapy.metamodels.dnnf_metamodel.transformations import FmToDDNNF
58
+ from flamapy.metamodels.dnnf_metamodel.operations import DDNNFConfigurationsNumber
59
+
60
+ fm = UVLReader('model.uvl').transform()
61
+ dnnf_model = FmToDDNNF(fm).transform() # add compile=True to also dump the d-DNNF file
62
+ count = DDNNFConfigurationsNumber().execute(dnnf_model).get_result()
63
+ ```
64
+
65
+ ## License
66
+
67
+ GPL-3.0-or-later.
@@ -0,0 +1,46 @@
1
+ # flamapy-dnnf
2
+
3
+ `flamapy-dnnf` is a [flamapy](https://flamapy.github.io) plugin for **exact** analysis of feature
4
+ models via **d-DNNF knowledge compilation**, using the [d4](https://github.com/crillab/d4) compiler.
5
+
6
+ d-DNNF (deterministic Decomposable Negation Normal Form) is a highly succinct compilation target
7
+ that supports exact, polytime model counting. It complements the ecosystem:
8
+
9
+ - `flamapy-bdd` — OBDD; exact, but can blow up on large models.
10
+ - `flamapy-sdd` — SDD; exact, more succinct than OBDD, pure-Python (PySDD).
11
+ - `flamapy-sharpsat` — ApproxMC; **approximate** count for very large models.
12
+ - `flamapy-dnnf` — d4/d-DNNF; **exact** count that scales to large industrial models.
13
+
14
+ ## Requirements
15
+
16
+ d4 is a native C++ binary with **no PyPI package**. Install it from
17
+ <https://github.com/crillab/d4> and either put it on your `PATH` as `d4` or point
18
+ `FLAMAPY_D4_PATH` at the binary.
19
+
20
+ ```
21
+ pip install flamapy-dnnf
22
+ export FLAMAPY_D4_PATH=/path/to/d4 # or have `d4` on PATH
23
+ ```
24
+
25
+ ## Operations
26
+
27
+ | Operation | Class |
28
+ |---|---|
29
+ | Exact number of configurations | `DDNNFConfigurationsNumber` |
30
+ | Satisfiable (non-void) | `DDNNFSatisfiable` |
31
+
32
+ ## Usage
33
+
34
+ ```python
35
+ from flamapy.metamodels.fm_metamodel.transformations import UVLReader
36
+ from flamapy.metamodels.dnnf_metamodel.transformations import FmToDDNNF
37
+ from flamapy.metamodels.dnnf_metamodel.operations import DDNNFConfigurationsNumber
38
+
39
+ fm = UVLReader('model.uvl').transform()
40
+ dnnf_model = FmToDDNNF(fm).transform() # add compile=True to also dump the d-DNNF file
41
+ count = DDNNFConfigurationsNumber().execute(dnnf_model).get_result()
42
+ ```
43
+
44
+ ## License
45
+
46
+ GPL-3.0-or-later.
@@ -0,0 +1,4 @@
1
+ from .dnnf_model import DDNNFModel, locate_d4
2
+
3
+
4
+ __all__ = ['DDNNFModel', 'locate_d4']
@@ -0,0 +1,46 @@
1
+ import os
2
+ import shutil
3
+ from typing import Optional
4
+
5
+ from flamapy.core.models import VariabilityModel
6
+ from flamapy.core.exceptions import FlamaException
7
+
8
+
9
+ def locate_d4() -> str:
10
+ """Return the path to the d4 compiler binary.
11
+
12
+ Resolved from the ``FLAMAPY_D4_PATH`` environment variable, or ``d4`` on ``PATH``. d4 is a
13
+ native C++ binary (https://github.com/crillab/d4) with no PyPI distribution, so it must be
14
+ installed separately.
15
+ """
16
+ candidate = os.environ.get('FLAMAPY_D4_PATH') or shutil.which('d4')
17
+ if not candidate or not os.path.exists(candidate):
18
+ raise FlamaException(
19
+ 'The d4 compiler was not found. Install d4 (https://github.com/crillab/d4) and '
20
+ 'expose it as "d4" on PATH or via the FLAMAPY_D4_PATH environment variable.'
21
+ )
22
+ return candidate
23
+
24
+
25
+ class DDNNFModel(VariabilityModel):
26
+ """A d-DNNF (deterministic Decomposable Negation Normal Form) view of a feature model.
27
+
28
+ The model keeps the CNF (as DIMACS) produced from the feature model; exact queries are
29
+ answered by the external d4 compiler, which compiles the CNF to d-DNNF internally. The
30
+ compiled d-DNNF artifact can optionally be dumped to ``nnf_path``.
31
+ """
32
+
33
+ @staticmethod
34
+ def get_extension() -> str:
35
+ return 'dnnf'
36
+
37
+ def __init__(self) -> None:
38
+ self.dimacs_path: str = '' # path to the CNF in DIMACS format
39
+ self.nnf_path: Optional[str] = None # optional compiled d-DNNF artifact
40
+ self.var_count: int = 0
41
+ self.variables: dict[str, int] = {} # feature name -> DIMACS variable index
42
+ self.features: dict[int, str] = {} # DIMACS variable index -> feature name
43
+ self.original_model: Optional[VariabilityModel] = None
44
+
45
+ def feature_variables(self) -> list[int]:
46
+ return list(self.features.keys())
@@ -0,0 +1,8 @@
1
+ from .dnnf_configurations_number import DDNNFConfigurationsNumber
2
+ from .dnnf_satisfiable import DDNNFSatisfiable
3
+
4
+
5
+ __all__ = [
6
+ 'DDNNFConfigurationsNumber',
7
+ 'DDNNFSatisfiable',
8
+ ]
@@ -0,0 +1,22 @@
1
+ import re
2
+ import subprocess
3
+
4
+ from flamapy.core.exceptions import FlamaException
5
+ from flamapy.metamodels.dnnf_metamodel.models import locate_d4
6
+
7
+ # d4 prints the exact model count on a solution line, e.g. "s 1904"; the count is unbounded so
8
+ # it is parsed as an arbitrary-precision Python int.
9
+ _COUNT_LINE = re.compile(r'^s\s+(\d+)\s*$', re.MULTILINE)
10
+
11
+
12
+ def d4_model_count(dimacs_path: str) -> int:
13
+ """Run d4 in exact model-counting mode over a DIMACS file and return the count."""
14
+ d4 = locate_d4()
15
+ completed = subprocess.run(
16
+ [d4, dimacs_path, '-mc'],
17
+ check=True, capture_output=True, text=True,
18
+ )
19
+ match = _COUNT_LINE.search(completed.stdout)
20
+ if match is None:
21
+ raise FlamaException(f'Could not parse a model count from d4 output:\n{completed.stdout}')
22
+ return int(match.group(1))
@@ -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.dnnf_metamodel.models import DDNNFModel
6
+ from flamapy.metamodels.dnnf_metamodel.operations.d4_runner import d4_model_count
7
+
8
+
9
+ class DDNNFConfigurationsNumber(ConfigurationsNumber):
10
+ """Exact number of valid configurations, computed by the d4 d-DNNF compiler.
11
+
12
+ d4 compiles the CNF to a d-DNNF and counts its models exactly. It scales to large models
13
+ where OBDD compilation (the bdd plugin) can blow up, and unlike the sharpsat plugin the
14
+ result is exact rather than approximate.
15
+ """
16
+
17
+ def __init__(self) -> None:
18
+ self._result = 0
19
+
20
+ def get_configurations_number(self) -> int:
21
+ return self._result
22
+
23
+ def get_result(self) -> int:
24
+ return self._result
25
+
26
+ def execute(self, model: VariabilityModel) -> 'DDNNFConfigurationsNumber':
27
+ dnnf_model = cast(DDNNFModel, model)
28
+ self._result = d4_model_count(dnnf_model.dimacs_path)
29
+ return self
@@ -0,0 +1,24 @@
1
+ from typing import cast
2
+
3
+ from flamapy.core.models import VariabilityModel
4
+ from flamapy.core.operations import Satisfiable
5
+ from flamapy.metamodels.dnnf_metamodel.models import DDNNFModel
6
+ from flamapy.metamodels.dnnf_metamodel.operations.d4_runner import d4_model_count
7
+
8
+
9
+ class DDNNFSatisfiable(Satisfiable):
10
+ """Whether the feature model is satisfiable (non-void): its exact model count is non-zero."""
11
+
12
+ def __init__(self) -> None:
13
+ self._result = False
14
+
15
+ def is_satisfiable(self) -> bool:
16
+ return self._result
17
+
18
+ def get_result(self) -> bool:
19
+ return self._result
20
+
21
+ def execute(self, model: VariabilityModel) -> 'DDNNFSatisfiable':
22
+ dnnf_model = cast(DDNNFModel, model)
23
+ self._result = d4_model_count(dnnf_model.dimacs_path) > 0
24
+ return self
@@ -0,0 +1,4 @@
1
+ from .fm_to_dnnf import FmToDDNNF
2
+
3
+
4
+ __all__ = ['FmToDDNNF']
@@ -0,0 +1,70 @@
1
+ import os
2
+ import subprocess
3
+ import tempfile
4
+
5
+ from flamapy.core.transformations import ModelToModel
6
+ from flamapy.metamodels.fm_metamodel.models import FeatureModel
7
+ from flamapy.metamodels.pysat_metamodel.transformations import FmToPysat
8
+ from flamapy.metamodels.dnnf_metamodel.models import DDNNFModel, locate_d4
9
+
10
+
11
+ class FmToDDNNF(ModelToModel):
12
+ """Transform a feature model into a d-DNNF-backed model.
13
+
14
+ Builds the CNF (reusing the SAT metamodel), writes it as DIMACS, and — when ``compile`` is
15
+ set — invokes d4 to dump the compiled d-DNNF artifact. Exact queries run d4 on the DIMACS.
16
+ """
17
+
18
+ @staticmethod
19
+ def get_source_extension() -> str:
20
+ return 'fm'
21
+
22
+ @staticmethod
23
+ def get_destination_extension() -> str:
24
+ return 'dnnf'
25
+
26
+ def __init__(
27
+ self,
28
+ source_model: FeatureModel,
29
+ cnf_method: str = 'distributive',
30
+ compile: bool = False,
31
+ ) -> None:
32
+ self.source_model = source_model
33
+ self.cnf_method = cnf_method
34
+ self.compile = compile
35
+ self.destination_model = DDNNFModel()
36
+
37
+ def transform(self) -> DDNNFModel:
38
+ if self.cnf_method == 'distributive':
39
+ sat_model = FmToPysat(self.source_model).transform()
40
+ else:
41
+ sat_model = FmToPysat(self.source_model, cnf_method=self.cnf_method).transform()
42
+
43
+ clauses = [list(clause) for clause in sat_model.get_all_clauses().clauses]
44
+ var_count = max((abs(literal) for clause in clauses for literal in clause), default=1)
45
+
46
+ dimacs_fd, dimacs_path = tempfile.mkstemp(suffix='.cnf', prefix='flamapy_dnnf_')
47
+ with os.fdopen(dimacs_fd, 'w') as dimacs_file:
48
+ dimacs_file.write(f'p cnf {var_count} {len(clauses)}\n')
49
+ for clause in clauses:
50
+ dimacs_file.write(' '.join(str(literal) for literal in clause) + ' 0\n')
51
+
52
+ model = self.destination_model
53
+ model.dimacs_path = dimacs_path
54
+ model.var_count = var_count
55
+ model.variables = dict(sat_model.variables)
56
+ model.features = dict(sat_model.features)
57
+ model.original_model = self.source_model
58
+
59
+ if self.compile:
60
+ nnf_fd, nnf_path = tempfile.mkstemp(suffix='.nnf', prefix='flamapy_dnnf_')
61
+ os.close(nnf_fd)
62
+ d4 = locate_d4()
63
+ # d4 compiles the CNF to a d-DNNF and dumps it to nnf_path.
64
+ subprocess.run(
65
+ [d4, dimacs_path, '-dDNNF', f'-out={nnf_path}'],
66
+ check=True, capture_output=True, text=True,
67
+ )
68
+ model.nnf_path = nnf_path
69
+
70
+ return model
@@ -0,0 +1,67 @@
1
+ Metadata-Version: 2.4
2
+ Name: flamapy-dnnf
3
+ Version: 2.6.0.dev6
4
+ Summary: flamapy-dnnf is a plugin to flamapy providing exact analysis of feature models via d-DNNF knowledge compilation with the d4 compiler
5
+ Author-email: Flamapy <flamapy@us.es>
6
+ License-Expression: GPL-3.0-or-later
7
+ Project-URL: Homepage, https://github.com/flamapy/dnnf_metamodel
8
+ Requires-Python: >=3.11
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: flamapy-fw~=2.6.0.dev5
12
+ Requires-Dist: flamapy-fm~=2.6.0.dev5
13
+ Requires-Dist: flamapy-sat~=2.6.0.dev5
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-dnnf
23
+
24
+ `flamapy-dnnf` is a [flamapy](https://flamapy.github.io) plugin for **exact** analysis of feature
25
+ models via **d-DNNF knowledge compilation**, using the [d4](https://github.com/crillab/d4) compiler.
26
+
27
+ d-DNNF (deterministic Decomposable Negation Normal Form) is a highly succinct compilation target
28
+ that supports exact, polytime model counting. It complements the ecosystem:
29
+
30
+ - `flamapy-bdd` — OBDD; exact, but can blow up on large models.
31
+ - `flamapy-sdd` — SDD; exact, more succinct than OBDD, pure-Python (PySDD).
32
+ - `flamapy-sharpsat` — ApproxMC; **approximate** count for very large models.
33
+ - `flamapy-dnnf` — d4/d-DNNF; **exact** count that scales to large industrial models.
34
+
35
+ ## Requirements
36
+
37
+ d4 is a native C++ binary with **no PyPI package**. Install it from
38
+ <https://github.com/crillab/d4> and either put it on your `PATH` as `d4` or point
39
+ `FLAMAPY_D4_PATH` at the binary.
40
+
41
+ ```
42
+ pip install flamapy-dnnf
43
+ export FLAMAPY_D4_PATH=/path/to/d4 # or have `d4` on PATH
44
+ ```
45
+
46
+ ## Operations
47
+
48
+ | Operation | Class |
49
+ |---|---|
50
+ | Exact number of configurations | `DDNNFConfigurationsNumber` |
51
+ | Satisfiable (non-void) | `DDNNFSatisfiable` |
52
+
53
+ ## Usage
54
+
55
+ ```python
56
+ from flamapy.metamodels.fm_metamodel.transformations import UVLReader
57
+ from flamapy.metamodels.dnnf_metamodel.transformations import FmToDDNNF
58
+ from flamapy.metamodels.dnnf_metamodel.operations import DDNNFConfigurationsNumber
59
+
60
+ fm = UVLReader('model.uvl').transform()
61
+ dnnf_model = FmToDDNNF(fm).transform() # add compile=True to also dump the d-DNNF file
62
+ count = DDNNFConfigurationsNumber().execute(dnnf_model).get_result()
63
+ ```
64
+
65
+ ## License
66
+
67
+ GPL-3.0-or-later.
@@ -0,0 +1,19 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ flamapy/metamodels/dnnf_metamodel/__init__.py
6
+ flamapy/metamodels/dnnf_metamodel/models/__init__.py
7
+ flamapy/metamodels/dnnf_metamodel/models/dnnf_model.py
8
+ flamapy/metamodels/dnnf_metamodel/operations/__init__.py
9
+ flamapy/metamodels/dnnf_metamodel/operations/d4_runner.py
10
+ flamapy/metamodels/dnnf_metamodel/operations/dnnf_configurations_number.py
11
+ flamapy/metamodels/dnnf_metamodel/operations/dnnf_satisfiable.py
12
+ flamapy/metamodels/dnnf_metamodel/transformations/__init__.py
13
+ flamapy/metamodels/dnnf_metamodel/transformations/fm_to_dnnf.py
14
+ flamapy_dnnf.egg-info/PKG-INFO
15
+ flamapy_dnnf.egg-info/SOURCES.txt
16
+ flamapy_dnnf.egg-info/dependency_links.txt
17
+ flamapy_dnnf.egg-info/requires.txt
18
+ flamapy_dnnf.egg-info/top_level.txt
19
+ tests/test_dnnf.py
@@ -0,0 +1,10 @@
1
+ flamapy-fw~=2.6.0.dev5
2
+ flamapy-fm~=2.6.0.dev5
3
+ flamapy-sat~=2.6.0.dev5
4
+
5
+ [dev]
6
+ pytest
7
+ pytest-mock
8
+ prospector
9
+ mypy
10
+ coverage
@@ -0,0 +1,76 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "flamapy-dnnf"
7
+ version = "2.6.0.dev6"
8
+ description = "flamapy-dnnf is a plugin to flamapy providing exact analysis of feature models via d-DNNF knowledge compilation with the d4 compiler"
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.dev5",
15
+ "flamapy-fm~=2.6.0.dev5",
16
+ "flamapy-sat~=2.6.0.dev5",
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/dnnf_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_dnnf.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,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from setuptools import setup
2
+
3
+ setup()
@@ -0,0 +1,71 @@
1
+ """Tests for the d-DNNF (d4) metamodel.
2
+
3
+ d4 is a native binary with no PyPI distribution, so these tests are skipped unless d4 is
4
+ available (on PATH or via FLAMAPY_D4_PATH). When present, exact counts are checked against the
5
+ SAT backend oracle.
6
+ """
7
+ import os
8
+ import shutil
9
+ import tempfile
10
+
11
+ import pytest
12
+
13
+ from flamapy.metamodels.fm_metamodel.transformations import UVLReader
14
+ from flamapy.metamodels.dnnf_metamodel.transformations import FmToDDNNF
15
+ from flamapy.metamodels.dnnf_metamodel.operations import (
16
+ DDNNFConfigurationsNumber,
17
+ DDNNFSatisfiable,
18
+ )
19
+ from flamapy.metamodels.pysat_metamodel.transformations import FmToPysat
20
+ from flamapy.metamodels.pysat_metamodel.operations.pysat_configurations_number import (
21
+ PySATConfigurationsNumber,
22
+ )
23
+
24
+ _D4_AVAILABLE = bool(os.environ.get('FLAMAPY_D4_PATH') or shutil.which('d4'))
25
+ requires_d4 = pytest.mark.skipif(not _D4_AVAILABLE, reason='the d4 compiler is not installed')
26
+
27
+ _UVL = """features
28
+ Root {abstract}
29
+ mandatory
30
+ Base
31
+ optional
32
+ A
33
+ B
34
+ C
35
+ constraints
36
+ A => B
37
+ A | B
38
+ """
39
+
40
+
41
+ def _fm(uvl):
42
+ handle, path = tempfile.mkstemp(suffix='.uvl')
43
+ try:
44
+ with os.fdopen(handle, 'w') as file:
45
+ file.write(uvl)
46
+ return UVLReader(path).transform()
47
+ finally:
48
+ os.remove(path)
49
+
50
+
51
+ @requires_d4
52
+ def test_count_matches_sat():
53
+ fm = _fm(_UVL)
54
+ exact = PySATConfigurationsNumber().execute(FmToPysat(fm).transform()).get_result()
55
+ dnnf = DDNNFConfigurationsNumber().execute(FmToDDNNF(fm).transform()).get_result()
56
+ assert dnnf == exact
57
+
58
+
59
+ @requires_d4
60
+ def test_satisfiable():
61
+ assert DDNNFSatisfiable().execute(FmToDDNNF(_fm(_UVL)).transform()).get_result() is True
62
+
63
+
64
+ def test_transformation_writes_dimacs():
65
+ """The DIMACS export does not need d4 and can always be checked."""
66
+ model = FmToDDNNF(_fm(_UVL)).transform()
67
+ assert os.path.exists(model.dimacs_path)
68
+ with open(model.dimacs_path) as dimacs:
69
+ header = dimacs.readline()
70
+ assert header.startswith('p cnf ')
71
+ assert model.var_count >= 5 # Root, Base, A, B, C