On 05-11-2012, at 23:56, hayduke wrote:

> 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:
> 

I see that on Nabble you have boldified the problem.
In the R-help mailing list this is converted to spurious * which is senseless.

> *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?
> 

No.

1. you have changed the original specification of the model.
2. the objective function has changed. It's return value no longer depends on 
the input parameter f.
3. the constraints for constrOptim only operate on the input parameter vector 
as clearly described in the documentation. And only on fixed linear constraints 
on the parameters.

4. if you really want to introduce a constraint as you described you 'll have 
to use an optimizer that can handle non linear constraints.
Package Rsolnp provides such an optimizer.

Berend

______________________________________________
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.

Reply via email to