我正在尝试解决 PuLP 中的线性问题,以最小化成本函数。成本函数本身是成本函数最大值的函数,例如,我有一个每日成本,我试图最小化每月成本,即每日成本加上当月最大每日成本的总和. 我不认为我在最终解决方案中捕获了函数的最大值,而且我不确定如何解决这个问题。代码的基本大纲如下:
# Initialize the problem to be solved
prob = LpProblem("monthly_cost", LpMinimize)
# The number of time steps
# price is a pre-existing array of variable prices
tmax = len(price)
# Time range
time = list(range(tmax))
# Price reduction at every time step
d = LpVariable.dict("d", (time), 0, 5)
# Price increase at every time step
c = LpVariable.dict("c", (time), 0, 5)
# Define revenues = price increase - price reduction + initial price
revenue = ([(c[t] - d[t] + price[t]) for t in time])
# Find maximum revenue
max_revenue = max(revenue)
# Initialize the problem
prob += sum([revenue[t]*0.0245 for t in time]) + max_revenue
# Solve the problem
prob.solve()
变量 max_revenue 始终等于 c_0 - d_0 + price[0] 即使 price[0] 不是 price 的最大值并且 c_0 和 d_0 都等于 0。有谁知道如何确保将动态最大值插入到问题中?谢谢!