r - Setting constraints in constrOptim -
is there easy method set theta, ui, ci following constraints in constroptim function?
c1<x1<=c2 x1+1<x2<=c2+1 x2+1<x3<=c2+2 x3+1<x4<=c2+3
i considered using simplex takes 3 constraints.
thanks
just rewrite constraints in desired form, ui %*% theta >= ci
.
# initial formulation of 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 )
Comments
Post a Comment