Skip to content
Prev 309649 / 398503 Next

constrained optimization help please!

On 01-11-2012, at 21:59, hayduke wrote:

            
Being pedantic: I assume you mean optim(...)?
Why make it so complicated?
q <- 01. will do what you want
or simply F <- .1 * F
Your init.eff is an array. It should be a vector as described in the documentation of constrOptim.
The argument ui is not the upperlimit but should be a matrix.
The documentation of constrOptim clearly states the constraints are of the form ui %*% theta - ci >= 0.

This will work:

init.eff <- init.eff - 1
B <- rbind(c(1,0,1,0),c(0,1,0,1))
constropt.eff<-constrOptim(as.vector(init.eff),obj,ui=-B, ci=-c(6,6), method="Nelder-Mead")
constropt.eff

- you need to do init.eff <- init.eff - 1 to get the initial parameter in the interior of the feasible region
- as.vector(init.eff) stacks the columns so the order is f[1,1],f[2,1],f[1,2],f[2,2]
- If I understand correctly what you want the constraints are f[1,1]+f[1,2] < 6 and f[2,1]+f[2,2] < 6
  That is B %*% as.vector(init.eff) -c(6,6) <= 0

To get the constraints in the correct format for constrOptim() you need to multiply by -1.
So ui=-B and ci=-c(6,6)

Whether the result is correct is for you to decide.
In addition: your problem appears to be quadratic with linear constraints.
Have a look at function lsei() in package limSolve.

Berend