【发布时间】:2014-05-24 12:27:46
【问题描述】:
我正在查看8 queens puzzle。我使用了下面的 R 代码,它直接来自 R lpsolve 文档。参数 num.bin.solution 设置为 3。在 R 文档中,它说 num.bin.solns 代表返回的解决方案数量的数字指标。在那种情况下,我怎样才能看到 3 种可能的解决方案?我使用了命令 chessing$solution,但输出并不容易理解。还有没有办法返回所有可能的解决方案?
chess.obj <- rep (1, 64)
q8 <- make.q8 ()
chess.dir <- rep (c("=", "<"), c(16, 26))#first 16 cosntraints are for row and columns, remaining constraints are for diagonals
chess.rhs <- rep (1, 42)
chessing=lp ('max', chess.obj, , chess.dir, chess.rhs, dense.const = q8,
all.bin=TRUE, num.bin.solns=3)
chessing$solution
更新:我的主要问题得到了解答。但仍然想知道是否有任何有效的方法来获得所有可能的解决方案。
【问题讨论】:
标签: r mathematical-optimization lpsolve