result not correct
Answeredfrom gurobipy import *
#input data
a=[5 ,6 ,4 ,6 ,7]#
k=['1','2','3'] # bins
C=20 # capacity of bin
#key parameters
N=range(len(a))
M=range(len(k))
#create a model
m=Model('Bin packing')
# create variables
x=m.addVars(N,M,lb=0.0,vtype=GRB.BINARY,name='x')
y=m.addVars(M,lb=0.0,vtype=GRB.BINARY,name='y')
#create constraints
m.addConstrs(x.sum(i,'*')==1 for i in N)
m.addConstrs(x.sum('*',k)*a[i]<=C*y[k] for i in N for k in M)
#create objective function
obj_fn=quicksum(y[k] for k in M)
m.setObjective(obj_fn, GRB.MINIMIZE)
m.optimize()
the result is: Best objective 3.000000000000e+00, best bound 3.000000000000e+00, gap 0.0000%
and it should be 2 bins

0
-
Official comment
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. -
You packing constraint is incorrect. It should read
m.addConstrs( quicksum(x[i,k]*a[i] for i in N) <= C*y[k] for k in K)
This should provide the correct answer.
Best regards,
Jaromił0 -
Thanks a lot Sir
0
Post is closed for comments.
Comments
3 comments