我正在尝试优化一组盒子的布局 wrt 他们的衣架位置 st 盒子与他们的衣架最对齐并且不会相互排挤。使用四驱。
吉文斯:
1. box hanger x-locations (P). =710 850 990 1130
2. box-sizes (W). =690 550 690 130
3. usable x-spread tuple (S). =-150 2090
4. number of boxes (K). =4
5. minimum interbox spread (G). =50
6. box x-locations (X). =objective
我们可以看到所需的总 x-spread 为 sum(W) + 3G = 2060 + 150 = 2210,而可用的 x-spread 为 S[2] - S 1 = 2240。因此,应该存在解决方案。
分钟:
sumof (P[i] – X[i])^2
s.t.:
(1) X[i+i] – X[i] >= G + ½ ( W[i+1] + W[i] ); i = 1..(K-1),即盒子不会互相排挤
-X[i] + X[i+1] >= -( -G – ½ (W[i+1] + W[i]) )
(2) X 1 >= S[left] + ½ W 1和 (3) X[K] <= S[right] – ½ W[K],即盒子在给定的 x-spread 内
X[1] >= - ( S[left] + ½ W[1] )
-X[K] >= - ( S[right] – ½ W[K] )
总共有 5 个约束 - 3 个用于跨箱传播,2 个用于四肢。
在 R 中:
> Dmat = matrix(0,4,4)
> diag(Dmat) = 1
> dvec = P, the hanger locations
[1] 710 850 990 1130
> bvec
[1] -670 -670 -460 -195 2025
> t(Amat)
[,1] [,2] [,3] [,4]
[1,] -1 1 0 0
[2,] 0 -1 1 0
[3,] 0 0 -1 1
[4,] 1 0 0 0
[5,] 0 0 0 -1
> solve.QP(Dmat, dvec, Amat, bvec)
Error in solve.QP(Dmat, dvec, Amat, bvec) :
constraints are inconsistent, no solution!
很明显我错过或错误指定了问题(包'quadprog')!我正在使用 quadprog,因为我找到了它的 JavaScript 端口。
非常感谢。