| Name | backtracker JSON |
| Version |
0.0.7
JSON |
| download |
| home_page | |
| Summary | Backtracking Python package |
| upload_time | 2024-01-19 00:41:55 |
| maintainer | |
| docs_url | None |
| author | Ryan Najafi |
| requires_python | |
| license | |
| keywords |
python
backtracker
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# 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](https://www3.cs.stonybrook.edu/~algorith/video-lectures/2007/lecture15.pdf).
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.
Raw data
{
"_id": null,
"home_page": "",
"name": "backtracker",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "python,backtracker",
"author": "Ryan Najafi",
"author_email": "ryan.m.najafi@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/76/79/7386b4be76c2ce25ee045d145433ad7a19b4bf410e726c576602fd0c0ac7/backtracker-0.0.7.tar.gz",
"platform": null,
"description": "# BackTracker Class\nThe 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.\n\nThis is based on [Steven Skiena](https://www3.cs.stonybrook.edu/~algorith/video-lectures/2007/lecture15.pdf).\n\nGitHub Page: https://github.com/ryan-najafi/backtracker\n\n\n## Features\nGeneric backtracking implementation.\nCustomizable for a wide range of problems.\nAllows defining problem-specific solution processing, candidate generation, and move making/unmaking.\n\n## Installation\npip install backtracker==0.0.7\n\n## Usage\nTo use the BackTracker class, you need to define functions for:\n\nChecking if a current state is a solution (is_solution).\nProcessing a complete solution (process_solution).\nGenerating candidate moves (get_candidates).\nMaking a move (make_move).\nUnmaking a move (unmake_move).\n\nHere's an example demonstrating how to use the BackTracker class to generate combinations of elements:\n\n```\nfrom backtracker import backtracker as bt\n\nfrom backtracker import BackTracker\n\na = []\nlevel = 0\n\ndef is_solution(a, k, input):\n return len(a) == len(input)\n\ndef process_solution(a, k, input):\n result = []\n for i, item in enumerate(a):\n if item:\n result.append(input[i])\n return ''.join(result)\n\ndef get_candidates(a, k, input):\n return [False, True]\n\ndef make_move(a, k, input, c):\n a.append(c)\n\ndef unmake_move(a, k, input, c):\n a.pop()\n\ninput = list('abc')\nback_tracker = BackTracker(a=a, level=0, input=input, \n is_solution=is_solution, \n process_solution=process_solution, \n get_candidates=get_candidates, \n make_move=make_move, \n unmake_move=unmake_move)\n\nfor sol in back_tracker.get_next_solution():\n print(sol)\n \n```\n\n\nIn 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.\n\n## Contributing\nContributions to enhance BackTracker are welcome. Please adhere to the standard Python coding guidelines.\n\n## License\nThis project is open-source and available under the MIT License.\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Backtracking Python package",
"version": "0.0.7",
"project_urls": null,
"split_keywords": [
"python",
"backtracker"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cb4714f852f61b80e16a3844c631c22441b3b21337d492ad2f7ec25edd7bdd3a",
"md5": "dc1fa7092a4d0586376dbb5b0a2951dc",
"sha256": "57eda9b97ad639cd29b0af288508fda10d4baad481513fe558ea2ef2c3b9e758"
},
"downloads": -1,
"filename": "backtracker-0.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc1fa7092a4d0586376dbb5b0a2951dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4958,
"upload_time": "2024-01-19T00:41:54",
"upload_time_iso_8601": "2024-01-19T00:41:54.297639Z",
"url": "https://files.pythonhosted.org/packages/cb/47/14f852f61b80e16a3844c631c22441b3b21337d492ad2f7ec25edd7bdd3a/backtracker-0.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "76797386b4be76c2ce25ee045d145433ad7a19b4bf410e726c576602fd0c0ac7",
"md5": "b1760629bf675cb00bc001b0246d40f2",
"sha256": "0b2b88f4e8829612fd7ca6ab7ff413c61915b54e05d4210380d06dbbd2b2bdc0"
},
"downloads": -1,
"filename": "backtracker-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "b1760629bf675cb00bc001b0246d40f2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4320,
"upload_time": "2024-01-19T00:41:55",
"upload_time_iso_8601": "2024-01-19T00:41:55.833633Z",
"url": "https://files.pythonhosted.org/packages/76/79/7386b4be76c2ce25ee045d145433ad7a19b4bf410e726c576602fd0c0ac7/backtracker-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-19 00:41:55",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "backtracker"
}