Originally posted by: open_ball
Hi,
I have a few questions on modelling the capacitated facility location problem in Python. Since I'm a beginner, some of my questions might be easy to answer. So I read my data in the following way;
warehouses = [tuple(x) for x in df_warehouses.values]
customers = [tuple(x) for x in df_customers.values]
flowcost = dict((tuple((a, b)), c) for a,b,c in df_flowcost.values)
Then, I create my variables.
mdl.use = mdl.binary_var_dict(warehouses)
mdl.ship = mdl.continuous_var_dict(key for key in flowcost)
1) My first question is that if I want to create ship variable by using the lists of warehouses and customers but also want to make sure that warehouse-customer pair exist in flow cost list, how can I do that?
For instance, in OPL, I can do the following and I'd like to do something similar;
tuple ship_tuple{
string warehouse;
string customer;}
setof(ship_tuple) shipdf = {<w,c> | w in warehouses, c in customers, f in flowcost : f.warehouse == w && f. customer == c}
2) So, this is question is little more technical. Here how I generate my supply constraints;
mdl.add_constraints(((mdl.sum(mdl.ship[f] for f in flowcost.keys()) <= w[1]*mdl.use[w]) for w in warehouses)
If I want to parse warehouse and customer to ship variable as key, how can I accomplish that? I receive an error if I try "mdl.sum(mdl.ship[(w,c)] for c in customers....."
3) Is there any difference (efficiency-wise) creating constraints with an external or internal for loop? So, I am sharing two samples to clarify what I mean by "external" and "internal"
External (from diet example):
for n in nutrients:
amount = mdl.sum(qty[f]*food_nutrients[f.name,n.name] for f in food)
mdl.add_range(n.qmin, amount,n.qmax)
Internal (from production example):
mdl.add_constraints((mdl.inside_vars[prod] + mdl.outside_vars[prod] >= prod[1]) for prod in products)
4) I'd like to write all the constraint into an LP file as we do in OPL. Is there such a thing in docplex or is there a better way to write up the constraints to see how the model is working?
#CPLEXOptimizers#DecisionOptimization