Variate Piece-wise Linear Function
回答済みMy modelling problem consists of finding a minimized cost for the model, and finding xij the decision variable. I want to apply a piece-wise linear function on it like so:

But I can only find examples when the functions in the linear functions are constant. Even then, I tried putting dummy values for the y points
y = model.addVar(name='y')
xpts = [0, 4800, 15000, 30000 ]
ypts = [50000, 345000, 444000]
model.addGenConstrPWL(x, y, xpts, ypts)
K = 46.35
objective_expr = gp.LinExpr()
for i in I:
for j in J:
objective_expr += K*((x[i, j])) + (shipping_cost_matrix[i][j] * dist_matrix[i][j] - cost_per_state[j]) * x[i, j]
model.setObjective(objective_expr, gp.GRB.MINIMIZE)
model.optimize()
-
If your function is continuous, perhaps you can first convert it into a linear function and then use addconstr
0 -
Hi Natalie,
In your code snippet, the definition of \(x\) variables is missing.
Note that the size of the \(\texttt{xpts}\) and \(\texttt{ypts}\) lists has to be the same, see addGenConstrPWL and the documentation on PWL.
In your case, you want the \(\texttt{ypts}\) to hold the values at break points of you function, i.e.,
xpts = [0, 4800, 15000, 30000 ] ypts = [0, 24960, 75960, 144960]
With the \(x\) points and \(y\) points Gurobi is able to compute the PWL segments that you define via linear terms in your function.
Best regards,
Jaromił0
サインインしてコメントを残してください。
コメント
2件のコメント