First time pyomo user here.
I have a function that defines a model
def define_problem(SET_gen, SET_time, SET_buses, demand):
model = pyo.ConcreteModel()
#Define sets
model.SET_GEN = pyo.Set(initialize = SET_gen) #Set of generators
model.SET_TIME = pyo.Set(initialize = SET_time) #Set of hours
model.SET_BUSES = pyo.Set(initialize = SET_buses) #Set of buses
#Define parameters
model.DEMAND = pyo.Param(model.SET_BUSES, model.SET_TIME, initialize = demand_init)
...
The argument 'demand' in the function is a pandas DataFrame
The function demand_init is define as the following
def demand_init(model, bus, t, data = demand):
if(bus in set(data.columns)):
return data.loc[t,bus]
return 0.0
It should define the parameter model.DEMAND for each hour and each bus as the corresponding 'cell' in the demand DataFrame, and 0 if the bus is not in the DataFrame. EDIT: Is defined outside the define_problem function.
But its not working. How can i define the parameters of my function from a pandas DataFrame?
EDIT: Thanks for the answers!
The demand data frame looks like this:
Bus1 Bus10 Bus11 Bus12 ... Bus6 Bus7 Bus8 Bus9
Hour ...
1 0.0 9.00 3.50 6.10 ... 11.20 0.0 0.0 29.50
2 0.0 7.34 2.85 4.97 ... 9.13 0.0 0.0 24.06
3 0.0 6.45 2.51 4.37 ... 8.03 0.0 0.0 21.14
4 0.0 5.78 2.25 3.92 ... 7.20 0.0 0.0 18.95
5 0.0 5.56 2.16 3.77 ... 6.92 0.0 0.0 18.22
[5 rows x 14 columns]
The 't' and the 'bus' that should get into the demand_init function are the numbers in the index and the names of the columns in the data frame. They are in the sets model.SET_HOURS and model.SET_BUSES respectively.