Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

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

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletionsconstraint/constraints.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 deletionsconstraint/domain.c
View file
Open in desktop

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

Loading

[8]ページ先頭

©2009-2025 Movatter.jp