99import numpy as np
1010from process_input_data import process_data_norm
1111
12+
1213class arl :
1314 """
1415 Aggregate responsive load (ARL) agent
1516 Attributes:
16- (1) house_number : The number of hvac to be aggragted
17- (2) Bid RNN
18- (3) Response RNN
17+ (1) house_number : The number of hvac to be aggregated
18+ (2) Bid RNN
19+ (3) Response RNN
1920
2021 Functions:
2122 1) Formulate bid RNN
22- Input:RNN input features (temp_rnn,schedule_rnn,limit_rnn,ramp_rnn,Hm_rnn,Ca_rnn,Cm_rnn,Ua_rnn)
23+ Input:RNN input features (temp_rnn, schedule_rnn, limit_rnn, ramp_rnn,
24+ Hm_rnn, Ca_rnn, Cm_rnn, Ua_rnn)
2325 historical input features
2426 Output: bids
2527
2628 2) Response to the clearing price (adjust the aggregated load)
27- Input:RNN input features (price_rnn,temp_rnn,schedule_rnn,limit_rnn,ramp_rnn,Hm_rnn,Ca_rnn,Cm_rnn,Ua_rnn,tint_rnn,sqft_rnn)
29+ Input: RNN input features (price_rnn, temp_rnn, schedule_rnn, limit_rnn, ramp_rnn,
30+ Hm_rnn, Ca_rnn, Cm_rnn, Ua_rnn, tint_rnn, sqft_rnn)
2831 Output: aggregate load
2932
3033 3) obtain clearing price
@@ -38,15 +41,15 @@ class arl:
3841
3942 """
4043
41- def __init__ (self ,house_num ,rnn1 ,rnn2 ,aucObj ,hn ):
44+ def __init__ (self , house_num , rnn1 , rnn2 , aucObj , hn ):
4245 """ Initializes the class
4346 """
4447 self .house_number = house_num
4548 self .bid_RNN = rnn1
4649 self .response_RNN = rnn2
4750 self .res_load = 0
4851 self .unres_load = 0
49- self .agg_resp_max = 0
52+ self .agg_resp_max = 0
5053 self .states = np .zeros (self .house_number )
5154 self .bid_q = np .zeros (self .house_number )
5255 self .bid_q .fill (0.5 )
@@ -58,26 +61,43 @@ def __init__(self,house_num,rnn1,rnn2,aucObj,hn):
5861 self .step = 288
5962 self .input_num = 13
6063 self .max_num = 1500
61-
62- self .inputs = np .zeros ((self .house_number ,self .day ,self .step ,self .input_num ))
63- self .inputs [:,:,:,1 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('temp' ), (self .house_number , 1 , 1 ))
64- self .inputs [:,:,:,2 ] = np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('schedule' )[:self .house_number ]
65- self .inputs [:,:,:,3 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('limit' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
66- self .inputs [:,:,:,4 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('ramp' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
67- self .inputs [:,:,:,5 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Hm' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
68- self .inputs [:,:,:,6 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Ca' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
69- self .inputs [:,:,:,7 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Cm' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
70- self .inputs [:,:,:,8 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Ua' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
71- self .inputs [:,:,:,9 ] = np .full ((self .house_number ,self .day ,self .step ), self .house_number )
72- self .inputs [:,:,:,10 ] = np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('p' )[:self .house_number ]
73- self .inputs [:,:,:,11 ] = np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('h' )[:self .house_number ]
74- self .inputs [:,:,:,12 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('sqft' ).reshape (self .max_num , 1 , 1 ), (1 , self .day , self .step ))[:self .house_number ]
75-
76- self .unresponsive_load = (np .load ('input/aul.npy' , allow_pickle = True ).item ().get (str (hn ))) * (self .house_number / hn )
77- self .rnn_q = np .load ('input/rnn_q.npy' , allow_pickle = True ).item ().get (str (hn ))
78- self .agg_un_tesp = self .unresponsive_load .reshape (self .day ,self .step )
79- self .unres_load_list = self .unresponsive_load
80-
64+
65+ self .inputs = np .zeros ((self .house_number , self .day , self .step , self .input_num ))
66+ self .inputs [:, :, :, 1 ] = np .tile (np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('temp' ),
67+ (self .house_number , 1 , 1 ))
68+ self .inputs [:, :, :, 2 ] = np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('schedule' )[
69+ :self .house_number ]
70+ self .inputs [:, :, :, 3 ] = np .tile (
71+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('limit' ).reshape (self .max_num , 1 , 1 ),
72+ (1 , self .day , self .step ))[:self .house_number ]
73+ self .inputs [:, :, :, 4 ] = np .tile (
74+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('ramp' ).reshape (self .max_num , 1 , 1 ),
75+ (1 , self .day , self .step ))[:self .house_number ]
76+ self .inputs [:, :, :, 5 ] = np .tile (
77+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Hm' ).reshape (self .max_num , 1 , 1 ),
78+ (1 , self .day , self .step ))[:self .house_number ]
79+ self .inputs [:, :, :, 6 ] = np .tile (
80+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Ca' ).reshape (self .max_num , 1 , 1 ),
81+ (1 , self .day , self .step ))[:self .house_number ]
82+ self .inputs [:, :, :, 7 ] = np .tile (
83+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Cm' ).reshape (self .max_num , 1 , 1 ),
84+ (1 , self .day , self .step ))[:self .house_number ]
85+ self .inputs [:, :, :, 8 ] = np .tile (
86+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('Ua' ).reshape (self .max_num , 1 , 1 ),
87+ (1 , self .day , self .step ))[:self .house_number ]
88+ self .inputs [:, :, :, 9 ] = np .full ((self .house_number , self .day , self .step ), self .house_number )
89+ self .inputs [:, :, :, 10 ] = np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('p' )[:self .house_number ]
90+ self .inputs [:, :, :, 11 ] = np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('h' )[:self .house_number ]
91+ self .inputs [:, :, :, 12 ] = np .tile (
92+ np .load ('input/inputs.npy' , allow_pickle = True ).item ().get ('sqft' ).reshape (self .max_num , 1 , 1 ),
93+ (1 , self .day , self .step ))[:self .house_number ]
94+
95+ self .unresponsive_load = (np .load ('input/aul.npy' , allow_pickle = True ).item ().get (str (hn ))) * (
96+ self .house_number / hn )
97+ self .rnn_q = np .load ('input/rnn_q.npy' , allow_pickle = True ).item ().get (str (hn ))
98+ self .agg_un_tesp = self .unresponsive_load .reshape (self .day , self .step )
99+ self .unres_load_list = self .unresponsive_load
100+
81101 self .Y_bid_max = np .load ('input/minmax.npy' , allow_pickle = True ).item ().get ('outp_max' )
82102 self .Y_bid_min = np .load ('input/minmax.npy' , allow_pickle = True ).item ().get ('outp_min' )
83103 self .X_response_max = np .load ('input/minmax.npy' , allow_pickle = True ).item ().get ('inl_max' )
@@ -86,81 +106,67 @@ def __init__(self,house_num,rnn1,rnn2,aucObj,hn):
86106 self .Y_response_min = np .load ('input/minmax.npy' , allow_pickle = True ).item ().get ('outl_min' )
87107 self .input_max = np .load ('input/input_max.npy' )
88108 self .input_min = np .load ('input/input_min.npy' )
89-
90- self .inputs_norm = process_data_norm (self .inputs ,self .input_max ,self .input_min )
91-
92- def inform_bid (self ,price ):
109+
110+ self .inputs_norm = process_data_norm (self .inputs , self .input_max , self .input_min )
111+
112+ def inform_bid (self , price ):
93113 """ Set the cleared_price attribute
94114 """
95115 self .cleared_price = price
96116
97- # def generate_bids(self,day,t,input_tensor,input_dim):
98- #
99- # input_tensor_day=input_tensor[:,day,0:t+1,:]
100- # chunks= torch.chunk(input_tensor_day,self.chunk_num, dim=0)
101- # out = np.zeros((self.chunk_num,(len(chunks[0])),2))
102- # for k in range(self.chunk_num):
103- # out[k,:len(chunks[k]),:] = self.bid_RNN(chunks[k][:,0:t+1,:])[:,t,:].cpu().detach().numpy()
104- #
105- # bid_pq_list=out.reshape(self.chunk_num*len(chunks[0]),2)[0:len(input_tensor),:]
106- # bid_p_list=bid_pq_list[:,0]
107- # bid_q_list=bid_pq_list[:,1]
108- # state= self.states
109- #
110- # return np.array([bid_p_list,bid_q_list,state])
111-
112-
113- def generate_bidsps (self ,day ,t ):
114-
115- input_tensor_day = self .inputs_norm [:,day ,0 :t + 1 ,1 :11 ]
116- chunks = torch .chunk (input_tensor_day ,self .chunk_num , dim = 0 )
117- outp = np .zeros ((self .chunk_num ,len (chunks [0 ])))
117+ # def generate_bids(self,day,t,input_tensor,input_dim):
118+ #
119+ # input_tensor_day=input_tensor[:,day,0:t+1,:]
120+ # chunks= torch.chunk(input_tensor_day,self.chunk_num, dim=0)
121+ # out = np.zeros((self.chunk_num,(len(chunks[0])),2))
122+ # for k in range(self.chunk_num):
123+ # out[k,:len(chunks[k]),:] = self.bid_RNN(chunks[k][:,0:t+1,:])[:,t,:].cpu().detach().numpy()
124+ #
125+ # bid_pq_list=out.reshape(self.chunk_num*len(chunks[0]),2)[0:len(input_tensor),:]
126+ # bid_p_list=bid_pq_list[:,0]
127+ # bid_q_list=bid_pq_list[:,1]
128+ # state= self.states
129+ #
130+ # return np.array([bid_p_list,bid_q_list,state])
131+
132+ def generate_bidsps (self , day , t ):
133+
134+ input_tensor_day = self .inputs_norm [:, day , 0 :t + 1 , 1 :11 ]
135+ chunks = torch .chunk (input_tensor_day , self .chunk_num , dim = 0 )
136+ outp = np .zeros ((self .chunk_num , len (chunks [0 ])))
118137
119138 for k in range (self .chunk_num ):
120- outp [k ,:len (chunks [k ])] = self .bid_RNN (chunks [k ][:,0 :t + 1 ,:10 ])[:,t ,0 ].cpu ().detach ().numpy ()
121-
122- bid_p_list = outp .reshape (self .chunk_num * len (chunks [0 ]))[0 :self .house_number ]
123- # bid_q_list=self.rnn_q[:self.house_number,day,t].ravel()
124- bid_q_list = np .full ((self .house_number ,),self .rnn_q [day ,t ])
125- state_list = self .states
126-
127- return np .array ([bid_p_list ,bid_q_list ,state_list ])
128-
129- def set_hvac_load (self ,day ,t ):
130-
131- input_tensor_day = self .inputs_norm [:,day ,0 :t + 1 ,[0 ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,12 ,9 ,11 ]]
132- chunks = torch .chunk (input_tensor_day ,self .chunk_num , dim = 0 )
133- out = np .zeros ((self .chunk_num ,(len (chunks [0 ]))))
134- for k in range (self .chunk_num ):
135- out [k ,:len (chunks [k ])] = self .response_RNN (chunks [k ][:,0 :t + 1 ,:])[:,t ,0 ].cpu ().detach ().numpy ()
136-
137- load_list = out .reshape (self .chunk_num * len (chunks [0 ]))[0 :self .house_number ]
138-
139- aggregate_load = np .sum (load_list )* self .Y_response_max
140- self .res_load = aggregate_load
141-
142- for n in range (self .house_number ):
143- if load_list [n ] > 0.25 :
144- self .states [n ] = 1
145- else :
146- self .states [n ] = 0
147-
148- return load_list
149-
150- def update_unresposive_load (self ,day ,t ):
151-
152- unres_t = self .unres_load_list [self .step * day + t ]- 150
153- self .unres_load = unres_t
154-
155-
156-
139+ outp [k , :len (chunks [k ])] = self .bid_RNN (chunks [k ][:, 0 :t + 1 , :10 ])[:, t , 0 ].cpu ().detach ().numpy ()
157140
141+ bid_p_list = outp .reshape (self .chunk_num * len (chunks [0 ]))[0 :self .house_number ]
142+ # bid_q_list=self.rnn_q[:self.house_number,day,t].ravel()
143+ bid_q_list = np .full ((self .house_number ,), self .rnn_q [day , t ])
144+ state_list = self .states
158145
146+ return np .array ([bid_p_list , bid_q_list , state_list ])
159147
148+ def set_hvac_load (self , day , t ):
160149
150+ input_tensor_day = self .inputs_norm [:, day , 0 :t + 1 , [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 12 , 9 , 11 ]]
151+ chunks = torch .chunk (input_tensor_day , self .chunk_num , dim = 0 )
152+ out = np .zeros ((self .chunk_num , (len (chunks [0 ]))))
153+ for k in range (self .chunk_num ):
154+ out [k , :len (chunks [k ])] = self .response_RNN (chunks [k ][:, 0 :t + 1 , :])[:, t , 0 ].cpu ().detach ().numpy ()
161155
156+ load_list = out .reshape (self .chunk_num * len (chunks [0 ]))[0 :self .house_number ]
162157
158+ aggregate_load = np .sum (load_list ) * self .Y_response_max
159+ self .res_load = aggregate_load
163160
161+ for n in range (self .house_number ):
162+ if load_list [n ] > 0.25 :
163+ self .states [n ] = 1
164+ else :
165+ self .states [n ] = 0
164166
167+ return load_list
165168
169+ def update_unresposive_load (self , day , t ):
166170
171+ unres_t = self .unres_load_list [self .step * day + t ] - 150
172+ self .unres_load = unres_t
0 commit comments