-
Notifications
You must be signed in to change notification settings - Fork 8
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
Inter-Temporal Skeleton (MARMOT) #1258
Draft
bqth29
wants to merge
21
commits into
main
Choose a base branch
from
feature/inter-temporal-skeleton
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 14 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7ac12bd
marmot first implementation
bqth29 16f212c
typo
bqth29 4ff261c
add TODOs
bqth29 0e5fb86
typo in TODO
bqth29 60d1a2c
Merge branch 'main' into feature/inter-temporal-skeleton
1cf4acf
Merge branch 'main' into feature/inter-temporal-skeleton
60c36b9
add initial sensi computation
5aa34b6
add topologyChanger + UT
974329b
fic style
73a8788
Add Result Merger
cf0e924
Merge branch 'main' into feature/inter-temporal-skeleton
bqth29 6df4030
refactor skeleton
bqth29 d9efbbd
parameters order
bqth29 961927e
Merge branch 'main' into feature/inter-temporal-skeleton
bqth29 8675be8
introduce skeleton
Godelaine f7f581c
Merge branch 'main' into feature/inter-temporal-skeleton
bqth29 8ec4461
inter-temporal linear optimization inputs ready
bqth29 0574922
create fillers from linear optimizer input
bqth29 971ee44
adapt PowerGradientConstraintFiller inputs
Godelaine a255519
minor
Godelaine 6c76df6
fix inputs of gradient filler
bqth29 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
98 changes: 98 additions & 0 deletions
98
...sation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/marmot/Marmot.java
This file contains 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,98 @@ | ||
/* | ||
* Copyright (c) 2025, 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.searchtreerao.marmot; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.powsybl.openrao.commons.TemporalData; | ||
import com.powsybl.openrao.commons.TemporalDataImpl; | ||
import com.powsybl.openrao.data.raoresult.api.RaoResult; | ||
import com.powsybl.openrao.raoapi.InterTemporalRaoInput; | ||
import com.powsybl.openrao.raoapi.InterTemporalRaoProvider; | ||
import com.powsybl.openrao.raoapi.Rao; | ||
import com.powsybl.openrao.raoapi.RaoInput; | ||
import com.powsybl.openrao.raoapi.parameters.RaoParameters; | ||
import com.powsybl.openrao.searchtreerao.result.api.LinearOptimizationResult; | ||
import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
|
||
import static com.powsybl.openrao.searchtreerao.marmot.MarmotUtils.getPostOptimizationResults; | ||
import static com.powsybl.openrao.searchtreerao.marmot.MarmotUtils.getTopologicalOptimizationResult; | ||
import static com.powsybl.openrao.searchtreerao.marmot.MarmotUtils.runInitialPrePerimeterSensitivityAnalysis; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
* @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
*/ | ||
@AutoService(InterTemporalRaoProvider.class) | ||
public class Marmot implements InterTemporalRaoProvider { | ||
|
||
private static final String INTER_TEMPORAL_RAO = "InterTemporalRao"; | ||
private static final String VERSION = "1.0.0"; | ||
|
||
@Override | ||
public CompletableFuture<TemporalData<RaoResult>> run(InterTemporalRaoInput raoInput, RaoParameters raoParameters) { | ||
// 1. Run independent RAOs to compute optimal preventive topological remedial actions | ||
TemporalData<RaoResult> topologicalOptimizationResults = runTopologicalOptimization(raoInput.getRaoInputs(), raoParameters); | ||
|
||
// if no inter-temporal constraints are defined, the results can be returned | ||
if (raoInput.getPowerGradientConstraints().isEmpty()) { | ||
return CompletableFuture.completedFuture(topologicalOptimizationResults); | ||
} | ||
|
||
// 2. Apply preventive topological remedial actions | ||
applyPreventiveTopologicalActionsOnNetwork(raoInput.getRaoInputs(), topologicalOptimizationResults); | ||
|
||
// 3. Run initial sensitivity analysis on all timestamps | ||
TemporalData<PrePerimeterResult> prePerimeterResults = runAllInitialPrePerimeterSensitivityAnalysis(raoInput.getRaoInputs(), raoParameters); | ||
|
||
// 4. Create and iteratively solve MIP to find optimal range actions' set-points | ||
TemporalData<LinearOptimizationResult> linearOptimizationResults = optimizeLinearRemedialActions(raoInput, prePerimeterResults, raoParameters); | ||
|
||
// 5. Merge topological and linear result | ||
TemporalData<RaoResult> mergedRaoResults = mergeTopologicalAndLinearOptimizationResults(raoInput.getRaoInputs(), prePerimeterResults, linearOptimizationResults, topologicalOptimizationResults); | ||
|
||
return CompletableFuture.completedFuture(mergedRaoResults); | ||
} | ||
|
||
private static TemporalData<RaoResult> runTopologicalOptimization(TemporalData<RaoInput> raoInputs, RaoParameters raoParameters) { | ||
return raoInputs.map(individualRaoInput -> Rao.run(individualRaoInput, raoParameters)); | ||
} | ||
|
||
private static void applyPreventiveTopologicalActionsOnNetwork(TemporalData<RaoInput> raoInputs, TemporalData<RaoResult> topologicalOptimizationResults) { | ||
getTopologicalOptimizationResult(raoInputs, topologicalOptimizationResults) | ||
.getDataPerTimestamp() | ||
.values() | ||
.forEach(TopologicalOptimizationResult::applyTopologicalActions); | ||
// TODO: also handle curative remedial actions | ||
} | ||
|
||
private static TemporalData<PrePerimeterResult> runAllInitialPrePerimeterSensitivityAnalysis(TemporalData<RaoInput> raoInputs, RaoParameters raoParameters) { | ||
return raoInputs.map(individualRaoInput -> runInitialPrePerimeterSensitivityAnalysis(individualRaoInput, raoParameters)); | ||
} | ||
|
||
private static TemporalData<LinearOptimizationResult> optimizeLinearRemedialActions(InterTemporalRaoInput raoInput, TemporalData<PrePerimeterResult> prePerimeterResults, RaoParameters parameters) { | ||
// TODO: create MIP with all timestamps and power gradient constraints | ||
return new TemporalDataImpl<>(); | ||
} | ||
|
||
private static TemporalData<RaoResult> mergeTopologicalAndLinearOptimizationResults(TemporalData<RaoInput> raoInputs, TemporalData<PrePerimeterResult> prePerimeterResults, TemporalData<LinearOptimizationResult> linearOptimizationResults, TemporalData<RaoResult> topologicalOptimizationResults) { | ||
// TODO: add curative RAs (range action and topological) | ||
return getPostOptimizationResults(raoInputs, prePerimeterResults, linearOptimizationResults, topologicalOptimizationResults).map(PostOptimizationResult::merge); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return INTER_TEMPORAL_RAO; | ||
} | ||
|
||
@Override | ||
public String getVersion() { | ||
return VERSION; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...n/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/marmot/MarmotUtils.java
This file contains 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,69 @@ | ||
/* | ||
* Copyright (c) 2025, 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.searchtreerao.marmot; | ||
|
||
import com.powsybl.iidm.network.Network; | ||
import com.powsybl.openrao.commons.TemporalData; | ||
import com.powsybl.openrao.commons.TemporalDataImpl; | ||
import com.powsybl.openrao.data.crac.api.Crac; | ||
import com.powsybl.openrao.data.crac.api.InstantKind; | ||
import com.powsybl.openrao.data.crac.api.State; | ||
import com.powsybl.openrao.data.crac.api.cnec.FlowCnec; | ||
import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction; | ||
import com.powsybl.openrao.data.crac.api.usagerule.UsageMethod; | ||
import com.powsybl.openrao.data.raoresult.api.RaoResult; | ||
import com.powsybl.openrao.raoapi.RaoInput; | ||
import com.powsybl.openrao.raoapi.parameters.RaoParameters; | ||
import com.powsybl.openrao.searchtreerao.castor.algorithm.PrePerimeterSensitivityAnalysis; | ||
import com.powsybl.openrao.searchtreerao.commons.ToolProvider; | ||
import com.powsybl.openrao.searchtreerao.result.api.LinearOptimizationResult; | ||
import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
* @author Roxane Chen {@literal <roxane.chen at rte-france.com>} | ||
*/ | ||
public final class MarmotUtils { | ||
|
||
private MarmotUtils() { | ||
} | ||
|
||
public static PrePerimeterResult runInitialPrePerimeterSensitivityAnalysis(RaoInput raoInput, RaoParameters raoParameters) { | ||
Crac crac = raoInput.getCrac(); | ||
Network network = raoInput.getNetwork(); | ||
State preventiveState = crac.getPreventiveState(); | ||
Set<RangeAction<?>> rangeActions = crac.getRangeActions(preventiveState, UsageMethod.AVAILABLE); | ||
return new PrePerimeterSensitivityAnalysis(getPreventivePerimeterCnecs(crac), rangeActions, raoParameters, ToolProvider.buildFromRaoInputAndParameters(raoInput, raoParameters)).runInitialSensitivityAnalysis(network, crac); | ||
} | ||
|
||
public static Set<FlowCnec> getPreventivePerimeterCnecs(Crac crac) { | ||
Set<FlowCnec> flowCnecs = crac.getFlowCnecs(crac.getPreventiveState()); | ||
crac.getStates(crac.getInstant(InstantKind.OUTAGE)).forEach(state -> flowCnecs.addAll(crac.getFlowCnecs(state))); | ||
return flowCnecs; | ||
} | ||
|
||
public static TemporalData<TopologicalOptimizationResult> getTopologicalOptimizationResult(TemporalData<RaoInput> raoInputs, TemporalData<RaoResult> topologicalOptimizationResults) { | ||
List<OffsetDateTime> timestamps = raoInputs.getTimestamps(); | ||
Map<OffsetDateTime, TopologicalOptimizationResult> topologicalOptimizationResultMap = new HashMap<>(); | ||
timestamps.forEach(timestamp -> topologicalOptimizationResultMap.put(timestamp, new TopologicalOptimizationResult(raoInputs.getData(timestamp).orElseThrow(), topologicalOptimizationResults.getData(timestamp).orElseThrow()))); | ||
return new TemporalDataImpl<>(topologicalOptimizationResultMap); | ||
} | ||
|
||
public static TemporalData<PostOptimizationResult> getPostOptimizationResults(TemporalData<RaoInput> raoInputs, TemporalData<PrePerimeterResult> initialResults, TemporalData<LinearOptimizationResult> linearOptimizationResults, TemporalData<RaoResult> topologicalOptimizationResults) { | ||
List<OffsetDateTime> timestamps = raoInputs.getTimestamps(); | ||
Map<OffsetDateTime, PostOptimizationResult> postOptimizationResults = new HashMap<>(); | ||
timestamps.forEach(timestamp -> postOptimizationResults.put(timestamp, new PostOptimizationResult(raoInputs.getData(timestamp).orElseThrow(), initialResults.getData(timestamp).orElseThrow(), linearOptimizationResults.getData(timestamp).orElseThrow(), topologicalOptimizationResults.getData(timestamp).orElseThrow()))); | ||
return new TemporalDataImpl<>(postOptimizationResults); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ee-rao/src/main/java/com/powsybl/openrao/searchtreerao/marmot/PostOptimizationResult.java
This file contains 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,33 @@ | ||
/* | ||
* Copyright (c) 2025, 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.searchtreerao.marmot; | ||
|
||
import com.powsybl.openrao.data.crac.api.Crac; | ||
import com.powsybl.openrao.data.crac.api.State; | ||
import com.powsybl.openrao.data.raoresult.api.RaoResult; | ||
import com.powsybl.openrao.raoapi.RaoInput; | ||
import com.powsybl.openrao.searchtreerao.result.api.LinearOptimizationResult; | ||
import com.powsybl.openrao.searchtreerao.result.api.OptimizationResult; | ||
import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; | ||
import com.powsybl.openrao.searchtreerao.result.impl.NetworkActionsResultImpl; | ||
import com.powsybl.openrao.searchtreerao.result.impl.OneStateOnlyRaoResultImpl; | ||
import com.powsybl.openrao.searchtreerao.result.impl.OptimizationResultImpl; | ||
|
||
import static com.powsybl.openrao.searchtreerao.marmot.MarmotUtils.getPreventivePerimeterCnecs; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public record PostOptimizationResult(RaoInput raoInput, PrePerimeterResult initialResult, LinearOptimizationResult linearOptimizationResult, RaoResult topologicalOptimizationResult) { | ||
public RaoResult merge() { | ||
Crac crac = raoInput.getCrac(); | ||
State preventiveState = crac.getPreventiveState(); | ||
OptimizationResult mergedOptimizationResult = new OptimizationResultImpl(linearOptimizationResult, linearOptimizationResult, linearOptimizationResult, new NetworkActionsResultImpl(topologicalOptimizationResult.getActivatedNetworkActionsDuringState(preventiveState)), linearOptimizationResult); | ||
return new OneStateOnlyRaoResultImpl(preventiveState, initialResult, mergedOptimizationResult, getPreventivePerimeterCnecs(crac)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...src/main/java/com/powsybl/openrao/searchtreerao/marmot/TopologicalOptimizationResult.java
This file contains 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,27 @@ | ||
/* | ||
* Copyright (c) 2025, 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.searchtreerao.marmot; | ||
|
||
import com.powsybl.openrao.data.raoresult.api.RaoResult; | ||
import com.powsybl.openrao.raoapi.RaoInput; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public record TopologicalOptimizationResult(RaoInput raoInput, RaoResult topologicalOptimizationResult) { | ||
private static final String VARIANT_NAME_SUFFIX = "_with_topological_actions"; | ||
|
||
public void applyTopologicalActions() { | ||
String currentNetworkVariantId = raoInput.getNetwork().getVariantManager().getWorkingVariantId(); | ||
String newNetworkVariantId = currentNetworkVariantId + VARIANT_NAME_SUFFIX; | ||
raoInput.getNetwork().getVariantManager().cloneVariant(currentNetworkVariantId, newNetworkVariantId); | ||
raoInput.getNetwork().getVariantManager().setWorkingVariant(newNetworkVariantId); | ||
topologicalOptimizationResult.getActivatedNetworkActionsDuringState(raoInput.getCrac().getPreventiveState()) | ||
.forEach(networkAction -> networkAction.apply(raoInput.getNetwork())); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't really understand the utility of this class. Can't we use raoResult ?