简体   繁体   中英

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.

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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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