动态优化(渔业模型)(Dynamic optimization (fishery model))

我正在尝试建立一个模型,渔民可以选择最大化其利润总额的捕捞努力水平。 我正在使用一个简单的逻辑增长方程式,一切似乎都运行良好,除了我无法弄清楚如何运行optim来获得解决方案。 可以找到最大化利润的e[i]向量吗? 这是我正在使用的代码:

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,50) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(0, length(time)) # vector for profit for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = p*H[i]-c*e[i] # profit equation } totalprofit <- function(e, x){-sum(p*q*x[i]*e[i]-c*(e[i]))} optim(par = eo, totalprofit, x=x[i], method = "Brent", lower = 0, upper = 20 )

I'm trying to set up a model where fishermen choose the level of fishing effort that maximizes their sum of profits over time. I'm using a simple logistic growth equation and everything seems to work fine, except I just can't figure out how to run optim to get a solution. Can optim find the vector of e[i] that maximizes profits? Here's the code I'm using:

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,50) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(0, length(time)) # vector for profit for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = p*H[i]-c*e[i] # profit equation } totalprofit <- function(e, x){-sum(p*q*x[i]*e[i]-c*(e[i]))} optim(par = eo, totalprofit, x=x[i], method = "Brent", lower = 0, upper = 20 )

最满意答案

我一直在挖掘,并能够使用optimx找到解决方案。 最大的问题是要优化的功能需要包括所有系统方程。 我为回答自己的问题而道歉。

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,100) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(1, length(time)) # vector for profit # Create function to be optimized # function contains all equations totalprofit <- function (e, npar = TRUE, print = TRUE) { for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*e[i])-(c*e[i]) # profit equation } result <- sum(profit) return(result) } # Optimize system by choosing effort maxfish <- optimx( par = e, fn = totalprofit, lower = 0, upper = 100, method = c("L-BFGS-B"), control = list( maximize = TRUE ) ) emax <- coef(maxfish) # Run system again to see performance for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*emax[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*emax[i])-(c*emax[i]) # profit equation } plot (time, x, type='b') plot (x,emax, type='b') plot (time, emax, type='b') plot (time, H, type='b') plot (time, profit, type='b')

I kept digging and was able to find a solution using optimx. The biggest problem was that the function to be optimized needed to include all of the system equations. I apologize for answering my own question.

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,100) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(1, length(time)) # vector for profit # Create function to be optimized # function contains all equations totalprofit <- function (e, npar = TRUE, print = TRUE) { for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*e[i])-(c*e[i]) # profit equation } result <- sum(profit) return(result) } # Optimize system by choosing effort maxfish <- optimx( par = e, fn = totalprofit, lower = 0, upper = 100, method = c("L-BFGS-B"), control = list( maximize = TRUE ) ) emax <- coef(maxfish) # Run system again to see performance for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*emax[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*emax[i])-(c*emax[i]) # profit equation } plot (time, x, type='b') plot (x,emax, type='b') plot (time, emax, type='b') plot (time, H, type='b') plot (time, profit, type='b')动态优化(渔业模型)(Dynamic optimization (fishery model))

我正在尝试建立一个模型,渔民可以选择最大化其利润总额的捕捞努力水平。 我正在使用一个简单的逻辑增长方程式,一切似乎都运行良好,除了我无法弄清楚如何运行optim来获得解决方案。 可以找到最大化利润的e[i]向量吗? 这是我正在使用的代码:

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,50) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(0, length(time)) # vector for profit for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = p*H[i]-c*e[i] # profit equation } totalprofit <- function(e, x){-sum(p*q*x[i]*e[i]-c*(e[i]))} optim(par = eo, totalprofit, x=x[i], method = "Brent", lower = 0, upper = 20 )

I'm trying to set up a model where fishermen choose the level of fishing effort that maximizes their sum of profits over time. I'm using a simple logistic growth equation and everything seems to work fine, except I just can't figure out how to run optim to get a solution. Can optim find the vector of e[i] that maximizes profits? Here's the code I'm using:

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,50) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(0, length(time)) # vector for profit for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = p*H[i]-c*e[i] # profit equation } totalprofit <- function(e, x){-sum(p*q*x[i]*e[i]-c*(e[i]))} optim(par = eo, totalprofit, x=x[i], method = "Brent", lower = 0, upper = 20 )

最满意答案

我一直在挖掘,并能够使用optimx找到解决方案。 最大的问题是要优化的功能需要包括所有系统方程。 我为回答自己的问题而道歉。

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,100) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(1, length(time)) # vector for profit # Create function to be optimized # function contains all equations totalprofit <- function (e, npar = TRUE, print = TRUE) { for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*e[i])-(c*e[i]) # profit equation } result <- sum(profit) return(result) } # Optimize system by choosing effort maxfish <- optimx( par = e, fn = totalprofit, lower = 0, upper = 100, method = c("L-BFGS-B"), control = list( maximize = TRUE ) ) emax <- coef(maxfish) # Run system again to see performance for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*emax[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*emax[i])-(c*emax[i]) # profit equation } plot (time, x, type='b') plot (x,emax, type='b') plot (time, emax, type='b') plot (time, H, type='b') plot (time, profit, type='b')

I kept digging and was able to find a solution using optimx. The biggest problem was that the function to be optimized needed to include all of the system equations. I apologize for answering my own question.

# Optimal fishery management by choosing effort # Set parameters r = 0.1 # intrinsic growth rate K = 1 # carrying capacity q = 0.01 # catchability eta = 0.3 # stiffness parameter p = 200 # price of fish c = 1 # unit cost of effort eo = 1 # initial effort xo = 1 # initial biomass Yo = 0.01 # initial growth (meaningless) Ho = 0.01 # initial harvest (meaningless) # set time periods time <- seq(0,100) # Logitstic growth x <- rep(xo,length(time)) # vector for stock biomass Y <- rep(Yo,length(time)) # vector for growth in the stock H <- rep(Ho, length(time)) # vector for harvest e <- rep(eo, length(time)) # vector for effort profit <- rep(1, length(time)) # vector for profit # Create function to be optimized # function contains all equations totalprofit <- function (e, npar = TRUE, print = TRUE) { for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*e[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*e[i])-(c*e[i]) # profit equation } result <- sum(profit) return(result) } # Optimize system by choosing effort maxfish <- optimx( par = e, fn = totalprofit, lower = 0, upper = 100, method = c("L-BFGS-B"), control = list( maximize = TRUE ) ) emax <- coef(maxfish) # Run system again to see performance for (i in 2:length(time)){ x[i]=x[i-1]+Y[i-1]-H[i-1] # stock equation H[i]=q*x[i]*emax[i] # harvest equation Y[i]=r*x[i]*(1-x[i]/K) # growth equation profit[i] = (p*q*x[i]*emax[i])-(c*emax[i]) # profit equation } plot (time, x, type='b') plot (x,emax, type='b') plot (time, emax, type='b') plot (time, H, type='b') plot (time, profit, type='b')