Snowflake
Snowflake

Reputation: 3081

Is it possible to create constraints in Pyomo across years and across hours?

I am wondering whether it is possible to create constraints over years and hours at the same time in Pyomo.

For example, my current time variable is:

model.T = pyo.RangeSet(len(hourly_data.index))

However, this does not allow me to distinguish between hours and years. I do have a timestamp variable, that contains the date and the time. So, I thought perhaps I could do:

model.T2 = pyo.Set(initialize=hourly_data.DateTime)

Now the problem comes on how to manipulate this TimeStamp object. Consider that the parameters are given and the variables are outputs from the solver. Let's first assume that our objective function is a maximisation function. We would like to create the following constraint:

Get the maximum water used, in normal circumstances, if we would like to get the maximum water usage of during all hours, we can do:

model.c_maxWater = pyo.ConstraintList()
for t in model.T:
     model.c_maxWater.add(model.waterUsage[t] <=
                          model.maxWater)

With a penalty in the objective function associated with model.maxWater. The problem becomes what if we want to penalise every year differently, because we have different water costs? I can imagine that our constraint would be somewhat like:

model.c_maxWater = pyo.ConstraintList()
for t in model.T2:
     model.c_maxWater.add(model.waterUsage[t] <=
                          model.maxWater[y])

My problem is: how can I associate the t variable with certain years y. One index is hourly (in this case the t and the other is annually (y)?

Note: a multi index set is possible, but how to deal with leap years etc.? Can a multi index set have different lengths in it's hourly dimensions for leap years?

Upvotes: 1

Views: 276

Answers (1)

AirSquid
AirSquid

Reputation: 11938

You could double-index your variables and data with [hour, year], but that would be redundant information, right? As you should be able to calculate the years from the hours (with or without some initial offset for the yearly rollover, if that is important.)

I would go about this making subsets of your time index associated with years. Do this outside of pyomo using set/list comprehensions and a little math and/or some of the functionality in DateTime if (as you say) you are spanning many years and leap years, etc. [Aside: If you are making an hourly model that spans years--it will probably collapse under it's own weight, but that is a secondary issue. :) ] Then you can use these subsets to build constraints in your model without muddying things up with extra indices.

Comment back if stuck...

Upvotes: 2

Related Questions