From 6a7f41a18f9f294b25754d3011f0c342045f907b Mon Sep 17 00:00:00 2001
From: Christian Doh Dinga <cdohdinga@tudelft.nl>
Date: Sun, 23 Jun 2024 20:17:37 +0200
Subject: [PATCH] define consumer parameters

---
 .../define_consumer_parameters.py             | 44 +++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/demoses_distibuted_optimization/define_consumer_parameters.py

diff --git a/src/demoses_distibuted_optimization/define_consumer_parameters.py b/src/demoses_distibuted_optimization/define_consumer_parameters.py
new file mode 100644
index 0000000..6721536
--- /dev/null
+++ b/src/demoses_distibuted_optimization/define_consumer_parameters.py
@@ -0,0 +1,44 @@
+import pandas as pd
+import pyomo.environ as pyo
+from typing import Dict
+
+
+def define_consumer_parameters(agent: str, model: pyo.AbstractModel, data: Dict, ts: pd.DataFrame) -> pyo.AbstractModel:
+    # Extract consumer parameter values from data
+    total_consumers = data['General']['totConsumers']
+    share_of_agent = data['Consumers'][agent]['Share']
+    # Demand
+    normalized_demand_profile = ts.loc[:, data['Consumers'][agent]['D']].values
+    demand_profile = total_consumers * share_of_agent * normalized_demand_profile
+    # PV
+    pv_availability_factor = ts.loc[:, data['Consumers'][agent]['PV_AF']].values
+    pv_capacity = data['Consumers'][agent]['PV_cap']
+    pv_profile = total_consumers * share_of_agent * pv_capacity * pv_availability_factor
+    # Declare consumer optimization parameters (but do not construct yet)
+    model.demand_profile = pyo.Param(model.time, name='demand_profile', initialize=dict(enumerate(demand_profile)), mutable=False)
+    model.pv_profile = pyo.Param(model.time, name='pv_profile', initialize=dict(enumerate(pv_profile)), mutable=False)
+    
+    return model
+
+
+
+# # Example usage
+# import yaml
+# from define_common_parameters import define_common_parameters
+
+
+# def read_config(config_file):
+#     with open(config_file, 'r') as file:
+#         config = yaml.safe_load(file)
+#     return config
+
+# data = read_config('config.yaml')
+# consumer_agents = [id for id in data['Consumers'].keys()]
+# ts = pd.read_csv('timeseries.csv', delimiter=';')
+# mdict = {m: define_common_parameters(m, data) for m in consumer_agents}
+
+# for agent, model in mdict.items():
+#     model = define_consumer_parameters(agent, model, data, ts)
+#     print(model.name)
+#     print()
+#     model.pprint()
\ No newline at end of file
-- 
GitLab