|
|
import numpy as np |
|
|
|
|
|
|
|
|
class PriceAwareAgent: |
|
|
""" |
|
|
Heuristic agent for EVChargeEnv. |
|
|
|
|
|
- Charges more when price is low and grid load is safe. |
|
|
- Charges less when price is high or grid load is high. |
|
|
""" |
|
|
|
|
|
def __init__(self, |
|
|
low_price_threshold: float = 0.4, |
|
|
high_price_threshold: float = 0.7, |
|
|
high_load_threshold: float = 0.8): |
|
|
self.low_price_threshold = low_price_threshold |
|
|
self.high_price_threshold = high_price_threshold |
|
|
self.high_load_threshold = high_load_threshold |
|
|
|
|
|
def select_action(self, observation): |
|
|
""" |
|
|
observation = [charge, price, load, time_step_norm] |
|
|
returns: np.array([action]) in [0, 1] |
|
|
""" |
|
|
charge, price, load, t = observation |
|
|
|
|
|
|
|
|
if charge >= 0.98: |
|
|
return np.array([0.0], dtype=np.float32) |
|
|
|
|
|
|
|
|
if load >= self.high_load_threshold: |
|
|
return np.array([0.1], dtype=np.float32) |
|
|
|
|
|
|
|
|
if price <= self.low_price_threshold: |
|
|
return np.array([0.9], dtype=np.float32) |
|
|
|
|
|
|
|
|
if price >= self.high_price_threshold: |
|
|
return np.array([0.2], dtype=np.float32) |
|
|
|
|
|
|
|
|
return np.array([0.5], dtype=np.float32) |
|
|
|