10

Is there an easy method to set theta, ui, ci for the following constraints in the constrOptim function?

c1<x1<=c2
x1+1<x2<=c2+1
x2+1<x3<=c2+2
x3+1<x4<=c2+3

I considered using simplex but it takes only 3 constraints.

Thanks

earthlink
  • 323
  • 5
  • 15

1 Answers1

19

Just rewrite the constraints in the desired form, 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 )
Vincent Zoonekynd
  • 31,893
  • 5
  • 69
  • 78
  • Thanks Vincent. That was helpful. I think I need to go back to high school...lol... – earthlink May 02 '13 at 23:37
  • 2
    For users who stumble upon this question, note that the feasible region is `ui %*% theta > ci` as per this [link](https://stat.ethz.ch/pipermail/r-devel/2010-June/057730.html) – earthlink May 03 '13 at 15:56
  • @vincent-zoonekynd You translated ops constraint `c1 < x1` to `c1 <= x1`. Strictly speaking this is not the same thing. Is it possible to set up the exact constraint `c1 < x1`? – crsh Sep 18 '14 at 14:54
  • 1
    @crash Well, that can only be done by something like `c1 + 0.00001 <= x1`. You cannot get rid of the = sign. – Braamstruik Jun 01 '15 at 07:49
  • @Vincent Zoonekynd, just wondering if the matrix ui defined by you in incorrect, as ui defined by you is a 1 x 32 matrix, whereas it should be 8 x 4 matrix. The way your represented is very helpful though. – Gaurav Singhal Jun 15 '16 at 19:45