Memuat
Memuat
Watch every step above performed live, with English narration.
0 plays
Class book
Page 1 / 6
Cover: Class Manajemen Energi Microgrid MPC #4: MPC Formulation: Prediction Horizon, Cost Function, and Constraints
Click a page or use ◀ ▶ to turn · swipe on mobile · to enlarge
Want to go deeper?
Join one of our courses or ask us directly on WhatsApp.
Picked from the software, topic, and level of “Class Manajemen Energi Microgrid MPC #4: MPC Formulation: Prediction Horizon, Cost Function, and Constraints”.
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, the CVXPi optimization planning the battery for 24 hours ahead in milliseconds. The battery is charged during the day and stored for peak load hours, thus reducing the import during high tariff periods from 267 to 53 kWh in a day. Let's start. Hello, welcome to episode four of the MPC-based microgrid energy management series. Model predictive control works like a driver looking ahead on the road, with forecasts of load, PV, and prices for several hours ahead, it finds the best decisions for the entire Horizon. Today we formulate the optimization problem with CVXPi.
Create file mpc.py The MPC class receives the battery model and Horizon H24 hours. The first part is parameters, net load forecast, purchase price, selling price, and initial SOC. CVXPi parameters can be changed every hour without re-formulating the problem. This satisfies the DPP rules, so repeated solutions are very fast. Decision variables, charging power, discharging power, import, export, all are non-negative, and SOC for H plus 1 time step.
Constraints, initial SOC equals current SOC. SOC dynamics are the same as the battery model, SOC between 20 and 95 percent, maximum charging and discharging power of 75 kW, PLN connection limits, and most importantly, power balance. Import minus export equals net load plus charging minus discharging. The cost function is purchase cost minus selling revenue, plus degradation cost of 150 rupiah per kilowatt hour that goes through the battery, minus the remaining energy value at the end of the horizon, so the battery is not drained unnecessarily.
The method fills in the parameter values, solves the problem with the HICE solver because this is a linear program, then returns the battery power plan, SOC, import, and export.
Create the file mpc-1-hari.py We optimize for August 8th with perfect forecasts and an initial SOC of 50%, then compare it with rule-based. Run. Optimal status, 121 variables, completed in about 30 milliseconds. The cost for that day dropped from around 859 thousand to 761 thousand rupiah, and import during WBP dropped from 267 to 53 kilowatt hours. Final SOC 20%, the energy was used up exactly during peak hours. Let's look at the graph.
Purple bar MPC, battery is charged during the day, even from PLN when the tariff is still cheap, Then it is fully emptied in the red WBP area. The gray rule-based bar empties in the morning. The SOC graph shows MPC rising up to 95% before 5 PM, while rule-based remains below. This is the power of looking ahead. Done.
We have formulated MPC with CVXPi, parameters and variables, SOC dynamics, power balance, cost function with degradation and remaining energy value, and then solved it for one day. In the next episode, we will run MPC on an hourly basis throughout the year, including with imperfect forecasts. Currently working on a thesis, dissertation, or research in the field of microgrid, battery, and renewable energy? Cerdas Inovasi Digital helps implement energy optimization, from solar panel modeling, wind turbine, and battery, rule-based strategies, up to model predictive control with CVXPi as well as opening a Python programming course for electrical engineering. Want to master the entire series, from weather data to operational cost comparison? All 6 episodes, complete with step-by-step PDF 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 the single class with lifetime access. Subscribe now on the premium page cerdasinovasidigital.com. Contact our 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 →