Thanks to visit codestin.com
Credit goes to github.com

Skip to content

String constraints, Parallel solver #91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 63 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
986cbda
Rewrite of optimized backtracking
fjwillemsen Jan 30, 2025
a2db389
Cythonized using 3.0.11
fjwillemsen Jan 30, 2025
ec68ba8
Optimized version of rewritten recursive backtracking
fjwillemsen Jan 31, 2025
517e3be
Added type hints to new optimized backtracking version
fjwillemsen Jan 31, 2025
2d6fc02
Optimized backtracking algorithm version 4: ordering and yielding
fjwillemsen Jan 31, 2025
e092278
Rewrote for linting compliance
fjwillemsen Jan 31, 2025
a301d2f
Regenerated C-version after changess
fjwillemsen Jan 31, 2025
189ae64
Implemented parallel version
fjwillemsen Feb 3, 2025
a5c36da
Implemented Python parallel version of solvver
fjwillemsen Feb 3, 2025
c9fcaa4
Implemented Parallel solver class
fjwillemsen Feb 3, 2025
8373d3f
Wrote tests for Parallel Solver
fjwillemsen Feb 3, 2025
f338beb
Initial implementation of parser
fjwillemsen Feb 7, 2025
417dde1
Implemented tests for parser
fjwillemsen Feb 7, 2025
6a05abe
Implemented tests for compile_restrictions
fjwillemsen Feb 8, 2025
5a9ab6b
Removed redundant formats
fjwillemsen Feb 8, 2025
aee2ad3
Made compliant with linting
fjwillemsen Feb 9, 2025
e61955b
Cythonized parser file, recythonized other files
fjwillemsen Feb 9, 2025
09c5fe7
Implemented compilation of string constraints
fjwillemsen Feb 9, 2025
14207ce
Recythonized parser and problem files
fjwillemsen Feb 9, 2025
7043d63
Added tests for string constraints
fjwillemsen Feb 9, 2025
7f4b173
Extended comments, improved linting compliance
fjwillemsen Feb 9, 2025
f9e1b6e
Minor changes due to recythonization
fjwillemsen Feb 9, 2025
89d822e
Merge branch 'main' into parser
fjwillemsen Feb 9, 2025
1287522
Merge with parser branch, recythonization
fjwillemsen Feb 9, 2025
817918a
Switched to ProcessPoolExecutor for parallel solver
fjwillemsen Feb 9, 2025
9da0118
Added string constraint to parallel tests
fjwillemsen Feb 9, 2025
bc91e35
Added the Compilable Function constraint to be compiled in parallel p…
fjwillemsen Feb 10, 2025
c124e73
Added picklable creation to parser
fjwillemsen Feb 10, 2025
1b4a1dd
Automatic handling of picklable constraints
fjwillemsen Feb 10, 2025
ee26107
Implemented runtime compilation of function constraints in parallel p…
fjwillemsen Feb 10, 2025
119fdbc
Extended ParallelSolver documentation, fixed example
fjwillemsen Feb 10, 2025
185d07e
Cythonized parallel solver and CompilableFunctionConstraint
fjwillemsen Feb 10, 2025
4ad605c
Implemented optimized backtracking solver for parallel version
fjwillemsen Feb 10, 2025
267d613
Removed redundant deepcopies
fjwillemsen Feb 10, 2025
0fb5f39
Removed unused imports, compliance with linting
fjwillemsen Feb 10, 2025
8f65a18
Added Python 3.13 and experimental 3.14 support, bumped version
fjwillemsen Feb 11, 2025
8a35a38
Updated package dependencies
fjwillemsen Feb 11, 2025
822b50a
Updated docs dependencies
fjwillemsen Feb 11, 2025
cf9c245
Updated the changelog and readme to reflect new additions
fjwillemsen Feb 11, 2025
aae52fe
Implemented switching between ProcessPool and ThreadPool, pickling op…
fjwillemsen Feb 11, 2025
13a6a1e
Error message when using FunctionConstraints when pickling
fjwillemsen Feb 11, 2025
f325e5a
Added tests for the ParallelSolver modes and understandable errors
fjwillemsen Feb 11, 2025
1be7d17
Extended tests to include testing for constraint types resulting from…
fjwillemsen Feb 11, 2025
c98da24
Added warnings for experimental parsing and ParallelSolver
fjwillemsen Feb 11, 2025
ea3b667
Wrote parser documentation
fjwillemsen Feb 11, 2025
1cc9174
Extended type hints and documentation docstrings
fjwillemsen Feb 11, 2025
c2def4f
Removed monolithic options
fjwillemsen Feb 11, 2025
46443fe
Removed monolithic options
fjwillemsen Feb 11, 2025
af7a037
Removed redundant parser tests
fjwillemsen Feb 11, 2025
1ac636d
Removed not parsing to constraints options
fjwillemsen Feb 11, 2025
caa2e72
Simplified compile function, linting fixes
fjwillemsen Feb 11, 2025
9370319
Optimized compilation by returning only Constraint types
fjwillemsen Feb 11, 2025
57e444b
Extended tests to picklable and non-picklable compilation of constraitns
fjwillemsen Feb 11, 2025
17c0f44
Applied consistent naming to constraints parser
fjwillemsen Feb 11, 2025
b9e6fe1
Improved addConstraint docstrings
fjwillemsen Feb 11, 2025
72548e3
Improved addConstraint docstrings
fjwillemsen Feb 11, 2025
9263a91
Added string constraints explanation and examples to README
fjwillemsen Feb 11, 2025
5dd698d
Apply consistent naming to constraints parser tests
fjwillemsen Feb 11, 2025
1d76568
Removed redundant optimization passes
fjwillemsen Feb 11, 2025
8e0b747
Fixed broken test
fjwillemsen Feb 11, 2025
66bc1f9
Silenced string constraints warning
fjwillemsen Feb 11, 2025
a9dff1a
Recythonization after various improvements and simplificiations
fjwillemsen Feb 11, 2025
4880ad4
Merge remote-tracking branch 'origin/main' into algorithm_improvements
fjwillemsen Feb 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

