-
Notifications
You must be signed in to change notification settings - Fork 8
Add forced actions in new RodaParameters extension #1691
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
Merged
+937
−7
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8253c67
Add forced actions in new RodaParameters extension
pet-mit e36edd9
checkstyle
pet-mit 8af1167
add roda to distribution pom
pet-mit 5575e34
try adding tests to distribution to measure cucumber coverage
pet-mit 7a855ad
revert last commit
pet-mit a1de182
add tests
pet-mit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...timisation/roda/src/main/java/com/powsybl/openrao/roda/parameters/JsonRodaParameters.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /* | ||
| * Copyright (c) 2026, 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.roda.parameters; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonGenerator; | ||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.databind.DeserializationContext; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.SerializerProvider; | ||
| import com.google.auto.service.AutoService; | ||
| import com.powsybl.action.ActionList; | ||
| import com.powsybl.action.json.ActionJsonModule; | ||
| import com.powsybl.commons.json.JsonUtil; | ||
| import com.powsybl.openrao.commons.OpenRaoException; | ||
| import com.powsybl.openrao.raoapi.json.JsonRaoParameters; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * RODA parameters extension json serializer & deserializer. | ||
| * Depends on PowSyBl's ActionList serializer & deserializer. | ||
| * | ||
| * @author Peter Mitri {@literal <peter.mitri at rte-france.com>} | ||
| */ | ||
| @AutoService(JsonRaoParameters.ExtensionSerializer.class) | ||
| public class JsonRodaParameters implements JsonRaoParameters.ExtensionSerializer<RodaParameters> { | ||
|
|
||
| private static final String PREVENTIVE_ACTION_LIST = "forced-preventive-actions-list"; | ||
|
|
||
| @Override | ||
| public void serialize(RodaParameters rodaParameters, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { | ||
| jsonGenerator.writeStartObject(); | ||
| jsonGenerator.writeFieldName(PREVENTIVE_ACTION_LIST); | ||
| createObjectMapper().writeValue(jsonGenerator, new ActionList(rodaParameters.getForcedPreventiveActions())); | ||
| jsonGenerator.writeEndObject(); | ||
| } | ||
|
|
||
| private static ObjectMapper createObjectMapper() { | ||
| return JsonUtil.createObjectMapper() | ||
| .registerModule(new ActionJsonModule()); | ||
| } | ||
|
|
||
| @Override | ||
| public RodaParameters deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { | ||
| ActionList actionList = null; | ||
| while (!jsonParser.nextToken().isStructEnd()) { | ||
| if (jsonParser.currentName().equals(PREVENTIVE_ACTION_LIST)) { | ||
| jsonParser.nextToken(); | ||
| actionList = createObjectMapper().readValue(jsonParser, ActionList.class); | ||
| } else { | ||
| throw new OpenRaoException("Unexpected token: " + jsonParser.currentName()); | ||
| } | ||
| } | ||
| if (actionList == null) { | ||
| return new RodaParameters(List.of()); | ||
| } | ||
| return new RodaParameters(actionList.getActions()); | ||
| } | ||
|
|
||
| @Override | ||
| public String getExtensionName() { | ||
| return RodaParameters.EXTENSION_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public String getCategoryName() { | ||
| return "rao-parameters"; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? super RodaParameters> getExtensionClass() { | ||
| return RodaParameters.class; | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
ra-optimisation/roda/src/main/java/com/powsybl/openrao/roda/parameters/RodaParameters.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright (c) 2026, 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.roda.parameters; | ||
|
|
||
| import com.powsybl.action.Action; | ||
| import com.powsybl.commons.extensions.AbstractExtension; | ||
| import com.powsybl.openrao.raoapi.parameters.RaoParameters; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * RODA specific RAO parameters. | ||
| * For now, only allows forcing actions on the network before running RAO. | ||
| * Could be useful to avoid pre-processing network multiple times (for example when testing topological changes | ||
| * in an outside loop). | ||
| * | ||
| * @author Peter Mitri {@literal <peter.mitri at rte-france.com>} | ||
| */ | ||
| public class RodaParameters extends AbstractExtension<RaoParameters> { | ||
| public static final String EXTENSION_NAME = "roda-parameters"; | ||
| private final List<Action> forcedPreventiveActions; | ||
|
|
||
| public RodaParameters(List<Action> forcedPreventiveActions) { | ||
| this.forcedPreventiveActions = Collections.unmodifiableList(forcedPreventiveActions); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return EXTENSION_NAME; | ||
| } | ||
|
|
||
| public List<Action> getForcedPreventiveActions() { | ||
| return forcedPreventiveActions; | ||
| } | ||
| } |
76 changes: 76 additions & 0 deletions
76
ra-optimisation/roda/src/test/java/com/powsybl/openrao/roda/RodaTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright (c) 2026, 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.roda; | ||
|
|
||
| import ch.qos.logback.classic.spi.ILoggingEvent; | ||
| import ch.qos.logback.core.read.ListAppender; | ||
| import com.powsybl.action.Action; | ||
| import com.powsybl.action.PhaseTapChangerTapPositionAction; | ||
| import com.powsybl.action.TerminalsConnectionAction; | ||
| import com.powsybl.iidm.network.Network; | ||
| import com.powsybl.openrao.commons.TemporalData; | ||
| import com.powsybl.openrao.commons.TemporalDataImpl; | ||
| import com.powsybl.openrao.commons.logs.RaoBusinessWarns; | ||
| import com.powsybl.openrao.data.crac.api.Crac; | ||
| import com.powsybl.openrao.data.crac.impl.utils.CommonCracCreation; | ||
| import com.powsybl.openrao.data.crac.impl.utils.NetworkImportsUtil; | ||
| import com.powsybl.openrao.raoapi.RaoInput; | ||
| import com.powsybl.openrao.roda.parameters.RodaParameters; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.time.OffsetDateTime; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
| * @author Peter Mitri {@literal <peter.mitri at rte-france.com>} | ||
| */ | ||
| class RodaTest { | ||
| Network network; | ||
| TemporalData<RaoInput> raoInput; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| network = NetworkImportsUtil.import12NodesNetwork(); | ||
| Crac crac = CommonCracCreation.createWithPreventivePstRange(); | ||
| String variantId = network.getVariantManager().getWorkingVariantId(); | ||
| raoInput = new TemporalDataImpl<>( | ||
| Map.of(OffsetDateTime.now(), RaoInput.buildWithPreventiveState(network, crac) | ||
| .withNetworkVariantId(variantId) | ||
| .build())); | ||
| } | ||
|
|
||
| @Test | ||
| void testApplyForcedActions() { | ||
| ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(RaoBusinessWarns.class); | ||
| ListAppender<ILoggingEvent> listAppender = new ListAppender<>(); | ||
| listAppender.start(); | ||
| logger.addAppender(listAppender); | ||
| List<ILoggingEvent> logsList = listAppender.list; | ||
|
|
||
| Action action1 = new PhaseTapChangerTapPositionAction("action1", "BBE2AA1 BBE3AA1 1", false, -8); | ||
| Action action2 = new TerminalsConnectionAction("action2", "FFR1AA1 FFR2AA1 1", true); | ||
| Action action3 = new TerminalsConnectionAction("wrong_action", "wrong_id", true); | ||
| RodaParameters rodaParameters = new RodaParameters(List.of(action1, action2, action3)); | ||
| Roda.applyForcedActions(raoInput, rodaParameters); | ||
| assertEquals(-8, network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1").getPhaseTapChanger().getTapPosition()); | ||
| assertFalse(network.getLine("FFR1AA1 FFR2AA1 1").getTerminal1().isConnected()); | ||
| assertFalse(network.getLine("FFR1AA1 FFR2AA1 1").getTerminal2().isConnected()); | ||
| assertTrue(logsList.stream().anyMatch(e -> e.getMessage().contains("Action 'wrong_action' could not be applied."))); | ||
| } | ||
|
|
||
| @Test | ||
| void testApplyForcedActionsNullOrEmpty() { | ||
| assertDoesNotThrow(() -> Roda.applyForcedActions(raoInput, null)); | ||
| assertDoesNotThrow(() -> Roda.applyForcedActions(raoInput, new RodaParameters(List.of()))); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.