-
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
Merged
Changes from 3 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; | ||
| } | ||
| } |
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.