[R] constrained optimization help please!

hayduke cusackc at onid.orst.edu
Mon Nov 5 23:56:09 CET 2012


Thank-you Berend. This approach does work. Now I need to constrain the
problem so that sum(d.NR) is positive for each fleet. I tried this but with
no luck:

*nfleets<-2
nareas<-2
M<-1
M<-array(M,dim=c(nfleets,nareas))
N<-1000
cost<-c(40,40)
cost<-array(cost,dim=c(nfleets,nareas))
Price<-2
Price<-array(Price,dim=c(nfleets,nareas))
q<-array(0.1,dim=c(nfleets,nareas))
f<-1
f<-array(f,dim=c(nfleets,nareas))
init.eff<-rbind(c(3,3),c(3,3),c(2,2))
#init.eff<-array(3,3,3,3,2,2,dim=c(nfleets,nareas))
OF<-array(c(q*f), dim=c(nfleets, nareas))
Catch<-array(0,dim=c(nfleets, nareas))
f <- array(f, dim=c(nfleets, nareas))
    F <- q*f
    Z <- M+sum(F)
    S <- exp(-Z)
    Catch<- N*F/Z*(1-S)
    Tot.Catch <- sum(Catch)

obj<-function(f){
    
    NR<-array(0,dim=c(nfleets,nareas))
    NR<-Price*Catch - f*cost
    d.NR<-array(0,dim=c(nfleets,nareas))
    f <- apply(f, 1, sum)
    d.NR<- N*q/Z*(1-S-F/Z+F/Z*S+F*S)*Price - cost 
    return(sum(d.NR*d.NR))
}
init.eff <- init.eff - 1
B <-
rbind(c(1,0,1,0,0,0),c(0,1,0,1,0,0),c(0,0,0,0,-sum(N*q/Z*(1-S-F/Z+F/Z*S+F*S)*Price
- cost),0),c(0,0,0,0,0,-sum(N*q/Z*(1-S-F/Z+F/Z*S+F*S)*Price - cost)))
constropt.eff<-constrOptim(as.vector(init.eff),obj, NULL ,ui=-B,
ci=-c(14,14,0,0), method="Nelder-Mead")
constropt.eff*

Is it possible to constrain my problem in this way?




--
View this message in context: http://r.789695.n4.nabble.com/constrained-optimization-help-please-tp4648176p4648526.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list