一些精确覆盖问题和它们的解决方案
项目描述
精确覆盖样本
包含一些精确覆盖样本及其解决方案。
安装
pip install exact-cover-samples
用法
问题
from exact_cover_samples import problems
problems
是一个具有以下结构的字典
{ "shortname": function, ... }
其中 shortname
是一个字符串,而 function
是一个函数,该函数返回一个具有以下结构的字典
{
"shortname": str, # short name of the problem
"name": str, # long name of the problem
"data": np.ndarray, # of ndim=2 and dtype=bool
"solutions": list[list[int]] # each solution is a list of indices in data
}
在某些情况下 solutions
也是一个 nd-array - 以下是如何规范化以比较解决方案。
摘要
您可以通过运行以下代码来显示可用的问题的摘要
from exact_cover_samples import summary
summary()
将显示所有已知问题
# you can also filter a bit
summary("pent")
->
the problems whose name contains 'pent' are:
===================== p3x20 ======================
size = (1236, 72), 8 solutions full_name=pentominos-3-20
===================== p4x15 ======================
size = (1696, 72), 1472 solutions full_name=pentominos-4-15
规范表示
from exact_cover_samples import problems, canonical
p = problems["knuth2000"]()
s = p["solutions"]
type(s)
-> list
type(s[0])
-> tuple
type(canonical(s))
-> set
p = problems["p8x8"]()
s = p["solutions"]
type(s)
-> numpy.ndarray
type(canonical(s))
-> set
因此,只要您的代码产生解决方案为一个可迭代的迭代,您应该能够使用 canonical
来比较它们,如下所示
# import this module
import exact_cover_samples as ecs
# import a solver module
from exact_cover_py import exact_covers
# get a problem
p = ecs.problems["knuth2000"]()
# get the expected solutions
expected = p["solutions"]
# get the computed solutions
computed = exact_covers(p["data"])
# compare them
assert ecs.canonical(expected) == ecs.canonical(computed)
因此,您可以通过简单地迭代 problems
中的问题,并将预期的解决方案与计算出的解决方案进行比较,来为您的精确覆盖求解器编写一个非常不错的测试套件。
项目详情
下载文件
下载适合您平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。
源分布
exact_cover_samples-0.0.8.tar.gz (11.7 MB 查看哈希值)
构建的分发版
exact_cover_samples-0.0.8-py3-none-any.whl (637.1 kB 查看哈希值)
关闭
exact_cover_samples-0.0.8.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | f4b5561f415c4ee71489154c6d43bcf3c1d5a89d95fddf1f884ebb3e3195285d |
|
MD5 | 8090b35970d3c09b162000b130edfaf5 |
|
BLAKE2b-256 | 9ac1d700df5b0739fc830784574996184408f5b0ce953b26aa0c475a99590b1f |
关闭
exact_cover_samples-0.0.8-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d34b0c7d481aff8aed2a5104c7c74ce0199aa123796c6751b8bcf005b10773db |
|
MD5 | c9adf5a4f5d95383a6636f50ce0b1d34 |
|
BLAKE2b-256 | de6b438c4152d9e456e4b6d1a0ca82d1f00c60011bbcb1da444d45c7bc8865db |