BackTracker Class
The BackTracker class is a Python implementation of the backtracking algorithm, designed for solving problems where a sequence of decisions leads to a solution. This generic framework can be adapted to various problems, such as puzzles, crosswords, combinatorial problems, etc.
This is based on Steven Skiena.
GitHub Page: https://github.com/ryan-najafi/backtracker
Features
Generic backtracking implementation. Customizable for a wide range of problems. Allows defining problem-specific solution processing, candidate generation, and move making/unmaking.
Installation
pip install backtracker==0.0.7
Usage
To use the BackTracker class, you need to define functions for:
Checking if a current state is a solution (is_solution). Processing a complete solution (process_solution). Generating candidate moves (get_candidates). Making a move (make_move). Unmaking a move (unmake_move).
Here's an example demonstrating how to use the BackTracker class to generate combinations of elements:
from backtracker import backtracker as bt
from backtracker import BackTracker
a = []
level = 0
def is_solution(a, k, input):
return len(a) == len(input)
def process_solution(a, k, input):
result = []
for i, item in enumerate(a):
if item:
result.append(input[i])
return ''.join(result)
def get_candidates(a, k, input):
return [False, True]
def make_move(a, k, input, c):
a.append(c)
def unmake_move(a, k, input, c):
a.pop()
input = list('abc')
back_tracker = BackTracker(a=a, level=0, input=input,
is_solution=is_solution,
process_solution=process_solution,
get_candidates=get_candidates,
make_move=make_move,
unmake_move=unmake_move)
for sol in back_tracker.get_next_solution():
print(sol)
In this example, the BackTracker class is used to generate all combinations of the elements in the list 'abc'. The is_solution, process_solution, get_candidates, make_move, and unmake_move functions are defined to suit this specific problem.
Contributing
Contributions to enhance BackTracker are welcome. Please adhere to the standard Python coding guidelines.
License
This project is open-source and available under the MIT License.
Metadata
Release files for backtracker 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| backtracker-0.0.7.tar.gz | 4.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| backtracker-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / backtracker-0.0.7.tar.gz
| Download URL | backtracker-0.0.7.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b2b88f4e8829612fd7ca6ab7ff413c61915b54e05d4210380d06dbbd2b2bdc0
|
|
BLAKE2b-256 checksum How to use checksums |
76797386b4be76c2ce25ee045d145433ad7a19b4bf410e726c576602fd0c0ac7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / backtracker-0.0.7-py3-none-any.whl
| Download URL | backtracker-0.0.7-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
57eda9b97ad639cd29b0af288508fda10d4baad481513fe558ea2ef2c3b9e758
|
|
BLAKE2b-256 checksum How to use checksums |
cb4714f852f61b80e16a3844c631c22441b3b21337d492ad2f7ec25edd7bdd3a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for backtracker 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.