Forum: help
Monitor Forum | Start New ThreadOptimization in R [ Reply ] By: Rodrigo Rodriguez on 2017-06-06 00:00 | [forum:45177] |
Dear R-users, I hope this message finds you well. I am using nlminb command to solve an following optimization problem: #---------------------------------------------------------- # Known quantities a <- 100 b <- 0.5 Ce <- 0.2 d <- 0.01 p <- 5 k1 <- 10 k2 <- 5 MinSales <- 0 MaxSales <- 1500 TMax <- 50 # Function to optimize Profit <- function(x){ if(length(x) != TMax) stop("Length of x must be equal to TMax") Sales <- 0; cont <- 1 repeat{ Sales <- c(Sales, (a * x[cont] + d * sum(Sales)) * b * exp(- Ce * p)) if(cont > TMax) break if(sum(Sales) > MaxSales) break cont <- cont + 1 } Sales <- Sales[-c(1, length(Sales))] if(cont - 1 < TMax) for(i in cont:TMax){ x[i] <- 0 Sales <- c(Sales, 0) } sum(p * Sales - (k1 * x + k2/2 * x^2)) } MinusProfit <- function(x) -Profit(x) MaxProfit <- nlminb(start = rep(0, TMax), objective = MinusProfit, lower = rep(0, TMax)) #---------------------------------------------------------- The Profit function allows the user to implement a diffusion model (i.e., the Sales vector) evaluated in t, with t in {0, 1, ..., TMax} and Sales(0) = 0. The vector Sales depends on the decision variables (x in Profit function) and this vector is constrained such that the cumulative sales cannot be higher than MaxSales. If t* is the time when the cumulative sales reach MaxSales, then Sales(t) = 0 for all t in {t* + 1, ..., TMax}. The decision variables form a vector of length TMax that represent advertising rates at times 0, 1, 2, ..., TMax - 1. I was wondering if you could tell me how to incorporate the following additional constraint into this optimization problem to find the advertising rates: the advertising rate must be zero for all t in {t*, t*+1, ..., TMax - 1}, where t* was mentioned before. I will appreciate any suggestion. Thank you. |