简体   繁体   English

物镜 function 中两个变量的纸浆最大值

[英]PuLP Max of two variables in objective function

I have an absolute value function being used in the objective function but it is not working.我有一个绝对值 function 用于目标 function 但它不起作用。

set_I = range(0,data_analysis_values.shape[0])
prob = LpProblem("Deliverable 1", LpMinimize)
X = pulp.LpVariable.dicts("X", set_I, cat='Continuous')
prob += 0.5*lpSum([X[i] for i in set_I])
prob += 0.5*lpSum([lpSum([max(simulation_data_without_text[i][j]-X[i],0)for j in range(200)]) for i in set_I])/200 
for i in set_I:
    prob += X[i] >= 0 
    prob += X[i] <= data_analysis_values[i][8]
prob.solve()
solution = np.array([X[i].varValue for i in set_I])

I want to take the max of simulation_data_without_text[i][j]-X[i] and 0 for all j in range 200 and sum across all I in set I but it is not allowing me to do that.我想为 200 范围内的所有 j 取 Simulation_data_without_text[i][j]-X[i] 的最大值和 0,并对集合 I 中的所有 I 求和,但它不允许我这样做。 Can anyone help me find an alternative way?谁能帮我找到另一种方法?

So the objective is (ignoring other parts):所以目标是(忽略其他部分):

 min sum(i, max(z[i],0))

With the help of additional variables y[i], this can be written as:在附加变量 y[i] 的帮助下,这可以写成:

 min sum(i, y[i])
     y[i] >= z[i]
     y[i] >= 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM