Skip to content

Commit

Permalink
Fix OnFlowConstraintInCountry with contingency interpretation in RAO (#…
Browse files Browse the repository at this point in the history
…1004)

* Fix OnFlowConstraintInCountry with contingency interpretation in RAO

Signed-off-by: Peter Mitri <peter.mitri@rte-france.com>
  • Loading branch information
pet-mit authored May 7, 2024
1 parent fb92e9c commit 481c574
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public Optional<Contingency> getContingency() {

@Override
public UsageMethod getUsageMethod(State state) {
if (contingency.isPresent() && !contingency.get().equals(state.getContingency().orElse(null))) {
return UsageMethod.UNDEFINED;
}
return state.getInstant().equals(instant) ? usageMethod : UsageMethod.UNDEFINED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.powsybl.openrao.data.cracimpl;

import com.powsybl.contingency.Contingency;
import com.powsybl.openrao.data.cracapi.Instant;
import com.powsybl.openrao.data.cracapi.InstantKind;
import com.powsybl.openrao.data.cracapi.State;
Expand Down Expand Up @@ -73,4 +74,41 @@ void testEquals() {
assertNotEquals(onFlowConstraint1, onFlowConstraint2);
assertNotEquals(onFlowConstraint1.hashCode(), onFlowConstraint2.hashCode());
}

@Test
void testGetUsageMethodWithContringency() {
Contingency contingency1 = Mockito.mock(Contingency.class);
Contingency contingency2 = Mockito.mock(Contingency.class);

State stateAuto1 = new PostContingencyState(contingency1, AUTO_INSTANT);
State stateCur1 = new PostContingencyState(contingency1, CURATIVE_INSTANT);
State stateAuto2 = new PostContingencyState(contingency2, AUTO_INSTANT);
State stateCur2 = new PostContingencyState(contingency2, CURATIVE_INSTANT);

OnFlowConstraintInCountry ur;

ur = new OnFlowConstraintInCountryImpl(UsageMethod.AVAILABLE, AUTO_INSTANT, Optional.of(contingency1), Country.ES);
assertEquals(UsageMethod.AVAILABLE, ur.getUsageMethod(stateAuto1));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateCur1));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateAuto2));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateCur2));

ur = new OnFlowConstraintInCountryImpl(UsageMethod.AVAILABLE, AUTO_INSTANT, Optional.empty(), Country.ES);
assertEquals(UsageMethod.AVAILABLE, ur.getUsageMethod(stateAuto1));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateCur1));
assertEquals(UsageMethod.AVAILABLE, ur.getUsageMethod(stateAuto2));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateCur2));

ur = new OnFlowConstraintInCountryImpl(UsageMethod.AVAILABLE, CURATIVE_INSTANT, Optional.of(contingency1), Country.ES);
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateAuto1));
assertEquals(UsageMethod.AVAILABLE, ur.getUsageMethod(stateCur1));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateAuto2));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateCur2));

ur = new OnFlowConstraintInCountryImpl(UsageMethod.AVAILABLE, CURATIVE_INSTANT, Optional.empty(), Country.ES);
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateAuto1));
assertEquals(UsageMethod.AVAILABLE, ur.getUsageMethod(stateCur1));
assertEquals(UsageMethod.UNDEFINED, ur.getUsageMethod(stateAuto2));
assertEquals(UsageMethod.AVAILABLE, ur.getUsageMethod(stateCur2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ void testIsOnFlowConstraintInCountryAvailableWithContingency() {
Instant curativeInstant = crac.getInstant(CURATIVE_INSTANT_ID);
State optimizedState = Mockito.mock(State.class);
when(optimizedState.getInstant()).thenReturn(curativeInstant);
when(optimizedState.getContingency()).thenReturn(Optional.of(crac.getContingency("Contingency FR1 FR3")));

FlowCnec cnecCont1 = crac.getFlowCnec("cnec1stateCurativeContingency1");
FlowCnec cnecCont2 = crac.getFlowCnec("cnec2stateCurativeContingency2");
Expand Down

0 comments on commit 481c574

Please sign in to comment.