Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Got it running
  • Loading branch information
SiobhanPowell committed Mar 19, 2019
commit 57051dfa28c5328e18bd66a22eaf20e7c179bc97
115 changes: 113 additions & 2 deletions Siobhan_scratch_testing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,122 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"{5: {0: [-2, -2, -2], 1: [3, 3, 3]}}"
"abc = {5: {0: [-2, -2, -2], 1: [3, 3, 3]}, 3: {0: [0,0,0]}}"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"abc = {}"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"for bus1, thing1 in abc.items():\n",
"# print(bus1)\n",
"# print(thing1)\n",
" for bus2, thing2 in thing1.items():\n",
" print(bus2)\n",
" print(thing2)"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
"abc = {}"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"abc.update({5: {0: [-2, -2, -2]}})"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Yes\n"
]
}
],
"source": [
"if 5 in abc:\n",
" print('Yes')"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{5: {0: [-2, -2, -2]}}"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abc"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"if 5 in abc:\n",
" abc[5].update({1: [0, 0, 0]})\n",
"else:\n",
" abc.update({5: {1: [0, 0, 0]}})"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{5: {0: [-2, -2, -2], 1: [0, 0, 0]}}"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"abc"
]
},
{
Expand Down
18 changes: 12 additions & 6 deletions virtual_microgrids/configs/standard_lv_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ def __init__(self, env_name, use_baseline, actor):
if not self.clear_loads_sgen:
if net.load.shape[0] > 0:
for idx, row in net.load.iterrows():
self.static_feeds[row['bus']] = row['p_kw'] * np.ones(self.max_ep_len)
if row['bus'] in self.static_feeds:
self.static_feeds[row['bus']].update({0: row['p_kw'] * np.ones(self.max_ep_len + 1)})
else:
self.static_feeds[row['bus']] = {0: row['p_kw'] * np.ones(self.max_ep_len + 1)}
if net.sgen.shape[0] > 0:
for idx, row in net.sgen.iterrows():
self.static_feeds[row['bus']] = row['p_kw'] * np.ones(self.max_ep_len)
if row['bus'] in self.static_feeds:
self.static_feeds[row['bus']].update({1: row['p_kw'] * np.ones(self.max_ep_len + 1)})
else:
self.static_feeds[row['bus']] = {1: row['p_kw'] * np.ones(self.max_ep_len + 1)}

self.battery_locations = None # Specify specific locations, or can pick options for random generation:
self.percent_battery_buses = 0.5 # How many of the buses should be assigned batteries
Expand All @@ -52,8 +58,8 @@ def __init__(self, env_name, use_baseline, actor):
# Action space
self.gen_p_min = -10.0
self.gen_p_max = 0.0
self.storage_p_min = -10.0
self.storage_p_max = 10.0
self.storage_p_min = -20.0
self.storage_p_max = 20.0

# # Generation
self.gen_locations = None
Expand All @@ -67,5 +73,5 @@ def __init__(self, env_name, use_baseline, actor):
self.with_soc = False

# reward function
self.reward_epsilon = 0.001
self.cont_reward_lambda = 0.1
self.reward_epsilon = 0.01
self.cont_reward_lambda = 1.0
26 changes: 14 additions & 12 deletions virtual_microgrids/powerflow/network_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,13 @@ def six_bus(vn_high=20, vn_low=0.4, length_km=0.03, std_type='NAYY 4x50 SE', bat
else:
if len(static_feeds) > 0:
for key, val in static_feeds.items():
init_flow = val[0]
print('init_flow: ', init_flow, 'at bus: ', key)
if init_flow > 0:
pp.create_load(net, bus=key, p_kw=init_flow, q_kvar=0)
else:
pp.create_sgen(net, bus=key, p_kw=init_flow, q_kvar=0)
for key2, val2 in val.items():
init_flow = val2[0]
print('init_flow: ', init_flow, 'at bus: ', key)
if init_flow > 0:
pp.create_load(net, bus=key, p_kw=init_flow, q_kvar=0)
else:
pp.create_sgen(net, bus=key, p_kw=init_flow, q_kvar=0)

return net

Expand Down Expand Up @@ -212,12 +213,13 @@ def standard_lv(env_name, remove_q=True, static_feeds_new=None, clear_loads_sgen
print('Didnt think static_feeds_new was None')
if len(static_feeds_new) > 0:
for key, val in static_feeds_new.items():
init_flow = val[0]
print('init_flow: ', init_flow, 'at bus: ', key)
if init_flow > 0:
pp.create_load(net, bus=key, p_kw=init_flow, q_kvar=0)
else:
pp.create_sgen(net, bus=key, p_kw=init_flow, q_kvar=0)
for key2, val2 in val.items():
init_flow = val2[0]
print('init_flow: ', init_flow, 'at bus: ', key)
if init_flow > 0:
pp.create_load(net, bus=key, p_kw=init_flow, q_kvar=0)
else:
pp.create_sgen(net, bus=key, p_kw=init_flow, q_kvar=0)

# Name buses for plotting
for i in range(net.bus.name.shape[0]):
Expand Down
13 changes: 7 additions & 6 deletions virtual_microgrids/powerflow/pp_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def step(self, p_set):
new_loads = pd.Series(data=None, index=self.net.load.bus)
new_sgens = pd.Series(data=None, index=self.net.sgen.bus)
for bus, feed in self.config.static_feeds.items():
p_new = feed[self.time]
if p_new > 0:
new_loads[bus] = p_new
else:
new_sgens[bus] = p_new
for idx, feed2 in feed.items():
p_new = feed2[self.time]
if p_new > 0:
new_loads[bus] = p_new
else:
new_sgens[bus] = p_new
self.update_loads(new_p=new_loads.values)
self.update_static_generation(new_p=new_sgens.values)
# Update controllable resources
Expand Down Expand Up @@ -289,7 +290,7 @@ def calculate_reward(self, eps=0.001, type=4):
line_flow_values = np.maximum(np.abs(self.net.res_line.p_to_kw),
np.abs(self.net.res_line.p_from_kw)) - self.net.res_line.pl_kw
self.reward_val -= self.config.cont_reward_lambda * np.sum(np.minimum(np.abs(line_flow_values),
1.0*np.ones(np.shape(line_flow_values)[0])))
0.5*np.ones(np.shape(line_flow_values)[0])))
# Costs for running batteries
cap_costs = self.net.storage.cap_cost
max_e = self.net.storage.max_e_kwh
Expand Down