From 879a0a2034d8c5cee22b82c0739c390dfe5d35a5 Mon Sep 17 00:00:00 2001 From: David HERNANDEZ Date: Mon, 30 May 2022 17:27:43 +0200 Subject: [PATCH] Modified LP solver parameter implementation and prepared new version --- CHANGELOG.md | 4 ++++ config_emhass.yaml | 2 ++ docs/conf.py | 2 +- docs/config.md | 2 ++ setup.py | 2 +- src/emhass/optimization.py | 19 +++++++++++-------- src/emhass/web_server.py | 2 ++ 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55d01940..f923ea16 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.11] - 2022-05-23 +### Improvement +- Added support to provide solver name and path as parameters in the configuration file. + ## [0.3.11] - 2022-05-23 ### Fix - Fixed unittests not passing. diff --git a/config_emhass.yaml b/config_emhass.yaml index 4c081ce6..1feb36ec 100644 --- a/config_emhass.yaml +++ b/config_emhass.yaml @@ -45,6 +45,8 @@ optim_conf: - prod_price_forecast_method: 'constant' # options are 'constant' for constant fixed value or 'csv' to load custom price forecast from a CSV file - prod_sell_price: 0.065 # power production selling price in €/kWh (only needed if prod_price_forecast_method='constant') - set_total_pv_sell: False # consider that all PV power is injected to the grid (self-consumption with total sell) + - lp_solver: 'PULP_CBC_CMD' # set the name of the linear programming solver that will be used + - lp_solver_path: '/usr/bin/cbc' # set the path to the LP solver plant_conf: - P_grid_max: 9000 # The maximum power that can be supplied by the utility grid in Watts diff --git a/docs/conf.py b/docs/conf.py index 430eadf8..82236b4e 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -22,7 +22,7 @@ author = 'David HERNANDEZ' # The full version, including alpha/beta/rc tags -release = '0.3.11' +release = '0.3.12' # -- General configuration --------------------------------------------------- diff --git a/docs/config.md b/docs/config.md index 1d9be0e0..acbb44b4 100644 --- a/docs/config.md +++ b/docs/config.md @@ -71,6 +71,8 @@ The following parameters and definitions are only needed if load_cost_forecast_m - prod_price_forecast_method: Define the method that will be used for PV power production price forecast. This is the price that is payed by the utility for energy injected to the grid. The options are 'constant' for a constant fixed value or 'csv' to load custom price forecast from a CSV file. The default CSV file path that will be used is '/data/data_prod_price_forecast.csv'. - prod_sell_price: The paid price for energy injected to the grid from excedent PV production in €/kWh. Defaults to 0.065. This parameter is only needed if prod_price_forecast_method='constant'. +- lp_solver: Set the name of the linear programming solver that will be used. Defaults to 'PULP_CBC_CMD'. +- lp_solver_path: Set the path to the LP solver. Defaults to '/usr/bin/cbc'. ## System configuration parameters diff --git a/setup.py b/setup.py index 5e3ac316..62345021 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup( name='emhass', # Required - version='0.3.11', # Required + version='0.3.12', # Required description='An Energy Management System for Home Assistant', # Optional long_description=long_description, # Optional long_description_content_type='text/markdown', # Optional (see note above) diff --git a/src/emhass/optimization.py b/src/emhass/optimization.py index 54c58c7a..e66dee90 100644 --- a/src/emhass/optimization.py +++ b/src/emhass/optimization.py @@ -27,8 +27,7 @@ class optimization: def __init__(self, retrieve_hass_conf: dict, optim_conf: dict, plant_conf: dict, var_load_cost: str, var_prod_price: str, days_list: pd.date_range, costfun: str, config_path: str, logger: logging.Logger, - opt_time_delta: Optional[int] = 24, lp_solver: Optional[str] = 'PULP_CBC_CMD', - lp_solver_path: Optional[str] = '/usr/bin/cbc') -> None: + opt_time_delta: Optional[int] = 24) -> None: """ Define constructor for optimization class. @@ -58,10 +57,6 @@ def __init__(self, retrieve_hass_conf: dict, optim_conf: dict, plant_conf: dict, more than one day then the optimization will be peformed by chunks of \ opt_time_delta periods, defaults to 24 :type opt_time_delta: float, optional - :param lp_solver: The linear programming solver name to use - :type lp_solver: str, optional - :param lp_solver_path: The path to the solver name to use - :type lp_solver_path: str, optional """ self.retrieve_hass_conf = retrieve_hass_conf @@ -79,8 +74,16 @@ def __init__(self, retrieve_hass_conf: dict, optim_conf: dict, plant_conf: dict, self.logger = logger self.var_load_cost = var_load_cost self.var_prod_price = var_prod_price - self.lp_solver = lp_solver - self.lp_solver_path = lp_solver_path + if 'lp_solver' in optim_conf.keys(): + self.lp_solver = optim_conf['lp_solver'] + else: + self.lp_solver = 'PULP_CBC_CMD' + if 'lp_solver_path' in optim_conf.keys(): + self.lp_solver_path = optim_conf['lp_solver_path'] + else: + self.lp_solver_path = r'/usr/bin/cbc' + if self.lp_solver != 'COIN_CMD' and 'lp_solver_path' in optim_conf.keys(): + self.logger.error("Use COIN_CMD solver name if you want to set a path for the LP solver") def perform_optimization(self, data_opt: pd.DataFrame, P_PV: np.array, P_load: np.array, unit_load_cost: np.array, unit_prod_price: np.array, diff --git a/src/emhass/web_server.py b/src/emhass/web_server.py index f4e6d5e2..a2a78c45 100644 --- a/src/emhass/web_server.py +++ b/src/emhass/web_server.py @@ -80,6 +80,8 @@ def build_params(params, options, addon): params['optim_conf'][12]['load_cost_hc'] = options['load_offpeak_hours_cost'] params['optim_conf'][14]['prod_sell_price'] = options['photovoltaic_production_sell_price'] params['optim_conf'][15]['set_total_pv_sell'] = options['set_total_pv_sell'] + params['optim_conf'][16]['lp_solver'] = options['lp_solver'] + params['optim_conf'][17]['lp_solver_path'] = options['lp_solver_path'] # Updating variables in plant_conf params['plant_conf'][0]['P_grid_max'] = options['maximum_power_from_grid'] params['plant_conf'][1]['module_model'] = [i['pv_module_model'] for i in options['list_pv_module_model']]