MPC-G2V-V2G

August 20, 2025 ยท View on GitHub

Open-source Model Predictive Control implementations. Open access paper Link

Installation

Make sure you installed the EV2Gym first.

pip install ev2gym

Run a simple example with MPC:


from ev2gym.models.ev2gym_env import EV2Gym
from occf_mpc import OCMF_V2G, OCMF_V2G
from eMPC import eMPC_V2G, eMPC_G2V

# path to the configuration file
config_file = "V2G_MPC.yaml"

# create the simulator environment
env = EV2Gym(config_file=config_file,
                    verbose=True,
                    save_replay=True,                       
                    save_plots=True,
                    )

state, _ = env.reset()
agent = eMPC_V2G(env, control_horizon=25, verbose=False)
# run the simulation
for t in range(env.simulation_length):        
    # get the action from the MPC algorithm
    actions = agent.get_action(env)
    # Step the simulation
    new_state, reward, done, _, stats = env.step(
        actions, visualize=True)  # takes action        
    
print(stats)

Citation

If you use this code in your research, please cite the following paper:

@article{DIAZLONDONO2026MPC,
title = {Open source algorithms for maximizing V2G flexibility based on model predictive control},
journal = {Electric Power Systems Research},
volume = {250},
pages = {112082},
year = {2026},
issn = {0378-7796},
doi = {https://doi.org/10.1016/j.epsr.2025.112082},
url = {https://www.sciencedirect.com/science/article/pii/S0378779625006704},
author = {Cesar Diaz-Londono and Stavros Orfanoudakis and Pedro P. Vergara and Peter Palensky and Fredy Ruiz and Giambattista Gruosso},
keywords = {Electric vehicles (EVs), Smart charging, Battery degradation, Vehicle-to-Grid (V2G), Model predictive control (MPC)}
}