LPSOLVE-查找最大值 - 具有乘法的公式

发布于 2025-02-09 02:52:10 字数 826 浏览 2 评论 0原文

我正在寻找一种与我在Excel中成功使用的方式使用LPSOLDEL的方法。我已经计算了各种产品的弹性。根据产品是否是弹性,我想就要问的价格提出建议。

我有以下值:

current.price = 15
sales.lastmonth = 50
elasticity = -1.5

我想通过更改建议的公式来优化销售

。 弹性)

sales.prediction =(sales.lastmonth--((abs ( 尝试以下内容:

# install.packages("lpSolve")
library(lpSolve)

objective.fn <- c(sales.prediction) # determine what the objective is

# constrain sales.lastmonth and current.price
const.mat <- matrix(c(1,1),ncol=1,byrow=T)
const.dir <- c("=","=")
const.rhs <- c(sales.lastmonth, current.price)

lp("max",objective.fn,const.mat,const.dir,const.rhs,compute.sens=TRUE)

有什么建议吗?

-------------

编辑-V2:根据下面的评论,我想补充一下建议的限制。提价应最大25%的25%,低于25%建议我在没有优化的情况下的建议。例如,假设我已经在考虑将价格降低到12.5。这也可能吗?

I'm looking for a way to use lpSolve in a similar way to how I use it succesfully in Excel. I've calculated elasticity for various product. Based on whether a product is elasticity or not elastic I want to give an advice on which price to ask.

I have the following values:

current.price = 15
sales.lastmonth = 50
elasticity = -1.5

And I want to optimize the sales.prediction by changing the suggested.price

Formula:
sales.prediction = (sales.lastmonth - ((abs(elasticity)(suggested.price-current.price))(sales.lastmonth/current.price)))*suggested.price

I've tried the following:

# install.packages("lpSolve")
library(lpSolve)

objective.fn <- c(sales.prediction) # determine what the objective is

# constrain sales.lastmonth and current.price
const.mat <- matrix(c(1,1),ncol=1,byrow=T)
const.dir <- c("=","=")
const.rhs <- c(sales.lastmonth, current.price)

lp("max",objective.fn,const.mat,const.dir,const.rhs,compute.sens=TRUE)

Any suggestions?

-----------

EDIT - V2: Based on the comment below, I would like to add the constraint that the suggested.price should be at max 25% higher of 25% lower than the the suggested price I have in my mind without the optimization. For example, let's say I am already thinking about lowering the price to 12.5. Is that possible as well?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

自此以后,行同陌路 2025-02-16 02:52:10

如果我正确理解您只是尝试优化(最大化)此功能,则没有任何约束,因为您的变量是恒定的。如果这是真的,那么您可以

optimize(
  f=function(x){
    sales.lastmonth-((abs(elasticity)*(x-current.price))*(sales.lastmonth/current.price))*x
  },
  interval=c(-100,100),
  maximum=T
)

$maximum
[1] 7.5

$objective
[1] 331.25

在7.5时进行最大值。

编辑:限制优化的一个简单hack是使用间隔参数,用于您的编辑Interval = C(Current.Price*0.75,Current.Price*1.25)

If I understand correctly you are simply trying to optimize (maximize) this function, there are no constraints since your variables are constant. If this is true then you can do

optimize(
  f=function(x){
    sales.lastmonth-((abs(elasticity)*(x-current.price))*(sales.lastmonth/current.price))*x
  },
  interval=c(-100,100),
  maximum=T
)

$maximum
[1] 7.5

$objective
[1] 331.25

maximum at 7.5.

Edit: a simple hack to limit the optimization is to use the interval argument, for your edit interval=c(current.price*0.75,current.price*1.25).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文