2
$\begingroup$

I would like to assign a single value to a paramter that depends on a created set in Pyomo. I have the following code:

import SetUpScenarios 
import pyomo.environ as pyo
import pandas as pd



#Define the model

model = pyo.ConcreteModel()


#Define the sets

model.set_timeslots = pyo.RangeSet(1, SetUpScenarios.numberOfTimeSlotsPerDay)


#Reading of the data
df_buildingData = pd.read_csv("C:/Users/Data/H9_HH1 - Day_4.csv", sep =";")



#Create the dictionaries for the set

#dictionaryHeatDemand= df_buildingData.set_index('Timeslot')['Q_htg'].to_dict()



model.param_heatDemand = pyo.Param(model.set_timeslots, initialize=df_buildingData['Q_htg'])

model.param_heatDemand.pprint()

Normally I did that with a dictionary but here the dataframe does not include the set 'timeslot' and with my currently used assignment "model.param_heatDemand = pyo.Param(model.set_timeslots, initialize=df_buildingData['Q_htg'])" the whole dataframe column is assigned to each value of the set. But I just want the first entry of the dataframe column 'Q_htg' to be assigned to the first value of the set timeslots. Any idea how I can do that? I'd appreciate every comment.

Update: A little more information to the code and the data The 'SetUpScenario' class just sets up static values that I can use in other classes. So for this example it is just important to know that the variable 'SetUpScenarios.numberOfTimeSlotsPerDay' has the value 288 (one day with a time resolution of 5 minutes). The dataframe df_buildingData contains 5 columns with 288 values each (one for each timeslot with a resolution of 5 minutes). One of them is the heat demand 'Q_htg'. The values of the Pyomo parameter 'model.param_heatDemand' should just contain one heat demand value of the row 'Q_htg' for each of the 288 elements of the Set 'model.set_timeslots'. So the first value in the set 'model.set_timeslots' should be assigned the first value of the dataframe column 'Q_htg'. The second value in the set 'model.set_timeslots' should be assigned the second value of the dataframe column 'Q_htg' and so on. Both of them have 288 entries.

Does anybody have an idea how I can do that?

$\endgroup$
5
  • $\begingroup$ What does SetUpScenarios do? How does df_buildingData look like after reading the CSV file? Can you explain what exactly the values of the parameter param_heatDemand should be? a dictionary? a row of a df? a single number? $\endgroup$ – Oguz Toragay Mar 17 at 13:07
  • $\begingroup$ Thanks Oguz for your answer. I updated my question (see Update:) and described the code and the data in more detail. I hiope it is now clear what I intend to do. $\endgroup$ – PeterBe Mar 17 at 14:00
  • $\begingroup$ @OguzToragay: Is the description (see update of the question) understandable now or do you need more information? $\endgroup$ – PeterBe Mar 18 at 8:20
  • $\begingroup$ Simply but long, you can assign using for loop. $\endgroup$ – kur ag Mar 19 at 18:24
  • $\begingroup$ Thanks kur ag for your answer. How would the code look like? $\endgroup$ – PeterBe Mar 22 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.