save
This commit is contained in:
parent
a03ce7b404
commit
0192a10874
|
@ -0,0 +1,9 @@
|
||||||
|
# 默认忽略的文件
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# 基于编辑器的 HTTP 客户端请求
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
/.idea/
|
|
@ -9,11 +9,8 @@ from parameters import *
|
||||||
class WgzGym(gym.Env):
|
class WgzGym(gym.Env):
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(WgzGym, self).__init__()
|
super(WgzGym, self).__init__()
|
||||||
self.excess = None
|
|
||||||
self.shedding = None
|
|
||||||
self.unbalance = None
|
self.unbalance = None
|
||||||
self.real_unbalance = None
|
self.reward = None
|
||||||
self.operation_cost = None
|
|
||||||
self.current_output = None
|
self.current_output = None
|
||||||
self.final_step_outputs = None
|
self.final_step_outputs = None
|
||||||
self.data_manager = DataManager()
|
self.data_manager = DataManager()
|
||||||
|
@ -24,7 +21,7 @@ class WgzGym(gym.Env):
|
||||||
self.current_time = None
|
self.current_time = None
|
||||||
self.episode_length = 24
|
self.episode_length = 24
|
||||||
self.penalty_coefficient = 50 # 约束惩罚系数
|
self.penalty_coefficient = 50 # 约束惩罚系数
|
||||||
self.sell_coefficient = 0.1 # 售出利润系数
|
self.sell_coefficient = 0.5 # 售出利润系数
|
||||||
self.EC_parameters = kwargs.get('EC_parameters', EC_parameters) # 电解水制氢器
|
self.EC_parameters = kwargs.get('EC_parameters', EC_parameters) # 电解水制氢器
|
||||||
self.HST_parameters = kwargs.get('dg_parameters', dg_parameters) # 储氢罐
|
self.HST_parameters = kwargs.get('dg_parameters', dg_parameters) # 储氢罐
|
||||||
|
|
||||||
|
@ -35,7 +32,7 @@ class WgzGym(gym.Env):
|
||||||
self.action_space = gym.spaces.Box(low=-1, high=1, shape=(3,), dtype=np.float32)
|
self.action_space = gym.spaces.Box(low=-1, high=1, shape=(3,), dtype=np.float32)
|
||||||
'''
|
'''
|
||||||
时间 光伏 温度(湿度暂未考虑) 电需 热需(转化为对应热水所需瓦数) 人数 电价 7
|
时间 光伏 温度(湿度暂未考虑) 电需 热需(转化为对应热水所需瓦数) 人数 电价 7
|
||||||
电解水制氢功率 市电功率 储氢罐容量占比 3
|
电解水制氢功率 储氢罐容量占比 市电功率(注意标准化) 3
|
||||||
'''
|
'''
|
||||||
self.state_space = gym.spaces.Box(low=0, high=1, shape=(10,), dtype=np.float32)
|
self.state_space = gym.spaces.Box(low=0, high=1, shape=(10,), dtype=np.float32)
|
||||||
|
|
||||||
|
@ -51,8 +48,8 @@ class WgzGym(gym.Env):
|
||||||
return self._build_state()
|
return self._build_state()
|
||||||
|
|
||||||
def _build_state(self):
|
def _build_state(self):
|
||||||
soc = self.HST.SOC()
|
hst_soc = self.HST.current_soc
|
||||||
ec_output = self.EC.current_output
|
ec_out = self.EC.get_hydrogen()
|
||||||
time_step = self.current_time
|
time_step = self.current_time
|
||||||
|
|
||||||
price = self.data_manager.get_price_data(self.month, self.day, self.current_time)
|
price = self.data_manager.get_price_data(self.month, self.day, self.current_time)
|
||||||
|
@ -62,63 +59,42 @@ class WgzGym(gym.Env):
|
||||||
heat = self.data_manager.get_heat_data(self.month, self.day, self.current_time)
|
heat = self.data_manager.get_heat_data(self.month, self.day, self.current_time)
|
||||||
people = self.data_manager.get_people_data(self.month, self.day, self.current_time)
|
people = self.data_manager.get_people_data(self.month, self.day, self.current_time)
|
||||||
|
|
||||||
obs = np.concatenate((np.float32(time_step), np.float32(soc), np.float32(price), np.float32(netload),
|
obs = np.concatenate((np.float32(time_step), np.float32(price), np.float32(temper),
|
||||||
np.float32(dg1_output), np.float32(dg2_output), np.float32(dg3_output),
|
np.float32(solar), np.float32(load), np.float32(heat),
|
||||||
np.float32(temperature), np.float32(irradiance), np.float32(windspeed)), axis=None)
|
np.float32(people), np.float32(ec_out), np.float32(hst_soc), np.float32(wind)), axis=None)
|
||||||
return obs
|
return obs
|
||||||
|
|
||||||
def step(self, action): # state transition: current_obs->take_action->get_reward->get_finish->next_obs
|
def step(self, action):
|
||||||
# 在每个组件中添加动作
|
# 在每个组件中添加动作
|
||||||
current_obs = self._build_state()
|
current_obs = self._build_state()
|
||||||
temperature = current_obs[7]
|
self.EC.step(action[0]) # 执行状态转换,电池当前容量也改变
|
||||||
irradiance = current_obs[8]
|
self.HST.step(action[1])
|
||||||
self.wind.current_power = current_obs[9]
|
|
||||||
self.battery.step(action[0]) # 执行状态转换,电池当前容量也改变
|
|
||||||
self.dg1.step(action[1])
|
|
||||||
self.dg2.step(action[2])
|
self.dg2.step(action[2])
|
||||||
self.dg3.step(action[3])
|
|
||||||
self.solar.step(temperature, irradiance, action[4])
|
|
||||||
self.current_output = np.array((self.dg1.current_output, self.dg2.current_output, self.dg3.current_output,
|
|
||||||
-self.battery.energy_change, self.solar.current_power, self.wind.current_power))
|
|
||||||
actual_production = sum(self.current_output)
|
|
||||||
price = current_obs[1]
|
price = current_obs[1]
|
||||||
netload = current_obs[3] - self.solar.output_change
|
temper = current_obs[2]
|
||||||
unbalance = actual_production - netload
|
solar = current_obs[3]
|
||||||
|
load = current_obs[4]
|
||||||
|
heat = current_obs[5]
|
||||||
|
gym_to_grid = solar + self.EC.get_hydrogen() - load
|
||||||
|
|
||||||
# reward = 0.0
|
# reward = 0.0
|
||||||
excess_penalty = 0
|
|
||||||
deficient_penalty = 0
|
|
||||||
sell_benefit, buy_cost = 0, 0
|
sell_benefit, buy_cost = 0, 0
|
||||||
self.excess, self.shedding = 0, 0
|
excess_penalty, deficient_penalty = 0, 0
|
||||||
if unbalance >= 0: # 过剩
|
if gym_to_grid >= 0: # 过剩
|
||||||
if unbalance <= self.grid.exchange_ability:
|
sell_benefit = self.grid.get_cost(price, gym_to_grid) * self.sell_coefficient
|
||||||
sell_benefit = self.grid.get_cost(price, unbalance) * self.sell_coefficient
|
excess_penalty = gym_to_grid * self.penalty_coefficient
|
||||||
else:
|
else: # 缺少
|
||||||
sell_benefit = self.grid.get_cost(price, self.grid.exchange_ability) * self.sell_coefficient
|
buy_cost = self.grid.get_cost(price, abs(gym_to_grid))
|
||||||
# real unbalance:超电网限值
|
deficient_penalty = abs(gym_to_grid) * self.penalty_coefficient
|
||||||
self.excess = unbalance - self.grid.exchange_ability
|
|
||||||
excess_penalty = self.excess * self.penalty_coefficient
|
|
||||||
else: # unbalance <0, 缺少惩罚
|
|
||||||
if abs(unbalance) <= self.grid.exchange_ability:
|
|
||||||
buy_cost = self.grid.get_cost(price, abs(unbalance))
|
|
||||||
else:
|
|
||||||
buy_cost = self.grid.get_cost(price, self.grid.exchange_ability)
|
|
||||||
self.shedding = abs(unbalance) - self.grid.exchange_ability
|
|
||||||
deficient_penalty = self.shedding * self.penalty_coefficient
|
|
||||||
battery_cost = self.battery.get_cost(self.battery.energy_change)
|
|
||||||
dg1_cost = self.dg1.get_cost(self.dg1.current_output)
|
|
||||||
dg2_cost = self.dg2.get_cost(self.dg2.current_output)
|
|
||||||
dg3_cost = self.dg3.get_cost(self.dg3.current_output)
|
|
||||||
solar_cost = self.solar.get_cost(self.solar.current_power)
|
|
||||||
wind_cost = self.wind.gen_cost(self.wind.current_power)
|
|
||||||
|
|
||||||
self.operation_cost = (battery_cost + dg1_cost + dg2_cost + dg3_cost + solar_cost + wind_cost
|
hst_cost = self.HST.get_cost()
|
||||||
+ excess_penalty + deficient_penalty - sell_benefit + buy_cost)
|
ec_cost = self.EC.get_cost(price)
|
||||||
reward = - self.operation_cost / 1e3
|
solar_cost = solar # 待补充
|
||||||
self.unbalance = unbalance
|
reward = - (hst_cost + ec_cost + solar_cost
|
||||||
self.real_unbalance = self.shedding + self.excess
|
+ excess_penalty + deficient_penalty - sell_benefit + buy_cost)
|
||||||
final_step_outputs = [self.dg1.current_output, self.dg2.current_output, self.dg3.current_output,
|
|
||||||
self.battery.current_capacity, self.solar.current_power, self.wind.current_power]
|
self.unbalance = gym_to_grid
|
||||||
|
final_step_outputs = [self.HST.current_soc, self.EC.current_power, self.grid.current_power]
|
||||||
self.current_time += 1
|
self.current_time += 1
|
||||||
finish = (self.current_time == self.episode_length)
|
finish = (self.current_time == self.episode_length)
|
||||||
if finish:
|
if finish:
|
||||||
|
|
|
@ -1,61 +1,63 @@
|
||||||
class EC:
|
class EC:
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
self.current_output = None
|
self.current_power = None
|
||||||
self.electricity_efficiency = params['electricity_efficiency']
|
|
||||||
self.hydrogen_produce = params['hydrogen_produce']
|
self.hydrogen_produce = params['hydrogen_produce']
|
||||||
self.power_max = params['power_max']
|
self.power_max = params['power_max']
|
||||||
self.power_min = params['power_min']
|
self.power_min = params['power_min']
|
||||||
self.ramp = params['ramp']
|
self.ramp = params['ramp']
|
||||||
self.lifetime = params['lifetime']
|
self.lifetime = params['lifetime']
|
||||||
self.equipment_cost = params['equipment_cost']
|
self.equipment_cost = params['equipment_cost']
|
||||||
|
self.electricity_efficiency = params['electricity_efficiency']
|
||||||
self.carbon_reduce = params['carbon_reduce']
|
self.carbon_reduce = params['carbon_reduce']
|
||||||
|
|
||||||
def step(self, action_ec):
|
def step(self, action_ec):
|
||||||
output = self.current_output + action_ec * self.ramp
|
output = self.current_power + action_ec * self.ramp
|
||||||
output = max(self.power_min, min(self.power_max, output)) if output > 0 else 0
|
output = max(self.power_min, min(self.power_max, output)) if output > 0 else 0
|
||||||
self.current_output = output
|
self.current_power = output
|
||||||
|
|
||||||
def get_cost(self, price):
|
def get_cost(self, price):
|
||||||
return self.equipment_cost / self.lifetime + price * self.current_output
|
# 成本 = 设备费用 / 生命周期 * 电价 * (用电量 / 最大用电量)
|
||||||
|
return self.equipment_cost / self.lifetime * price * self.current_power / self.power_max
|
||||||
|
|
||||||
def get_hydrogen(self):
|
def get_hydrogen(self):
|
||||||
return self.current_output * self.electricity_efficiency * self.hydrogen_produce
|
return self.current_power * self.electricity_efficiency * self.hydrogen_produce
|
||||||
|
|
||||||
|
def get_carbon(self):
|
||||||
|
return self.current_power * self.carbon_reduce
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.current_output = 0
|
self.current_power = 0
|
||||||
|
|
||||||
|
|
||||||
class HST:
|
class HST:
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
self.current_capacity = None
|
self.current_soc = None
|
||||||
self.hydrogen_change = None
|
self.hydrogen_change = None
|
||||||
self.capacity = params['capacity']
|
self.capacity = params['capacity']
|
||||||
self.min_soc = params['min_soc']
|
self.min_soc = params['min_soc']
|
||||||
self.max_soc = params['max_soc']
|
self.max_soc = params['max_soc']
|
||||||
self.degradation = params['degradation']
|
|
||||||
self.holding = params['holding']
|
|
||||||
self.ramp = params['ramp']
|
self.ramp = params['ramp']
|
||||||
|
self.lifetime = params['lifetime']
|
||||||
|
self.equipment_cost = params['equipment_cost']
|
||||||
self.efficiency = params['efficiency']
|
self.efficiency = params['efficiency']
|
||||||
|
|
||||||
'''
|
'''
|
||||||
储氢罐的充气速率 = 电解水制氢速率 (电解水制氢会满足热水需求?)
|
储氢罐的充气速率 = 电解水制氢速率 (电解水制氢放的热会满足热水需求?)
|
||||||
|
|
||||||
|
储氢罐的放气速率 = 供电 (电价低时多电解,电价高时释放)
|
||||||
'''
|
'''
|
||||||
def step(self, action_hst):
|
def step(self, action_hst):
|
||||||
energy = action_hst * self.ramp
|
energy = action_hst * self.ramp
|
||||||
current_energy = self.current_capacity * self.capacity
|
updated_soc = max(self.min_soc, min(self.max_soc, (self.current_soc * self.capacity + energy) / self.capacity))
|
||||||
updated_capacity = max(self.min_soc, min(self.max_soc, (current_energy + energy) / self.capacity))
|
self.hydrogen_change = (updated_capacity - self.current_soc) * self.capacity
|
||||||
self.hydrogen_change = (updated_capacity - self.current_capacity) * self.capacity
|
self.current_soc = updated_soc
|
||||||
self.current_capacity = updated_capacity # update capacity to current state
|
|
||||||
|
|
||||||
def get_cost(self, energy_change):
|
def get_cost(self):
|
||||||
cost = abs(energy_change) * self.degradation
|
cost = self.equipment_cost / self.lifetime * abs(self.hydrogen_change)
|
||||||
return cost
|
return cost
|
||||||
|
|
||||||
def SOC(self):
|
|
||||||
return self.current_capacity
|
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self.current_capacity = 0.2
|
self.current_soc = 0.1
|
||||||
|
|
||||||
|
|
||||||
class Grid:
|
class Grid:
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
EC_parameters = {
|
EC_parameters = {
|
||||||
'electrolysis_efficiency': 0.8,
|
|
||||||
'hydrogen_produce': 0.5,
|
'hydrogen_produce': 0.5,
|
||||||
'power_max': 200,
|
'power_max': 200,
|
||||||
'power_min': 0,
|
'power_min': 0,
|
||||||
'ramp': 100,
|
'ramp': 100,
|
||||||
'lifetime': 6000, # hour
|
'lifetime': 6000, # hour
|
||||||
'equipment_cost': 10000, # yuan
|
'equipment_cost': 10000, # yuan
|
||||||
|
'electrolysis_efficiency': 0.8,
|
||||||
'carbon_reduce': 1,
|
'carbon_reduce': 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,5 +13,7 @@ HST_parameters = {
|
||||||
'capacity': 1000,
|
'capacity': 1000,
|
||||||
'min_soc': 0.1,
|
'min_soc': 0.1,
|
||||||
'max_soc': 0.9,
|
'max_soc': 0.9,
|
||||||
|
'lifetime': 6000, # hour
|
||||||
|
'equipment_cost': 10000, # yuan
|
||||||
'efficiency': 0.95,
|
'efficiency': 0.95,
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ def test_one_episode(env, act, device):
|
||||||
record_init_info = [] # include month,day,time,intial soc
|
record_init_info = [] # include month,day,time,intial soc
|
||||||
env.TRAIN = False
|
env.TRAIN = False
|
||||||
state = env.reset()
|
state = env.reset()
|
||||||
record_init_info.append([env.month, env.day, env.current_time, env.battery.current_capacity])
|
record_init_info.append([env.month, env.day, env.current_time, env.battery.current_soc])
|
||||||
print(f'current testing month is {env.month}, day is {env.day},initial_soc is {env.battery.current_capacity}')
|
print(f'current testing month is {env.month}, day is {env.day},initial_soc is {env.battery.current_soc}')
|
||||||
for i in range(24):
|
for i in range(24):
|
||||||
s_tensor = torch.as_tensor((state,), device=device)
|
s_tensor = torch.as_tensor((state,), device=device)
|
||||||
a_tensor = act(s_tensor)
|
a_tensor = act(s_tensor)
|
||||||
|
|
Loading…
Reference in New Issue