classdef bessim < rl.env.MATLABEnvironment
EnvName= 'EnergyTrading';
properties(Access = protected)
function this = bessim(~)
ObservationInfo = rlNumericSpec([3 1]);
ObservationInfo.Name = 'BatteryLevel';
ObservationInfo.LowerLimit = [0; -2000; 0];
ObservationInfo.UpperLimit = [8000; 2000; inf];
ActionInfo = rlNumericSpec([1 1]);
ActionInfo.Name = 'Charging Power';
ActionInfo.LowerLimit = 0;
ActionInfo.UpperLimit = 2000;
this = this@rl.env.MATLABEnvironment(ObservationInfo, ActionInfo);
this.BatteryLevel = this.Capacity/2;
data1 = load('Energypriceprofile.mat');
this.EnergyPricedata = data1.Energypriceprofile;
function [Observation,Reward,IsDone,LoggedSignals] = step(this,Action)
DischargingPower = -Action;
CurrentPrice=this.EnergyPricedata(this.current_hour);
NetProfit = DischargingPower * CurrentPrice - ChargingPower * CurrentPrice;
ChargingTime = min((this.Capacity - this.BatteryLevel) / ChargingPower, this.Ts);
this.BatteryLevel = this.BatteryLevel + ChargingPower * ChargingTime;
DischargingTime = min(this.BatteryLevel / abs(DischargingPower), this.Ts);
this.BatteryLevel = this.BatteryLevel + DischargingPower * DischargingTime;
this.power = ChargingPower - DischargingPower;
Observation = [this.BatteryLevel; this.power; CurrentPrice];
this.current_hour = this.current_hour + 1;
function InitialObservation = reset(this)
this.BatteryLevel = this.Capacity/2;
this.State = [this.BatteryLevel] ;
InitialObservation = [this.BatteryLevel; this.power; this.EnergyPricedata(this.current_hour)];