--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
def TB_init(model, i0, i1): return inst.TB_ii.loc[i0, i1] model.TB = Param(model.I, model.I, initialize=TB_init, doc='Transport cost of second echelon') def objective_function(model): return sum(model.FJ[j] * model.w[j] for j in model.J) + \ sum(model.FK[k] * model.z[k] for k in model.K) + \ sum(model.FV[v] * model.q[v] for v in model.V) + \ sum(model.TB[i0, i1] * model.e[i0, i1, v] for i0 in model.I for i1 in model.I for v in model.V) + \ sum((model.TA[j, k] + model.H[k] / 2) * model.x[j, k, l, v] for j in model.J for k in model.K for l in model.L for v in model.V) + \ sum(model.S * model.s[l] for l in model.L)
model.objective = Objective( rule=objective_function, sense=minimize, doc='Objective function')
File: Modelo.pyFunction: GerarModelo at line 8
Line # Hits Time Per Hit % Time Line Contents============================================================== 53 200 2249 11.2 0.0 if method == "old": 54 100 934 9.3 0.0 def TB_init(model, i0, i1): 55 return inst.TB_ii.loc[i0, i1] 56 100 88857385 888573.8 11.5 model.TB = Param(model.I, model.I, initialize=TB_init, doc='Transportation cost of second echelon') 57 58 200 2046 10.2 0.0 if method == "new": 59 100 604928 6049.3 0.1 dic_TB = dict(((i0, i1), dist) for i0, serie in inst.TB_ii.iterrows() for i1, dist in serie.iteritems()) 60 100 2935910 29359.1 0.4 model.TB = Param(model.I, model.I, initialize=dic_TB, doc='Transportation cost of second echelon') # The old method - 888 ms/iter
if method == "old": def TB_init(model, i0, i1): return inst.TB_ii.loc[i0, i1] model.TB = Param(model.I, model.I, initialize=TB_init, doc='Transportation cost of second echelon')
# The new method, converting the Pandas DataFrame to a dictionary - 35 ms/iter if method == "new": dic_TB = dict(((i0, i1), dist) for i0, serie in inst.TB_ii.iterrows() for i1, dist in serie.iteritems()) model.TB = Param(model.I, model.I, initialize=dic_TB, doc='Transportation cost of second echelon')
I did exactly what you said, and it worked correctly! I was wondering if there are other advantages of creating abstract models instead of concrete models, beyond the ability to import .dat files.
As my model was taking a while to be generated, I profiled the code and found that it was spending 17% of the time populating this parameter
and 26% of the time generating the objective function.
On Oct 13, 2016, at 5:52 PM, Gustavo Bittencourt <gustavo.b...@engenharia.ufjf.br> wrote:
Dear Gabe,I just saw your answer today. Thank you very much for the kindness of your response!I did exactly what you said, and it worked correctly! I was wondering if there are other advantages of creating abstract models instead of concrete models, beyond the ability to import .dat files.Also, I have a two index parameter which represents a distance matrix between vertices (i0, i1) and is stored as a Pandas DataFrame. As my model was taking a while to be generated, I profiled the code and found that it was spending 17% of the time populating this parameter and 26% of the time generating the objective function. Do you have any clue about what can be done to make it faster?Populating the parameter TB:def TB_init(model, i0, i1):return inst.TB_ii.loc[i0, i1]model.TB = Param(model.I, model.I, initialize=TB_init, doc='Transport cost of second echelon')
Generating objective function:def objective_function(model):return sum(model.FJ[j] * model.w[j] for j in model.J) + \sum(model.FK[k] * model.z[k] for k in model.K) + \sum(model.FV[v] * model.q[v] for v in model.V) + \sum(model.TB[i0, i1] * model.e[i0, i1, v]for i0 in model.I for i1 in model.I for v in model.V) + \sum((model.TA[j, k] + model.H[k] / 2) * model.x[j, k, l, v]for j in model.J for k in model.K for l in model.L for v in model.V) + \sum(model.S * model.s[l] for l in model.L)model.objective = Objective(rule=objective_function, sense=minimize, doc='Objective function')Thank you again!Best regards,Gustavo