Reputation: 1
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?
Upvotes: 0
Views: 1067
Reputation: 16782
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
Upvotes: 1