Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending tauEncoding given list to retrive topo_sub even if a line i… #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 22 additions & 3 deletions leap_net/proxy/proxyLeapNet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1093,13 +1093,32 @@ def _given_list_topo_encode(self, obs):
continue

# so i have a different topology that the reference one
lookup = (sub_id, tuple([el if el >= 1 else 1 for el in this_sub_topo]))
if lookup in self.dict_topo:
res[self.dict_topo[lookup]] = 1.
#lookup = (sub_id, tuple([el if el >= 1 else 1 for el in this_sub_topo]))
topo_found=False

if (np.all(conn)):
lookup = (sub_id, tuple([el if el >= 1 else 1 for el in this_sub_topo]))
if lookup in self.dict_topo:
res[self.dict_topo[lookup]] = 1.
topo_found = True
else:
for topo_sub in self.dict_topo:
if topo_sub[0] == sub_id:
topo=np.array(topo_sub[1])
if np.all(topo[conn]==this_sub_topo[conn]):
res[self.dict_topo[topo_sub]] = 1.
topo_found=True
conn_elements_bus_bar_2=conn[(topo_found==2)]
break

#if lookup in self.dict_topo:
# res[self.dict_topo[lookup]] = 1.
#else:
if not topo_found:
warnings.warn(f"Topology {lookup} is not found on the topo dictionary")
return res


def _online_list_topo_encode(self, obs):
"""
This method behaves exaclyt like :func:`ProxyLeapNet._given_list_topo_encode` with one difference: you do not
Expand Down
19 changes: 18 additions & 1 deletion leap_net/test/test_LeapNetProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
proxy = ProxyLeapNet(attr_tau=("line_status", "topo_vect",),
topo_vect_to_tau="given_list",
kwargs_tau=[(0, (2, 1, 1)), (0, (1, 2, 1)), (1, (2, 1, 1, 1, 1, 1)),
(12, (2, 1, 1, 2)), (13, (2, 1, 2)), (13, (1, 2, 2))]
(12, (2, 1, 1, 2)), (13, (2, 1, 2)), (13, (1, 2, 2)), (1, (2, 1, 2, 1, 2, 1))]
)
proxy.init([self.obs])

Expand Down Expand Up @@ -296,6 +296,23 @@ def _aux_test_tau_from_list_topo(self, proxy=None):
assert np.sum(res) == 1
assert res[2] == 1.

# test that if a line is disconnected, we are still able to match the topologies
env = self.env
obs = env.reset()
act = env.action_space({"set_bus": {"substations_id": [(1, (2, 1, -1, 1, 2, 1))]}})#(2, 1, 2, 1, 2, 1)
obs, reward, done, info = env.step(act)
res = proxy.topo_vect_handler(obs)
assert np.sum(res) == 1
assert res[6] == 1.

env = self.env
obs = env.reset()
act = env.action_space({"set_bus": {"substations_id": [(1, (2, -1, 2, 1, 2, 1))]}})
obs, reward, done, info = env.step(act)
res = proxy.topo_vect_handler(obs)
assert np.sum(res) == 1
assert res[6] == 1.

def test_tau_from_online_topo(self):
self._aux_test_tau_from_online_topo()

Expand Down