Python中的精确覆盖求解器
项目描述
使用算法X在Python/numba中实现的exact cover
Donald Knuth的Dancing Links算法X在Python / numba中的实现
用法
pip install exact_cover_py
from exact_cover_py import exact_covers
problem = np.array([
[1, 0, 0, 1, 0, 0, 1],
[1, 0, 0, 1, 0, 0, 0], # <--
[0, 0, 0, 1, 1, 0, 1],
[0, 0, 1, 0, 1, 1, 0], # <--
[0, 1, 1, 0, 0, 0, 1],
[0, 1, 1, 0, 0, 1, 1], # <--
[0, 1, 0, 0, 0, 0, 1],
])
# exact_covers returns a generator of solutions
# one solution
print(next(exact_covers(problem)))
[1, 5, 3]
# all solutions
print(list(exact_covers(problem)))
[[1, 5, 3]]
# number of solutions
def mylen(iterable):
return sum(map(lambda x: 1, iterable))
print(mylen(exact_covers(problem)))
2
项目详情
下载文件
为您的平台下载文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
exact_cover_py-0.1.2.tar.gz (60.7 kB 查看哈希值)
构建分布
exact_cover_py-0.1.2-py3-none-any.whl (57.4 kB 查看哈希值)
关闭
exact_cover_py-0.1.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 52e8146f99c9116d80d20d8caff2a7e1281900bbb00afa5257c5068985e5c7bc |
|
MD5 | 63584f49a57ab6808efa3809850e4494 |
|
BLAKE2b-256 | 514a31ce33da7c723df17945b40784afaca2cb5bd190c69394c021395ab9b527 |