From da1993608ac504c7e7f13a74e4f3b6282e713660 Mon Sep 17 00:00:00 2001 From: Thomas Bouquet <63302082+bqth29@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:33:10 +0100 Subject: [PATCH] Power Gradient Constraint (#1229) * Power Gradient Constraint Signed-off-by: Thomas Bouquet * JUnit Signed-off-by: Thomas Bouquet * typo in test name Signed-off-by: Thomas Bouquet * extract VariationDirection from RangeAction Signed-off-by: Thomas Bouquet * replace record by class Signed-off-by: Thomas Bouquet * update pom Signed-off-by: Thomas Bouquet * add module to jacoco Signed-off-by: Thomas Bouquet * add pgcs to RAO inputs Signed-off-by: Thomas Bouquet * fix poms Signed-off-by: Godelaine de Montmorillon * udate new POM tp 6.3.0-SNAPSHOT Signed-off-by: Thomas Bouquet --------- Signed-off-by: Thomas Bouquet Signed-off-by: Godelaine de Montmorillon Co-authored-by: Godelaine de Montmorillon --- .../api/rangeaction/PstRangeActionAdder.java | 2 +- .../crac/api/rangeaction/RangeAction.java | 5 --- .../rangeaction/StandardRangeActionAdder.java | 2 +- .../api/rangeaction/VariationDirection.java | 15 +++++++ .../data/crac/impl/AbstractRangeAction.java | 1 + .../AbstractStandardRangeActionAdder.java | 6 +-- .../impl/CounterTradeRangeActionImpl.java | 1 + .../data/crac/impl/HvdcRangeActionImpl.java | 1 + .../crac/impl/InjectionRangeActionImpl.java | 1 + .../crac/impl/PstRangeActionAdderImpl.java | 6 +-- .../data/crac/impl/PstRangeActionImpl.java | 1 + .../CounterTradeRangeActionAdderImplTest.java | 14 +++---- .../impl/HvdcRangeActionAdderImplTest.java | 14 +++---- .../InjectionRangeActionAdderImplTest.java | 14 +++---- .../impl/PstRangeActionAdderImplTest.java | 14 +++---- .../impl/utils/ExhaustiveCracCreation.java | 10 ++--- .../io/json/JsonSerializationConstants.java | 11 +++--- .../io/json/JsonRetrocompatibilityTest.java | 25 ++++++------ data/inter-temporal-constraint/pom.xml | 34 ++++++++++++++++ .../PowerGradientConstraint.java | 27 +++++++++++++ .../PowerGradientConstraintTest.java | 39 +++++++++++++++++++ data/pom.xml | 1 + distribution/pom.xml | 25 +++++++----- docs/input-data/crac/json.md | 4 +- ra-optimisation/rao-api/pom.xml | 5 +++ .../openrao/raoapi/InterTemporalRaoInput.java | 14 +++++-- .../raoapi/InterTemporalRaoInputTest.java | 11 ++++-- .../RemedialActionCostEvaluator.java | 3 +- .../RemedialActionCostEvaluatorImplTest.java | 26 ++++++------- 29 files changed, 236 insertions(+), 96 deletions(-) create mode 100644 data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/VariationDirection.java create mode 100644 data/inter-temporal-constraint/pom.xml create mode 100644 data/inter-temporal-constraint/src/main/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraint.java create mode 100644 data/inter-temporal-constraint/src/test/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraintTest.java diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/PstRangeActionAdder.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/PstRangeActionAdder.java index c77badb3f0..23b803ac43 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/PstRangeActionAdder.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/PstRangeActionAdder.java @@ -28,7 +28,7 @@ public interface PstRangeActionAdder extends RemedialActionAdder tapToAngleConversionMap); - PstRangeActionAdder withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection); + PstRangeActionAdder withVariationCost(Double variationCost, VariationDirection variationDirection); TapRangeAdder newTapRange(); diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/RangeAction.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/RangeAction.java index d2fa23fdf1..cf7c3b6026 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/RangeAction.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/RangeAction.java @@ -55,9 +55,4 @@ public interface RangeAction> extends RemedialAction Optional getGroupId(); Optional getVariationCost(VariationDirection variationDirection); - - enum VariationDirection { - UP, DOWN - } - } diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/StandardRangeActionAdder.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/StandardRangeActionAdder.java index 499757b77a..328690e4d9 100644 --- a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/StandardRangeActionAdder.java +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/StandardRangeActionAdder.java @@ -20,6 +20,6 @@ public interface StandardRangeActionAdder> T withInitialSetpoint(double initialSetpoint); - T withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection); + T withVariationCost(Double variationCost, VariationDirection variationDirection); } diff --git a/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/VariationDirection.java b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/VariationDirection.java new file mode 100644 index 0000000000..5df6e807c6 --- /dev/null +++ b/data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/rangeaction/VariationDirection.java @@ -0,0 +1,15 @@ +/* + * 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.crac.api.rangeaction; + +/** + * @author Thomas Bouquet {@literal } + */ +public enum VariationDirection { + UP, DOWN +} diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractRangeAction.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractRangeAction.java index 4332b50fd8..6e93e750d9 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractRangeAction.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractRangeAction.java @@ -7,6 +7,7 @@ package com.powsybl.openrao.data.crac.impl; import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageRule; import java.util.HashMap; diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractStandardRangeActionAdder.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractStandardRangeActionAdder.java index b773fd4314..d5d5230b23 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractStandardRangeActionAdder.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/AbstractStandardRangeActionAdder.java @@ -9,8 +9,8 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.data.crac.api.range.StandardRange; import com.powsybl.openrao.data.crac.api.range.StandardRangeAdder; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.StandardRangeActionAdder; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import java.util.ArrayList; import java.util.HashMap; @@ -26,7 +26,7 @@ public abstract class AbstractStandardRangeActionAdder ranges; - protected Map variationCosts; + protected Map variationCosts; AbstractStandardRangeActionAdder(CracImpl crac) { super(crac); @@ -47,7 +47,7 @@ public T withInitialSetpoint(double initialSetpoint) { } @Override - public T withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection) { + public T withVariationCost(Double variationCost, VariationDirection variationDirection) { this.variationCosts.put(variationDirection, variationCost); return (T) this; } diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionImpl.java index 3f75f99c4e..d69e5e31b1 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionImpl.java @@ -10,6 +10,7 @@ import com.powsybl.openrao.data.crac.api.NetworkElement; import com.powsybl.openrao.data.crac.api.range.StandardRange; import com.powsybl.openrao.data.crac.api.rangeaction.CounterTradeRangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageRule; import com.powsybl.iidm.network.Country; import com.powsybl.iidm.network.Network; diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionImpl.java index 2e599f79c1..e06ea85d54 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionImpl.java @@ -13,6 +13,7 @@ import com.powsybl.openrao.data.crac.api.NetworkElement; import com.powsybl.openrao.data.crac.api.range.StandardRange; import com.powsybl.openrao.data.crac.api.rangeaction.HvdcRangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageRule; import com.powsybl.iidm.network.HvdcLine; import com.powsybl.iidm.network.Network; diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionImpl.java index bc158905e9..e64b164797 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionImpl.java @@ -13,6 +13,7 @@ import com.powsybl.openrao.data.crac.api.NetworkElement; import com.powsybl.openrao.data.crac.api.range.StandardRange; import com.powsybl.openrao.data.crac.api.rangeaction.InjectionRangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageRule; import com.powsybl.iidm.network.Generator; import com.powsybl.iidm.network.Load; diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImpl.java index ed36958570..acf34f041e 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImpl.java @@ -14,7 +14,7 @@ import com.powsybl.openrao.data.crac.api.range.RangeType; import com.powsybl.openrao.data.crac.api.range.TapRange; import com.powsybl.openrao.data.crac.api.range.TapRangeAdder; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageRule; import java.util.*; @@ -34,7 +34,7 @@ public class PstRangeActionAdderImpl extends AbstractRemedialActionAdder tapToAngleConversionMap; - private Map variationCosts; + private Map variationCosts; @Override protected String getTypeDescription() { @@ -78,7 +78,7 @@ public PstRangeActionAdder withTapToAngleConversionMap(Map tapT } @Override - public PstRangeActionAdder withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection) { + public PstRangeActionAdder withVariationCost(Double variationCost, VariationDirection variationDirection) { this.variationCosts.put(variationDirection, variationCost); return this; } diff --git a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionImpl.java b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionImpl.java index fa410615f9..4eb89a0b4b 100644 --- a/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionImpl.java +++ b/data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/PstRangeActionImpl.java @@ -14,6 +14,7 @@ import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; import com.powsybl.openrao.data.crac.api.range.RangeType; import com.powsybl.openrao.data.crac.api.range.TapRange; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageRule; import com.powsybl.iidm.network.*; import org.apache.commons.lang3.tuple.Pair; diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionAdderImplTest.java index a43aed0a95..32896958c6 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/CounterTradeRangeActionAdderImplTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.crac.api.InstantKind; import com.powsybl.openrao.data.crac.api.rangeaction.CounterTradeRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.CounterTradeRangeActionAdder; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageMethod; import com.powsybl.iidm.network.Country; import org.junit.jupiter.api.BeforeEach; @@ -39,8 +39,8 @@ void testAdd() { .withOperator("BE") .withGroupId("groupId1") .withActivationCost(1000d) - .withVariationCost(10000d, RangeAction.VariationDirection.UP) - .withVariationCost(20000d, RangeAction.VariationDirection.DOWN) + .withVariationCost(10000d, VariationDirection.UP) + .withVariationCost(20000d, VariationDirection.DOWN) .newRange().withMin(-5).withMax(10).add() .newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add() .withExportingCountry(Country.FR) @@ -51,8 +51,8 @@ void testAdd() { assertEquals("id1", counterTradeRangeAction.getName()); assertEquals("BE", counterTradeRangeAction.getOperator()); assertEquals(Optional.of(1000d), counterTradeRangeAction.getActivationCost()); - assertEquals(Optional.of(10000d), counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.UP)); - assertEquals(Optional.of(20000d), counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN)); + assertEquals(Optional.of(10000d), counterTradeRangeAction.getVariationCost(VariationDirection.UP)); + assertEquals(Optional.of(20000d), counterTradeRangeAction.getVariationCost(VariationDirection.DOWN)); assertTrue(counterTradeRangeAction.getGroupId().isPresent()); assertEquals("groupId1", counterTradeRangeAction.getGroupId().get()); assertEquals(1, counterTradeRangeAction.getRanges().size()); @@ -78,8 +78,8 @@ void testAddWithoutGroupId() { assertEquals("BE", counterTradeRangeAction.getOperator()); assertTrue(counterTradeRangeAction.getGroupId().isEmpty()); assertTrue(counterTradeRangeAction.getActivationCost().isEmpty()); - assertTrue(counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertTrue(counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); + assertTrue(counterTradeRangeAction.getVariationCost(VariationDirection.UP).isEmpty()); + assertTrue(counterTradeRangeAction.getVariationCost(VariationDirection.DOWN).isEmpty()); assertEquals(1, counterTradeRangeAction.getRanges().size()); assertEquals(1, counterTradeRangeAction.getUsageRules().size()); assertEquals(Country.FR, counterTradeRangeAction.getExportingCountry()); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionAdderImplTest.java index 2422a8a31e..98121f9c2f 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionAdderImplTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.crac.api.networkaction.ActionType; import com.powsybl.openrao.data.crac.api.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.HvdcRangeActionAdder; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageMethod; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,8 +49,8 @@ void testAdd() { .withNetworkElement(networkElementId) .withGroupId("groupId1") .withActivationCost(100d) - .withVariationCost(500d, RangeAction.VariationDirection.UP) - .withVariationCost(800d, RangeAction.VariationDirection.DOWN) + .withVariationCost(500d, VariationDirection.UP) + .withVariationCost(800d, VariationDirection.DOWN) .newRange().withMin(-5).withMax(10).add() .newOnInstantUsageRule() .withInstant(PREVENTIVE_INSTANT_ID) @@ -61,8 +61,8 @@ void testAdd() { assertEquals(1, crac.getRangeActions().size()); assertEquals(networkElementId, hvdcRangeAction.getNetworkElement().getId()); assertEquals(Optional.of(100d), hvdcRangeAction.getActivationCost()); - assertEquals(Optional.of(500d), hvdcRangeAction.getVariationCost(RangeAction.VariationDirection.UP)); - assertEquals(Optional.of(800d), hvdcRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN)); + assertEquals(Optional.of(500d), hvdcRangeAction.getVariationCost(VariationDirection.UP)); + assertEquals(Optional.of(800d), hvdcRangeAction.getVariationCost(VariationDirection.DOWN)); assertEquals("BE", hvdcRangeAction.getOperator()); assertEquals(1, hvdcRangeAction.getRanges().size()); assertEquals(1, hvdcRangeAction.getUsageRules().size()); @@ -90,8 +90,8 @@ void testAddAuto() { assertEquals(networkElementId, hvdcRangeAction.getNetworkElement().getId()); assertEquals("BE", hvdcRangeAction.getOperator()); assertTrue(hvdcRangeAction.getActivationCost().isEmpty()); - assertTrue(hvdcRangeAction.getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertTrue(hvdcRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); + assertTrue(hvdcRangeAction.getVariationCost(VariationDirection.UP).isEmpty()); + assertTrue(hvdcRangeAction.getVariationCost(VariationDirection.DOWN).isEmpty()); assertEquals(1, hvdcRangeAction.getRanges().size()); assertEquals(1, hvdcRangeAction.getUsageRules().size()); assertEquals(1, crac.getNetworkElements().size()); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionAdderImplTest.java index 207081ecc7..819e29c5f4 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/InjectionRangeActionAdderImplTest.java @@ -11,7 +11,7 @@ import com.powsybl.openrao.data.crac.api.InstantKind; import com.powsybl.openrao.data.crac.api.rangeaction.InjectionRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.InjectionRangeActionAdder; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageMethod; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -49,8 +49,8 @@ void testAdd() { .withOperator("BE") .withGroupId("groupId1") .withActivationCost(200d) - .withVariationCost(700d, RangeAction.VariationDirection.UP) - .withVariationCost(1000d, RangeAction.VariationDirection.DOWN) + .withVariationCost(700d, VariationDirection.UP) + .withVariationCost(1000d, VariationDirection.DOWN) .withNetworkElementAndKey(1., injectionId1) .withNetworkElementAndKey(-1., injectionId2, injectionName2) .newRange().withMin(-5).withMax(10).add() @@ -61,8 +61,8 @@ void testAdd() { assertEquals("id1", injectionRangeAction.getName()); assertEquals("BE", injectionRangeAction.getOperator()); assertEquals(Optional.of(200d), injectionRangeAction.getActivationCost()); - assertEquals(Optional.of(700d), injectionRangeAction.getVariationCost(RangeAction.VariationDirection.UP)); - assertEquals(Optional.of(1000d), injectionRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN)); + assertEquals(Optional.of(700d), injectionRangeAction.getVariationCost(VariationDirection.UP)); + assertEquals(Optional.of(1000d), injectionRangeAction.getVariationCost(VariationDirection.DOWN)); assertTrue(injectionRangeAction.getGroupId().isPresent()); assertEquals("groupId1", injectionRangeAction.getGroupId().get()); assertEquals(1, injectionRangeAction.getRanges().size()); @@ -96,8 +96,8 @@ void testAddWithSumOnSameInjection() { assertEquals("id1", injectionRangeAction.getName()); assertEquals("BE", injectionRangeAction.getOperator()); assertTrue(injectionRangeAction.getActivationCost().isEmpty()); - assertTrue(injectionRangeAction.getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertTrue(injectionRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); + assertTrue(injectionRangeAction.getVariationCost(VariationDirection.UP).isEmpty()); + assertTrue(injectionRangeAction.getVariationCost(VariationDirection.DOWN).isEmpty()); assertTrue(injectionRangeAction.getGroupId().isPresent()); assertEquals("groupId1", injectionRangeAction.getGroupId().get()); assertEquals(1, injectionRangeAction.getRanges().size()); diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImplTest.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImplTest.java index 29269b2c30..4ae97518f3 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImplTest.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/PstRangeActionAdderImplTest.java @@ -13,7 +13,7 @@ import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeActionAdder; import com.powsybl.openrao.data.crac.api.range.RangeType; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageMethod; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -55,8 +55,8 @@ void testAdd() { .withNetworkElement(networkElementId) .withGroupId("groupId1") .withActivationCost(0d) - .withVariationCost(0d, RangeAction.VariationDirection.UP) - .withVariationCost(0d, RangeAction.VariationDirection.DOWN) + .withVariationCost(0d, VariationDirection.UP) + .withVariationCost(0d, VariationDirection.DOWN) .newTapRange() .withMinTap(-10) .withMaxTap(10) @@ -74,8 +74,8 @@ void testAdd() { assertEquals(networkElementId, pstRangeAction.getNetworkElement().getId()); assertEquals("BE", pstRangeAction.getOperator()); assertEquals(Optional.of(0d), pstRangeAction.getActivationCost()); - assertEquals(Optional.of(0d), pstRangeAction.getVariationCost(RangeAction.VariationDirection.UP)); - assertEquals(Optional.of(0d), pstRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN)); + assertEquals(Optional.of(0d), pstRangeAction.getVariationCost(VariationDirection.UP)); + assertEquals(Optional.of(0d), pstRangeAction.getVariationCost(VariationDirection.DOWN)); assertEquals(1, pstRangeAction.getRanges().size()); assertEquals(1, pstRangeAction.getUsageRules().size()); assertEquals(1, crac.getNetworkElements().size()); @@ -127,8 +127,8 @@ void testAddAutoWithSpeed() { assertEquals(123, pstRangeAction.getSpeed().get().intValue()); assertTrue(pstRangeAction.getActivationCost().isEmpty()); - assertTrue(pstRangeAction.getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertTrue(pstRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); + assertTrue(pstRangeAction.getVariationCost(VariationDirection.UP).isEmpty()); + assertTrue(pstRangeAction.getVariationCost(VariationDirection.DOWN).isEmpty()); } @Test diff --git a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/ExhaustiveCracCreation.java b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/ExhaustiveCracCreation.java index 5c26e44dbd..9742fb416f 100644 --- a/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/ExhaustiveCracCreation.java +++ b/data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/utils/ExhaustiveCracCreation.java @@ -15,7 +15,7 @@ import com.powsybl.openrao.data.crac.api.InstantKind; import com.powsybl.openrao.data.crac.api.networkaction.ActionType; import com.powsybl.openrao.data.crac.api.range.RangeType; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.UsageMethod; import java.util.HashMap; @@ -310,8 +310,8 @@ public static Crac create(CracFactory cracFactory) { .withNetworkElementAndKey(1., "generator1Id") .withNetworkElementAndKey(-1., "generator2Id", "generator2Name") .withActivationCost(100d) - .withVariationCost(750d, RangeAction.VariationDirection.UP) - .withVariationCost(1000d, RangeAction.VariationDirection.DOWN) + .withVariationCost(750d, VariationDirection.UP) + .withVariationCost(1000d, VariationDirection.DOWN) .newRange().withMin(-500).withMax(500).add() .newRange().withMin(-1000).withMax(1000).add() .newOnFlowConstraintInCountryUsageRule().withInstant(CURATIVE_INSTANT_ID).withContingency("contingency2Id").withCountry(Country.ES).withUsageMethod(UsageMethod.AVAILABLE).add() @@ -322,8 +322,8 @@ public static Crac create(CracFactory cracFactory) { .withName("counterTradeRange1Name") .withExportingCountry(Country.FR) .withImportingCountry(Country.DE) - .withVariationCost(2000d, RangeAction.VariationDirection.UP) - .withVariationCost(1000d, RangeAction.VariationDirection.DOWN) + .withVariationCost(2000d, VariationDirection.UP) + .withVariationCost(1000d, VariationDirection.DOWN) .newRange().withMin(-500).withMax(500).add() .newRange().withMin(-1000).withMax(1000).add() .newOnFlowConstraintInCountryUsageRule().withInstant(CURATIVE_INSTANT_ID).withCountry(Country.ES).withUsageMethod(UsageMethod.AVAILABLE).add() diff --git a/data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/JsonSerializationConstants.java b/data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/JsonSerializationConstants.java index 91a685f4da..9358a77c5b 100644 --- a/data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/JsonSerializationConstants.java +++ b/data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/JsonSerializationConstants.java @@ -17,6 +17,7 @@ import com.powsybl.openrao.data.crac.api.networkaction.SingleNetworkElementActionAdder; import com.powsybl.openrao.data.crac.api.range.RangeType; import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.threshold.BranchThreshold; import com.powsybl.openrao.data.crac.api.threshold.Threshold; import com.powsybl.openrao.data.crac.api.usagerule.OnConstraint; @@ -509,8 +510,8 @@ public static void serializeActivationCost(RemedialAction remedialAction, Jso } public static void serializeVariationCosts(RangeAction rangeAction, JsonGenerator gen) throws IOException { - Optional variationCostUp = rangeAction.getVariationCost(RangeAction.VariationDirection.UP); - Optional variationCostDown = rangeAction.getVariationCost(RangeAction.VariationDirection.DOWN); + Optional variationCostUp = rangeAction.getVariationCost(VariationDirection.UP); + Optional variationCostDown = rangeAction.getVariationCost(VariationDirection.DOWN); if (variationCostUp.isEmpty() && variationCostDown.isEmpty()) { return; } @@ -524,11 +525,11 @@ public static void serializeVariationCosts(RangeAction rangeAction, JsonGener gen.writeEndObject(); } - public static RangeAction.VariationDirection deserializeVariationDirection(String variationDirection) { + public static VariationDirection deserializeVariationDirection(String variationDirection) { if (JsonSerializationConstants.UP.equals(variationDirection)) { - return RangeAction.VariationDirection.UP; + return VariationDirection.UP; } else if (JsonSerializationConstants.DOWN.equals(variationDirection)) { - return RangeAction.VariationDirection.DOWN; + return VariationDirection.DOWN; } else { throw new OpenRaoException("Unexpected variation direction '%s'.".formatted(variationDirection)); } diff --git a/data/crac/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/crac/io/json/JsonRetrocompatibilityTest.java b/data/crac/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/crac/io/json/JsonRetrocompatibilityTest.java index 50296c6708..a1356c16a2 100644 --- a/data/crac/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/crac/io/json/JsonRetrocompatibilityTest.java +++ b/data/crac/crac-io/crac-io-json/src/test/java/com/powsybl/openrao/data/crac/io/json/JsonRetrocompatibilityTest.java @@ -18,6 +18,7 @@ import com.powsybl.openrao.data.crac.api.NetworkElement; import com.powsybl.openrao.data.crac.api.RaUsageLimits; import com.powsybl.openrao.data.crac.api.RemedialAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.data.crac.api.usagerule.OnConstraint; import com.powsybl.openrao.data.crac.api.usagerule.OnContingencyState; import com.powsybl.openrao.data.crac.api.usagerule.OnFlowConstraintInCountry; @@ -864,17 +865,17 @@ private void testContentOfV2Point6Crac(Crac crac) { assertTrue(crac.getNetworkAction("switchPairRaId").getActivationCost().isEmpty()); // variation costs - assertEquals(Optional.of(0.0), crac.getPstRangeAction("pstRange3Id").getVariationCost(RangeAction.VariationDirection.UP)); - assertEquals(Optional.of(0.0), crac.getPstRangeAction("pstRange3Id").getVariationCost(RangeAction.VariationDirection.DOWN)); - assertTrue(crac.getPstRangeAction("pstRange1Id").getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertTrue(crac.getPstRangeAction("pstRange1Id").getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); - assertTrue(crac.getRangeAction("hvdcRange1Id").getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertTrue(crac.getRangeAction("hvdcRange1Id").getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); - assertTrue(crac.getRangeAction("hvdcRange2Id").getVariationCost(RangeAction.VariationDirection.UP).isEmpty()); - assertEquals(Optional.of(500.0), crac.getRangeAction("hvdcRange2Id").getVariationCost(RangeAction.VariationDirection.DOWN)); - assertEquals(Optional.of(2000.0), crac.getRangeAction("injectionRange1Id").getVariationCost(RangeAction.VariationDirection.UP)); - assertTrue(crac.getRangeAction("injectionRange1Id").getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty()); - assertEquals(Optional.of(15000.0), crac.getRangeAction("counterTradeRange1Id").getVariationCost(RangeAction.VariationDirection.UP)); - assertEquals(Optional.of(18000.0), crac.getRangeAction("counterTradeRange1Id").getVariationCost(RangeAction.VariationDirection.DOWN)); + assertEquals(Optional.of(0.0), crac.getPstRangeAction("pstRange3Id").getVariationCost(VariationDirection.UP)); + assertEquals(Optional.of(0.0), crac.getPstRangeAction("pstRange3Id").getVariationCost(VariationDirection.DOWN)); + assertTrue(crac.getPstRangeAction("pstRange1Id").getVariationCost(VariationDirection.UP).isEmpty()); + assertTrue(crac.getPstRangeAction("pstRange1Id").getVariationCost(VariationDirection.DOWN).isEmpty()); + assertTrue(crac.getRangeAction("hvdcRange1Id").getVariationCost(VariationDirection.UP).isEmpty()); + assertTrue(crac.getRangeAction("hvdcRange1Id").getVariationCost(VariationDirection.DOWN).isEmpty()); + assertTrue(crac.getRangeAction("hvdcRange2Id").getVariationCost(VariationDirection.UP).isEmpty()); + assertEquals(Optional.of(500.0), crac.getRangeAction("hvdcRange2Id").getVariationCost(VariationDirection.DOWN)); + assertEquals(Optional.of(2000.0), crac.getRangeAction("injectionRange1Id").getVariationCost(VariationDirection.UP)); + assertTrue(crac.getRangeAction("injectionRange1Id").getVariationCost(VariationDirection.DOWN).isEmpty()); + assertEquals(Optional.of(15000.0), crac.getRangeAction("counterTradeRange1Id").getVariationCost(VariationDirection.UP)); + assertEquals(Optional.of(18000.0), crac.getRangeAction("counterTradeRange1Id").getVariationCost(VariationDirection.DOWN)); } } diff --git a/data/inter-temporal-constraint/pom.xml b/data/inter-temporal-constraint/pom.xml new file mode 100644 index 0000000000..1743bb9bf9 --- /dev/null +++ b/data/inter-temporal-constraint/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + + open-rao-data + com.powsybl + 6.3.0-SNAPSHOT + + + open-rao-inter-temporal-constraint + jar + Inter-temporal Constraints + Module for inter-temporal constraints + + + + + ${project.groupId} + open-rao-crac-api + ${project.version} + + + + + org.junit.jupiter + junit-jupiter + test + + + + \ No newline at end of file diff --git a/data/inter-temporal-constraint/src/main/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraint.java b/data/inter-temporal-constraint/src/main/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraint.java new file mode 100644 index 0000000000..8b81e5d68f --- /dev/null +++ b/data/inter-temporal-constraint/src/main/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraint.java @@ -0,0 +1,27 @@ +/* + * 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.intertemporalconstraint; + +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; + +/** + * Power Gradient Constraint that applies on a generator or a load. + * It is always positive and represents the rate of change of the set-point (in MW/hour) and + * can apply either for upward or downward variation. + * + * @author Thomas Bouquet {@literal } + */ +public record PowerGradientConstraint(String networkElementId, double powerGradient, + VariationDirection variationDirection) { + public PowerGradientConstraint { + if (powerGradient < 0) { + throw new OpenRaoException("powerGradient must be a positive value. For a decreasing variation, use VariationDirection.DOWN as the third parameter of the constructor."); + } + } +} diff --git a/data/inter-temporal-constraint/src/test/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraintTest.java b/data/inter-temporal-constraint/src/test/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraintTest.java new file mode 100644 index 0000000000..04b5ab1381 --- /dev/null +++ b/data/inter-temporal-constraint/src/test/java/com/powsybl/openrao/data/intertemporalconstraint/PowerGradientConstraintTest.java @@ -0,0 +1,39 @@ +/* + * 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.intertemporalconstraint; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; +import org.junit.jupiter.api.Test; + +/** + * @author Thomas Bouquet {@literal } + */ +class PowerGradientConstraintTest { + @Test + void testPowerGradientConstraints() { + PowerGradientConstraint pgc1 = new PowerGradientConstraint("generator", 200.0, VariationDirection.UP); + assertEquals("generator", pgc1.networkElementId()); + assertEquals(200.0, pgc1.powerGradient()); + assertEquals(VariationDirection.UP, pgc1.variationDirection()); + + PowerGradientConstraint pgc2 = new PowerGradientConstraint("load", 50.0, VariationDirection.DOWN); + assertEquals("load", pgc2.networkElementId()); + assertEquals(50.0, pgc2.powerGradient()); + assertEquals(VariationDirection.DOWN, pgc2.variationDirection()); + } + + @Test + void testConstraintWithNegativeGradientThrowsException() { + OpenRaoException exception = assertThrows(OpenRaoException.class, () -> new PowerGradientConstraint("generator", -100.0, VariationDirection.DOWN)); + assertEquals("powerGradient must be a positive value. For a decreasing variation, use VariationDirection.DOWN as the third parameter of the constructor.", exception.getMessage()); + } +} diff --git a/data/pom.xml b/data/pom.xml index d6e1987040..d873a3e001 100755 --- a/data/pom.xml +++ b/data/pom.xml @@ -19,6 +19,7 @@ crac flowbased-domain glsk + inter-temporal-constraint rao-result refprog virtual-hubs diff --git a/distribution/pom.xml b/distribution/pom.xml index ac0312586a..e642c55d7d 100755 --- a/distribution/pom.xml +++ b/distribution/pom.xml @@ -24,12 +24,12 @@ ${project.groupId} - open-rao-core-cne-exporter + open-rao-commons ${project.version} ${project.groupId} - open-rao-swe-cne-exporter + open-rao-core-cne-exporter ${project.version} @@ -39,12 +39,12 @@ ${project.groupId} - open-rao-crac-io-commons + open-rao-crac-impl ${project.version} ${project.groupId} - open-rao-crac-impl + open-rao-crac-io-commons ${project.version} @@ -64,27 +64,27 @@ ${project.groupId} - open-rao-commons + open-rao-flowbased-computation-api ${project.version} ${project.groupId} - open-rao-flowbased-domain + open-rao-flowbased-computation-impl ${project.version} ${project.groupId} - open-rao-flowbased-computation-api + open-rao-flowbased-domain ${project.version} ${project.groupId} - open-rao-flowbased-computation-impl + open-rao-glsk-virtual-hubs ${project.version} ${project.groupId} - open-rao-glsk-virtual-hubs + open-rao-inter-temporal-constraint ${project.version} @@ -92,6 +92,11 @@ open-rao-loopflow-computation ${project.version} + + ${project.groupId} + open-rao-rao-api + ${project.version} + ${project.groupId} open-rao-rao-result-api @@ -129,7 +134,7 @@ ${project.groupId} - open-rao-rao-api + open-rao-swe-cne-exporter ${project.version} diff --git a/docs/input-data/crac/json.md b/docs/input-data/crac/json.md index fa6cf29bf9..fb4a1ac586 100644 --- a/docs/input-data/crac/json.md +++ b/docs/input-data/crac/json.md @@ -1367,8 +1367,8 @@ It is a costly remedial action which is currently not handled by the RAO. .withGroupId("group-id") .withOperator("operator") .withActivationCost(100d) - .withVariationCost(1000d, RangeAction.VariationDirection.UP) - .withVariationCost(2000d, RangeAction.VariationDirection.DOWN) + .withVariationCost(1000d, VariationDirection.UP) + .withVariationCost(2000d, VariationDirection.DOWN) .withExportingCountry(Country.FR) .withImportingCountry(Country.ES) .withInitialSetpoint(50) diff --git a/ra-optimisation/rao-api/pom.xml b/ra-optimisation/rao-api/pom.xml index bc2f43b24f..d87051979c 100644 --- a/ra-optimisation/rao-api/pom.xml +++ b/ra-optimisation/rao-api/pom.xml @@ -22,6 +22,11 @@ open-rao-crac-api ${project.version} + + com.powsybl + open-rao-inter-temporal-constraint + ${project.version} + ${project.groupId} open-rao-rao-result-api diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/InterTemporalRaoInput.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/InterTemporalRaoInput.java index 6ed748951a..02187bac08 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/InterTemporalRaoInput.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/InterTemporalRaoInput.java @@ -8,10 +8,11 @@ package com.powsybl.openrao.raoapi; import com.powsybl.openrao.commons.TemporalData; +import com.powsybl.openrao.data.intertemporalconstraint.PowerGradientConstraint; import java.time.OffsetDateTime; +import java.util.HashSet; import java.util.Set; -import java.util.stream.Collectors; /** * @author Thomas Bouquet {@literal } @@ -20,14 +21,16 @@ public class InterTemporalRaoInput { private final TemporalData raoInputs; private final Set timestampsToRun; + private final Set powerGradientConstraints; - public InterTemporalRaoInput(TemporalData raoInputs, Set timestampsToRun) { + public InterTemporalRaoInput(TemporalData raoInputs, Set timestampsToRun, Set powerGradientConstraints) { this.raoInputs = raoInputs; this.timestampsToRun = timestampsToRun; + this.powerGradientConstraints = powerGradientConstraints; } - public InterTemporalRaoInput(TemporalData raoInputs) { - this(raoInputs, raoInputs.getTimestamps().stream().collect(Collectors.toSet())); + public InterTemporalRaoInput(TemporalData raoInputs, Set powerGradientConstraints) { + this(raoInputs, new HashSet<>(raoInputs.getTimestamps()), powerGradientConstraints); } public TemporalData getRaoInputs() { @@ -38,4 +41,7 @@ public Set getTimestampsToRun() { return timestampsToRun; } + public Set getPowerGradientConstraints() { + return powerGradientConstraints; + } } diff --git a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/InterTemporalRaoInputTest.java b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/InterTemporalRaoInputTest.java index e328632db3..55a2589419 100644 --- a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/InterTemporalRaoInputTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/InterTemporalRaoInputTest.java @@ -9,6 +9,8 @@ import com.powsybl.openrao.commons.TemporalData; import com.powsybl.openrao.commons.TemporalDataImpl; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; +import com.powsybl.openrao.data.intertemporalconstraint.PowerGradientConstraint; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -25,11 +27,11 @@ * @author Roxane Chen {@literal } */ class InterTemporalRaoInputTest { - private OffsetDateTime timestamp1; private OffsetDateTime timestamp2; private OffsetDateTime timestamp3; private TemporalData temporalData; + private Set powerGradientConstraints; @BeforeEach void setUp() { @@ -40,19 +42,22 @@ void setUp() { timestamp2 = OffsetDateTime.of(2024, 12, 10, 17, 21, 0, 0, ZoneOffset.UTC); timestamp3 = OffsetDateTime.of(2024, 12, 10, 18, 21, 0, 0, ZoneOffset.UTC); temporalData = new TemporalDataImpl<>(Map.of(timestamp1, raoInput1, timestamp2, raoInput2, timestamp3, raoInput3)); + powerGradientConstraints = Set.of(new PowerGradientConstraint("generator-1", 200, VariationDirection.UP), new PowerGradientConstraint("generator-2", 50, VariationDirection.DOWN)); } @Test void testInstantiateInterTemporalRaoInput() { - InterTemporalRaoInput input = new InterTemporalRaoInput(temporalData, Set.of(timestamp1, timestamp3)); + InterTemporalRaoInput input = new InterTemporalRaoInput(temporalData, Set.of(timestamp1, timestamp3), powerGradientConstraints); assertEquals(temporalData, input.getRaoInputs()); assertEquals(Set.of(timestamp1, timestamp3), input.getTimestampsToRun()); + assertEquals(powerGradientConstraints, input.getPowerGradientConstraints()); } @Test void testInstantiateInterTemporalRaoInputAllTimestamps() { - InterTemporalRaoInput input = new InterTemporalRaoInput(temporalData); + InterTemporalRaoInput input = new InterTemporalRaoInput(temporalData, powerGradientConstraints); assertEquals(temporalData, input.getRaoInputs()); assertEquals(Set.of(timestamp1, timestamp2, timestamp3), input.getTimestampsToRun()); + assertEquals(powerGradientConstraints, input.getPowerGradientConstraints()); } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluator.java index 4d7c67e349..8d0eff1b8d 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluator.java @@ -10,6 +10,7 @@ import com.powsybl.openrao.data.crac.api.State; import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.searchtreerao.commons.costevaluatorresult.AbsoluteCostEvaluatorResult; import com.powsybl.openrao.searchtreerao.commons.costevaluatorresult.CostEvaluatorResult; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; @@ -52,7 +53,7 @@ private double computeRangeActionCost(RangeAction rangeAction, State state, R return 0.0; } double activationCost = rangeAction.getActivationCost().orElse(0.0); - RangeAction.VariationDirection variationDirection = variation > 0 ? RangeAction.VariationDirection.UP : RangeAction.VariationDirection.DOWN; + VariationDirection variationDirection = variation > 0 ? VariationDirection.UP : VariationDirection.DOWN; return activationCost + Math.abs(variation) * rangeAction.getVariationCost(variationDirection).orElse(0.0); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluatorImplTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluatorImplTest.java index 920ca9283c..687a7a2da6 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluatorImplTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/RemedialActionCostEvaluatorImplTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.crac.api.rangeaction.HvdcRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.InjectionRangeAction; import com.powsybl.openrao.data.crac.api.rangeaction.PstRangeAction; -import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; +import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.result.api.RemedialActionActivationResult; @@ -42,33 +42,33 @@ void setUp() { PstRangeAction pstRangeAction1 = Mockito.mock(PstRangeAction.class); Mockito.when(pstRangeAction1.getActivationCost()).thenReturn(Optional.empty()); - Mockito.when(pstRangeAction1.getVariationCost(RangeAction.VariationDirection.UP)).thenReturn(Optional.of(1d)); - Mockito.when(pstRangeAction1.getVariationCost(RangeAction.VariationDirection.DOWN)).thenReturn(Optional.empty()); + Mockito.when(pstRangeAction1.getVariationCost(VariationDirection.UP)).thenReturn(Optional.of(1d)); + Mockito.when(pstRangeAction1.getVariationCost(VariationDirection.DOWN)).thenReturn(Optional.empty()); PstRangeAction pstRangeAction2 = Mockito.mock(PstRangeAction.class); Mockito.when(pstRangeAction2.getActivationCost()).thenReturn(Optional.of(10d)); - Mockito.when(pstRangeAction2.getVariationCost(RangeAction.VariationDirection.UP)).thenReturn(Optional.empty()); - Mockito.when(pstRangeAction2.getVariationCost(RangeAction.VariationDirection.DOWN)).thenReturn(Optional.empty()); + Mockito.when(pstRangeAction2.getVariationCost(VariationDirection.UP)).thenReturn(Optional.empty()); + Mockito.when(pstRangeAction2.getVariationCost(VariationDirection.DOWN)).thenReturn(Optional.empty()); InjectionRangeAction injectionRangeAction1 = Mockito.mock(InjectionRangeAction.class); Mockito.when(injectionRangeAction1.getActivationCost()).thenReturn(Optional.of(5d)); - Mockito.when(injectionRangeAction1.getVariationCost(RangeAction.VariationDirection.UP)).thenReturn(Optional.of(150d)); - Mockito.when(injectionRangeAction1.getVariationCost(RangeAction.VariationDirection.DOWN)).thenReturn(Optional.of(200d)); + Mockito.when(injectionRangeAction1.getVariationCost(VariationDirection.UP)).thenReturn(Optional.of(150d)); + Mockito.when(injectionRangeAction1.getVariationCost(VariationDirection.DOWN)).thenReturn(Optional.of(200d)); InjectionRangeAction injectionRangeAction2 = Mockito.mock(InjectionRangeAction.class); Mockito.when(injectionRangeAction2.getActivationCost()).thenReturn(Optional.of(0.25)); - Mockito.when(injectionRangeAction2.getVariationCost(RangeAction.VariationDirection.UP)).thenReturn(Optional.of(200d)); - Mockito.when(injectionRangeAction2.getVariationCost(RangeAction.VariationDirection.DOWN)).thenReturn(Optional.empty()); + Mockito.when(injectionRangeAction2.getVariationCost(VariationDirection.UP)).thenReturn(Optional.of(200d)); + Mockito.when(injectionRangeAction2.getVariationCost(VariationDirection.DOWN)).thenReturn(Optional.empty()); HvdcRangeAction hvdcRangeAction1 = Mockito.mock(HvdcRangeAction.class); Mockito.when(hvdcRangeAction1.getActivationCost()).thenReturn(Optional.of(100d)); - Mockito.when(hvdcRangeAction1.getVariationCost(RangeAction.VariationDirection.UP)).thenReturn(Optional.of(10d)); - Mockito.when(hvdcRangeAction1.getVariationCost(RangeAction.VariationDirection.DOWN)).thenReturn(Optional.of(15d)); + Mockito.when(hvdcRangeAction1.getVariationCost(VariationDirection.UP)).thenReturn(Optional.of(10d)); + Mockito.when(hvdcRangeAction1.getVariationCost(VariationDirection.DOWN)).thenReturn(Optional.of(15d)); HvdcRangeAction hvdcRangeAction2 = Mockito.mock(HvdcRangeAction.class); Mockito.when(hvdcRangeAction2.getActivationCost()).thenReturn(Optional.of(200d)); - Mockito.when(hvdcRangeAction2.getVariationCost(RangeAction.VariationDirection.UP)).thenReturn(Optional.of(0.1)); - Mockito.when(hvdcRangeAction2.getVariationCost(RangeAction.VariationDirection.DOWN)).thenReturn(Optional.empty()); + Mockito.when(hvdcRangeAction2.getVariationCost(VariationDirection.UP)).thenReturn(Optional.of(0.1)); + Mockito.when(hvdcRangeAction2.getVariationCost(VariationDirection.DOWN)).thenReturn(Optional.empty()); NetworkAction topologyAction = Mockito.mock(NetworkAction.class); Mockito.when(topologyAction.getActivationCost()).thenReturn(Optional.of(20d));