Skip to content

Commit

Permalink
Modified LP solver parameter implementation and prepared new version
Browse files Browse the repository at this point in the history
  • Loading branch information
davidusb-geek committed May 30, 2022
1 parent 09f43bb commit 879a0a2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions config_emhass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 11 additions & 8 deletions src/emhass/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/emhass/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']]
Expand Down

0 comments on commit 879a0a2

Please sign in to comment.