diff --git a/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImpl.java b/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImpl.java index a400055786..dcc6121bbc 100644 --- a/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImpl.java +++ b/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImpl.java @@ -37,7 +37,11 @@ public Instant getInstant() { @Override public UsageMethod getUsageMethod(State state) { - return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED; + if (state.isPreventive()) { + return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED; + } else { + return state.getInstant().equals(instant) && state.equals(this.angleCnec.getState()) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED; + } } @Override diff --git a/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImpl.java b/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImpl.java index 7869f6cc6a..bea8c9f687 100644 --- a/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImpl.java +++ b/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImpl.java @@ -37,7 +37,11 @@ public Instant getInstant() { @Override public UsageMethod getUsageMethod(State state) { - return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED; + if (state.isPreventive()) { + return state.getInstant().equals(instant) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED; + } else { + return state.getInstant().equals(instant) && state.equals(this.flowCnec.getState()) ? UsageMethod.TO_BE_EVALUATED : UsageMethod.UNDEFINED; + } } @Override diff --git a/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImplTest.java b/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImplTest.java index 3c54b690a4..c64feab7e2 100644 --- a/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnAngleConstraintImplTest.java @@ -30,8 +30,10 @@ public void setUp() { angleCnec = Mockito.mock(AngleCnec.class); preventiveState = Mockito.mock(State.class); Mockito.when(preventiveState.getInstant()).thenReturn(Instant.PREVENTIVE); + Mockito.when(preventiveState.isPreventive()).thenReturn(true); curativeState = Mockito.mock(State.class); Mockito.when(curativeState.getInstant()).thenReturn(Instant.CURATIVE); + Mockito.when(curativeState.isPreventive()).thenReturn(false); } @Test @@ -66,4 +68,22 @@ public void testEquals() { assertNotEquals(onAngleConstraint1, onAngleConstraint2); assertNotEquals(onAngleConstraint1.hashCode(), onAngleConstraint2.hashCode()); } + + @Test + public void testGetUsageMethod() { + State curativeState2 = Mockito.mock(State.class); + Mockito.when(curativeState2.getInstant()).thenReturn(Instant.CURATIVE); + Mockito.when(curativeState2.isPreventive()).thenReturn(false); + + OnAngleConstraint onAngleConstraint = new OnAngleConstraintImpl(Instant.PREVENTIVE, angleCnec); + assertEquals(UsageMethod.TO_BE_EVALUATED, onAngleConstraint.getUsageMethod(preventiveState)); + assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(curativeState)); + assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(curativeState2)); + + Mockito.when(angleCnec.getState()).thenReturn(curativeState); + onAngleConstraint = new OnAngleConstraintImpl(Instant.CURATIVE, angleCnec); + assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(preventiveState)); + assertEquals(UsageMethod.TO_BE_EVALUATED, onAngleConstraint.getUsageMethod(curativeState)); + assertEquals(UsageMethod.UNDEFINED, onAngleConstraint.getUsageMethod(curativeState2)); + } } diff --git a/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImplTest.java b/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImplTest.java index f25ea652f4..4655f78424 100644 --- a/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/farao_community/farao/data/crac_impl/OnFlowConstraintImplTest.java @@ -30,8 +30,10 @@ public void setUp() { flowCnec = Mockito.mock(FlowCnec.class); preventiveState = Mockito.mock(State.class); Mockito.when(preventiveState.getInstant()).thenReturn(Instant.PREVENTIVE); + Mockito.when(preventiveState.isPreventive()).thenReturn(true); curativeState = Mockito.mock(State.class); Mockito.when(curativeState.getInstant()).thenReturn(Instant.CURATIVE); + Mockito.when(curativeState.isPreventive()).thenReturn(false); } @Test @@ -66,4 +68,22 @@ public void testEquals() { assertNotEquals(onFlowConstraint1, onFlowConstraint2); assertNotEquals(onFlowConstraint1.hashCode(), onFlowConstraint2.hashCode()); } + + @Test + public void testGetUsageMethod() { + State curativeState2 = Mockito.mock(State.class); + Mockito.when(curativeState2.getInstant()).thenReturn(Instant.CURATIVE); + Mockito.when(curativeState2.isPreventive()).thenReturn(false); + + OnFlowConstraint onFlowConstraint = new OnFlowConstraintImpl(Instant.PREVENTIVE, flowCnec); + assertEquals(UsageMethod.TO_BE_EVALUATED, onFlowConstraint.getUsageMethod(preventiveState)); + assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(curativeState)); + assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(curativeState2)); + + Mockito.when(flowCnec.getState()).thenReturn(curativeState); + onFlowConstraint = new OnFlowConstraintImpl(Instant.CURATIVE, flowCnec); + assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(preventiveState)); + assertEquals(UsageMethod.TO_BE_EVALUATED, onFlowConstraint.getUsageMethod(curativeState)); + assertEquals(UsageMethod.UNDEFINED, onFlowConstraint.getUsageMethod(curativeState2)); + } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/castor/algorithm/CastorFullOptimizationTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/castor/algorithm/CastorFullOptimizationTest.java index 076c8e64b3..126d40ea23 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/castor/algorithm/CastorFullOptimizationTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/castor/algorithm/CastorFullOptimizationTest.java @@ -374,10 +374,10 @@ public void testIsRangeActionAvailableInState() { assertFalse(CastorFullOptimization.isRangeActionAvailableInState(ra5, state1, crac)); assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra5, state2, crac)); - // ra6 is available in preventive and in state1 and in state2 + // ra6 is available in preventive and in state1 assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra6, crac.getPreventiveState(), crac)); assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra6, state1, crac)); - assertTrue(CastorFullOptimization.isRangeActionAvailableInState(ra6, state2, crac)); + assertFalse(CastorFullOptimization.isRangeActionAvailableInState(ra6, state2, crac)); } @Test diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/RaoUtilTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/RaoUtilTest.java index 246a9ffa33..45d22642f1 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/RaoUtilTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/RaoUtilTest.java @@ -187,8 +187,7 @@ public void testGetLargestCnecThreshold() { @Test public void testIsOnFlowConstraintAvailable() { - State optimizedState = Mockito.mock(State.class); - when(optimizedState.getInstant()).thenReturn(Instant.CURATIVE); + State optimizedState = crac.getState("Contingency FR1 FR3", Instant.CURATIVE); FlowCnec flowCnec = crac.getFlowCnec("cnec1stateCurativeContingency1"); FlowResult flowResult = mock(FlowResult.class); @@ -217,7 +216,7 @@ public void testIsOnFlowConstraintAvailable() { assertTrue(RaoUtil.isOnFlowConstraintAvailable(onFlowConstraint, optimizedState, flowResult)); assertTrue(RaoUtil.isRemedialActionAvailable(na2, optimizedState, flowResult, crac.getFlowCnecs(), network)); - when(optimizedState.getInstant()).thenReturn(Instant.PREVENTIVE); + optimizedState = crac.getPreventiveState(); assertFalse(RaoUtil.isRemedialActionAvailable(na1, optimizedState, flowResult, crac.getFlowCnecs(), network)); assertFalse(RaoUtil.isOnFlowConstraintAvailable(onFlowConstraint, optimizedState, flowResult)); assertFalse(RaoUtil.isRemedialActionAvailable(na2, optimizedState, flowResult, crac.getFlowCnecs(), network));