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

Check physical parameters in RaoResult's isSecure #905

Merged
merged 34 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ec14273
Check parameters
bqth29 Feb 27, 2024
485986e
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Feb 27, 2024
2994c82
Check physical parameters in isSecure
bqth29 Feb 28, 2024
240db5e
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Mar 22, 2024
5423aa5
Test Instant.min
bqth29 Mar 22, 2024
18ab9f2
Exhaustive tests with all 2 types of CNECs
bqth29 Mar 22, 2024
a5eee12
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Mar 22, 2024
c528edf
Remove comments
bqth29 Mar 22, 2024
8336a69
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Mar 22, 2024
4109876
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Mar 25, 2024
a83a13b
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Apr 4, 2024
af2c3f3
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Apr 4, 2024
8cdd91b
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Apr 4, 2024
efed6ad
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Apr 10, 2024
784885c
Merge branch 'main' into check_physical_parameters_in_is_secure
pet-mit Apr 11, 2024
867460c
Merge branch 'main' into check_physical_parameters_in_is_secure
pet-mit Apr 11, 2024
032152e
Change test 12.15.6
pet-mit Apr 12, 2024
9b1540a
Rollb
bqth29 Apr 12, 2024
4b238f6
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Apr 17, 2024
d966b9a
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Apr 22, 2024
7f1c8da
Merge branch 'main' into change_swe_cne_test
bqth29 Apr 22, 2024
49599f1
Merge branch 'change_swe_cne_test' into check_physical_parameters_in_…
bqth29 Apr 22, 2024
243d906
Merge branch 'main' into check_physical_parameters_in_is_secure
pet-mit May 6, 2024
78e746e
Merge branch 'check_physical_parameters_in_is_secure' of https://gith…
bqth29 May 27, 2024
0a0cb2b
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 May 27, 2024
27e892d
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Jun 17, 2024
88a0a2c
Fix test 12.15.6 + remove dupliacted code (now default RaoResul method)
bqth29 Jun 17, 2024
f12c823
Merge branch 'main' into check_physical_parameters_in_is_secure
bqth29 Jun 17, 2024
1e23795
Merge branch 'main' into check_physical_parameters_in_is_secure
pet-mit Jun 20, 2024
30c682d
Update data/result-exporter/swe-cne-exporter/src/main/java/com/powsyb…
bqth29 Jun 21, 2024
cdc1968
Fix tests and remove duplicated code
bqth29 Jun 21, 2024
d6f4a56
Promote default methods to Instant interface
bqth29 Jun 21, 2024
93b0b35
Update data/result-exporter/swe-cne-exporter/src/main/java/com/powsyb…
bqth29 Jun 24, 2024
d3607c8
Fix after comments
bqth29 Jun 24, 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 @@ -25,15 +25,39 @@ public interface Instant extends Identifiable<Instant>, Comparable<Instant> {
@Override
String toString();

boolean comesBefore(Instant otherInstant);
default boolean comesBefore(Instant otherInstant) {
return getOrder() < otherInstant.getOrder();
}

boolean comesAfter(Instant otherInstant);
default boolean comesAfter(Instant otherInstant) {
return getOrder() > otherInstant.getOrder();
}

boolean isPreventive();
default boolean isPreventive() {
return InstantKind.PREVENTIVE.equals(getKind());
}

boolean isOutage();
default boolean isOutage() {
return InstantKind.OUTAGE.equals(getKind());
}

boolean isAuto();
default boolean isAuto() {
return InstantKind.AUTO.equals(getKind());
}

boolean isCurative();
default boolean isCurative() {
return InstantKind.CURATIVE.equals(getKind());
}

@Override
default int compareTo(Instant otherInstant) {
return Integer.compare(getOrder(), otherInstant.getOrder());
}

static Instant min(Instant instant1, Instant instant2) {
if (instant1 == null || instant2 == null) {
return null;
}
return instant1.comesBefore(instant2) ? instant1 : instant2;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package com.powsybl.openrao.data.cracapi;

import com.powsybl.commons.extensions.Extension;
import org.junit.jupiter.api.Test;

import java.util.Collection;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
class InstantTest {
static class InstantImplTest implements Instant {

private final int order;
private final InstantKind instantKind;

public InstantImplTest(int order, InstantKind instantKind) {
this.order = order;
this.instantKind = instantKind;
}

@Override
public String getId() {
return null;
}

@Override
public String getName() {
return null;
}

@Override
public int getOrder() {
return order;
}

@Override
public InstantKind getKind() {
return instantKind;
}

@Override
public <E extends Extension<Instant>> void addExtension(Class<? super E> aClass, E e) {

}

@Override
public <E extends Extension<Instant>> E getExtension(Class<? super E> aClass) {
return null;
}

@Override
public <E extends Extension<Instant>> E getExtensionByName(String s) {
return null;
}

@Override
public <E extends Extension<Instant>> boolean removeExtension(Class<E> aClass) {
return false;
}

@Override
public <E extends Extension<Instant>> Collection<E> getExtensions() {
return null;
}
}

private final Instant preventiveInstant = new InstantImplTest(1, InstantKind.PREVENTIVE);
private final Instant outageInstant = new InstantImplTest(2, InstantKind.OUTAGE);
private final Instant autoInstant = new InstantImplTest(3, InstantKind.AUTO);
private final Instant curativeInstant = new InstantImplTest(4, InstantKind.CURATIVE);

@Test
void testIsPreventive() {
assertTrue(preventiveInstant.isPreventive());
assertFalse(outageInstant.isPreventive());
assertFalse(autoInstant.isPreventive());
assertFalse(curativeInstant.isPreventive());
}

@Test
void testIsOutage() {
assertFalse(preventiveInstant.isOutage());
assertTrue(outageInstant.isOutage());
assertFalse(autoInstant.isOutage());
assertFalse(curativeInstant.isOutage());
}

@Test
void testIsAuto() {
assertFalse(preventiveInstant.isAuto());
assertFalse(outageInstant.isAuto());
assertTrue(autoInstant.isAuto());
assertFalse(curativeInstant.isAuto());
}

@Test
void testIsCurative() {
assertFalse(preventiveInstant.isCurative());
assertFalse(outageInstant.isCurative());
assertFalse(autoInstant.isCurative());
assertTrue(curativeInstant.isCurative());
}

@Test
void testComesBefore() {
assertFalse(preventiveInstant.comesBefore(preventiveInstant));
assertTrue(preventiveInstant.comesBefore(outageInstant));
assertTrue(preventiveInstant.comesBefore(autoInstant));
assertTrue(preventiveInstant.comesBefore(curativeInstant));
assertFalse(outageInstant.comesBefore(outageInstant));
assertTrue(outageInstant.comesBefore(autoInstant));
assertTrue(outageInstant.comesBefore(curativeInstant));
assertFalse(autoInstant.comesBefore(autoInstant));
assertTrue(autoInstant.comesBefore(curativeInstant));
assertFalse(curativeInstant.comesBefore(curativeInstant));
}

@Test
void testComesAfter() {
assertFalse(curativeInstant.comesAfter(curativeInstant));
assertTrue(curativeInstant.comesAfter(autoInstant));
assertTrue(curativeInstant.comesAfter(outageInstant));
assertTrue(curativeInstant.comesAfter(preventiveInstant));
assertFalse(autoInstant.comesAfter(autoInstant));
assertTrue(autoInstant.comesAfter(outageInstant));
assertTrue(autoInstant.comesAfter(preventiveInstant));
assertFalse(outageInstant.comesAfter(outageInstant));
assertTrue(outageInstant.comesAfter(preventiveInstant));
assertFalse(preventiveInstant.comesAfter(preventiveInstant));
}

@Test
void testCompareInstants() {
assertEquals(0, preventiveInstant.compareTo(preventiveInstant));
assertEquals(0, curativeInstant.compareTo(curativeInstant));
assertEquals(-1, preventiveInstant.compareTo(curativeInstant));
assertEquals(1, curativeInstant.compareTo(preventiveInstant));
}

@Test
void testMin() {
assertNull(Instant.min(null, null));
assertNull(Instant.min(preventiveInstant, null));
assertNull(Instant.min(null, curativeInstant));
assertEquals(preventiveInstant, Instant.min(preventiveInstant, curativeInstant));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,6 @@ public String toString() {
return name;
}

public boolean comesBefore(Instant otherInstant) {
return this.order < otherInstant.getOrder();
}

public boolean comesAfter(Instant otherInstant) {
return this.order > otherInstant.getOrder();
}

@Override
public boolean isPreventive() {
return instantKind == InstantKind.PREVENTIVE;
}

@Override
public boolean isOutage() {
return instantKind == InstantKind.OUTAGE;
}

@Override
public boolean isAuto() {
return instantKind == InstantKind.AUTO;
}

@Override
public boolean isCurative() {
return instantKind == InstantKind.CURATIVE;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -106,9 +78,4 @@ public int hashCode() {
Instant getInstantBefore() {
return previous;
}

@Override
public int compareTo(Instant otherInstant) {
return Integer.compare(getOrder(), otherInstant.getOrder());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,14 @@ void testInstantBeforeAfter() {

assertFalse(preventiveInstant.comesAfter(preventiveInstant));
}

@Test
void testMin() {
InstantImpl instant1 = new InstantImpl("instant1", InstantKind.PREVENTIVE, null);
InstantImpl instant2 = new InstantImpl("instant2", InstantKind.CURATIVE, instant1);
assertEquals(instant1, Instant.min(instant1, instant2));
assertNull(Instant.min(instant1, null));
assertNull(Instant.min(null, instant2));
assertNull(Instant.min(null, null));
}
}
Loading
Loading