lower bounds of variables given by iterating over dictionary instead of matrix
回答済みI have a large problem with binary variables.
The binary variables sometime should be one. This is given by the lower bound on this binary variable.
The normal condition: lower bound=0, upper bound=1
Must-equal-1: lower bound=1, upper bound=1
Gurobi violates the lower bound for the Must-equal-1 case: It returns a value of zero sometime. That happens if I store the lower bound and upper bound as a dictionary. For example, I have 100 (n_j=100) devices and 5 time steps (n_t=5).
The dictionary keys will be numbers between 0-99. For example, the lower bound dictionary for device 0 will be like this:
B_lb[0]=[0,0,1,0,0]
This is how I add the binary variable with the bounds to my model:
B = m.addVars(n_j,n_t,vtype=GRB.BINARY,lb=B_lb, ub=B_ub)
If I convert my dictionary to a matrix, it works fine?
-
Hi Hussein,
Your B_lb dictionary has the following structure:
keys = single indices for device
values = list of lower bounds at each timestepBut it needs to be structured like so (as per the addVars docs):
keys = 2-tuple of (device,time step) pairs
values = a single number, the lower bound, for the corresponding device and time stepYou can convert the former into the latter with the following code
B_lb_new = {
(device,time_step):lb
for device,lb_per_timestep in B_lb.items()
for time_step,lb in enumerate(lb_per_timestep)
}- Riley
1
サインインしてコメントを残してください。
コメント
1件のコメント