Binary variables are not binary
回答済みHi!
I have had a lot of problems with my MIP formulation which has led to some equality constraints being left out. Now, I have two binary variables y_it and o_it where y_it = 1 if b_it > 0 else y_it = 0. Likewise, o_it = 1 if b_it < l_it where l_it is a predetermined value, i.e. not a variable.
Now since the following constraint is seldom fulfilled;
b_it = b_i(t-1) + c_it + sum(x_ji * k for j in range(C)) - sum(x_ij for j in range(C))
Then b_it is replaced with the long expression in the constraints where b_i0 is a predetermined value, i.e. also not a variable.
Now to the question;
I have this moderately big model.
In the model, the binary indicator(s) y and o are either 0 or 1, depending on whether a condition is met. And my problem is that y is fractional.
The coefficients in the model has a large range. Everything between 0.001 up till 10**8. In this model, M=10**12. I know that these coefficients creates numerical instabilities but are there any (more) parameters that can be set to avoid this problem?
model = gp.Model()
model.setParam("NumericFocus", 3)
model.setParam("FeasibilityTol", 1e-9)
y = model.addVars(num_ccy, self.horizon, vtype=BINARY, name="RATE_TYPE")
o = model.addVars(num_ccy, self.horizon, vtype=GRB.BINARY, name="OVERDRAFT_TYPE")
b_pos = model.addVars(num_ccy, self.horizon, lb=0, vtype=GRB.CONTINUOUS, name="POSITIVE_BALANCE")
b_neg = model.addVars(num_ccy, self.horizon, ub=0, vtype=GRB.CONTINUOUS, name="NEGATIVE_BALANCE")
b_ovr = model.addVars(num_ccy, self.horizon, ub=0, vtype=GRB.CONTINUOUS, name="OVERDRAFT_BALANCE")
x = model.addVars(num_ccy, num_ccy, self.horizon, lb=0, ub=M-10**8, vtype=GRB.CONTINUOUS, name="TRANSFER")
fx_costs = gp.quicksum(x[i,j,t] * m[i, j, t]
for i in range(num_ccy)
for j in range(num_ccy)
for t in range(self.horizon))
deposit_costs = gp.quicksum(- b_pos[i, t] * r_borrow[t, i]
for i in range(num_ccy)
for t in range(self.horizon))
lending_costs = gp.quicksum(- b_neg[i, t] * r_lend[t, i]
for i in range(num_ccy)
for t in range(self.horizon))
overdraft_costs = gp.quicksum(- b_ovr[i, t] * r_ovr[t, i]
for i in range(num_ccy)
for t in range(self.horizon))
currency_risk = gp.quicksum(k[i] * (b_pos[i, t] - b_neg[i, t]) * sigma[i]
for i in range(num_ccy)
for t in range(self.horizon))
interest_costs = deposit_costs + lending_costs + overdraft_costs
model.setObjective(fx_costs + interest_costs + currency_risk, sense=GRB.MINIMIZE)
for i in range(num_ccy):
for t in range(self.horizon):
model.addLConstr(lhs=x[i, i, t], sense=GRB.EQUAL, rhs=0)
for i in range(num_ccy):
for t in range(self.horizon):
received = gp.quicksum(x[j, i, 0] * (1 - m[j, i, 0]) * fx_rates[j, i, 0] for j in range(num_ccy))
transfered = gp.quicksum(x[i, j, 0] for j in range(num_ccy))
b_t = b0[i] + received - transfered
for t_bar in range(1, t):
received = gp.quicksum(x[j, i, t_bar] * (1 - m[j, i, t_bar]) * fx_rates[j, i, t_bar] for j in range(num_ccy))
transfered = gp.quicksum(x[i, j, t_bar] for j in range(num_ccy))
b_t += received - transfered + c[t, I]
model.addLConstr(b_t >= -M * (1 - y[i, t]))
model.addConstr(b_t <= M * y[i, t])
model.addConstr(b_t >= l[t, i] - M * o[i, t])
model.addConstr(b_t <= l[t, i] + M * (1 - o[i, t]))
model.addConstr(b_pos[i, t] <= y[i, t] * M)
model.addConstr(b_pos[i, t] <= b_t + (1 - y[i, t]) * M)
model.addConstr(b_pos[i, t] >= b_t - (1 - y[i, t]) * M)
model.addConstr(b_neg[i, t] >= -M * (1 - y[i, t]))
model.addConstr(b_neg[i, t] <= b_t + y[i, t] * M)
model.addConstr(b_neg[i, t] >= b_t - y[i, t] * M)
model.addConstr(b_ovr[i, t] >= -M * o[i, t])
model.addConstr(b_ovr[i, t] <= (b_t - l[t, i]) + (1 - o[i, t]) * M)
model.addConstr(b_ovr[i, t] >= (b_t - l[t, i]) - (1 - o[i, t]) * M
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
To increase integer accuracy, you could try decrease the value of the IntFeasTol parameter. Alternatively (or in addition) you could try setting the IntegralityFocus parameter.
0
投稿コメントは受け付けていません。
コメント
2件のコメント