Facility location problem with a variable capacity constraint
Awaiting user inputI have a classical facility location problem with product type.
Fac : set of facilities
Cust : set of customers
Pro : product type
x = m.addVars(fac, cust, pro,vtype=GRB.BINARY,name="assign")
y = m.addVars(fac,vtype=GRB.BINARY,name="open")
All facilities can handle all type of products- individually or mix of products. Each customer has a single product type. The following two constraints are simply that each customer must be assigned to one facility and one assigned to an open facility
m.addConstrs((x.sum('*',i,'*') == 1 for i in cus),"assignFac")
m.addConstrs((x.sum(i,'*', '*') <= bm*y[i] for i in fac),"1on1")
General capacity constraint :
m.addConstrs(x.prod(s,i,'*','*')<= CAP for i in fac)
My problem that I need to get an idea on is :
Each customer has a volume or size of their demand Sj and there are only two type of products [0,1]- the vast majority of the customers require type 1. The capacity of the facility depend on the products that go through. All facilities have a capacity of CAP1 but if product type 0 goes through that facility then the capacity is CAP2. So it's similar to if else constraint. If type 0 goes through a facility i then the capacity is CAP2, otherwise CAP1.
How can I model such a constraint.
-
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 why not try our AI Gurobot?. -
Hi,
Are your facility variables y one or two dimensional? They are created for each facility but they seem to be used in the second set of constraints for each facility and product?
If they would be defined in the latter way, i.e., to decide whether some facility i is open and serves product k, then you could directly use them in your capacity constraints to differentiate between the two capacities, i.e.,m.addConstrs( ... <= CAP1 + (CAP2-CAP1) * y[i,0] ... )
I hope I understood your problem correctly and this solves your modeling issue?
Best regards,
Mario1 -
Mario,
Thank you for your response. Sorry for the confusion, but that was I mistake in my post that I have corrected. Yes I was trying to limit facilities to one type of products but that was wrong since a facility can handle multiple type of products at the same time.
For my problem, I was thinking to formulate the same idea you proposed but using my one dimensional variable. I want to create an indicator variable for each facility that equals to 1 if a customer with product 0 is assigned to that facility, and equal to 0 otherwise. Then use that indicator variable in the capacity constraint the same way you use the two dimensional variable. I'm not sure to how to formulate that though.
Here is what I tried. Let's say the indicator variable is q
q = m.addVars(fac,vtype=GRB.BINARY,name="indicator")
q[i] =(x.sum(i,'*', 0) for i in fac)now if no customer with product 0 is assigned to facility i, then q[i] is zero and will work on the constraint. But if we have more than one customers with product 0 assigned to facility i, then q[i] is more than one, and will not work on the constraint.
That was the idea I had, but maybe there is a different way to go about that.
Thank you!
0 -
Hi,
If you only want to handle product 0 in a special way, then your approach with using a single additional binary variable for each facility is perfectly fine.
But you have to link variables q and x differently, i.e., by using one constraint for each facility and each customer:
m.addConstrs((x[i,c,0] <= q[i] for i in fac for c in cust), name="prod0")
Does this work for you?
Best regards,
Mario0
Post is closed for comments.
Comments
4 comments