Hi All, I am having some real difficulty in trying to carry out constrained optimization. I have had no problems with the Optim() function but when I try to constrain the problem I am getting all sorts of error messages. The model is a simple 2 area, 2 fleet, 1 stock model of a fishery. The code is below. This code runs well but when I try the constrOptim() command with an upper limit of f=6 for each fleet (total across 2 areas), the solver does not run. Does anybody have any suggestions? Thanks. 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<-array(3,dim=c(nfleets,nareas)) OF<-array(c(q*f), dim=c(nfleets, nareas)) Catch<-array(0,dim=c(nfleets, nareas))
obj<-function(f){ 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) 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)) } #zero.bnd <- rep.int(0, length(f)) #opt.eff <- optim( init.eff, obj, method="L-BFGS-B" ) upper<-c(6,6) lower<-c(0,0) constropt.eff<-constrOptim(init.eff,obj,ui=upper, ci=lower, method="Nelder-Mead") -- View this message in context: http://r.789695.n4.nabble.com/constrained-optimization-help-please-tp4648176.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.