Setting constraints in constrOptim

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

Answers


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 
  ),
  byrow=TRUE
)
ci <- c( c1, -c2, 1, -c2-1, 1, -c2-2, 1, -c2-3 )

Need Your Help

Another PartCover Empty Report Question

nunit partcover nunit-console

I've tried the steps listed here, but I still can't get partcover to generate any output other than:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.