Skip to content

feat(solvers): implement solution iterator for RecursiveBacktrackingSolver (#60) - #111

Open
harmehak0173 wants to merge 1 commit into
python-constraint:mainfrom
harmehak0173:feature/issue-60-recursive-solver-iterator
Open

harmehak0173 wants to merge 1 commit into
python-constraint:mainfrom
harmehak0173:feature/issue-60-recursive-solver-iterator

Conversation

@harmehak0173

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request implements lazy solution iteration via getSolutionIter() for RecursiveBacktrackingSolver, resolving #60 and bringing it to full feature parity with BacktrackingSolver and OptimizedBacktrackingSolver. (Supersedes closed #110 which was closed when the fork was accidentally cleaned up).

Key Implementation Details

  1. Generator Method (recursiveBacktrackingIter):
    • Added recursiveBacktrackingIter(self, domains, vconstraints, assignments) generator to yield solutions on demand using recursive depth-first backtracking with Degree and MRV heuristics.
    • Wrapped constraint checking and domain state unwinding in a try...finally block to ensure domain.popState() is reliably executed if the generator is closed early (e.g. next(problem.getSolutionIter())).
  2. Solver Interface:
    • Implemented RecursiveBacktrackingSolver.getSolutionIter() to return the lazy iterator.
  3. Documentation & Doctests:
    • Updated class docstring and doctests in RecursiveBacktrackingSolver to demonstrate and verify getSolutionIter().
  4. Unit Tests:
    • Added test_recursive_backtracking_solver_iterator in tests/test_solvers.py verifying lazy yielding, early stopping, unsatisfiable problems, and solution equivalence with BacktrackingSolver across both forwardcheck=True and forwardcheck=False.

Fixes #60.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 83.905% — harmehak0173:feature/issue-60-recursive-solver-iterator into python-constraint:main. No base build found for python-constraint:main.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

solution iterator implementation for RecursiveBacktrackingSolver

2 participants