Approximation of non-linear functions
ユーザーの入力を待っています。Hello, I have the following question. I have integrated various non-linear functions into my model as follows. Unfortunately, the calculation time is significantly longer than when I leave out the constraints. Is there perhaps another way to approximate these curves linearly? Unfortunately, it is not clear how many support points I need for this.
I want to linearize this relationship:
\(f(r)=base+(1−base)⋅(1−e ^{−kr})\)
These are my constraints in the code:
a = Model.addVars(I, D, R, vtype=GRB.BINARY, name="a")
b = Model.addVars(I, D, vtype=GRB.CONTINUOUS, lb=0, ub=1, name="b")
k = 0.1
exp_values = {r: base + (1 - base) * (1 - math.exp(-k * r)) for r in R}
for i in I:
for d in D:
Model.addLConstr(1 == quicksum(a[i, d, r] for r in R))
Model.addLConstr(S[i, d] == quicksum(y[i, t] for t in range(Q[i], d + 1)))
Model.addLConstr(S[i, d] == quicksum(r * a[i, d, r] for r in R))
Model.addLConstr(C[i, d] == quicksum(exp_values[r] * a[i, d, r] for r in R))
Model.addLConstr(b[i, d] <= y[i, d])
Model.addLConstr(b[i, d] <= C[i, d])
Model.addLConstr(b[i, d] >= C[i, d] - (1 - y[i, d]))
Model.addConstr(l[i, d] * R_i[i] <= quicksum(quicksum(x[i, t, j, itr] for j in range(Q[i], d + 1)) for t in T) + quicksum(b[i, j] for j in range(Q[i], d + 1)))
-
Hi Lasse,
You can actually get Gurobi to use a static PWL approximation using the FuncNonLinear parameter.
Can you try this first?
- Riley
0 -
Hi Lasse,
If you are using version 12+ then you should try using Gurobi's nonlinear expressions to write your constraints.
For your particular function this would be something like
import gurobipy as gp from gurobipy import nlfunc resultvar = model.addVar(lb=-gp.GRB.INFINITY) model.addConstr(resultvar == base + (1 + base)*(1 - gp.nlfunc.exp(-k*r))Note that every nonlinear constraint has to be an equality constraint and be equal to an optimization variable.
If this still does not solve your problem, then you can follow Riley's recommendation about the PWL approximation.
Best regards,
Jaromił0
サインインしてコメントを残してください。
コメント
2件のコメント