This project explores and implements multiple strategies for battery optimization, including rule-based, threshold-based, and linear programming (LP) approaches. It provides a modular framework for simulation, evaluation, and sensitivity analysis of these strategies.
battery_optimization_strategy-dev/
├── main.py # Main entry point
├── models/ # Optimization strategies
│ ├── LP_optimization.py
│ ├── rule_based.py
│ ├── threshold_based.py
│ └── base_simulator.py # Common simulation base
├── utils/ # Utility functions
│ ├── plotting.py
│ └── utils.py
├── notebooks/ # Jupyter notebooks for analysis
│ ├── Battery_optimisation_strategy.ipynb
│ ├── EDA.ipynb
│ └── Sensitivity_Analysis.ipynb
└── .gitignore
Ensure you have Python 3.8+ installed.
- Install
uvpackage manager:
pip install uv- Create a new environment using
uv:
uv venv- Activate the environment:
- On macOS/Linux:
source .venv/bin/activate- On Windows:
.venv\Scripts\activate- Install the required packages:
uv pip install .This project uses pyproject.toml to manage dependencies with uv.
Ensure that all required input data is placed in the data/ directory at the project root.
The main.py script accepts the following argument:
-
--simulate: (optional)
Run a new simulation instead of using saved results. -
--data-path: (required)
Path to the CSV file containing price data. Example:data/Day-ahead_prices.csv -
--strategy: (required)
Name of the strategy to simulate. Choices:Threshold-BasedRule-BasedLinear-Programming
python main.py --simulate \
--data-path data/Day-ahead_prices.csv \
--strategy Linear-Programming- Rule-Based Strategy: Simple heuristics for charging/discharging based on predefined rules.
- Threshold-Based Strategy: Uses upper/lower thresholds for decision-making.
- LP Optimization: Applies Linear Programming to optimize energy storage/usage cost-effectively.
Each strategy is implemented in a modular fashion under models/.
EDA.ipynb: Exploratory Data Analysis of the input data.Battery_optimisation_strategy.ipynb: Demonstrates strategy simulations and visualizations.Sensitivity_Analysis.ipynb: Examines robustness of strategies to parameter variations.
Custom plots and charts for performance evaluation are handled via utils/plotting.py.
Helper functions are available in utils/utils.py for common tasks like data handling, metrics, and logging.
Contributions are welcome! Please fork the repo, create a feature branch, and submit a pull request.
To ensure code quality and consistency, this project uses pre-commit for automatic code formatting and static checks.
-
Install pre-commit (once per machine):
pip install pre-commit
-
Install the Git hook (once per repo):
pre-commit install
-
Run all checks manually (optional):
pre-commit run --all-files
This will automatically run formatters like black, isort, and type checks (mypy) before every commit. Please make sure all checks pass before pushing.
This project is licensed under the MIT License — see the LICENSE file for details.