This project represents an advanced technical solution for the Unit Commitment optimization challenge. Its fundamental purpose is to calculate the optimal load each power plant must generate to meet a specific demand, minimizing operating costs while ensuring compliance with each unit's technical constraints.
The application is implemented as a REST API developed with FastAPI and Python 3.13, designed to process load data, fuel costs, and generation capacities. Regarding the core logic, a Merit Order algorithm has been implemented to prioritize energy sources based on their marginal cost. It is important to highlight that the system integrates the calculation of CO2 emission rights (0.3 ton/MWh) for gas-fired plants, aligning the solution with current energy sector sustainability standards.
In relation to the software design, a separation of concerns approach has been followed to maximize maintainability. Specifically, FastAPI & Pydantic handle the transport layer and strict data schema validation, while a framework-independent Logic Solver facilitates unit testing. Furthermore, a Logging & Observability system provides event tracking for execution monitoring and real-time error management. Ultimately, the project uses Docker for full containerization to ensure consistent deployment across any environment.
To ensure portability, the project includes a Dockerfile. The API can be started by executing the following commands in the repository root:
- Build the image:
docker build -t powerplant-api . - Run the container:
docker run -p 8888:8888 powerplant-api
If you prefer a native execution, using a virtual environment is recommended:
- Create and activate the environment:
python -m venv venvand.\venv\Scripts\activate(Windows). - Install dependencies:
pip install -r requirements.txt. - Launch the API:
python -m app.main.
In compliance with the test requirements, the application remains accessible on port 8888.
Regarding internal operations, the algorithm dynamically manages minimum (
The API includes interactive documentation accessible at http://localhost:8888/docs. To validate the solution, the files located in ./example_payloads have been used, confirming that the production plan generated for payload3.json fully aligns with the results expected by the engineering team.
Furthermore, specific test cases have been incorporated to verify the stability of the algorithm under technical constraints:
- payload_custom_limit_0.json & response_custom_limit_0.json: Validation of the early termination logic (break) when the demand is met exactly before processing more expensive units.
- payload_custom_limit_1.json & response_custom_limit_1.json: Verification of the backtracking/skip protocol. This test demonstrates how the API handles a "technical deadlock" by skipping a rigid plant (
$P_{min}$ constraints) that cannot be adjusted, successfully fulfilling the load with the next available flexible unit.
Developed for the Short-term Power as-a-Service team recruitment process.