EV2Gym
A V2G Simulation Environment for large scale EV charging optimization.
https://github.com/stavrosorf/ev2gym
Category: Consumption
Sub Category: Mobility and Transportation
Keywords
deep-reinforcement-learning electric-vehicles gurobi gym mathematical-programming model-predictive-control simulator
Last synced: about 20 hours ago
JSON representation
Repository metadata
A V2G Simulation Environment for large scale EV charging optimization
- Host: GitHub
- URL: https://github.com/stavrosorf/ev2gym
- Owner: StavrosOrf
- License: mit
- Created: 2023-07-17T12:39:41.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-04T14:38:32.000Z (23 days ago)
- Last Synced: 2025-04-25T14:43:38.029Z (2 days ago)
- Topics: deep-reinforcement-learning, electric-vehicles, gurobi, gym, mathematical-programming, model-predictive-control, simulator
- Language: Python
- Homepage:
- Size: 94.7 MB
- Stars: 98
- Watchers: 2
- Forks: 25
- Open Issues: 0
- Releases: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
README.md
EV2Gym: A Realistic EV-V2G-Gym Simulator for EV Smart Charging
Develop and evaluate any type of smart charging algorithm: from simple heuristics, Model Predictive Control, Mathematical Programming, to Reinforcement Learning!
EV2Gym is fully customizable and easily configurable!
The EV2Gym Paper can be found at: link.
The developed MPC algorithms Paper can be found at: link.
Installation
Install the package using pip:
pip install ev2gym
Run the example code below to get started ...
from ev2gym.models.ev2gym_env import EV2Gym
from ev2gym.baselines.mpc.V2GProfitMax import V2GProfitMaxOracle
from ev2gym.baselines.heuristics import ChargeAsFastAsPossible
config_file = "ev2gym/example_config_files/V2GProfitPlusLoads.yaml"
# Initialize the environment
env = EV2Gym(config_file=config_file,
save_replay=True,
save_plots=True)
state, _ = env.reset()
agent = V2GProfitMaxOracle(env,verbose=True) # optimal solution
# or
agent = ChargeAsFastAsPossible() # heuristic
for t in range(env.simulation_length):
actions = agent.get_action(env) # get action from the agent/ algorithm
new_state, reward, done, truncated, stats = env.step(actions) # takes action
-
For Reinforcement Learning:
To train an RL agent, using the StableBaselines3 library, you can use the following code:
import gymnasium as gym
from stable_baselines3 import PPO, A2C, DDPG, SAC, TD3
from sb3_contrib import TQC, TRPO, ARS, RecurrentPPO
from ev2gym.models.ev2gym_env import EV2Gym
# Choose a default reward function and state function or create your own!!!
from ev2gym.rl_agent.reward import profit_maximization, SquaredTrackingErrorReward, ProfitMax_TrPenalty_UserIncentives
from ev2gym.rl_agent.state import V2G_profit_max, PublicPST, V2G_profit_max_loads
config_file = "ev2gym/example_config_files/V2GProfitPlusLoads.yaml"
env = gym.make('EV2Gym-v1',
config_file=config_file,
reward_function=reward_function,
state_function=state_function)
# Initialize the RL agent
model = DDPG("MlpPolicy", env)
# Train the agent
model.learn(total_timesteps=1_000_000,
progress_bar=True)
# Evaluate the agent
env = model.get_env()
obs = env.reset()
stats = []
for i in range(1000):
action, _states = model.predict(obs, deterministic=True)
obs, reward, done, info = env.step(action)
if done:
stats.append(info)
!!! You can develop your own reward and state functions and use them in the environment.
Table of Contents
Overview
- The simulator can be used to evaluate any type of algorithm to gain insights into its efficiency.
- The “gym environment” can readily support the development of RL algorithms.
- Replays of simulations are saved and can be solved optimally using the Gurobi Solver.
- Easy to incorporate additional functionality for any use-case.
- Does not simulate the grid yet, but groups EV chargers at the level of the transformer/ parking lot, etc, so extra functionality can be easily added.
- The number and the topology of Transformers, Charging stations, and Electric Vehicles are parameterizable.
- The user can import custom data.
- Uses only open-source data:
- EV spawn rate, time of stay, and energy required are based on realistic probability distributions ElaadNL conditioned on time, day, month and year.
- Pecan Street data is used for the load profiles.
- Renewables Ninja data is used for the PV generation profiles.
- EV and Charger characteristics are based on real EVs and chargers existing in NL (RVO Survey).
- Charging/ Discharging prices are based on historical day-ahead prices from ENTSO-e.
Focused on realistic parameters and fully customizable:
- Power Transformer model:
- Max Power Limit
- Inflexible Loads, PV, Capacity Reduction events
- Charging Stations model:
- Min and Max charge/discharge power/ Current
- Voltage and phases, AC or DC
- List of connected transformers
- Electric Vehicle model:
- Connected charging station and port
- Min and Max battery energy level
- Time of arrival and departure
- Energy at arrival/ desired energy at departure
- Min and Max power levels
- Charge and discharge efficiency
- Constant-Current/ Constant-Voltage load-curve option
- Battery Degradation model:
- Cyclic aging
- Calendar aging
An EV2Gym simulation comprises three phases: the configuration phase, which initializes the models; the simulation phase, which spans $T$ steps, during which the state of models like EVs and charging stations is updated according to the decision-making algorithm; and finally, in the last phase, the simulator generates evaluation metrics for comparisons, produces replay files for reproducibility, and generates real-time renders for evaluation.
Configuration File
The configuration file is used to set the parameters of the simulation. The configuration file is a YAML file that contains the following parameters:
##############################################################################
# Simulation Parameters
##############################################################################
timescale: 15 # in minutes per step
simulation_length: 96 #90 # in steps per simulation
##############################################################################
# Date and Time
##############################################################################
# Year, month,
year: 2022 # 2015-2023
month: 1 # 1-12
day: 17 # 1-31
# Whether to get a random date every time the environment is reset
random_day: False # True or False
# Simulation Starting Hour and minute do not change after the environment has been reset
hour: 12 # Simulation starting hour (24 hour format)
minute: 0 # Simulation starting minute (0-59)
# Simulate weekdays, weekends, or both
simulation_days: both # weekdays, weekends, or both
# EV Spawn Behavior
scenario: public # public, private, or workplace
spawn_multiplier: 10 # 1 is default, the higher the number the more EVs spawn
##############################################################################
# Prices
##############################################################################
discharge_price_factor: 1.2 # how many times more abs(expensive/cheaper) it is to discharge than to charge
##############################################################################
# Charging Network
##############################################################################
v2g_enabled: True # True or False
number_of_charging_stations: 15
number_of_transformers: 3
number_of_ports_per_cs: 2
# Provide path if you want to load a specific charging topology,
# else write None for a randomized one with the above parameters
charging_network_topology: None #./config_files/charging_topology_10.json
##############################################################################
# Power Setpoints Settings
##############################################################################
# How much the power setpoints can vary in percentage compared to the nominal power
# The higher the number the easier it is to meet the power setpoints, the opposite for negative numbers
power_setpoint_flexiblity: 20 # (in percentage +/- %)
##############################################################################
# Inflexible Loads, Solar Generation, and Demand Response
##############################################################################
# Whether to include inflexible loads in the transformer power limit, such as residential loads
tr_seed: -1 # Seed for the transformer loads, -1 for random
inflexible_loads:
include: False # True or False
inflexible_loads_capacity_multiplier_mean: 0.8 # 1 is default, the higher the number the more inflexible loads
forecast_mean: 100 # in percentage of load at time t%
forecast_std: 0 # in percentage of load at time t%
# PV solar Power
solar_power:
include: False # True or False
solar_power_capacity_multiplier_mean: 2 # 1 is default, the higher the number the more solar power
forecast_mean: 100 # in percentage of load at time t%
forecast_std: 0 # in percentage of load at time t%
# Whether to include demand response in the transformer power limit
demand_response:
include: False # True or False
events_per_day: 1
#How much of the transformer power limit can be used for demand response
event_capacity_percentage_mean: 25 # (in percentage +/- %)
event_capacity_percentage_std: 5 # (in percentage +/- %)
event_length_minutes_min: 60
event_length_minutes_max: 60
event_start_hour_mean: 18
event_start_hour_std: 2
# How many minutes ahead we know the event is going to happen
notification_of_event_minutes: 15
##############################################################################
# EV Specifications
##############################################################################
heterogeneous_ev_specs: False #if False, each EV has the same specifications
# such as battery capacity, charging rate, etc.
##############################################################################
# Default Model values
##############################################################################
# These values are used if not using a charging network topology file or
# if the EV specifications are not provided
# Default Transformer model
transformer:
max_power: 100 # in kW
# Default Charging Station model
charging_station:
min_charge_current: 0 # Amperes
max_charge_current: 56 # Amperes
min_discharge_current: 0 # Amperes
max_discharge_current: -56 # Amperes
voltage: 230 # Volts
phases: 3 # 1,2, or 3
# Default EV model
ev:
battery_capacity: 50 # in kWh
min_battery_capacity: 10 # in kWh
desired_capacity: 40 # in kWh
max_ac_charge_power: 22 # in kW
min_ac_charge_power: 0 # in kW
max_dc_charge_power: 50 # in kW
max_discharge_power: -22 # in kW
min_discharge_power: 0 # in kW
ev_phases: 3
transition_soc: 1 # 0-1 (0% - 100%)
charge_efficiency: 1 # 0-1 (0% - 100%)
discharge_efficiency: 1 # 0-1 (0% - 100%)
min_time_of_stay: 120 # in minutes
File Structure
The file structure of the EV2Gym package is as follows:
├── ev2gym
│ ├── baselines
│ │ ├── gurobi_models/
│ │ ├── mpc/
│ │ ├── heuristics.py
│ ├── data/
│ ├── models
│ │ ├── ev2gym_env.py
│ │ ├── ev.py
│ │ ├── transformer.py
│ │ ├── ev_charger.py
│ │ ├── replay.py
│ │ ├── grid.py
│ ├── rl_agent
│ │ ├── reward.py
│ │ ├── state.py
│ ├── utilities
│ │ ├── loaders.py
│ │ ├── utils.py
│ │ ├── arg_parser.py
│ ├── example_config_files
│ │ ├── BusinessPST.yaml
│ │ ├── PublicPST.yaml
│ │ ├── V2GProfitPlusLoads.yaml
│ ├── visuals
│ │ ├── plots.py
│ │ ├── renderer.py
│ ├── scripts/
Class Diagram of the EV2Gym Environment:
Citing EV2Gym
If you use this code in your research, please cite as:
@ARTICLE{10803908,
author={Orfanoudakis, Stavros and Diaz-Londono, Cesar and Emre Yılmaz, Yunus and Palensky, Peter and Vergara, Pedro P.},
journal={IEEE Transactions on Intelligent Transportation Systems},
title={EV2Gym: A Flexible V2G Simulator for EV Smart Charging Research and Benchmarking},
year={2025},
volume={26},
number={2},
pages={2410-2421},
keywords={Vehicle-to-grid;Smart charging;Optimization;Benchmark testing;Batteries;Data models;Schedules;Reinforcement learning;Prediction algorithms;Power transformers;Electric vehicle optimization;gym environment;reinforcement learning;mathematical programming;model predictive control (MPC)},
doi={10.1109/TITS.2024.3510945}}
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Contributing
EV2Gym is an open-source project and welcomes contributions! Please get in contact with us if you would like to discuss about the simulator.
Owner metadata
- Name: Stavros Orfanoudakis
- Login: StavrosOrf
- Email:
- Kind: user
- Description: Ph.D. Candidate, EEMCS TU Delft | A.I. for the Smart Grid
- Website:
- Location: The Netherlands
- Twitter:
- Company: Machine Learning Researcher
- Icon url: https://avatars.githubusercontent.com/u/17108978?u=de1171f1866a444e2809bf3e21d70cf21b69ea06&v=4
- Repositories: 1
- Last ynced at: 2023-11-23T18:41:07.811Z
- Profile URL: https://github.com/StavrosOrf
GitHub Events
Total
- Create event: 2
- Issues event: 10
- Release event: 1
- Watch event: 55
- Issue comment event: 10
- Push event: 16
- Pull request event: 4
- Fork event: 11
Last Year
- Create event: 2
- Issues event: 10
- Release event: 1
- Watch event: 55
- Issue comment event: 10
- Push event: 16
- Pull request event: 4
- Fork event: 11
Committers metadata
Last synced: 6 days ago
Total Commits: 384
Total Committers: 3
Avg Commits per committer: 128.0
Development Distribution Score (DDS): 0.07
Commits in past year: 22
Committers in past year: 2
Avg Commits per committer in past year: 11.0
Development Distribution Score (DDS) in past year: 0.045
Name | Commits | |
---|---|---|
Stavros Orfanoudakis | s****1@y****r | 357 |
StavrosOrf | s****9@g****m | 26 |
bob.elders | b****s@g****m | 1 |
Committer domains:
- yahoo.gr: 1
Issue and Pull Request metadata
Last synced: 2 days ago
Total issues: 12
Total pull requests: 18
Average time to close issues: 10 days
Average time to close pull requests: about 1 hour
Total issue authors: 8
Total pull request authors: 2
Average comments per issue: 1.5
Average comments per pull request: 0.0
Merged pull request: 18
Bot issues: 0
Bot pull requests: 0
Past year issues: 10
Past year pull requests: 3
Past year average time to close issues: 12 days
Past year average time to close pull requests: about 7 hours
Past year issue authors: 7
Past year pull request authors: 2
Past year average comments per issue: 1.6
Past year average comments per pull request: 0.0
Past year merged pull request: 3
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- STW1994 (2)
- Kallinteris-Andreas (2)
- seonjin13 (2)
- Electric-V (2)
- GanMocai (1)
- lqhdehub (1)
- VicKolo (1)
- Sweetbill0 (1)
Top Pull Request Authors
- StavrosOrf (17)
- COMMEX147 (1)
Top Issue Labels
Top Pull Request Labels
Package metadata
- Total packages: 1
-
Total downloads:
- pypi: 272 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
pypi.org: ev2gym
A realistic V2G simulator environment
- Homepage:
- Documentation: https://ev2gym.readthedocs.io/
- Licenses: MIT License
- Latest release: 1.1.0 (published 5 months ago)
- Last Synced: 2025-04-25T14:32:55.246Z (2 days ago)
- Versions: 3
- Dependent Packages: 0
- Dependent Repositories: 0
- Downloads: 272 Last month
-
Rankings:
- Dependent packages count: 9.692%
- Average: 36.819%
- Dependent repos count: 63.946%
- Maintainers (1)
Dependencies
- autoapi *
- gurobipy *
- gymnasium *
- matplotlib *
- networkx *
- pandas *
- pyyaml *
Score: 11.293051562523642