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

Network action compatibility filter #912

Merged
merged 25 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
af13c6b
Network actions compatibility
bqth29 Feb 6, 2024
b6d536f
Move compatibility checker to RAO utils
bqth29 Mar 5, 2024
e468fd2
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Mar 5, 2024
ccc0e5f
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Mar 6, 2024
bef7b8f
Refactor by adding methods in respective APIs
bqth29 Mar 6, 2024
38e691f
Remove RA if equal to an already applied RA
bqth29 Mar 6, 2024
ca8e675
Remove checker and add method in bloomer directly
bqth29 Mar 6, 2024
67ca1d7
Declare function in interface
bqth29 Mar 6, 2024
bc23dd9
Simplify filter in bloomer
bqth29 Mar 6, 2024
9ab96c3
Merge branch 'main' into coreCSA/remedial_action_compatibility
pet-mit Mar 7, 2024
72f2dc0
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Mar 25, 2024
db4b1fb
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Mar 25, 2024
386a4a2
Change compatibility rule for switch pairs
bqth29 Mar 25, 2024
577f339
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 4, 2024
1439f7e
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 4, 2024
72c5a9f
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 4, 2024
15ece16
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 10, 2024
e443317
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 17, 2024
3b2a568
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 22, 2024
a82dcaf
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Apr 24, 2024
55b777c
Duplicate isCompatibleWith tests in NetworkActionTest
bqth29 Apr 24, 2024
0d9bf83
Merge branch 'main' into coreCSA/remedial_action_compatibility
pet-mit May 6, 2024
584bf31
Merge branch 'coreCSA/remedial_action_compatibility' of https://githu…
bqth29 Jun 17, 2024
7a0cb1e
Merge branch 'main' into coreCSA/remedial_action_compatibility
bqth29 Jun 17, 2024
01a35b0
Update filter on EA + better tests coverage
bqth29 Jun 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public interface ElementaryAction {
* Get the Network Elements associated to the elementary action
*/
Set<NetworkElement> getNetworkElements();

/**
* States if the elementary action can be applied without infringing on elementary network action's scope.
* @param otherElementaryAction the other elementary action to check compatibility with
* @return true if both elementary actions can be applied without any conflictual behaviour
*/
boolean isCompatibleWith(ElementaryAction otherElementaryAction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ public interface NetworkAction extends RemedialAction<NetworkAction> {
* Get the set of the elementary actions constituting then network action
*/
Set<ElementaryAction> getElementaryActions();

/**
* States if the network action can be applied without infringing on another network action's scope.
* @param otherNetworkAction the other network action to check compatibility with
* @return true if both network actions can be applied without any conflictual behaviour
*/
boolean isCompatibleWith(NetworkAction otherNetworkAction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.commons.Unit;
import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction;
import com.powsybl.openrao.data.cracapi.networkaction.InjectionSetpoint;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.iidm.network.*;
Expand Down Expand Up @@ -95,6 +96,14 @@ public Set<NetworkElement> getNetworkElements() {
return Collections.singleton(networkElement);
}

@Override
public boolean isCompatibleWith(ElementaryAction otherElementaryAction) {
if (otherElementaryAction instanceof InjectionSetpoint injectionSetpoint) {
return !networkElement.equals(injectionSetpoint.getNetworkElement()) || setpoint == injectionSetpoint.getSetpoint();
}
return true;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ public Set<NetworkElement> getNetworkElements() {
return networkElements;
}

@Override
public boolean isCompatibleWith(NetworkAction otherNetworkAction) {
for (ElementaryAction elementaryAction1 : elementaryActions) {
for (ElementaryAction elementaryAction2 : otherNetworkAction.getElementaryActions()) {
if (!elementaryAction1.isCompatibleWith(elementaryAction2)) {
return false;
}
}
}
return true;
}
bqth29 marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction;
import com.powsybl.openrao.data.cracapi.networkaction.PstSetpoint;
import com.powsybl.iidm.network.Network;
import com.powsybl.iidm.network.PhaseTapChanger;
Expand Down Expand Up @@ -98,6 +99,14 @@ public boolean canBeApplied(Network network) {
return true;
}

@Override
public boolean isCompatibleWith(ElementaryAction otherElementaryAction) {
if (otherElementaryAction instanceof PstSetpoint pstSetpoint) {
return !networkElement.equals(pstSetpoint.getNetworkElement()) || setpoint == pstSetpoint.getSetpoint();
}
return true;
}

@Override
public int hashCode() {
return networkElement.hashCode() + 7 * Double.valueOf(setpoint).hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction;
import com.powsybl.openrao.data.cracapi.networkaction.SwitchPair;
import com.powsybl.iidm.network.Network;

Expand Down Expand Up @@ -57,6 +58,15 @@ public NetworkElement getSwitchToClose() {
return switchToClose;
}

@Override
public boolean isCompatibleWith(ElementaryAction otherElementaryAction) {
if (otherElementaryAction instanceof SwitchPair switchPair) {
return !switchToOpen.equals(switchPair.getSwitchToOpen()) && !switchToOpen.equals(switchPair.getSwitchToClose()) && !switchToClose.equals(switchPair.getSwitchToClose()) && !switchToClose.equals(switchPair.getSwitchToOpen())
|| switchToOpen.equals(switchPair.getSwitchToOpen()) || switchToClose.equals(switchPair.getSwitchToClose());
bqth29 marked this conversation as resolved.
Show resolved Hide resolved
}
return true;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.powsybl.openrao.data.cracapi.networkaction.ActionType;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction;
import com.powsybl.openrao.data.cracapi.networkaction.TopologicalAction;
import com.powsybl.iidm.network.Branch;
import com.powsybl.iidm.network.Identifiable;
Expand Down Expand Up @@ -104,6 +105,14 @@ public Set<NetworkElement> getNetworkElements() {
return Collections.singleton(networkElement);
}

@Override
public boolean isCompatibleWith(ElementaryAction otherElementaryAction) {
if (otherElementaryAction instanceof TopologicalAction topologicalAction) {
return !networkElement.equals(topologicalAction.getNetworkElement()) || actionType.equals(topologicalAction.getActionType());
}
return true;
}

@Override
public int hashCode() {
return networkElement.hashCode() + 37 * actionType.hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.commons.Unit;
import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.networkaction.InjectionSetpoint;
import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil;
import com.powsybl.iidm.network.Network;
import org.apache.commons.lang3.NotImplementedException;
Expand All @@ -19,6 +21,7 @@

import java.util.Set;

import static com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation.createCracWithRemedialActions;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -198,4 +201,31 @@ void equals() {
12., Unit.MEGAWATT);
assertNotEquals(injectionSetpoint, differentInjectionSetpoint);
}

@Test
void compatibility() {
Crac crac = createCracWithRemedialActions();
InjectionSetpoint injectionSetpoint = (InjectionSetpoint) crac.getNetworkAction("generator-1-75-mw").getElementaryActions().iterator().next();

assertTrue(injectionSetpoint.isCompatibleWith(injectionSetpoint));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-2").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("close-switch-1").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("close-switch-2").getElementaryActions().iterator().next()));

assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("generator-1-75-mw").getElementaryActions().iterator().next()));
assertFalse(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("generator-1-100-mw").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("generator-2-75-mw").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("generator-2-100-mw").getElementaryActions().iterator().next()));

assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("pst-1-tap-3").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("pst-1-tap-8").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("pst-2-tap-3").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("pst-2-tap-8").getElementaryActions().iterator().next()));

assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-1-close-switch-2").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-2-close-switch-1").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-3-close-switch-4").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-1-close-switch-3").getElementaryActions().iterator().next()));
assertTrue(injectionSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-3-close-switch-2").getElementaryActions().iterator().next()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.cracapi.Identifiable;
import com.powsybl.openrao.data.cracapi.networkaction.ElementaryAction;
import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction;
Expand All @@ -19,6 +20,7 @@
import java.util.*;
import java.util.stream.Collectors;

import static com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation.createCracWithRemedialActions;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -121,4 +123,20 @@ void testHasImpactOnNetworkAction() {
Mockito.when(mockedElementaryAction1.hasImpactOnNetwork(Mockito.any())).thenReturn(false);
assertFalse(networkAction.hasImpactOnNetwork(network));
}

@Test
void compatibility() {
Crac crac = createCracWithRemedialActions();

assertTrue(crac.getNetworkAction("hvdc-fr-es-200-mw").isCompatibleWith(crac.getNetworkAction("hvdc-fr-es-200-mw")));
assertFalse(crac.getNetworkAction("hvdc-fr-es-200-mw").isCompatibleWith(crac.getNetworkAction("hvdc-es-fr-200-mw")));
assertTrue(crac.getNetworkAction("hvdc-fr-es-200-mw").isCompatibleWith(crac.getNetworkAction("aligned-psts")));
assertTrue(crac.getNetworkAction("hvdc-fr-es-200-mw").isCompatibleWith(crac.getNetworkAction("switch-pair-and-pst")));
assertTrue(crac.getNetworkAction("hvdc-es-fr-200-mw").isCompatibleWith(crac.getNetworkAction("hvdc-es-fr-200-mw")));
assertTrue(crac.getNetworkAction("hvdc-es-fr-200-mw").isCompatibleWith(crac.getNetworkAction("aligned-psts")));
assertTrue(crac.getNetworkAction("hvdc-es-fr-200-mw").isCompatibleWith(crac.getNetworkAction("switch-pair-and-pst")));
assertTrue(crac.getNetworkAction("aligned-psts").isCompatibleWith(crac.getNetworkAction("aligned-psts")));
assertFalse(crac.getNetworkAction("aligned-psts").isCompatibleWith(crac.getNetworkAction("switch-pair-and-pst")));
assertTrue(crac.getNetworkAction("switch-pair-and-pst").isCompatibleWith(crac.getNetworkAction("switch-pair-and-pst")));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.networkaction.PstSetpoint;
import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil;
Expand All @@ -17,6 +18,7 @@

import java.util.Set;

import static com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation.createCracWithRemedialActions;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -111,4 +113,31 @@ void equals() {
-10);
assertNotEquals(pstSetpoint, differentPstSetpoint);
}

@Test
void compatibility() {
Crac crac = createCracWithRemedialActions();
PstSetpoint pstSetpoint = (PstSetpoint) crac.getNetworkAction("pst-1-tap-3").getElementaryActions().iterator().next();

assertTrue(pstSetpoint.isCompatibleWith(pstSetpoint));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-2").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("close-switch-1").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("close-switch-2").getElementaryActions().iterator().next()));

assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("generator-1-75-mw").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("generator-1-100-mw").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("generator-2-75-mw").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("generator-2-100-mw").getElementaryActions().iterator().next()));

assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("pst-1-tap-3").getElementaryActions().iterator().next()));
assertFalse(pstSetpoint.isCompatibleWith(crac.getNetworkAction("pst-1-tap-8").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("pst-2-tap-3").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("pst-2-tap-8").getElementaryActions().iterator().next()));

assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-1-close-switch-2").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-2-close-switch-1").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-3-close-switch-4").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-1-close-switch-3").getElementaryActions().iterator().next()));
assertTrue(pstSetpoint.isCompatibleWith(crac.getNetworkAction("open-switch-3-close-switch-2").getElementaryActions().iterator().next()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.data.cracapi.Crac;
import com.powsybl.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.networkaction.SwitchPair;
import com.powsybl.openrao.data.cracapi.networkaction.TopologicalAction;
Expand All @@ -17,6 +18,7 @@

import java.util.Set;

import static com.powsybl.openrao.data.cracimpl.utils.CommonCracCreation.createCracWithRemedialActions;
import static org.junit.jupiter.api.Assertions.*;

/**
Expand Down Expand Up @@ -111,4 +113,31 @@ void testEquals() {
SwitchPairImpl switchPairImpl = new SwitchPairImpl(switch1, switch2);
assertEquals(switchPair, switchPairImpl);
}

@Test
void compatibility() {
Crac crac = createCracWithRemedialActions();
SwitchPair switchPair = (SwitchPair) crac.getNetworkAction("open-switch-1-close-switch-2").getElementaryActions().iterator().next();

assertTrue(switchPair.isCompatibleWith(switchPair));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("open-switch-2").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("close-switch-1").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("close-switch-2").getElementaryActions().iterator().next()));

assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("generator-1-75-mw").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("generator-1-100-mw").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("generator-2-75-mw").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("generator-2-100-mw").getElementaryActions().iterator().next()));

assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("pst-1-tap-3").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("pst-1-tap-8").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("pst-2-tap-3").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("pst-2-tap-8").getElementaryActions().iterator().next()));

assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("open-switch-1-close-switch-2").getElementaryActions().iterator().next()));
assertFalse(switchPair.isCompatibleWith(crac.getNetworkAction("open-switch-2-close-switch-1").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("open-switch-3-close-switch-4").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("open-switch-1-close-switch-3").getElementaryActions().iterator().next()));
assertTrue(switchPair.isCompatibleWith(crac.getNetworkAction("open-switch-3-close-switch-2").getElementaryActions().iterator().next()));
}
}
Loading
Loading