NUCS 2.0.0__tar.gz → 2.2.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.
- nucs-2.2.0/NUCS.egg-info/PKG-INFO +147 -0
- {nucs-2.0.0 → nucs-2.2.0}/NUCS.egg-info/SOURCES.txt +2 -0
- nucs-2.2.0/PKG-INFO +147 -0
- nucs-2.2.0/README.md +125 -0
- {nucs-2.0.0 → nucs-2.2.0}/docs/source/conf.py +2 -2
- {nucs-2.0.0 → nucs-2.2.0}/nucs/constants.py +12 -2
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/alpha/__main__.py +10 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/bibd/__main__.py +3 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/donald/__main__.py +10 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/golomb/__main__.py +3 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/golomb/golomb_problem.py +16 -8
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/knapsack/__main__.py +10 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/magic_sequence/__main__.py +6 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/magic_square/__main__.py +6 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/quasigroup/__main__.py +6 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/queens/__main__.py +6 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/schur_lemma/__main__.py +3 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/sports_tournament_scheduling/__main__.py +6 -1
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/propagators.py +18 -4
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/backtrack_solver.py +76 -51
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/bound_consistency_algorithm.py +23 -14
- nucs-2.2.0/nucs/solvers/choice_points.py +84 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/consistency_algorithms.py +2 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/heuristics.py +16 -4
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/multiprocessing_solver.py +13 -2
- nucs-2.2.0/nucs/solvers/shaving_consistency_algorithm.py +269 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/solver.py +14 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/statistics.py +13 -9
- {nucs-2.0.0 → nucs-2.2.0}/pyproject.toml +1 -1
- nucs-2.0.0/NUCS.egg-info/PKG-INFO +0 -113
- nucs-2.0.0/PKG-INFO +0 -113
- nucs-2.0.0/README.md +0 -91
- {nucs-2.0.0 → nucs-2.2.0}/LICENSE.md +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/NUCS.egg-info/dependency_links.txt +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/NUCS.egg-info/requires.txt +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/NUCS.egg-info/top_level.txt +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/alpha/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/alpha/alpha_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/bibd/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/bibd/bibd_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/donald/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/donald/donald_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/golomb/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/knapsack/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/knapsack/knapsack_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/magic_sequence/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/magic_sequence/magic_sequence_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/magic_square/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/magic_square/magic_square_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/quasigroup/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/quasigroup/quasigroup_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/queens/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/queens/queens_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/schur_lemma/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/schur_lemma/schur_lemma_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/sports_tournament_scheduling/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/sports_tournament_scheduling/sports_tournament_scheduling_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/sudoku/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/examples/sudoku/sudoku_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/numba_helper.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/numpy_helper.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/problems/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/problems/latin_square_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/problems/problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/affine_eq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/affine_geq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/affine_leq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/alldifferent_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/and_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/count_eq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/dummy_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/element_lic_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/element_liv_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/exactly_eq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/exactly_true_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/gcc_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/lexicographic_leq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/max_eq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/max_leq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/min_eq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/min_geq_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/propagators/relation_propagator.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/nucs/solvers/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/setup.cfg +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_alpha.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_bibd.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_donald.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_golomb.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_knapsack.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_latin_square.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_magic_sequence.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_magic_square.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_quasigroup.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_queens.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_schur_lemma.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_sports_tournament_scheduling.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/examples/test_sudokus.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/problems/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/problems/test_problem.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_affine_eq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_affine_geq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_affine_leq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_alldifferent.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_count_eq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_element_lic.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_element_liv.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_exactly_eq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_gcc.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_lexicographic_leq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_max_eq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_max_leq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_min_eq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_min_geq.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/propagators/test_relation.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/solvers/__init__.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/solvers/test_backtrack_solver.py +0 -0
- {nucs-2.0.0 → nucs-2.2.0}/tests/solvers/test_multiprocessing_solver.py +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: NUCS
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: A Numpy and Numba based Python library for solving Constraint Satisfaction Problems over finite domains
|
|
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/issues
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.md
|
|
20
|
+
Requires-Dist: numba==0.60.0
|
|
21
|
+
Requires-Dist: numpy==2.0.1
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
## TLDR
|
|
37
|
+
NuCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
38
|
+
Because it is 100% written in Python,
|
|
39
|
+
NuCS is easy to install and allows to model complex problems in a few lines of code.
|
|
40
|
+
The NuCS solver is also very fast because it is powered by [Numpy](https://numpy.org/) and [Numba](https://numba.pydata.org/).
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
```bash
|
|
44
|
+
pip install nucs
|
|
45
|
+
```
|
|
46
|
+
## Documentation
|
|
47
|
+
Check out [NUCS documentation](https://nucs.readthedocs.io/).
|
|
48
|
+
|
|
49
|
+
## With NuCS, in a few seconds you can ...
|
|
50
|
+
### Find all 14200 solutions to the [12-queens problem](https://www.csplib.org/Problems/prob054/)
|
|
51
|
+
```bash
|
|
52
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.queens -n 12 --log_level=INFO
|
|
53
|
+
```
|
|
54
|
+
```bash
|
|
55
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.solver - Problem has 3 propagators
|
|
56
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.solver - Problem has 12 variables
|
|
57
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
58
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 0
|
|
59
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 0
|
|
60
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
61
|
+
2024-11-12 17:24:49,200 - INFO - nucs.solvers.multiprocessing_solver - MultiprocessingSolver has 1 processors
|
|
62
|
+
{
|
|
63
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
64
|
+
'PROBLEM_FILTER_NB': 262011,
|
|
65
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
66
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
67
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
68
|
+
'PROPAGATOR_ENTAILMENT_NB': 0,
|
|
69
|
+
'PROPAGATOR_FILTER_NB': 2269980,
|
|
70
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 990450,
|
|
71
|
+
'PROPAGATOR_INCONSISTENCY_NB': 116806,
|
|
72
|
+
'SOLVER_BACKTRACK_NB': 131005,
|
|
73
|
+
'SOLVER_CHOICE_NB': 131005,
|
|
74
|
+
'SOLVER_CHOICE_DEPTH': 10,
|
|
75
|
+
'SOLVER_SOLUTION_NB': 14200
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Compute the 92 solutions to the [BIBD(8,14,7,4,3) problem](https://www.csplib.org/Problems/prob028/)
|
|
80
|
+
```bash
|
|
81
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.bibd -v 8 -b 14 -r 7 -k 4 -l 3 --symmetry_breaking --log_level=INFO
|
|
82
|
+
```
|
|
83
|
+
```bash
|
|
84
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.solver - Problem has 462 propagators
|
|
85
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.solver - Problem has 504 variables
|
|
86
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
87
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 1
|
|
88
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 0
|
|
89
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
90
|
+
{
|
|
91
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
92
|
+
'PROBLEM_FILTER_NB': 1425,
|
|
93
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
94
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
95
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
96
|
+
'PROPAGATOR_ENTAILMENT_NB': 4711,
|
|
97
|
+
'PROPAGATOR_FILTER_NB': 104392,
|
|
98
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 73792,
|
|
99
|
+
'PROPAGATOR_INCONSISTENCY_NB': 621,
|
|
100
|
+
'SOLVER_BACKTRACK_NB': 712,
|
|
101
|
+
'SOLVER_CHOICE_NB': 712,
|
|
102
|
+
'SOLVER_CHOICE_DEPTH': 19,
|
|
103
|
+
'SOLVER_SOLUTION_NB': 92
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Demonstrate that the optimal [10-marks Golomb ruler](https://www.csplib.org/Problems/prob006/) length is 55
|
|
108
|
+
```bash
|
|
109
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.golomb -n 10 --symmetry_breaking --log_level=INFO
|
|
110
|
+
```
|
|
111
|
+
```bash
|
|
112
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.solver - Problem has 82 propagators
|
|
113
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.solver - Problem has 45 variables
|
|
114
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
115
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 0
|
|
116
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 2
|
|
117
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
118
|
+
2024-11-12 17:27:45,172 - INFO - nucs.solvers.backtrack_solver - Minimizing variable 8
|
|
119
|
+
2024-11-12 17:27:45,644 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 80
|
|
120
|
+
2024-11-12 17:27:45,677 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 75
|
|
121
|
+
2024-11-12 17:27:45,677 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 73
|
|
122
|
+
2024-11-12 17:27:45,678 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 72
|
|
123
|
+
2024-11-12 17:27:45,679 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 70
|
|
124
|
+
2024-11-12 17:27:45,682 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 68
|
|
125
|
+
2024-11-12 17:27:45,687 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 66
|
|
126
|
+
2024-11-12 17:27:45,693 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 62
|
|
127
|
+
2024-11-12 17:27:45,717 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 60
|
|
128
|
+
2024-11-12 17:27:45,977 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 55
|
|
129
|
+
{
|
|
130
|
+
'OPTIMIZER_SOLUTION_NB': 10,
|
|
131
|
+
'PROBLEM_FILTER_NB': 22652,
|
|
132
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
133
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
134
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
135
|
+
'PROPAGATOR_ENTAILMENT_NB': 107911,
|
|
136
|
+
'PROPAGATOR_FILTER_NB': 2813035,
|
|
137
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 1745836,
|
|
138
|
+
'PROPAGATOR_INCONSISTENCY_NB': 11289,
|
|
139
|
+
'SOLVER_BACKTRACK_NB': 11288,
|
|
140
|
+
'SOLVER_CHOICE_NB': 11353,
|
|
141
|
+
'SOLVER_CHOICE_DEPTH': 9,
|
|
142
|
+
'SOLVER_SOLUTION_NB': 10
|
|
143
|
+
}
|
|
144
|
+
[ 1 6 10 23 26 34 41 53 55]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
|
@@ -74,9 +74,11 @@ nucs/propagators/relation_propagator.py
|
|
|
74
74
|
nucs/solvers/__init__.py
|
|
75
75
|
nucs/solvers/backtrack_solver.py
|
|
76
76
|
nucs/solvers/bound_consistency_algorithm.py
|
|
77
|
+
nucs/solvers/choice_points.py
|
|
77
78
|
nucs/solvers/consistency_algorithms.py
|
|
78
79
|
nucs/solvers/heuristics.py
|
|
79
80
|
nucs/solvers/multiprocessing_solver.py
|
|
81
|
+
nucs/solvers/shaving_consistency_algorithm.py
|
|
80
82
|
nucs/solvers/solver.py
|
|
81
83
|
tests/__init__.py
|
|
82
84
|
tests/examples/test_alpha.py
|
nucs-2.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: NUCS
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: A Numpy and Numba based Python library for solving Constraint Satisfaction Problems over finite domains
|
|
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/issues
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE.md
|
|
20
|
+
Requires-Dist: numba==0.60.0
|
|
21
|
+
Requires-Dist: numpy==2.0.1
|
|
22
|
+
|
|
23
|
+

|
|
24
|
+
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+

|
|
28
|
+
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+

|
|
35
|
+
|
|
36
|
+
## TLDR
|
|
37
|
+
NuCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
38
|
+
Because it is 100% written in Python,
|
|
39
|
+
NuCS is easy to install and allows to model complex problems in a few lines of code.
|
|
40
|
+
The NuCS solver is also very fast because it is powered by [Numpy](https://numpy.org/) and [Numba](https://numba.pydata.org/).
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
```bash
|
|
44
|
+
pip install nucs
|
|
45
|
+
```
|
|
46
|
+
## Documentation
|
|
47
|
+
Check out [NUCS documentation](https://nucs.readthedocs.io/).
|
|
48
|
+
|
|
49
|
+
## With NuCS, in a few seconds you can ...
|
|
50
|
+
### Find all 14200 solutions to the [12-queens problem](https://www.csplib.org/Problems/prob054/)
|
|
51
|
+
```bash
|
|
52
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.queens -n 12 --log_level=INFO
|
|
53
|
+
```
|
|
54
|
+
```bash
|
|
55
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.solver - Problem has 3 propagators
|
|
56
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.solver - Problem has 12 variables
|
|
57
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
58
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 0
|
|
59
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 0
|
|
60
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
61
|
+
2024-11-12 17:24:49,200 - INFO - nucs.solvers.multiprocessing_solver - MultiprocessingSolver has 1 processors
|
|
62
|
+
{
|
|
63
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
64
|
+
'PROBLEM_FILTER_NB': 262011,
|
|
65
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
66
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
67
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
68
|
+
'PROPAGATOR_ENTAILMENT_NB': 0,
|
|
69
|
+
'PROPAGATOR_FILTER_NB': 2269980,
|
|
70
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 990450,
|
|
71
|
+
'PROPAGATOR_INCONSISTENCY_NB': 116806,
|
|
72
|
+
'SOLVER_BACKTRACK_NB': 131005,
|
|
73
|
+
'SOLVER_CHOICE_NB': 131005,
|
|
74
|
+
'SOLVER_CHOICE_DEPTH': 10,
|
|
75
|
+
'SOLVER_SOLUTION_NB': 14200
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Compute the 92 solutions to the [BIBD(8,14,7,4,3) problem](https://www.csplib.org/Problems/prob028/)
|
|
80
|
+
```bash
|
|
81
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.bibd -v 8 -b 14 -r 7 -k 4 -l 3 --symmetry_breaking --log_level=INFO
|
|
82
|
+
```
|
|
83
|
+
```bash
|
|
84
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.solver - Problem has 462 propagators
|
|
85
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.solver - Problem has 504 variables
|
|
86
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
87
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 1
|
|
88
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 0
|
|
89
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
90
|
+
{
|
|
91
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
92
|
+
'PROBLEM_FILTER_NB': 1425,
|
|
93
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
94
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
95
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
96
|
+
'PROPAGATOR_ENTAILMENT_NB': 4711,
|
|
97
|
+
'PROPAGATOR_FILTER_NB': 104392,
|
|
98
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 73792,
|
|
99
|
+
'PROPAGATOR_INCONSISTENCY_NB': 621,
|
|
100
|
+
'SOLVER_BACKTRACK_NB': 712,
|
|
101
|
+
'SOLVER_CHOICE_NB': 712,
|
|
102
|
+
'SOLVER_CHOICE_DEPTH': 19,
|
|
103
|
+
'SOLVER_SOLUTION_NB': 92
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Demonstrate that the optimal [10-marks Golomb ruler](https://www.csplib.org/Problems/prob006/) length is 55
|
|
108
|
+
```bash
|
|
109
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.golomb -n 10 --symmetry_breaking --log_level=INFO
|
|
110
|
+
```
|
|
111
|
+
```bash
|
|
112
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.solver - Problem has 82 propagators
|
|
113
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.solver - Problem has 45 variables
|
|
114
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
115
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 0
|
|
116
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 2
|
|
117
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
118
|
+
2024-11-12 17:27:45,172 - INFO - nucs.solvers.backtrack_solver - Minimizing variable 8
|
|
119
|
+
2024-11-12 17:27:45,644 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 80
|
|
120
|
+
2024-11-12 17:27:45,677 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 75
|
|
121
|
+
2024-11-12 17:27:45,677 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 73
|
|
122
|
+
2024-11-12 17:27:45,678 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 72
|
|
123
|
+
2024-11-12 17:27:45,679 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 70
|
|
124
|
+
2024-11-12 17:27:45,682 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 68
|
|
125
|
+
2024-11-12 17:27:45,687 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 66
|
|
126
|
+
2024-11-12 17:27:45,693 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 62
|
|
127
|
+
2024-11-12 17:27:45,717 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 60
|
|
128
|
+
2024-11-12 17:27:45,977 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 55
|
|
129
|
+
{
|
|
130
|
+
'OPTIMIZER_SOLUTION_NB': 10,
|
|
131
|
+
'PROBLEM_FILTER_NB': 22652,
|
|
132
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
133
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
134
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
135
|
+
'PROPAGATOR_ENTAILMENT_NB': 107911,
|
|
136
|
+
'PROPAGATOR_FILTER_NB': 2813035,
|
|
137
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 1745836,
|
|
138
|
+
'PROPAGATOR_INCONSISTENCY_NB': 11289,
|
|
139
|
+
'SOLVER_BACKTRACK_NB': 11288,
|
|
140
|
+
'SOLVER_CHOICE_NB': 11353,
|
|
141
|
+
'SOLVER_CHOICE_DEPTH': 9,
|
|
142
|
+
'SOLVER_SOLUTION_NB': 10
|
|
143
|
+
}
|
|
144
|
+
[ 1 6 10 23 26 34 41 53 55]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
|
nucs-2.2.0/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
## TLDR
|
|
15
|
+
NuCS is a Python library for solving Constraint Satisfaction and Optimization Problems.
|
|
16
|
+
Because it is 100% written in Python,
|
|
17
|
+
NuCS is easy to install and allows to model complex problems in a few lines of code.
|
|
18
|
+
The NuCS solver is also very fast because it is powered by [Numpy](https://numpy.org/) and [Numba](https://numba.pydata.org/).
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
```bash
|
|
22
|
+
pip install nucs
|
|
23
|
+
```
|
|
24
|
+
## Documentation
|
|
25
|
+
Check out [NUCS documentation](https://nucs.readthedocs.io/).
|
|
26
|
+
|
|
27
|
+
## With NuCS, in a few seconds you can ...
|
|
28
|
+
### Find all 14200 solutions to the [12-queens problem](https://www.csplib.org/Problems/prob054/)
|
|
29
|
+
```bash
|
|
30
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.queens -n 12 --log_level=INFO
|
|
31
|
+
```
|
|
32
|
+
```bash
|
|
33
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.solver - Problem has 3 propagators
|
|
34
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.solver - Problem has 12 variables
|
|
35
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
36
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 0
|
|
37
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 0
|
|
38
|
+
2024-11-12 17:24:49,061 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
39
|
+
2024-11-12 17:24:49,200 - INFO - nucs.solvers.multiprocessing_solver - MultiprocessingSolver has 1 processors
|
|
40
|
+
{
|
|
41
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
42
|
+
'PROBLEM_FILTER_NB': 262011,
|
|
43
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
44
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
45
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
46
|
+
'PROPAGATOR_ENTAILMENT_NB': 0,
|
|
47
|
+
'PROPAGATOR_FILTER_NB': 2269980,
|
|
48
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 990450,
|
|
49
|
+
'PROPAGATOR_INCONSISTENCY_NB': 116806,
|
|
50
|
+
'SOLVER_BACKTRACK_NB': 131005,
|
|
51
|
+
'SOLVER_CHOICE_NB': 131005,
|
|
52
|
+
'SOLVER_CHOICE_DEPTH': 10,
|
|
53
|
+
'SOLVER_SOLUTION_NB': 14200
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Compute the 92 solutions to the [BIBD(8,14,7,4,3) problem](https://www.csplib.org/Problems/prob028/)
|
|
58
|
+
```bash
|
|
59
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.bibd -v 8 -b 14 -r 7 -k 4 -l 3 --symmetry_breaking --log_level=INFO
|
|
60
|
+
```
|
|
61
|
+
```bash
|
|
62
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.solver - Problem has 462 propagators
|
|
63
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.solver - Problem has 504 variables
|
|
64
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
65
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 1
|
|
66
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 0
|
|
67
|
+
2024-11-12 17:26:39,734 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
68
|
+
{
|
|
69
|
+
'OPTIMIZER_SOLUTION_NB': 0,
|
|
70
|
+
'PROBLEM_FILTER_NB': 1425,
|
|
71
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
72
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
73
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
74
|
+
'PROPAGATOR_ENTAILMENT_NB': 4711,
|
|
75
|
+
'PROPAGATOR_FILTER_NB': 104392,
|
|
76
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 73792,
|
|
77
|
+
'PROPAGATOR_INCONSISTENCY_NB': 621,
|
|
78
|
+
'SOLVER_BACKTRACK_NB': 712,
|
|
79
|
+
'SOLVER_CHOICE_NB': 712,
|
|
80
|
+
'SOLVER_CHOICE_DEPTH': 19,
|
|
81
|
+
'SOLVER_SOLUTION_NB': 92
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Demonstrate that the optimal [10-marks Golomb ruler](https://www.csplib.org/Problems/prob006/) length is 55
|
|
86
|
+
```bash
|
|
87
|
+
NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.golomb -n 10 --symmetry_breaking --log_level=INFO
|
|
88
|
+
```
|
|
89
|
+
```bash
|
|
90
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.solver - Problem has 82 propagators
|
|
91
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.solver - Problem has 45 variables
|
|
92
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses variable heuristic 0
|
|
93
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses domain heuristic 0
|
|
94
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - BacktrackSolver uses consistency algorithm 2
|
|
95
|
+
2024-11-12 17:27:45,110 - INFO - nucs.solvers.backtrack_solver - Choice points stack has a maximal height of 128
|
|
96
|
+
2024-11-12 17:27:45,172 - INFO - nucs.solvers.backtrack_solver - Minimizing variable 8
|
|
97
|
+
2024-11-12 17:27:45,644 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 80
|
|
98
|
+
2024-11-12 17:27:45,677 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 75
|
|
99
|
+
2024-11-12 17:27:45,677 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 73
|
|
100
|
+
2024-11-12 17:27:45,678 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 72
|
|
101
|
+
2024-11-12 17:27:45,679 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 70
|
|
102
|
+
2024-11-12 17:27:45,682 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 68
|
|
103
|
+
2024-11-12 17:27:45,687 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 66
|
|
104
|
+
2024-11-12 17:27:45,693 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 62
|
|
105
|
+
2024-11-12 17:27:45,717 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 60
|
|
106
|
+
2024-11-12 17:27:45,977 - INFO - nucs.solvers.backtrack_solver - Found a (new) solution: 55
|
|
107
|
+
{
|
|
108
|
+
'OPTIMIZER_SOLUTION_NB': 10,
|
|
109
|
+
'PROBLEM_FILTER_NB': 22652,
|
|
110
|
+
'PROBLEM_SHAVING_NB': 0,
|
|
111
|
+
'PROBLEM_SHAVING_CHANGE_NB': 0,
|
|
112
|
+
'PROBLEM_SHAVING_NO_CHANGE_NB': 0,
|
|
113
|
+
'PROPAGATOR_ENTAILMENT_NB': 107911,
|
|
114
|
+
'PROPAGATOR_FILTER_NB': 2813035,
|
|
115
|
+
'PROPAGATOR_FILTER_NO_CHANGE_NB': 1745836,
|
|
116
|
+
'PROPAGATOR_INCONSISTENCY_NB': 11289,
|
|
117
|
+
'SOLVER_BACKTRACK_NB': 11288,
|
|
118
|
+
'SOLVER_CHOICE_NB': 11353,
|
|
119
|
+
'SOLVER_CHOICE_DEPTH': 9,
|
|
120
|
+
'SOLVER_SOLUTION_NB': 10
|
|
121
|
+
}
|
|
122
|
+
[ 1 6 10 23 26 34 41 53 55]
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
|
|
@@ -42,8 +42,10 @@ SIGNATURE_CONSISTENCY_ALG = int64(
|
|
|
42
42
|
int32[:, :], # props_dom_offsets
|
|
43
43
|
int32[:], # props_parameters
|
|
44
44
|
bool[:, :, :], # shr_domains_propagators
|
|
45
|
-
int32[:, :], #
|
|
46
|
-
bool[:], #
|
|
45
|
+
int32[:, :, :], # shr_domains_stack
|
|
46
|
+
bool[:, :], # not_entailed_propagators_stack
|
|
47
|
+
uint16[:, :], # dom_update_stack
|
|
48
|
+
uint8[:], # stacks_height
|
|
47
49
|
bool[:], # triggered_propagators
|
|
48
50
|
int64[:], # compute_domains_addrs
|
|
49
51
|
)
|
|
@@ -54,3 +56,11 @@ TYPE_VAR_HEURISTIC = types.FunctionType(SIGNATURE_VAR_HEURISTIC)
|
|
|
54
56
|
TYPE_CONSISTENCY_ALG = types.FunctionType(SIGNATURE_CONSISTENCY_ALG)
|
|
55
57
|
|
|
56
58
|
NUMBA_DISABLE_JIT = os.getenv("NUMBA_DISABLE_JIT")
|
|
59
|
+
|
|
60
|
+
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(name)s - %(message)s"
|
|
61
|
+
LOG_LEVEL_DEBUG = "DEBUG"
|
|
62
|
+
LOG_LEVEL_INFO = "INFO"
|
|
63
|
+
LOG_LEVEL_WARNING = "WARNING"
|
|
64
|
+
LOG_LEVEL_ERROR = "ERROR"
|
|
65
|
+
LOG_LEVEL_CRITICAL = "CRITICAL"
|
|
66
|
+
LOG_LEVELS = [LOG_LEVEL_DEBUG, LOG_LEVEL_INFO, LOG_LEVEL_WARNING, LOG_LEVEL_ERROR, LOG_LEVEL_CRITICAL]
|
|
@@ -10,8 +10,11 @@
|
|
|
10
10
|
#
|
|
11
11
|
# Copyright 2024 - Yan Georget
|
|
12
12
|
###############################################################################
|
|
13
|
+
import argparse
|
|
14
|
+
|
|
13
15
|
from rich import print
|
|
14
16
|
|
|
17
|
+
from nucs.constants import LOG_LEVEL_INFO, LOG_LEVELS
|
|
15
18
|
from nucs.examples.alpha.alpha_problem import AlphaProblem
|
|
16
19
|
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
17
20
|
from nucs.solvers.heuristics import DOM_HEURISTIC_MIN_VALUE, VAR_HEURISTIC_SMALLEST_DOMAIN
|
|
@@ -20,9 +23,15 @@ from nucs.statistics import get_statistics
|
|
|
20
23
|
# Run with the following command (the second run is much faster because the code has been compiled):
|
|
21
24
|
# NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.alpha
|
|
22
25
|
if __name__ == "__main__":
|
|
26
|
+
parser = argparse.ArgumentParser()
|
|
27
|
+
parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
|
|
28
|
+
args = parser.parse_args()
|
|
23
29
|
problem = AlphaProblem()
|
|
24
30
|
solver = BacktrackSolver(
|
|
25
|
-
problem,
|
|
31
|
+
problem,
|
|
32
|
+
var_heuristic_idx=VAR_HEURISTIC_SMALLEST_DOMAIN,
|
|
33
|
+
dom_heuristic_idx=DOM_HEURISTIC_MIN_VALUE,
|
|
34
|
+
log_level=args.log_level,
|
|
26
35
|
)
|
|
27
36
|
solutions = solver.find_all()
|
|
28
37
|
print(get_statistics(solver.statistics))
|
|
@@ -14,6 +14,7 @@ import argparse
|
|
|
14
14
|
|
|
15
15
|
from rich import print
|
|
16
16
|
|
|
17
|
+
from nucs.constants import LOG_LEVEL_INFO, LOG_LEVELS
|
|
17
18
|
from nucs.examples.bibd.bibd_problem import BIBDProblem
|
|
18
19
|
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
19
20
|
from nucs.solvers.heuristics import DOM_HEURISTIC_MAX_VALUE
|
|
@@ -29,8 +30,9 @@ if __name__ == "__main__":
|
|
|
29
30
|
parser.add_argument("-k", type=int)
|
|
30
31
|
parser.add_argument("-l", type=int)
|
|
31
32
|
parser.add_argument("--symmetry_breaking", action=argparse.BooleanOptionalAction, default=True)
|
|
33
|
+
parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
|
|
32
34
|
args = parser.parse_args()
|
|
33
35
|
problem = BIBDProblem(args.v, args.b, args.r, args.k, args.l, args.symmetry_breaking)
|
|
34
|
-
solver = BacktrackSolver(problem, dom_heuristic_idx=DOM_HEURISTIC_MAX_VALUE)
|
|
36
|
+
solver = BacktrackSolver(problem, dom_heuristic_idx=DOM_HEURISTIC_MAX_VALUE, log_level=args.log_level)
|
|
35
37
|
solver.solve_all()
|
|
36
38
|
print(get_statistics(solver.statistics))
|
|
@@ -10,8 +10,11 @@
|
|
|
10
10
|
#
|
|
11
11
|
# Copyright 2024 - Yan Georget
|
|
12
12
|
###############################################################################
|
|
13
|
+
import argparse
|
|
14
|
+
|
|
13
15
|
from rich import print
|
|
14
16
|
|
|
17
|
+
from nucs.constants import LOG_LEVEL_INFO, LOG_LEVELS
|
|
15
18
|
from nucs.examples.donald.donald_problem import DonaldProblem
|
|
16
19
|
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
17
20
|
from nucs.solvers.heuristics import DOM_HEURISTIC_MIN_VALUE, VAR_HEURISTIC_SMALLEST_DOMAIN
|
|
@@ -20,9 +23,15 @@ from nucs.statistics import get_statistics
|
|
|
20
23
|
# Run with the following command (the second run is much faster because the code has been compiled):
|
|
21
24
|
# NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.donald
|
|
22
25
|
if __name__ == "__main__":
|
|
26
|
+
parser = argparse.ArgumentParser()
|
|
27
|
+
parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
|
|
28
|
+
args = parser.parse_args()
|
|
23
29
|
problem = DonaldProblem()
|
|
24
30
|
solver = BacktrackSolver(
|
|
25
|
-
problem,
|
|
31
|
+
problem,
|
|
32
|
+
var_heuristic_idx=VAR_HEURISTIC_SMALLEST_DOMAIN,
|
|
33
|
+
dom_heuristic_idx=DOM_HEURISTIC_MIN_VALUE,
|
|
34
|
+
log_level=args.log_level,
|
|
26
35
|
)
|
|
27
36
|
print(get_statistics(solver.statistics))
|
|
28
37
|
for solution in solver.solve():
|
|
@@ -14,6 +14,7 @@ import argparse
|
|
|
14
14
|
|
|
15
15
|
from rich import print
|
|
16
16
|
|
|
17
|
+
from nucs.constants import LOG_LEVEL_INFO, LOG_LEVELS
|
|
17
18
|
from nucs.examples.golomb.golomb_problem import GolombProblem, golomb_consistency_algorithm
|
|
18
19
|
from nucs.solvers.backtrack_solver import BacktrackSolver
|
|
19
20
|
from nucs.solvers.consistency_algorithms import register_consistency_algorithm
|
|
@@ -25,10 +26,11 @@ if __name__ == "__main__":
|
|
|
25
26
|
parser = argparse.ArgumentParser()
|
|
26
27
|
parser.add_argument("-n", type=int, default=10)
|
|
27
28
|
parser.add_argument("--symmetry_breaking", action=argparse.BooleanOptionalAction, default=True)
|
|
29
|
+
parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
|
|
28
30
|
args = parser.parse_args()
|
|
29
31
|
problem = GolombProblem(args.n, args.symmetry_breaking)
|
|
30
32
|
consistency_alg_golomb = register_consistency_algorithm(golomb_consistency_algorithm)
|
|
31
|
-
solver = BacktrackSolver(problem, consistency_alg_idx=consistency_alg_golomb)
|
|
33
|
+
solver = BacktrackSolver(problem, consistency_alg_idx=consistency_alg_golomb, log_level=args.log_level)
|
|
32
34
|
solution = solver.minimize(problem.length_idx)
|
|
33
35
|
print(get_statistics(solver.statistics))
|
|
34
36
|
if solution is not None:
|
|
@@ -18,7 +18,7 @@ from numpy.typing import NDArray
|
|
|
18
18
|
|
|
19
19
|
from nucs.constants import MAX, MIN
|
|
20
20
|
from nucs.problems.problem import Problem
|
|
21
|
-
from nucs.propagators.propagators import ALG_AFFINE_EQ, ALG_AFFINE_LEQ, ALG_ALLDIFFERENT
|
|
21
|
+
from nucs.propagators.propagators import ALG_AFFINE_EQ, ALG_AFFINE_LEQ, ALG_ALLDIFFERENT, add_propagators
|
|
22
22
|
from nucs.solvers.bound_consistency_algorithm import bound_consistency_algorithm
|
|
23
23
|
from nucs.solvers.heuristics import first_not_instantiated_var_heuristic
|
|
24
24
|
|
|
@@ -124,8 +124,10 @@ def golomb_consistency_algorithm(
|
|
|
124
124
|
props_dom_offsets: NDArray,
|
|
125
125
|
props_parameters: NDArray,
|
|
126
126
|
shr_domains_propagators: NDArray,
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
shr_domains_stack: NDArray,
|
|
128
|
+
not_entailed_propagators_stack: NDArray,
|
|
129
|
+
dom_update_stack: NDArray,
|
|
130
|
+
stacks_height: NDArray,
|
|
129
131
|
triggered_propagators: NDArray,
|
|
130
132
|
compute_domains_addrs: NDArray,
|
|
131
133
|
) -> int:
|
|
@@ -137,7 +139,7 @@ def golomb_consistency_algorithm(
|
|
|
137
139
|
"""
|
|
138
140
|
# first prune the search space
|
|
139
141
|
mark_nb = (1 + int(math.sqrt(8 * len(dom_indices_arr) + 1))) // 2
|
|
140
|
-
ni_var_idx = first_not_instantiated_var_heuristic(
|
|
142
|
+
ni_var_idx = first_not_instantiated_var_heuristic(shr_domains_stack[0]) # no domains shared between vars
|
|
141
143
|
if 1 < ni_var_idx < mark_nb - 1: # otherwise useless
|
|
142
144
|
used_distance = np.zeros(sum_first(mark_nb - 2) + 1, dtype=np.bool)
|
|
143
145
|
# a reusable array for storing the minimal sum of different integers:
|
|
@@ -146,7 +148,7 @@ def golomb_consistency_algorithm(
|
|
|
146
148
|
# the following will mark at most sum(n-3) numbers as used
|
|
147
149
|
# hence there will be at least n-2 unused numbers greater than 0
|
|
148
150
|
for var_idx in range(index(mark_nb, ni_var_idx - 2, ni_var_idx - 1) + 1):
|
|
149
|
-
dist =
|
|
151
|
+
dist = shr_domains_stack[0, dom_indices_arr[var_idx], MIN] # no offset
|
|
150
152
|
if dist < len(used_distance):
|
|
151
153
|
used_distance[dist] = True
|
|
152
154
|
# let's compute the sum of non-used numbers
|
|
@@ -158,7 +160,11 @@ def golomb_consistency_algorithm(
|
|
|
158
160
|
distance += 1
|
|
159
161
|
for i in range(ni_var_idx - 1, mark_nb - 1):
|
|
160
162
|
for j in range(i + 1, mark_nb):
|
|
161
|
-
|
|
163
|
+
dom_idx = dom_indices_arr[index(mark_nb, i, j)]
|
|
164
|
+
shr_domains_stack[0, dom_idx, MIN] = minimal_sum[j - i] # no offset
|
|
165
|
+
add_propagators(
|
|
166
|
+
triggered_propagators, not_entailed_propagators_stack[0], shr_domains_propagators, dom_idx, MIN
|
|
167
|
+
)
|
|
162
168
|
return bound_consistency_algorithm(
|
|
163
169
|
statistics,
|
|
164
170
|
algorithms,
|
|
@@ -170,8 +176,10 @@ def golomb_consistency_algorithm(
|
|
|
170
176
|
props_dom_offsets,
|
|
171
177
|
props_parameters,
|
|
172
178
|
shr_domains_propagators,
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
shr_domains_stack,
|
|
180
|
+
not_entailed_propagators_stack,
|
|
181
|
+
dom_update_stack,
|
|
182
|
+
stacks_height,
|
|
175
183
|
triggered_propagators,
|
|
176
184
|
compute_domains_addrs,
|
|
177
185
|
)
|