Skip to content

Commit

Permalink
greedy_battery: charge only with surplus
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan.schirmeister committed Nov 7, 2024
1 parent c7f2a53 commit dffe904
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions spice_ev/strategies/greedy_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ def __init__(self, components, start_time, **kwargs):
self.description = "greedy battery"

def step(self):
power_used = {}
avail_bat_power = {}
for gc_id, gc in self.world_state.grid_connectors.items():
power_used[gc_id] = gc.get_current_load()
avail_bat_power[gc_id] = 0
for battery in self.world_state.batteries.values():
avail_bat_power[battery.parent] += battery.get_available_power(self.interval)
Expand All @@ -38,11 +36,10 @@ def step(self):
power_needed = (
vehicle.get_delta_soc() * vehicle.battery.capacity /
vehicle.battery.efficiency * self.ts_per_hour)
power_available = gc.cur_max_power - power_used[gc_id] + avail_bat_power[gc_id]
power_available = gc.cur_max_power - gc.get_current_load() + avail_bat_power[gc_id]
power = clamp_power(min(power_needed, power_available), vehicle, cs)
avg_power = vehicle.battery.load(self.interval, target_power=power)['avg_power']
cs.current_power = avg_power
power_used[gc_id] += avg_power
avail_bat_power[gc_id] -= min(avg_power, avail_bat_power[gc_id])
charging_stations[cs_id] = gc.add_load(cs_id, avg_power)

Expand All @@ -56,7 +53,7 @@ def step(self):
gc_id = cs.parent
gc = self.world_state.grid_connectors[gc_id]
# add surplus, if any
power = clamp_power(max(-power_used[gc_id], 0), vehicle, cs)
power = clamp_power(max(-gc.get_current_load(), 0), vehicle, cs)
avg_power = vehicle.battery.load(self.interval, target_power=power)['avg_power']
charging_stations[cs_id] = gc.add_load(cs_id, avg_power)

Expand All @@ -70,8 +67,8 @@ def step(self):
bat_power = battery.unload(self.interval, target_power=gc_current_load)['avg_power']
gc.add_load(bat_id, -bat_power)
else:
# GC does not draw power or has surplus: charge battery greedy
power = gc.cur_max_power - gc_current_load
# use surplus to charge battery
power = -gc_current_load
power = 0 if power < battery.min_charging_power else power
avg_power = battery.load(self.interval, target_power=power)['avg_power']
gc.add_load(bat_id, avg_power)
Expand Down

0 comments on commit dffe904

Please sign in to comment.