constrOptim中的设置约束
问题描述:
在constrOptim函数中是否有一个简单的方法来设置theta,ui,ci以下约束条件?constrOptim中的设置约束
c1<x1<=c2
x1+1<x2<=c2+1
x2+1<x3<=c2+2
x3+1<x4<=c2+3
我考虑过使用simplex,但它只需要3个约束。
由于
答
只是改写限制在期望的形式,ui %*% theta >= ci
。
# Initial formulation of the constraints
c1 <= x1
x1 <= c2
x1+1 <= x2
x2 <= c2+1
x2+1 <= x3
x3 <= c2+2
x3+1 <= x4
x4 <= c2+3
# Rewrite them
x1 >= c1
- x1 >= -c2
- x1 + x2 >= 1
- x2 >= -c2 - 1
- x2 + x3 >= 1
- x3 >= -c2 - 2
- x3 + x4 >= 1
- x4 >= -c2 - 3
# In matrix form
ui <- matrix(c(
1, 0, 0, 0,
-1, 0, 0, 0,
-1, 1, 0, 0,
0, -1, 0, 0,
0, -1, 1, 0,
0, 0, -1, 0,
0, 0, -1, 1,
0, 0, 0, -1
),
ncol = 4,
byrow = TRUE
)
ci <- c(c1, -c2, 1, -c2-1, 1, -c2-2, 1, -c2-3)
谢谢文森特。这很有帮助。我想我需要回到高中...笑... – earthlink 2013-05-02 23:37:15
对于在这个问题谁绊倒的用户,注意合理区域'UI%*%THETA> ci'按本[链接](HTTPS: //stat.ethz.ch/pipermail/r-devel/2010-June/057730.html) – earthlink 2013-05-03 15:56:02
@文森特-zoonekynd您翻译OPS约束'C1
crsh
2014-09-18 14:54:51