Pyomo-based optimization system for multi-device energy hub scheduling. Supports both linear (MILP) and quadratic (MIQP) optimization using IPOPT solver.
- Multi-device energy hub optimization (CHP, PEM, Battery, Methanation, Heat Pump)
- MILP and MIQP solving via IPOPT
- MQTT integration for real-time scheduling
- Comprehensive test suite with 80%+ code coverage
- All configuration centralized in project_config.json
- Python 3.8+
- IPOPT solver (install separately, e.g., via conda:
conda install -c conda-forge ipopt)
# Clone the repository
cd energy-hub-milp
# Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
# Install development dependencies (for testing)
uv pip install -e ".[dev]"All dependencies are listed in pyproject.toml:
pyomo- Optimization modelingnumpy- Numerical computingpandas- Data handlingmatplotlib,seaborn- Visualizationpaho-mqtt- MQTT integrationrequests- HTTP requests
Dev dependencies:
pytest- Testing frameworkpytest-cov- Coverage reporting
All configuration is managed through project_config.json. Key configuration sections:
paths.data_dir- Data directory (default: "Daten")paths.output_dir- Output directory (default: "output")paths.logs_dir- Logs directory (default: "logs")
solver.ipopt_executable- IPOPT executable path
MQTT credentials are stored in credentials.json. Update this file with your broker details before running the MQTT runner.
# Run all tests with coverage
pytest tests/ --cov=. --cov-report=term-missing
# Run tests quietly
pytest tests/ -q
# Run specific test file
pytest tests/test_schedule_generator.py -vpython main.pypython main.py --quadraticfrom schedule_generator import connect_and_schedule
connect_and_schedule(
timeframe=96,
step_length=900, # 15 minutes in seconds
all_results_file="output.json",
result_schedule_file="schedule.csv",
quadratic=True,
load_ts="TargetFromResults.pkl",
days=5
)python mqtt_runner.pymilp/
├── config.py # Configuration loader
├── project_config.json # Project configuration
├── main.py # Main optimization script
├── schedule_generator.py # Optimization orchestration
├── mqtt_runner.py # MQTT integration
├── indexed_model.py # Pyomo model
├── components/ # Device models
│ ├── converter.py
│ ├── storage.py
│ ├── grid.py
│ ├── target.py
│ └── heat_target.py
├── tests/ # Test suite
│ ├── test_indexed_model.py
│ ├── test_schedule_generator.py
│ ├── test_mqtt_runner.py
│ ├── test_components.py
│ └── test_utils.py
├── Daten/ # Data and results
│ └── results/
└── .gitlab-ci.yml # CI/CD pipeline
The .gitlab-ci.yml includes a test stage that runs automatically with coverage enforcement:
test:
stage: test
script:
- pytest tests/ --cov=. --cov-report=term-missing --cov-report=html --cov-fail-under=80Tests run automatically on every push to the repository. The pipeline enforces minimum 80% code coverage.
MIT