NUCS 0.1__tar.gz → 0.1.2__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.
- {nucs-0.1 → nucs-0.1.2}/LICENSE.md +2 -2
- nucs-0.1.2/NUCS.egg-info/PKG-INFO +140 -0
- nucs-0.1.2/PKG-INFO +140 -0
- nucs-0.1.2/README.md +125 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/bibd_problem.py +1 -2
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/golomb_problem.py +2 -1
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/problem.py +2 -2
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/queens_problem.py +2 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/schur_lemma_problem.py +1 -1
- nucs-0.1.2/nucs/statistics.py +45 -0
- {nucs-0.1 → nucs-0.1.2}/pyproject.toml +2 -2
- nucs-0.1/NUCS.egg-info/PKG-INFO +0 -78
- nucs-0.1/PKG-INFO +0 -78
- nucs-0.1/README.md +0 -63
- nucs-0.1/nucs/statistics.py +0 -44
- {nucs-0.1 → nucs-0.1.2}/NUCS.egg-info/SOURCES.txt +0 -0
- {nucs-0.1 → nucs-0.1.2}/NUCS.egg-info/dependency_links.txt +0 -0
- {nucs-0.1 → nucs-0.1.2}/NUCS.egg-info/requires.txt +0 -0
- {nucs-0.1 → nucs-0.1.2}/NUCS.egg-info/top_level.txt +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/__init__.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/heuristics/heuristic.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/heuristics/variable_heuristic.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/memory.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/__init__.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/alpha_problem.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/problems/sudoku_problem.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/__init__.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/affine_eq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/affine_geq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/affine_leq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/alldifferent_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/count_eq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/dummy_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/exactly_eq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/lexicographic_leq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/max_eq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/max_leq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/min_eq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/min_geq_propagator.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/propagators/propagators.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/solvers/__init__.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/solvers/backtrack_solver.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/nucs/solvers/solver.py +0 -0
- {nucs-0.1 → nucs-0.1.2}/setup.cfg +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: NUCS
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A Numpy and Numba based Python library for solving Constraint Satifaction Problems
|
|
5
|
+
Author-email: Yan Georget <yan.georget@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/yangeorget/nucs
|
|
7
|
+
Project-URL: Issues, https://github.com/yangeorget/nucs
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Requires-Dist: numba==0.60.0
|
|
14
|
+
Requires-Dist: numpy==2.0.1
|
|
15
|
+
|
|
16
|
+
# NUCS
|
|
17
|
+
|
|
18
|
+
## TLDR
|
|
19
|
+
NUCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
20
|
+
Because it is 100% written in Python, NUCS is easy to install and use.
|
|
21
|
+
NUCS is also very fast because it is powered by [Numpy](https://numpy.org/) and [Numba](https://numba.pydata.org/).
|
|
22
|
+
|
|
23
|
+
With NUCS, in a few seconds you can ...
|
|
24
|
+
|
|
25
|
+
Compute the 92 solutions to the BIBD(8,14,7,4,3) problem:
|
|
26
|
+
```python
|
|
27
|
+
{
|
|
28
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
29
|
+
'PROBLEM_FILTERS_NB': 2797,
|
|
30
|
+
'PROPAGATOR_ENTAILMENT_NB': 36977,
|
|
31
|
+
'PROPAGATOR_FILTERS_NB': 564122,
|
|
32
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 534436,
|
|
33
|
+
'PROPAGATOR_INCONSISTENCY_NB': 1307,
|
|
34
|
+
'SOLVER_BACKTRACK_NB': 1398,
|
|
35
|
+
'SOLVER_CHOICE_DEPTH': 41,
|
|
36
|
+
'SOLVER_CHOICE_NB': 1398,
|
|
37
|
+
'SOLVER_SOLUTION_NB': 92
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
Demonstrate that the optimal 10-marks Golomb ruler length is 55:
|
|
41
|
+
```python
|
|
42
|
+
{
|
|
43
|
+
'OPTIMIZER_SOLUTION_NB': 10,
|
|
44
|
+
'PROBLEM_FILTERS_NB': 49623,
|
|
45
|
+
'PROPAGATOR_ENTAILMENT_NB': 855996,
|
|
46
|
+
'PROPAGATOR_FILTERS_NB': 5160649,
|
|
47
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 2893864,
|
|
48
|
+
'PROPAGATOR_INCONSISTENCY_NB': 24773,
|
|
49
|
+
'SOLVER_BACKTRACK_NB': 24772,
|
|
50
|
+
'SOLVER_CHOICE_DEPTH': 9,
|
|
51
|
+
'SOLVER_CHOICE_NB': 24840,
|
|
52
|
+
'SOLVER_SOLUTION_NB': 10
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
Find all 14200 solutions to the 12-queens problem:
|
|
56
|
+
```python
|
|
57
|
+
{
|
|
58
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
59
|
+
'PROBLEM_FILTERS_NB': 262011,
|
|
60
|
+
'PROPAGATOR_ENTAILMENT_NB': 0,
|
|
61
|
+
'PROPAGATOR_FILTERS_NB': 1910609,
|
|
62
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 631079,
|
|
63
|
+
'PROPAGATOR_INCONSISTENCY_NB': 116806,
|
|
64
|
+
'SOLVER_BACKTRACK_NB': 131005,
|
|
65
|
+
'SOLVER_CHOICE_DEPTH': 10,
|
|
66
|
+
'SOLVER_CHOICE_NB': 131005,
|
|
67
|
+
'SOLVER_SOLUTION_NB': 14200
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## How to use NUCS ?
|
|
72
|
+
It is very simple to get started with NUCS.
|
|
73
|
+
You can either install the Pip package or install NUCS from the sources.
|
|
74
|
+
|
|
75
|
+
### Install the NUCS package
|
|
76
|
+
Let's install the Pip package for NUCS:
|
|
77
|
+
```bash
|
|
78
|
+
pip install nucs
|
|
79
|
+
````
|
|
80
|
+
Now we can write the following `queens.py` program,
|
|
81
|
+
refer to [the technical documentation](DOCUMENTATION.md) to better understand how NUCS works under the hood:
|
|
82
|
+
```python
|
|
83
|
+
from nucs.problems.problem import Problem
|
|
84
|
+
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
85
|
+
from nucs.propagators.propagators import ALG_ALLDIFFERENT
|
|
86
|
+
|
|
87
|
+
n = 8 # the number of queens
|
|
88
|
+
problem = Problem(
|
|
89
|
+
shr_domains=[(0, n - 1)] * n, # these n domains are shared between 3n variables with different offsets
|
|
90
|
+
dom_indices=list(range(n)) * 3, # for each variable, its domain
|
|
91
|
+
dom_offsets=[0] * n + list(range(n)) + list(range(0, -n, -1)) # for each variable, its offset
|
|
92
|
+
)
|
|
93
|
+
problem.set_propagators([
|
|
94
|
+
(list(range(n)), ALG_ALLDIFFERENT, []),
|
|
95
|
+
(list(range(n, 2 * n)), ALG_ALLDIFFERENT, []),
|
|
96
|
+
(list(range(2 * n, 3 * n)), ALG_ALLDIFFERENT, [])
|
|
97
|
+
])
|
|
98
|
+
print(BacktrackSolver(problem).solve_one()[:n])
|
|
99
|
+
```
|
|
100
|
+
Let's run this model with the following command:
|
|
101
|
+
```bash
|
|
102
|
+
PYTHONPATH=. python queens.py
|
|
103
|
+
```
|
|
104
|
+
The first solution found is:
|
|
105
|
+
```bash
|
|
106
|
+
[0, 4, 7, 5, 2, 6, 1, 3]
|
|
107
|
+
```
|
|
108
|
+
> [!TIP]
|
|
109
|
+
> Note that the second run will always be much faster since the Python code will already have been compiled and cached by Numba.
|
|
110
|
+
|
|
111
|
+
### Install NUCS from the sources
|
|
112
|
+
Let's install NUCS from the sources by cloning the NUCS Github repository:
|
|
113
|
+
```bash
|
|
114
|
+
git clone https://github.com/yangeorget/nucs.git
|
|
115
|
+
pip install -r requirements.txt
|
|
116
|
+
```
|
|
117
|
+
From there, we will launch some NUCS examples.
|
|
118
|
+
|
|
119
|
+
#### Run some examples
|
|
120
|
+
Some of the examples come with a command line interface and can be run directly.
|
|
121
|
+
|
|
122
|
+
Let's find all solutions to the [12-queens problem](https://www.csplib.org/Problems/prob054/):
|
|
123
|
+
```bash
|
|
124
|
+
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python tests/examples/test_queens.py -n 12
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Let's find the optimal solution to the [Golomb ruler problem](https://www.csplib.org/Problems/prob006/) with 10 marks:
|
|
128
|
+
```bash
|
|
129
|
+
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python tests/examples/test_golomb.py -n 10
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Other constraint solvers in Python
|
|
133
|
+
### python-constraint
|
|
134
|
+
_The Python constraint module offers solvers for Constraint Solving Problems (CSPs) over finite domains in simple and pure Python._
|
|
135
|
+
|
|
136
|
+
### CCPMpy
|
|
137
|
+
_CPMpy is a Constraint Programming and Modeling library in Python, based on numpy, with direct solver access._
|
|
138
|
+
|
|
139
|
+
### PyCSP
|
|
140
|
+
_PyCSP3 is a Python library for developping models of combinatorial constrained problems in a declarative manner; you can write models of constraint satisfaction (CSP) and constraint optimization (COP) problems._
|
nucs-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: NUCS
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: A Numpy and Numba based Python library for solving Constraint Satifaction Problems
|
|
5
|
+
Author-email: Yan Georget <yan.georget@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/yangeorget/nucs
|
|
7
|
+
Project-URL: Issues, https://github.com/yangeorget/nucs
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Requires-Dist: numba==0.60.0
|
|
14
|
+
Requires-Dist: numpy==2.0.1
|
|
15
|
+
|
|
16
|
+
# NUCS
|
|
17
|
+
|
|
18
|
+
## TLDR
|
|
19
|
+
NUCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
20
|
+
Because it is 100% written in Python, NUCS is easy to install and use.
|
|
21
|
+
NUCS is also very fast because it is powered by [Numpy](https://numpy.org/) and [Numba](https://numba.pydata.org/).
|
|
22
|
+
|
|
23
|
+
With NUCS, in a few seconds you can ...
|
|
24
|
+
|
|
25
|
+
Compute the 92 solutions to the BIBD(8,14,7,4,3) problem:
|
|
26
|
+
```python
|
|
27
|
+
{
|
|
28
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
29
|
+
'PROBLEM_FILTERS_NB': 2797,
|
|
30
|
+
'PROPAGATOR_ENTAILMENT_NB': 36977,
|
|
31
|
+
'PROPAGATOR_FILTERS_NB': 564122,
|
|
32
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 534436,
|
|
33
|
+
'PROPAGATOR_INCONSISTENCY_NB': 1307,
|
|
34
|
+
'SOLVER_BACKTRACK_NB': 1398,
|
|
35
|
+
'SOLVER_CHOICE_DEPTH': 41,
|
|
36
|
+
'SOLVER_CHOICE_NB': 1398,
|
|
37
|
+
'SOLVER_SOLUTION_NB': 92
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
Demonstrate that the optimal 10-marks Golomb ruler length is 55:
|
|
41
|
+
```python
|
|
42
|
+
{
|
|
43
|
+
'OPTIMIZER_SOLUTION_NB': 10,
|
|
44
|
+
'PROBLEM_FILTERS_NB': 49623,
|
|
45
|
+
'PROPAGATOR_ENTAILMENT_NB': 855996,
|
|
46
|
+
'PROPAGATOR_FILTERS_NB': 5160649,
|
|
47
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 2893864,
|
|
48
|
+
'PROPAGATOR_INCONSISTENCY_NB': 24773,
|
|
49
|
+
'SOLVER_BACKTRACK_NB': 24772,
|
|
50
|
+
'SOLVER_CHOICE_DEPTH': 9,
|
|
51
|
+
'SOLVER_CHOICE_NB': 24840,
|
|
52
|
+
'SOLVER_SOLUTION_NB': 10
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
Find all 14200 solutions to the 12-queens problem:
|
|
56
|
+
```python
|
|
57
|
+
{
|
|
58
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
59
|
+
'PROBLEM_FILTERS_NB': 262011,
|
|
60
|
+
'PROPAGATOR_ENTAILMENT_NB': 0,
|
|
61
|
+
'PROPAGATOR_FILTERS_NB': 1910609,
|
|
62
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 631079,
|
|
63
|
+
'PROPAGATOR_INCONSISTENCY_NB': 116806,
|
|
64
|
+
'SOLVER_BACKTRACK_NB': 131005,
|
|
65
|
+
'SOLVER_CHOICE_DEPTH': 10,
|
|
66
|
+
'SOLVER_CHOICE_NB': 131005,
|
|
67
|
+
'SOLVER_SOLUTION_NB': 14200
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## How to use NUCS ?
|
|
72
|
+
It is very simple to get started with NUCS.
|
|
73
|
+
You can either install the Pip package or install NUCS from the sources.
|
|
74
|
+
|
|
75
|
+
### Install the NUCS package
|
|
76
|
+
Let's install the Pip package for NUCS:
|
|
77
|
+
```bash
|
|
78
|
+
pip install nucs
|
|
79
|
+
````
|
|
80
|
+
Now we can write the following `queens.py` program,
|
|
81
|
+
refer to [the technical documentation](DOCUMENTATION.md) to better understand how NUCS works under the hood:
|
|
82
|
+
```python
|
|
83
|
+
from nucs.problems.problem import Problem
|
|
84
|
+
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
85
|
+
from nucs.propagators.propagators import ALG_ALLDIFFERENT
|
|
86
|
+
|
|
87
|
+
n = 8 # the number of queens
|
|
88
|
+
problem = Problem(
|
|
89
|
+
shr_domains=[(0, n - 1)] * n, # these n domains are shared between 3n variables with different offsets
|
|
90
|
+
dom_indices=list(range(n)) * 3, # for each variable, its domain
|
|
91
|
+
dom_offsets=[0] * n + list(range(n)) + list(range(0, -n, -1)) # for each variable, its offset
|
|
92
|
+
)
|
|
93
|
+
problem.set_propagators([
|
|
94
|
+
(list(range(n)), ALG_ALLDIFFERENT, []),
|
|
95
|
+
(list(range(n, 2 * n)), ALG_ALLDIFFERENT, []),
|
|
96
|
+
(list(range(2 * n, 3 * n)), ALG_ALLDIFFERENT, [])
|
|
97
|
+
])
|
|
98
|
+
print(BacktrackSolver(problem).solve_one()[:n])
|
|
99
|
+
```
|
|
100
|
+
Let's run this model with the following command:
|
|
101
|
+
```bash
|
|
102
|
+
PYTHONPATH=. python queens.py
|
|
103
|
+
```
|
|
104
|
+
The first solution found is:
|
|
105
|
+
```bash
|
|
106
|
+
[0, 4, 7, 5, 2, 6, 1, 3]
|
|
107
|
+
```
|
|
108
|
+
> [!TIP]
|
|
109
|
+
> Note that the second run will always be much faster since the Python code will already have been compiled and cached by Numba.
|
|
110
|
+
|
|
111
|
+
### Install NUCS from the sources
|
|
112
|
+
Let's install NUCS from the sources by cloning the NUCS Github repository:
|
|
113
|
+
```bash
|
|
114
|
+
git clone https://github.com/yangeorget/nucs.git
|
|
115
|
+
pip install -r requirements.txt
|
|
116
|
+
```
|
|
117
|
+
From there, we will launch some NUCS examples.
|
|
118
|
+
|
|
119
|
+
#### Run some examples
|
|
120
|
+
Some of the examples come with a command line interface and can be run directly.
|
|
121
|
+
|
|
122
|
+
Let's find all solutions to the [12-queens problem](https://www.csplib.org/Problems/prob054/):
|
|
123
|
+
```bash
|
|
124
|
+
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python tests/examples/test_queens.py -n 12
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Let's find the optimal solution to the [Golomb ruler problem](https://www.csplib.org/Problems/prob006/) with 10 marks:
|
|
128
|
+
```bash
|
|
129
|
+
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python tests/examples/test_golomb.py -n 10
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Other constraint solvers in Python
|
|
133
|
+
### python-constraint
|
|
134
|
+
_The Python constraint module offers solvers for Constraint Solving Problems (CSPs) over finite domains in simple and pure Python._
|
|
135
|
+
|
|
136
|
+
### CCPMpy
|
|
137
|
+
_CPMpy is a Constraint Programming and Modeling library in Python, based on numpy, with direct solver access._
|
|
138
|
+
|
|
139
|
+
### PyCSP
|
|
140
|
+
_PyCSP3 is a Python library for developping models of combinatorial constrained problems in a declarative manner; you can write models of constraint satisfaction (CSP) and constraint optimization (COP) problems._
|
nucs-0.1.2/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# NUCS
|
|
2
|
+
|
|
3
|
+
## TLDR
|
|
4
|
+
NUCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
5
|
+
Because it is 100% written in Python, NUCS is easy to install and use.
|
|
6
|
+
NUCS is also very fast because it is powered by [Numpy](https://numpy.org/) and [Numba](https://numba.pydata.org/).
|
|
7
|
+
|
|
8
|
+
With NUCS, in a few seconds you can ...
|
|
9
|
+
|
|
10
|
+
Compute the 92 solutions to the BIBD(8,14,7,4,3) problem:
|
|
11
|
+
```python
|
|
12
|
+
{
|
|
13
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
14
|
+
'PROBLEM_FILTERS_NB': 2797,
|
|
15
|
+
'PROPAGATOR_ENTAILMENT_NB': 36977,
|
|
16
|
+
'PROPAGATOR_FILTERS_NB': 564122,
|
|
17
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 534436,
|
|
18
|
+
'PROPAGATOR_INCONSISTENCY_NB': 1307,
|
|
19
|
+
'SOLVER_BACKTRACK_NB': 1398,
|
|
20
|
+
'SOLVER_CHOICE_DEPTH': 41,
|
|
21
|
+
'SOLVER_CHOICE_NB': 1398,
|
|
22
|
+
'SOLVER_SOLUTION_NB': 92
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
Demonstrate that the optimal 10-marks Golomb ruler length is 55:
|
|
26
|
+
```python
|
|
27
|
+
{
|
|
28
|
+
'OPTIMIZER_SOLUTION_NB': 10,
|
|
29
|
+
'PROBLEM_FILTERS_NB': 49623,
|
|
30
|
+
'PROPAGATOR_ENTAILMENT_NB': 855996,
|
|
31
|
+
'PROPAGATOR_FILTERS_NB': 5160649,
|
|
32
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 2893864,
|
|
33
|
+
'PROPAGATOR_INCONSISTENCY_NB': 24773,
|
|
34
|
+
'SOLVER_BACKTRACK_NB': 24772,
|
|
35
|
+
'SOLVER_CHOICE_DEPTH': 9,
|
|
36
|
+
'SOLVER_CHOICE_NB': 24840,
|
|
37
|
+
'SOLVER_SOLUTION_NB': 10
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
Find all 14200 solutions to the 12-queens problem:
|
|
41
|
+
```python
|
|
42
|
+
{
|
|
43
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
44
|
+
'PROBLEM_FILTERS_NB': 262011,
|
|
45
|
+
'PROPAGATOR_ENTAILMENT_NB': 0,
|
|
46
|
+
'PROPAGATOR_FILTERS_NB': 1910609,
|
|
47
|
+
'PROPAGATOR_FILTERS_NO_CHANGE_NB': 631079,
|
|
48
|
+
'PROPAGATOR_INCONSISTENCY_NB': 116806,
|
|
49
|
+
'SOLVER_BACKTRACK_NB': 131005,
|
|
50
|
+
'SOLVER_CHOICE_DEPTH': 10,
|
|
51
|
+
'SOLVER_CHOICE_NB': 131005,
|
|
52
|
+
'SOLVER_SOLUTION_NB': 14200
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## How to use NUCS ?
|
|
57
|
+
It is very simple to get started with NUCS.
|
|
58
|
+
You can either install the Pip package or install NUCS from the sources.
|
|
59
|
+
|
|
60
|
+
### Install the NUCS package
|
|
61
|
+
Let's install the Pip package for NUCS:
|
|
62
|
+
```bash
|
|
63
|
+
pip install nucs
|
|
64
|
+
````
|
|
65
|
+
Now we can write the following `queens.py` program,
|
|
66
|
+
refer to [the technical documentation](DOCUMENTATION.md) to better understand how NUCS works under the hood:
|
|
67
|
+
```python
|
|
68
|
+
from nucs.problems.problem import Problem
|
|
69
|
+
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
70
|
+
from nucs.propagators.propagators import ALG_ALLDIFFERENT
|
|
71
|
+
|
|
72
|
+
n = 8 # the number of queens
|
|
73
|
+
problem = Problem(
|
|
74
|
+
shr_domains=[(0, n - 1)] * n, # these n domains are shared between 3n variables with different offsets
|
|
75
|
+
dom_indices=list(range(n)) * 3, # for each variable, its domain
|
|
76
|
+
dom_offsets=[0] * n + list(range(n)) + list(range(0, -n, -1)) # for each variable, its offset
|
|
77
|
+
)
|
|
78
|
+
problem.set_propagators([
|
|
79
|
+
(list(range(n)), ALG_ALLDIFFERENT, []),
|
|
80
|
+
(list(range(n, 2 * n)), ALG_ALLDIFFERENT, []),
|
|
81
|
+
(list(range(2 * n, 3 * n)), ALG_ALLDIFFERENT, [])
|
|
82
|
+
])
|
|
83
|
+
print(BacktrackSolver(problem).solve_one()[:n])
|
|
84
|
+
```
|
|
85
|
+
Let's run this model with the following command:
|
|
86
|
+
```bash
|
|
87
|
+
PYTHONPATH=. python queens.py
|
|
88
|
+
```
|
|
89
|
+
The first solution found is:
|
|
90
|
+
```bash
|
|
91
|
+
[0, 4, 7, 5, 2, 6, 1, 3]
|
|
92
|
+
```
|
|
93
|
+
> [!TIP]
|
|
94
|
+
> Note that the second run will always be much faster since the Python code will already have been compiled and cached by Numba.
|
|
95
|
+
|
|
96
|
+
### Install NUCS from the sources
|
|
97
|
+
Let's install NUCS from the sources by cloning the NUCS Github repository:
|
|
98
|
+
```bash
|
|
99
|
+
git clone https://github.com/yangeorget/nucs.git
|
|
100
|
+
pip install -r requirements.txt
|
|
101
|
+
```
|
|
102
|
+
From there, we will launch some NUCS examples.
|
|
103
|
+
|
|
104
|
+
#### Run some examples
|
|
105
|
+
Some of the examples come with a command line interface and can be run directly.
|
|
106
|
+
|
|
107
|
+
Let's find all solutions to the [12-queens problem](https://www.csplib.org/Problems/prob054/):
|
|
108
|
+
```bash
|
|
109
|
+
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python tests/examples/test_queens.py -n 12
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Let's find the optimal solution to the [Golomb ruler problem](https://www.csplib.org/Problems/prob006/) with 10 marks:
|
|
113
|
+
```bash
|
|
114
|
+
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python tests/examples/test_golomb.py -n 10
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Other constraint solvers in Python
|
|
118
|
+
### python-constraint
|
|
119
|
+
_The Python constraint module offers solvers for Constraint Solving Problems (CSPs) over finite domains in simple and pure Python._
|
|
120
|
+
|
|
121
|
+
### CCPMpy
|
|
122
|
+
_CPMpy is a Constraint Programming and Modeling library in Python, based on numpy, with direct solver access._
|
|
123
|
+
|
|
124
|
+
### PyCSP
|
|
125
|
+
_PyCSP3 is a Python library for developping models of combinatorial constrained problems in a declarative manner; you can write models of constraint satisfaction (CSP) and constraint optimization (COP) problems._
|
|
@@ -8,8 +8,7 @@ from nucs.propagators.propagators import (
|
|
|
8
8
|
|
|
9
9
|
class BIBDProblem(Problem):
|
|
10
10
|
"""
|
|
11
|
-
|
|
12
|
-
See https://www.csplib.org/Problems/prob028/ for a complete description of the problem.
|
|
11
|
+
This is problem #28 on CSPLIB (https://www.csplib.org/Problems/prob028/).
|
|
13
12
|
"""
|
|
14
13
|
|
|
15
14
|
def __init__(self, v: int, b: int, r: int, k: int, l: int):
|
|
@@ -35,7 +35,8 @@ class GolombProblem(Problem):
|
|
|
35
35
|
- mark_0 <...< mark_n-1,
|
|
36
36
|
- for all i<j, mark_j-mark_i are different,
|
|
37
37
|
- mark_n-1 is minimal.
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
This is problem #6 on CSPLIB (https://www.csplib.org/Problems/prob006/).
|
|
39
40
|
"""
|
|
40
41
|
|
|
41
42
|
def __init__(self, mark_nb: int) -> None:
|
|
@@ -36,7 +36,7 @@ from nucs.statistics import (
|
|
|
36
36
|
STATS_PROPAGATOR_FILTER_NB,
|
|
37
37
|
STATS_PROPAGATOR_FILTER_NO_CHANGE_NB,
|
|
38
38
|
STATS_PROPAGATOR_INCONSISTENCY_NB,
|
|
39
|
-
|
|
39
|
+
init_statistics,
|
|
40
40
|
)
|
|
41
41
|
|
|
42
42
|
|
|
@@ -58,7 +58,7 @@ class Problem:
|
|
|
58
58
|
self.shr_domains = new_domains_by_values(shr_domains)
|
|
59
59
|
self.dom_indices = new_indices_by_values(dom_indices)
|
|
60
60
|
self.dom_offsets = new_domain_offsets_by_values(dom_offsets)
|
|
61
|
-
self.statistics =
|
|
61
|
+
self.statistics = init_statistics()
|
|
62
62
|
|
|
63
63
|
def reset_shr_domains(self) -> None:
|
|
64
64
|
"""
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from typing import Dict
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
from numpy.typing import NDArray
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def init_statistics() -> NDArray:
|
|
8
|
+
"""
|
|
9
|
+
Inits a Numpy array for storing the statistics.
|
|
10
|
+
:return: a Numpy array
|
|
11
|
+
"""
|
|
12
|
+
return np.array([0] * STATS_MAX, dtype=np.int32, order="C")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_statistics(stats: NDArray) -> Dict[str, int]:
|
|
16
|
+
"""
|
|
17
|
+
Returns the statistics as a dictionary.
|
|
18
|
+
:param stats: a Numpy array of statistics
|
|
19
|
+
:return: a dictionary
|
|
20
|
+
"""
|
|
21
|
+
return {
|
|
22
|
+
"OPTIMIZER_SOLUTION_NB": int(stats[STATS_OPTIMIZER_SOLUTION_NB]),
|
|
23
|
+
"PROBLEM_FILTERS_NB": int(stats[STATS_PROBLEM_FILTER_NB]),
|
|
24
|
+
"PROPAGATOR_ENTAILMENT_NB": int(stats[STATS_PROPAGATOR_ENTAILMENT_NB]),
|
|
25
|
+
"PROPAGATOR_FILTERS_NB": int(stats[STATS_PROPAGATOR_FILTER_NB]),
|
|
26
|
+
"PROPAGATOR_FILTERS_NO_CHANGE_NB": int(stats[STATS_PROPAGATOR_FILTER_NO_CHANGE_NB]),
|
|
27
|
+
"PROPAGATOR_INCONSISTENCY_NB": int(stats[STATS_PROPAGATOR_INCONSISTENCY_NB]),
|
|
28
|
+
"SOLVER_BACKTRACK_NB": int(stats[STATS_SOLVER_BACKTRACK_NB]),
|
|
29
|
+
"SOLVER_CHOICE_NB": int(stats[STATS_SOLVER_CHOICE_NB]),
|
|
30
|
+
"SOLVER_CHOICE_DEPTH": int(stats[STATS_SOLVER_CHOICE_DEPTH]),
|
|
31
|
+
"SOLVER_SOLUTION_NB": int(stats[STATS_SOLVER_SOLUTION_NB]),
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
STATS_MAX = 10
|
|
36
|
+
STATS_OPTIMIZER_SOLUTION_NB = 0
|
|
37
|
+
STATS_PROBLEM_FILTER_NB = 1
|
|
38
|
+
STATS_PROPAGATOR_ENTAILMENT_NB = 2
|
|
39
|
+
STATS_PROPAGATOR_FILTER_NB = 3
|
|
40
|
+
STATS_PROPAGATOR_FILTER_NO_CHANGE_NB = 4
|
|
41
|
+
STATS_PROPAGATOR_INCONSISTENCY_NB = 5
|
|
42
|
+
STATS_SOLVER_BACKTRACK_NB = 6
|
|
43
|
+
STATS_SOLVER_CHOICE_NB = 7
|
|
44
|
+
STATS_SOLVER_CHOICE_DEPTH = 8
|
|
45
|
+
STATS_SOLVER_SOLUTION_NB = 9
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name="NUCS"
|
|
3
|
-
version="0.1"
|
|
3
|
+
version="0.1.2"
|
|
4
4
|
authors = [
|
|
5
5
|
{ name="Yan Georget", email="yan.georget@gmail.com" },
|
|
6
6
|
]
|
|
7
7
|
description="A Numpy and Numba based Python library for solving Constraint Satifaction Problems"
|
|
8
8
|
readme = "README.md"
|
|
9
|
-
requires-python = ">=3.
|
|
9
|
+
requires-python = ">=3.9"
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Programming Language :: Python :: 3",
|
|
12
12
|
"Operating System :: OS Independent",
|
nucs-0.1/NUCS.egg-info/PKG-INFO
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: NUCS
|
|
3
|
-
Version: 0.1
|
|
4
|
-
Summary: A Numpy and Numba based Python library for solving Constraint Satifaction Problems
|
|
5
|
-
Author-email: Yan Georget <yan.georget@gmail.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/yangeorget/nucs
|
|
7
|
-
Project-URL: Issues, https://github.com/yangeorget/nucs
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.8
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.md
|
|
13
|
-
Requires-Dist: numba==0.60.0
|
|
14
|
-
Requires-Dist: numpy==2.0.1
|
|
15
|
-
|
|
16
|
-
# NUCS
|
|
17
|
-
|
|
18
|
-
## TLDR
|
|
19
|
-
NUCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
20
|
-
|
|
21
|
-
NUCS is powered by Numpy (https://numpy.org/) and Numba (https://numba.pydata.org/).
|
|
22
|
-
|
|
23
|
-
NUCS is fast and easy to use.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## How to use NUCS ?
|
|
27
|
-
It is very simple to get started with NUCS.
|
|
28
|
-
Either clone the Github repository or install the package.
|
|
29
|
-
|
|
30
|
-
### Clone the NUCS Github repository
|
|
31
|
-
Let's install NUCS from the source:
|
|
32
|
-
```
|
|
33
|
-
git clone https://github.com/yangeorget/nucs.git
|
|
34
|
-
pip install -r requirements.txt
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
From there, you can launch some NUCS examples.
|
|
38
|
-
Note that the second run will be much faster since the Python code will have been compiled.
|
|
39
|
-
|
|
40
|
-
#### Run the NUCS tests
|
|
41
|
-
```
|
|
42
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. pytest tests/
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
#### Run some examples
|
|
46
|
-
Find all solutions to the 12-queens problem:
|
|
47
|
-
```
|
|
48
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python3 tests/examples/test_queens.py -n 12
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Find the optimal solution to the Golomb ruler problem with 10 marks:
|
|
52
|
-
```
|
|
53
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python3 tests/examples/test_golomb.py -n 10
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Install the NUCS package
|
|
57
|
-
```
|
|
58
|
-
pip install nucs
|
|
59
|
-
````
|
|
60
|
-
|
|
61
|
-
## Why Python ?
|
|
62
|
-
NUCS is a Python library leveraging Numpy and Numba.
|
|
63
|
-
|
|
64
|
-
Python is a powerful and flexible programing language that allows to express complex problems in a few lines of code.
|
|
65
|
-
|
|
66
|
-
Numpy brings the computational power of languages like C and Fortran to Python, a language much easier to learn and use.
|
|
67
|
-
|
|
68
|
-
Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library.
|
|
69
|
-
Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN.
|
|
70
|
-
|
|
71
|
-
## Architecture
|
|
72
|
-
|
|
73
|
-
## Speed matters
|
|
74
|
-
|
|
75
|
-
## Other constraint solvers in Python
|
|
76
|
-
- python-constraint
|
|
77
|
-
- CCPMpy
|
|
78
|
-
- PyCSP
|
nucs-0.1/PKG-INFO
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: NUCS
|
|
3
|
-
Version: 0.1
|
|
4
|
-
Summary: A Numpy and Numba based Python library for solving Constraint Satifaction Problems
|
|
5
|
-
Author-email: Yan Georget <yan.georget@gmail.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/yangeorget/nucs
|
|
7
|
-
Project-URL: Issues, https://github.com/yangeorget/nucs
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.8
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.md
|
|
13
|
-
Requires-Dist: numba==0.60.0
|
|
14
|
-
Requires-Dist: numpy==2.0.1
|
|
15
|
-
|
|
16
|
-
# NUCS
|
|
17
|
-
|
|
18
|
-
## TLDR
|
|
19
|
-
NUCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
20
|
-
|
|
21
|
-
NUCS is powered by Numpy (https://numpy.org/) and Numba (https://numba.pydata.org/).
|
|
22
|
-
|
|
23
|
-
NUCS is fast and easy to use.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
## How to use NUCS ?
|
|
27
|
-
It is very simple to get started with NUCS.
|
|
28
|
-
Either clone the Github repository or install the package.
|
|
29
|
-
|
|
30
|
-
### Clone the NUCS Github repository
|
|
31
|
-
Let's install NUCS from the source:
|
|
32
|
-
```
|
|
33
|
-
git clone https://github.com/yangeorget/nucs.git
|
|
34
|
-
pip install -r requirements.txt
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
From there, you can launch some NUCS examples.
|
|
38
|
-
Note that the second run will be much faster since the Python code will have been compiled.
|
|
39
|
-
|
|
40
|
-
#### Run the NUCS tests
|
|
41
|
-
```
|
|
42
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. pytest tests/
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
#### Run some examples
|
|
46
|
-
Find all solutions to the 12-queens problem:
|
|
47
|
-
```
|
|
48
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python3 tests/examples/test_queens.py -n 12
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
Find the optimal solution to the Golomb ruler problem with 10 marks:
|
|
52
|
-
```
|
|
53
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python3 tests/examples/test_golomb.py -n 10
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Install the NUCS package
|
|
57
|
-
```
|
|
58
|
-
pip install nucs
|
|
59
|
-
````
|
|
60
|
-
|
|
61
|
-
## Why Python ?
|
|
62
|
-
NUCS is a Python library leveraging Numpy and Numba.
|
|
63
|
-
|
|
64
|
-
Python is a powerful and flexible programing language that allows to express complex problems in a few lines of code.
|
|
65
|
-
|
|
66
|
-
Numpy brings the computational power of languages like C and Fortran to Python, a language much easier to learn and use.
|
|
67
|
-
|
|
68
|
-
Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library.
|
|
69
|
-
Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN.
|
|
70
|
-
|
|
71
|
-
## Architecture
|
|
72
|
-
|
|
73
|
-
## Speed matters
|
|
74
|
-
|
|
75
|
-
## Other constraint solvers in Python
|
|
76
|
-
- python-constraint
|
|
77
|
-
- CCPMpy
|
|
78
|
-
- PyCSP
|
nucs-0.1/README.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# NUCS
|
|
2
|
-
|
|
3
|
-
## TLDR
|
|
4
|
-
NUCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
5
|
-
|
|
6
|
-
NUCS is powered by Numpy (https://numpy.org/) and Numba (https://numba.pydata.org/).
|
|
7
|
-
|
|
8
|
-
NUCS is fast and easy to use.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## How to use NUCS ?
|
|
12
|
-
It is very simple to get started with NUCS.
|
|
13
|
-
Either clone the Github repository or install the package.
|
|
14
|
-
|
|
15
|
-
### Clone the NUCS Github repository
|
|
16
|
-
Let's install NUCS from the source:
|
|
17
|
-
```
|
|
18
|
-
git clone https://github.com/yangeorget/nucs.git
|
|
19
|
-
pip install -r requirements.txt
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
From there, you can launch some NUCS examples.
|
|
23
|
-
Note that the second run will be much faster since the Python code will have been compiled.
|
|
24
|
-
|
|
25
|
-
#### Run the NUCS tests
|
|
26
|
-
```
|
|
27
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. pytest tests/
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
#### Run some examples
|
|
31
|
-
Find all solutions to the 12-queens problem:
|
|
32
|
-
```
|
|
33
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python3 tests/examples/test_queens.py -n 12
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Find the optimal solution to the Golomb ruler problem with 10 marks:
|
|
37
|
-
```
|
|
38
|
-
NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python3 tests/examples/test_golomb.py -n 10
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Install the NUCS package
|
|
42
|
-
```
|
|
43
|
-
pip install nucs
|
|
44
|
-
````
|
|
45
|
-
|
|
46
|
-
## Why Python ?
|
|
47
|
-
NUCS is a Python library leveraging Numpy and Numba.
|
|
48
|
-
|
|
49
|
-
Python is a powerful and flexible programing language that allows to express complex problems in a few lines of code.
|
|
50
|
-
|
|
51
|
-
Numpy brings the computational power of languages like C and Fortran to Python, a language much easier to learn and use.
|
|
52
|
-
|
|
53
|
-
Numba translates Python functions to optimized machine code at runtime using the industry-standard LLVM compiler library.
|
|
54
|
-
Numba-compiled numerical algorithms in Python can approach the speeds of C or FORTRAN.
|
|
55
|
-
|
|
56
|
-
## Architecture
|
|
57
|
-
|
|
58
|
-
## Speed matters
|
|
59
|
-
|
|
60
|
-
## Other constraint solvers in Python
|
|
61
|
-
- python-constraint
|
|
62
|
-
- CCPMpy
|
|
63
|
-
- PyCSP
|
nucs-0.1/nucs/statistics.py
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import numpy as np
|
|
2
|
-
from numpy.typing import NDArray
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
def statistics_init() -> NDArray:
|
|
6
|
-
"""
|
|
7
|
-
Inits a Numpy array for storing the statistics.
|
|
8
|
-
:return: a Numpy array
|
|
9
|
-
"""
|
|
10
|
-
return np.array([0] * STATS_MAX, dtype=np.int32, order="C")
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def statistics_print(stats: NDArray) -> None:
|
|
14
|
-
"""
|
|
15
|
-
Pretty-prints an array of statistics.
|
|
16
|
-
:param stats: a Numpy array of statistics
|
|
17
|
-
"""
|
|
18
|
-
print(
|
|
19
|
-
{
|
|
20
|
-
"OPTIMIZER_SOLUTION_NB": int(stats[STATS_OPTIMIZER_SOLUTION_NB]),
|
|
21
|
-
"PROBLEM_FILTERS_NB": int(stats[STATS_PROBLEM_FILTER_NB]),
|
|
22
|
-
"PROPAGATOR_ENTAILMENT_NB": int(stats[STATS_PROPAGATOR_ENTAILMENT_NB]),
|
|
23
|
-
"PROPAGATOR_FILTERS_NB": int(stats[STATS_PROPAGATOR_FILTER_NB]),
|
|
24
|
-
"PROPAGATOR_FILTERS_NO_CHANGE_NB": int(stats[STATS_PROPAGATOR_FILTER_NO_CHANGE_NB]),
|
|
25
|
-
"PROPAGATOR_INCONSISTENCY_NB": int(stats[STATS_PROPAGATOR_INCONSISTENCY_NB]),
|
|
26
|
-
"SOLVER_BACKTRACK_NB": int(stats[STATS_SOLVER_BACKTRACK_NB]),
|
|
27
|
-
"SOLVER_CHOICE_NB": int(stats[STATS_SOLVER_CHOICE_NB]),
|
|
28
|
-
"SOLVER_CHOICE_DEPTH": int(stats[STATS_SOLVER_CHOICE_DEPTH]),
|
|
29
|
-
"SOLVER_SOLUTION_NB": int(stats[STATS_SOLVER_SOLUTION_NB]),
|
|
30
|
-
}
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
STATS_MAX = 10
|
|
35
|
-
STATS_OPTIMIZER_SOLUTION_NB = 0
|
|
36
|
-
STATS_PROBLEM_FILTER_NB = 1
|
|
37
|
-
STATS_PROPAGATOR_ENTAILMENT_NB = 2
|
|
38
|
-
STATS_PROPAGATOR_FILTER_NB = 3
|
|
39
|
-
STATS_PROPAGATOR_FILTER_NO_CHANGE_NB = 4
|
|
40
|
-
STATS_PROPAGATOR_INCONSISTENCY_NB = 5
|
|
41
|
-
STATS_SOLVER_BACKTRACK_NB = 6
|
|
42
|
-
STATS_SOLVER_CHOICE_NB = 7
|
|
43
|
-
STATS_SOLVER_CHOICE_DEPTH = 8
|
|
44
|
-
STATS_SOLVER_SOLUTION_NB = 9
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|