NUCS 2.1.0__tar.gz → 2.3.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.
Files changed (123) hide show
  1. nucs-2.3.0/NUCS.egg-info/PKG-INFO +147 -0
  2. {nucs-2.1.0 → nucs-2.3.0}/NUCS.egg-info/SOURCES.txt +0 -1
  3. nucs-2.3.0/PKG-INFO +147 -0
  4. nucs-2.3.0/README.md +125 -0
  5. {nucs-2.1.0 → nucs-2.3.0}/docs/source/conf.py +2 -2
  6. {nucs-2.1.0 → nucs-2.3.0}/nucs/constants.py +39 -0
  7. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/alpha/__main__.py +12 -4
  8. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/bibd/__main__.py +5 -4
  9. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/donald/__main__.py +12 -4
  10. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/golomb/__main__.py +5 -4
  11. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/knapsack/__main__.py +12 -4
  12. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/magic_sequence/__main__.py +8 -4
  13. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/magic_square/__main__.py +8 -4
  14. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/quasigroup/__main__.py +8 -4
  15. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/queens/__main__.py +5 -3
  16. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/schur_lemma/__main__.py +5 -4
  17. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/sports_tournament_scheduling/__main__.py +8 -4
  18. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/backtrack_solver.py +85 -35
  19. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/bound_consistency_algorithm.py +6 -8
  20. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/choice_points.py +1 -1
  21. nucs-2.3.0/nucs/solvers/multiprocessing_solver.py +132 -0
  22. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/shaving_consistency_algorithm.py +14 -9
  23. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/solver.py +23 -1
  24. {nucs-2.1.0 → nucs-2.3.0}/pyproject.toml +1 -1
  25. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_alpha.py +1 -1
  26. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_bibd.py +1 -1
  27. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_donald.py +1 -1
  28. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_latin_square.py +1 -1
  29. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_magic_sequence.py +1 -1
  30. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_magic_square.py +1 -1
  31. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_quasigroup.py +1 -1
  32. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_queens.py +1 -1
  33. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_schur_lemma.py +1 -1
  34. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_sudokus.py +1 -1
  35. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_lexicographic_leq.py +1 -2
  36. {nucs-2.1.0 → nucs-2.3.0}/tests/solvers/test_backtrack_solver.py +11 -12
  37. {nucs-2.1.0 → nucs-2.3.0}/tests/solvers/test_multiprocessing_solver.py +9 -5
  38. nucs-2.1.0/NUCS.egg-info/PKG-INFO +0 -114
  39. nucs-2.1.0/PKG-INFO +0 -114
  40. nucs-2.1.0/README.md +0 -92
  41. nucs-2.1.0/nucs/solvers/multiprocessing_solver.py +0 -66
  42. nucs-2.1.0/nucs/statistics.py +0 -112
  43. {nucs-2.1.0 → nucs-2.3.0}/LICENSE.md +0 -0
  44. {nucs-2.1.0 → nucs-2.3.0}/NUCS.egg-info/dependency_links.txt +0 -0
  45. {nucs-2.1.0 → nucs-2.3.0}/NUCS.egg-info/requires.txt +0 -0
  46. {nucs-2.1.0 → nucs-2.3.0}/NUCS.egg-info/top_level.txt +0 -0
  47. {nucs-2.1.0 → nucs-2.3.0}/nucs/__init__.py +0 -0
  48. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/__init__.py +0 -0
  49. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/alpha/__init__.py +0 -0
  50. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/alpha/alpha_problem.py +0 -0
  51. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/bibd/__init__.py +0 -0
  52. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/bibd/bibd_problem.py +0 -0
  53. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/donald/__init__.py +0 -0
  54. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/donald/donald_problem.py +0 -0
  55. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/golomb/__init__.py +0 -0
  56. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/golomb/golomb_problem.py +0 -0
  57. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/knapsack/__init__.py +0 -0
  58. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/knapsack/knapsack_problem.py +0 -0
  59. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/magic_sequence/__init__.py +0 -0
  60. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/magic_sequence/magic_sequence_problem.py +0 -0
  61. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/magic_square/__init__.py +0 -0
  62. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/magic_square/magic_square_problem.py +0 -0
  63. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/quasigroup/__init__.py +0 -0
  64. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/quasigroup/quasigroup_problem.py +0 -0
  65. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/queens/__init__.py +0 -0
  66. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/queens/queens_problem.py +0 -0
  67. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/schur_lemma/__init__.py +0 -0
  68. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/schur_lemma/schur_lemma_problem.py +0 -0
  69. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/sports_tournament_scheduling/__init__.py +0 -0
  70. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/sports_tournament_scheduling/sports_tournament_scheduling_problem.py +0 -0
  71. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/sudoku/__init__.py +0 -0
  72. {nucs-2.1.0 → nucs-2.3.0}/nucs/examples/sudoku/sudoku_problem.py +0 -0
  73. {nucs-2.1.0 → nucs-2.3.0}/nucs/numba_helper.py +0 -0
  74. {nucs-2.1.0 → nucs-2.3.0}/nucs/numpy_helper.py +0 -0
  75. {nucs-2.1.0 → nucs-2.3.0}/nucs/problems/__init__.py +0 -0
  76. {nucs-2.1.0 → nucs-2.3.0}/nucs/problems/latin_square_problem.py +0 -0
  77. {nucs-2.1.0 → nucs-2.3.0}/nucs/problems/problem.py +0 -0
  78. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/__init__.py +0 -0
  79. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/affine_eq_propagator.py +0 -0
  80. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/affine_geq_propagator.py +0 -0
  81. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/affine_leq_propagator.py +0 -0
  82. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/alldifferent_propagator.py +0 -0
  83. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/and_propagator.py +0 -0
  84. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/count_eq_propagator.py +0 -0
  85. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/dummy_propagator.py +0 -0
  86. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/element_lic_propagator.py +0 -0
  87. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/element_liv_propagator.py +0 -0
  88. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/exactly_eq_propagator.py +0 -0
  89. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/exactly_true_propagator.py +0 -0
  90. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/gcc_propagator.py +0 -0
  91. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/lexicographic_leq_propagator.py +0 -0
  92. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/max_eq_propagator.py +0 -0
  93. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/max_leq_propagator.py +0 -0
  94. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/min_eq_propagator.py +0 -0
  95. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/min_geq_propagator.py +0 -0
  96. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/propagators.py +0 -0
  97. {nucs-2.1.0 → nucs-2.3.0}/nucs/propagators/relation_propagator.py +0 -0
  98. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/__init__.py +0 -0
  99. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/consistency_algorithms.py +0 -0
  100. {nucs-2.1.0 → nucs-2.3.0}/nucs/solvers/heuristics.py +0 -0
  101. {nucs-2.1.0 → nucs-2.3.0}/setup.cfg +0 -0
  102. {nucs-2.1.0 → nucs-2.3.0}/tests/__init__.py +0 -0
  103. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_golomb.py +0 -0
  104. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_knapsack.py +0 -0
  105. {nucs-2.1.0 → nucs-2.3.0}/tests/examples/test_sports_tournament_scheduling.py +0 -0
  106. {nucs-2.1.0 → nucs-2.3.0}/tests/problems/__init__.py +0 -0
  107. {nucs-2.1.0 → nucs-2.3.0}/tests/problems/test_problem.py +0 -0
  108. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/__init__.py +0 -0
  109. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_affine_eq.py +0 -0
  110. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_affine_geq.py +0 -0
  111. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_affine_leq.py +0 -0
  112. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_alldifferent.py +0 -0
  113. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_count_eq.py +0 -0
  114. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_element_lic.py +0 -0
  115. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_element_liv.py +0 -0
  116. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_exactly_eq.py +0 -0
  117. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_gcc.py +0 -0
  118. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_max_eq.py +0 -0
  119. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_max_leq.py +0 -0
  120. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_min_eq.py +0 -0
  121. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_min_geq.py +0 -0
  122. {nucs-2.1.0 → nucs-2.3.0}/tests/propagators/test_relation.py +0 -0
  123. {nucs-2.1.0 → nucs-2.3.0}/tests/solvers/__init__.py +0 -0
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.1
2
+ Name: NUCS
3
+ Version: 2.3.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
+ ![NucS logo](https://github.com/yangeorget/nucs/blob/main/assets/nucs.png?raw=true)
24
+
25
+
26
+ ![pypi version](https://img.shields.io/pypi/v/nucs?color=blue&label=pypi%20version&logo=pypi&logoColor=white)
27
+ ![pypi downloads](https://img.shields.io/pypi/dm/NUCS)
28
+
29
+ ![numba version](https://img.shields.io/badge/numba-v0.60-blue)
30
+ ![numpy version](https://img.shields.io/badge/numpy-v2.0-blue)
31
+
32
+ ![tests](https://github.com/yangeorget/nucs/actions/workflows/test.yml/badge.svg)
33
+ ![doc](https://img.shields.io/readthedocs/nucs)
34
+ ![license](https://img.shields.io/github/license/yangeorget/nucs)
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
+ 'ALG_BC_NB': 262011,
64
+ 'ALG_BC_WITH_SHAVING_NB': 0,
65
+ 'ALG_SHAVING_NB': 0,
66
+ 'ALG_SHAVING_CHANGE_NB': 0,
67
+ 'ALG_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
+ 'ALG_BC_NB': 1425,
92
+ 'ALG_BC_WITH_SHAVING_NB': 0,
93
+ 'ALG_SHAVING_NB': 0,
94
+ 'ALG_SHAVING_CHANGE_NB': 0,
95
+ 'ALG_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
+ 'ALG_BC_NB': 22652,
131
+ 'ALG_BC_WITH_SHAVING_NB': 0,
132
+ 'ALG_SHAVING_NB': 0,
133
+ 'ALG_SHAVING_CHANGE_NB': 0,
134
+ 'ALG_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
+
@@ -11,7 +11,6 @@ nucs/__init__.py
11
11
  nucs/constants.py
12
12
  nucs/numba_helper.py
13
13
  nucs/numpy_helper.py
14
- nucs/statistics.py
15
14
  nucs/examples/__init__.py
16
15
  nucs/examples/alpha/__init__.py
17
16
  nucs/examples/alpha/__main__.py
nucs-2.3.0/PKG-INFO ADDED
@@ -0,0 +1,147 @@
1
+ Metadata-Version: 2.1
2
+ Name: NUCS
3
+ Version: 2.3.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
+ ![NucS logo](https://github.com/yangeorget/nucs/blob/main/assets/nucs.png?raw=true)
24
+
25
+
26
+ ![pypi version](https://img.shields.io/pypi/v/nucs?color=blue&label=pypi%20version&logo=pypi&logoColor=white)
27
+ ![pypi downloads](https://img.shields.io/pypi/dm/NUCS)
28
+
29
+ ![numba version](https://img.shields.io/badge/numba-v0.60-blue)
30
+ ![numpy version](https://img.shields.io/badge/numpy-v2.0-blue)
31
+
32
+ ![tests](https://github.com/yangeorget/nucs/actions/workflows/test.yml/badge.svg)
33
+ ![doc](https://img.shields.io/readthedocs/nucs)
34
+ ![license](https://img.shields.io/github/license/yangeorget/nucs)
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
+ 'ALG_BC_NB': 262011,
64
+ 'ALG_BC_WITH_SHAVING_NB': 0,
65
+ 'ALG_SHAVING_NB': 0,
66
+ 'ALG_SHAVING_CHANGE_NB': 0,
67
+ 'ALG_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
+ 'ALG_BC_NB': 1425,
92
+ 'ALG_BC_WITH_SHAVING_NB': 0,
93
+ 'ALG_SHAVING_NB': 0,
94
+ 'ALG_SHAVING_CHANGE_NB': 0,
95
+ 'ALG_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
+ 'ALG_BC_NB': 22652,
131
+ 'ALG_BC_WITH_SHAVING_NB': 0,
132
+ 'ALG_SHAVING_NB': 0,
133
+ 'ALG_SHAVING_CHANGE_NB': 0,
134
+ 'ALG_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.3.0/README.md ADDED
@@ -0,0 +1,125 @@
1
+ ![NucS logo](https://github.com/yangeorget/nucs/blob/main/assets/nucs.png?raw=true)
2
+
3
+
4
+ ![pypi version](https://img.shields.io/pypi/v/nucs?color=blue&label=pypi%20version&logo=pypi&logoColor=white)
5
+ ![pypi downloads](https://img.shields.io/pypi/dm/NUCS)
6
+
7
+ ![numba version](https://img.shields.io/badge/numba-v0.60-blue)
8
+ ![numpy version](https://img.shields.io/badge/numpy-v2.0-blue)
9
+
10
+ ![tests](https://github.com/yangeorget/nucs/actions/workflows/test.yml/badge.svg)
11
+ ![doc](https://img.shields.io/readthedocs/nucs)
12
+ ![license](https://img.shields.io/github/license/yangeorget/nucs)
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
+ 'ALG_BC_NB': 262011,
42
+ 'ALG_BC_WITH_SHAVING_NB': 0,
43
+ 'ALG_SHAVING_NB': 0,
44
+ 'ALG_SHAVING_CHANGE_NB': 0,
45
+ 'ALG_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
+ 'ALG_BC_NB': 1425,
70
+ 'ALG_BC_WITH_SHAVING_NB': 0,
71
+ 'ALG_SHAVING_NB': 0,
72
+ 'ALG_SHAVING_CHANGE_NB': 0,
73
+ 'ALG_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
+ 'ALG_BC_NB': 22652,
109
+ 'ALG_BC_WITH_SHAVING_NB': 0,
110
+ 'ALG_SHAVING_NB': 0,
111
+ 'ALG_SHAVING_CHANGE_NB': 0,
112
+ 'ALG_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
+
@@ -6,8 +6,8 @@ project = 'NUCS'
6
6
  copyright = '2024, Yan Georget'
7
7
  author = 'Yan Georget'
8
8
 
9
- release = '2.1.0'
10
- version = '2.1.0'
9
+ release = '2.3.0'
10
+ version = '2.3.0'
11
11
 
12
12
  # -- General configuration
13
13
 
@@ -56,3 +56,42 @@ TYPE_VAR_HEURISTIC = types.FunctionType(SIGNATURE_VAR_HEURISTIC)
56
56
  TYPE_CONSISTENCY_ALG = types.FunctionType(SIGNATURE_CONSISTENCY_ALG)
57
57
 
58
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]
67
+
68
+ STATS_MAX = 13
69
+ (
70
+ STATS_IDX_ALG_BC_NB,
71
+ STATS_IDX_ALG_BC_WITH_SHAVING_NB,
72
+ STATS_IDX_ALG_SHAVING_NB,
73
+ STATS_IDX_ALG_SHAVING_CHANGE_NB,
74
+ STATS_IDX_ALG_SHAVING_NO_CHANGE_NB,
75
+ STATS_IDX_PROPAGATOR_ENTAILMENT_NB,
76
+ STATS_IDX_PROPAGATOR_FILTER_NB,
77
+ STATS_IDX_PROPAGATOR_FILTER_NO_CHANGE_NB,
78
+ STATS_IDX_PROPAGATOR_INCONSISTENCY_NB,
79
+ STATS_IDX_SOLVER_BACKTRACK_NB,
80
+ STATS_IDX_SOLVER_CHOICE_NB,
81
+ STATS_IDX_SOLVER_CHOICE_DEPTH,
82
+ STATS_IDX_SOLVER_SOLUTION_NB,
83
+ ) = tuple(range(STATS_MAX))
84
+
85
+ STATS_LBL_ALG_BC_NB = "ALG_BC_NB"
86
+ STATS_LBL_ALG_BC_WITH_SHAVING_NB = "ALG_BC_WITH_SHAVING_NB"
87
+ STATS_LBL_ALG_SHAVING_NB = "ALG_SHAVING_NB"
88
+ STATS_LBL_ALG_SHAVING_CHANGE_NB = "ALG_SHAVING_CHANGE_NB"
89
+ STATS_LBL_ALG_SHAVING_NO_CHANGE_NB = "ALG_SHAVING_NO_CHANGE_NB"
90
+ STATS_LBL_PROPAGATOR_ENTAILMENT_NB = "PROPAGATOR_ENTAILMENT_NB"
91
+ STATS_LBL_PROPAGATOR_FILTER_NB = "PROPAGATOR_FILTER_NB"
92
+ STATS_LBL_PROPAGATOR_FILTER_NO_CHANGE_NB = "PROPAGATOR_FILTER_NO_CHANGE_NB"
93
+ STATS_LBL_PROPAGATOR_INCONSISTENCY_NB = "PROPAGATOR_INCONSISTENCY_NB"
94
+ STATS_LBL_SOLVER_BACKTRACK_NB = "SOLVER_BACKTRACK_NB"
95
+ STATS_LBL_SOLVER_CHOICE_NB = "SOLVER_CHOICE_NB"
96
+ STATS_LBL_SOLVER_CHOICE_DEPTH = "SOLVER_CHOICE_DEPTH"
97
+ STATS_LBL_SOLVER_SOLUTION_NB = "SOLVER_SOLUTION_NB"
@@ -10,20 +10,28 @@
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
18
- from nucs.statistics import get_statistics
19
21
 
20
22
  # Run with the following command (the second run is much faster because the code has been compiled):
21
- # NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.alpha
23
+ # NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.alpha
22
24
  if __name__ == "__main__":
25
+ parser = argparse.ArgumentParser()
26
+ parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
27
+ args = parser.parse_args()
23
28
  problem = AlphaProblem()
24
29
  solver = BacktrackSolver(
25
- problem, var_heuristic_idx=VAR_HEURISTIC_SMALLEST_DOMAIN, dom_heuristic_idx=DOM_HEURISTIC_MIN_VALUE
30
+ problem,
31
+ var_heuristic_idx=VAR_HEURISTIC_SMALLEST_DOMAIN,
32
+ dom_heuristic_idx=DOM_HEURISTIC_MIN_VALUE,
33
+ log_level=args.log_level,
26
34
  )
27
35
  solutions = solver.find_all()
28
- print(get_statistics(solver.statistics))
36
+ print(solver.get_statistics())
29
37
  print(problem.solution_as_dict(solutions[0]))
@@ -14,13 +14,13 @@ 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
20
- from nucs.statistics import get_statistics
21
21
 
22
22
  # Run with the following command (the second run is much faster because the code has been compiled):
23
- # NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.bibd -v 8 -b 14 -r 7 -k 4 -l 3 --symmetry_breaking
23
+ # NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.bibd -v 8 -b 14 -r 7 -k 4 -l 3 --symmetry_breaking
24
24
  if __name__ == "__main__":
25
25
  parser = argparse.ArgumentParser()
26
26
  parser.add_argument("-v", type=int)
@@ -29,8 +29,9 @@ if __name__ == "__main__":
29
29
  parser.add_argument("-k", type=int)
30
30
  parser.add_argument("-l", type=int)
31
31
  parser.add_argument("--symmetry_breaking", action=argparse.BooleanOptionalAction, default=True)
32
+ parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
32
33
  args = parser.parse_args()
33
34
  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)
35
+ solver = BacktrackSolver(problem, dom_heuristic_idx=DOM_HEURISTIC_MAX_VALUE, log_level=args.log_level)
35
36
  solver.solve_all()
36
- print(get_statistics(solver.statistics))
37
+ print(solver.get_statistics())
@@ -10,20 +10,28 @@
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
18
- from nucs.statistics import get_statistics
19
21
 
20
22
  # Run with the following command (the second run is much faster because the code has been compiled):
21
- # NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.donald
23
+ # NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.donald
22
24
  if __name__ == "__main__":
25
+ parser = argparse.ArgumentParser()
26
+ parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
27
+ args = parser.parse_args()
23
28
  problem = DonaldProblem()
24
29
  solver = BacktrackSolver(
25
- problem, var_heuristic_idx=VAR_HEURISTIC_SMALLEST_DOMAIN, dom_heuristic_idx=DOM_HEURISTIC_MIN_VALUE
30
+ problem,
31
+ var_heuristic_idx=VAR_HEURISTIC_SMALLEST_DOMAIN,
32
+ dom_heuristic_idx=DOM_HEURISTIC_MIN_VALUE,
33
+ log_level=args.log_level,
26
34
  )
27
- print(get_statistics(solver.statistics))
35
+ print(solver.get_statistics())
28
36
  for solution in solver.solve():
29
37
  print(problem.solution_as_dict(solution))
@@ -14,22 +14,23 @@ 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
20
- from nucs.statistics import get_statistics
21
21
 
22
22
  # Run with the following command (the second run is much faster because the code has been compiled):
23
- # NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.golomb -n 10 --symmetry_breaking
23
+ # NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.golomb -n 10 --symmetry_breaking
24
24
  if __name__ == "__main__":
25
25
  parser = argparse.ArgumentParser()
26
26
  parser.add_argument("-n", type=int, default=10)
27
27
  parser.add_argument("--symmetry_breaking", action=argparse.BooleanOptionalAction, default=True)
28
+ parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
28
29
  args = parser.parse_args()
29
30
  problem = GolombProblem(args.n, args.symmetry_breaking)
30
31
  consistency_alg_golomb = register_consistency_algorithm(golomb_consistency_algorithm)
31
- solver = BacktrackSolver(problem, consistency_alg_idx=consistency_alg_golomb)
32
+ solver = BacktrackSolver(problem, consistency_alg_idx=consistency_alg_golomb, log_level=args.log_level)
32
33
  solution = solver.minimize(problem.length_idx)
33
- print(get_statistics(solver.statistics))
34
+ print(solver.get_statistics())
34
35
  if solution is not None:
35
36
  print(solution[: (args.n - 1)])
@@ -10,24 +10,32 @@
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.knapsack.knapsack_problem import KnapsackProblem
16
19
  from nucs.solvers.backtrack_solver import BacktrackSolver
17
20
  from nucs.solvers.heuristics import DOM_HEURISTIC_MAX_VALUE, VAR_HEURISTIC_FIRST_NOT_INSTANTIATED
18
- from nucs.statistics import get_statistics
19
21
 
20
22
  # Run with the following command (the second run is much faster because the code has been compiled):
21
- # NUMBA_CACHE_DIR=.numba/cache PYTHONPATH=. python -m nucs.examples.knapsack
23
+ # NUMBA_CACHE_DIR=.numba/cache python -m nucs.examples.knapsack
22
24
  if __name__ == "__main__":
25
+ parser = argparse.ArgumentParser()
26
+ parser.add_argument("--log_level", choices=LOG_LEVELS, default=LOG_LEVEL_INFO)
27
+ args = parser.parse_args()
23
28
  problem = KnapsackProblem(
24
29
  [40, 40, 38, 38, 36, 36, 34, 34, 32, 32, 30, 30, 28, 28, 26, 26, 24, 24, 22, 22],
25
30
  [40, 40, 38, 38, 36, 36, 34, 34, 32, 32, 30, 30, 28, 28, 26, 26, 24, 24, 22, 22],
26
31
  55,
27
32
  )
28
33
  solver = BacktrackSolver(
29
- problem, var_heuristic_idx=VAR_HEURISTIC_FIRST_NOT_INSTANTIATED, dom_heuristic_idx=DOM_HEURISTIC_MAX_VALUE
34
+ problem,
35
+ var_heuristic_idx=VAR_HEURISTIC_FIRST_NOT_INSTANTIATED,
36
+ dom_heuristic_idx=DOM_HEURISTIC_MAX_VALUE,
37
+ log_level=args.log_level,
30
38
  )
31
39
  solution = solver.maximize(problem.weight)
32
- print(get_statistics(solver.statistics))
40
+ print(solver.get_statistics())
33
41
  print(solution)