## Python Constraint

All notable changes to this code base will be documented in this file, for every released major and minor version.
All notable changes to this code base will be documented in this file, for every released major and minor version. For all versions, see [releases](https://github.com/python-constraint/python-constraint/releases).

### Version 2.1.0

- Released: TBD
- Issues / Enhancements:
- Implemented a new string format for constraints, that is automatically parsed to constraint types (currently in beta, please report issues)
- Implemented a new `ParallelSolver` with both Thread and Process mode (currently experimental)
- Added Python 3.13 and experimental 3.14 support

### Version 2.0.0

- Released: 2025-01-29
- Maintainer: Floris-Jan Willemsen <[email protected]>
- Issues/Enhancements:
- Issues / Enhancements:
- Cythonized the package
- Added the `OptimizedBacktracking` solver based on [issue #62](https://github.com/python-constraint/python-constraint/issues/62)
- Added type-hints to improve Cythonization
Expand All @@ -30,7 +38,7 @@ All notable changes to this code base will be documented in this file, for every
### Version 1.4.0

- Released: 2018-11-05
- Issues/Enhancements:
- Issues / Enhancements:
- Add tests around `SomeNotInSetConstraint.`
- Minor `README` fixes
- Fix `dict.keys()` issue with Python 3 and add some unit tests
Expand All @@ -39,14 +47,14 @@ All notable changes to this code base will be documented in this file, for every
### Version 1.3.1

- Released: 2017-03-31
- Issues/Enhancements:
- Issues / Enhancements:
- Better `README` rendering (using reStructuredText)

### Version 1.3

- Released: 2017-03-31
- Maintainer: Sébastien Celles <[email protected]>
- Issues/Enhancements:
- Issues / Enhancements:
- Original code forked from https://labix.org/python-constraint
- Publish on Github
- Python 2 / 3 support
Expand Down
11 changes: 7 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ python-constraint
| For an overview of recent changes, visit the `Changelog <https://github.com/python-constraint/python-constraint/blob/main/CHANGELOG.md>`_.
| The complete documentation can be found `here <http://python-constraint.github.io/python-constraint/>`_.

| New: writing constraints in the new string format is preferable over functions and lambdas.
| These strings, even as compound statements, are automatically parsed to faster built-in constraints, are more concise, and do not require constraint solving familiarity by the user to be efficient.
| For example, :code:`problem.addConstraint(["50 <= x * y < 100"])` is parsed to :code:`[MinProdConstraint(50, ["x", "y"]), MaxProdConstraint(100, ["x", "y"])]`.
| This feature is in beta and subject to possible change, please provide feedback.

.. contents::
:local:
:depth: 1
Expand Down Expand Up @@ -40,8 +45,7 @@ This interactive Python session demonstrates basic operations:
{'a': 2, 'b': 6}, {'a': 2, 'b': 5}, {'a': 2, 'b': 4},
{'a': 1, 'b': 6}, {'a': 1, 'b': 5}, {'a': 1, 'b': 4}]

>>> problem.addConstraint(lambda a, b: a*2 == b,
("a", "b"))
>>> problem.addConstraint("a*2 == b") # string constraints are preferable over the black-box problem.addConstraint(lambda a, b: a*2 == b, ("a", "b"))
>>> problem.getSolutions()
[{'a': 3, 'b': 6}, {'a': 2, 'b': 4}]

Expand Down Expand Up @@ -114,6 +118,7 @@ The following solvers are available:
- Optimized backtracking solver
- Recursive backtracking solver
- Minimum conflicts solver
- Parallel solver

.. role:: python(code)
:language: python
Expand Down Expand Up @@ -168,8 +173,6 @@ For an overview of recent changes, visit the `Changelog <https://github.com/pyth

Planned development:

- Add a string parser for constraints
- Add parallel-capable solver
- Add `benchmarking tests <https://pypi.org/project/pytest-benchmark/>`_ automated with `GH actions <https://github.com/benchmark-action/github-action-benchmark>`_
- Versioned documentation

Expand Down
1 change: 1 addition & 0 deletions constraint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from constraint.domain import * # noqa: F403
from constraint.constraints import * # noqa: F403
from constraint.solvers import * # noqa: F403
from constraint.parser import * # noqa: F403

if __name__ == "__main__":
from tests import test_doctests
Expand Down
6,122 changes: 3,374 additions & 2,748 deletions constraint/constraints.c

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions constraint/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ def __call__( # noqa: D102
not forwardcheck or missing != 1 or self.forwardCheck(variables, domains, assignments)
)
return self._func(*parms)

class CompilableFunctionConstraint(Constraint):
"""Wrapper function for picklable string constraints that must be compiled into a FunctionConstraint later on."""

def __init__(self, func: str, assigned: bool = True): # noqa: D102, D107
self._func = func
self._assigned = assigned

def __call__(self, variables, domains, assignments, forwardcheck=False, _unassigned=Unassigned): # noqa: D102
raise NotImplementedError("CompilableFunctionConstraint can not be called directly")


class AllDifferentConstraint(Constraint):
Expand Down
10 changes: 5 additions & 5 deletions constraint/domain.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading