Skip to content

Commit

Permalink
Fix OnFlowConstraintInCountry with contingency interpretation in RAO
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Mitri <peter.mitri@rte-france.com>
  • Loading branch information
pet-mit committed May 7, 2024
1 parent fb92e9c commit e4205a4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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
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));
}
}

0 comments on commit e4205a4

Please sign in to comment.