Memuat
Memuat
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Microgrid Energy Management MPC #5: Solving MPC with Optimization (CVXPY) per Time Step”.
Other ways we can help with Python.
Learn with a mentor
Scheduled Simulation & Engineering courses with live guidance and a certificate.

Course/Training Ansys ~ Heat Transfer and Heat Flux Analysis
★ 5.0 (10)

Course/Training MATLAB — MATLAB App Design: The Ultimate Guide to MATLAB Apps
★ 5.0 (10)

Course/Training Ansys — Airflow Simulation of a Car Radiator with ANSYS
★ 5.0 (9)
Have it built for you
No time to learn Python? Our team can do the project for you.

Matlab Development Service — Complete Neural Signal Processing and Analysis Zero to Hero
★ 5.0 (59)

Ansys Maxwell Development Service
★ 5.0 (50)

Petrel Development Service
★ 5.0 (14)
Get notified about new Python classes
At most one email a week. Unfollow anytime with one click.
The full narration of this video. The current sentence is highlighted while the video plays; click any sentence to jump there.
Here is the final result, MPC is run every hour throughout the year, 8,736 optimizations, only about 20 seconds. Even with inaccurate PV and load forecasts, the cost is almost the same as with perfect forecasts. Let's get started. Hello, welcome to episode five of the MPC-based microgrid energy management series. The 24-hour plan is not executed entirely. MPC only executes the decision for the first hour, then one hour later, it replans with the latest data and forecasts. This is Receding Horizon. Today we are simulating it for an entire year, with perfect forecasts or imperfect forecasts.
Create a simulation file underscore mpc.py. The forecast function generates the net load for the next hours. Without a random generator, the forecast is perfect. With a random generator, the PV forecast is given a growing error of 5% in the first hour up to 30% after 12 hours, and the load is given an error of 2 to 6%. This pattern of growing errors over time is similar to real weather forecasts.
The MPC simulation function creates two batteries, one for the controller, one for the real battery. Every hour, a forecast is created, MPC plans for 24 hours, and then only the decision for the first hour is executed on the real battery. Import and export are calculated from the actual net load, not from the forecast, so the forecast error truly has an impact. The real battery's SoC becomes the initial SoC of the next hour. The main part runs both versions and saves the results to an NPZ file for the next episode.
Run Each version solves 8,736 optimizations in about 21 seconds thanks to the DPP parameter. With perfect forecasts, the annual cost is 258.9 million rupiah. With noisy forecasts, 260.2 million, only about 1.3 million more expensive. The battery shifts 154 MW hours, 2.5 times more than rule-based. Why is MPC resilient to forecast errors?
Since the plan is updated every hour, forecasts for several hours ahead are never executed, and the first hour's decision uses the most accurate forecast. This is the main advantage of Residing Horizon over making a daily schedule.
Done We have been running the Residing Horizon MPC throughout the year, comparing perfect and noisy forecasts, and observing that MPC remains reliable even when forecasts are off. In the last episode, we compared all strategies, costs, PLN usage, and battery lifespan. Currently working on a thesis, dissertation, or research in the field of microgrid, batteries, and renewable energy? Cerdas Inovasi Digital helps with energy optimization implementation, from solar panel, wind turbine, and battery modeling, rule-based strategies, up to model predictive control with CVXPY, as well as offering Python programming courses for electrical engineering. Want to master the entire series, from weather data to cost comparison? All 6 episodes, complete with PDF step-by-step guides and source code, are available to premium tutorial subscribers. Subscribe starting at Rp69.000 per month, save 28% with the 12-month package, or pay once Rp999.000 for lifetime access. Want just one class? Buy a single class with lifetime access. Subscribe now at the premium page cerdasinovasidigital.com Contact us via WhatsApp or visit cerdasinovasidigital.com Thank you for watching, see you in the next episode.
Type a question or keyword; we find the part of this episode that explains it and jump the video there.
Notes are saved with the current video time and are only visible to you.
Stuck on a step? Ask here; the instructor and other learners can answer.
No questions yet.

Cerdas Inovasi Digital Team
Software developers, BIM & 3D engineers, and AI practitioners
We build software, BIM models, games and AI automations for clients every day, and turn that hands-on work into step-by-step classes: every step is shown on screen and comes with a PDF guide you can keep.
See our clients →