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

Export execution details #1193

Merged
merged 16 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -7,54 +7,18 @@

package com.powsybl.openrao.data.raoresult.api;

import java.util.Collections;
import java.util.Set;

/**
* Enum representing the different optimizations the rao went through
*
* @author Martin Belthle {@literal <martin.belthle at rte-france.com>}
*/

public enum OptimizationStepsExecuted {
SECOND_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION(true, true, false, Collections.emptySet()),
FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION(false, true, false, Collections.emptySet()),
SECOND_PREVENTIVE_IMPROVED_FIRST(true, false, false, Set.of(SECOND_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION)),
SECOND_PREVENTIVE_FELLBACK_TO_FIRST_PREVENTIVE_SITUATION(true, false, true, Set.of(SECOND_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION)),
FIRST_PREVENTIVE_ONLY(false, false, false, Set.of(FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION, SECOND_PREVENTIVE_IMPROVED_FIRST, SECOND_PREVENTIVE_FELLBACK_TO_FIRST_PREVENTIVE_SITUATION, SECOND_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION));

private final boolean secondPreventive;
private final boolean fellBackToInitialSituation;
private final boolean fellBackToFirstPreventiveSituation;
private final Set<OptimizationStepsExecuted> possibleOverwrite;

OptimizationStepsExecuted(boolean secondPreventive, boolean fellBackToInitialSituation, boolean fellBackToFirstPreventiveSituation, Set<OptimizationStepsExecuted> possibleOverwrite) {
this.secondPreventive = secondPreventive;
this.fellBackToInitialSituation = fellBackToInitialSituation;
this.fellBackToFirstPreventiveSituation = fellBackToFirstPreventiveSituation;
this.possibleOverwrite = possibleOverwrite;
}

public boolean hasRunSecondPreventive() {
return secondPreventive;
}

public boolean hasFallenBackToInitialSituation() {
return fellBackToInitialSituation;
}

public boolean hasFallenBackToFirstPreventiveSituation() {
return fellBackToFirstPreventiveSituation;
}

public Set<OptimizationStepsExecuted> getPossibleOverwrite() {
return possibleOverwrite;
}
public final class OptimizationStepsExecuted {
public static final String FIRST_PREVENTIVE_ONLY = "The RAO only went through first preventive";
public static final String FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION = "First preventive fell back to initial situation";
public static final String SECOND_PREVENTIVE_IMPROVED_FIRST = "Second preventive improved first preventive results";
public static final String SECOND_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION = "Second preventive fell back to initial situation";
public static final String SECOND_PREVENTIVE_FELLBACK_TO_FIRST_PREVENTIVE_SITUATION = "Second preventive fell back to first preventive results";

public boolean isOverwritePossible(OptimizationStepsExecuted optimizationStepsExecuted) {
if (!getPossibleOverwrite().isEmpty()) {
return getPossibleOverwrite().contains(optimizationStepsExecuted);
}
return false;
}
private OptimizationStepsExecuted() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ default boolean isActivated(State state, NetworkAction networkAction) {
/**
* Know which RAO steps were executed by the RAO
*/
OptimizationStepsExecuted getOptimizationStepsExecuted();
String getExecutionDetails();

void setOptimizationStepsExecuted(OptimizationStepsExecuted optimizationStepsExecuted);
void setExecutionDetails(String executionDetails);

/**
* Indicates whether the all the CNECs of a given type at a given instant are secure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ public Map<RangeAction<?>, Double> getOptimizedSetPointsOnState(State state) {
}

@Override
public void setOptimizationStepsExecuted(OptimizationStepsExecuted optimizationStepsExecuted) {
raoResult.setOptimizationStepsExecuted(optimizationStepsExecuted);
public void setExecutionDetails(String executionDetails) {
raoResult.setExecutionDetails(executionDetails);
}

@Override
Expand All @@ -182,7 +182,7 @@ public boolean isSecure() {
}

@Override
public OptimizationStepsExecuted getOptimizationStepsExecuted() {
return raoResult.getOptimizationStepsExecuted();
public String getExecutionDetails() {
return raoResult.getExecutionDetails();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ public Map<RangeAction<?>, Double> getOptimizedSetPointsOnState(State state) {
}

@Override
public OptimizationStepsExecuted getOptimizationStepsExecuted() {
public String getExecutionDetails() {
return null;
}

@Override
public void setOptimizationStepsExecuted(OptimizationStepsExecuted optimizationStepsExecuted) {
public void setExecutionDetails(String executionDetails) {
//not used
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,37 @@ public class RaoResultImpl implements RaoResult {

private final Crac crac;

private ComputationStatus sensitivityStatus;
private final Map<State, ComputationStatus> sensitivityStatusPerState = new HashMap<>();
private ComputationStatus computationStatus;
private final Map<State, ComputationStatus> computationStatusPerState = new HashMap<>();
private final Map<FlowCnec, FlowCnecResult> flowCnecResults = new HashMap<>();
private final Map<AngleCnec, AngleCnecResult> angleCnecResults = new HashMap<>();
private final Map<VoltageCnec, VoltageCnecResult> voltageCnecResults = new HashMap<>();
private final Map<NetworkAction, NetworkActionResult> networkActionResults = new HashMap<>();
private final Map<RangeAction<?>, RangeActionResult> rangeActionResults = new HashMap<>();
private final Map<String, CostResult> costResults = new HashMap<>();

private OptimizationStepsExecuted optimizationStepsExecuted = OptimizationStepsExecuted.FIRST_PREVENTIVE_ONLY;
private String executionDetails = OptimizationStepsExecuted.FIRST_PREVENTIVE_ONLY;

public RaoResultImpl(Crac crac) {
this.crac = crac;
}

public void setComputationStatus(ComputationStatus computationStatus) {
this.sensitivityStatus = computationStatus;
this.computationStatus = computationStatus;
}

public void setComputationStatus(State state, ComputationStatus computationStatus) {
this.sensitivityStatusPerState.put(state, computationStatus);
this.computationStatusPerState.put(state, computationStatus);
}

@Override
public ComputationStatus getComputationStatus() {
return sensitivityStatus;
return computationStatus;
}

@Override
public ComputationStatus getComputationStatus(State state) {
return sensitivityStatusPerState.getOrDefault(state, ComputationStatus.DEFAULT);
return computationStatusPerState.getOrDefault(state, ComputationStatus.DEFAULT);
}

private Instant checkOptimizedInstant(Instant optimizedInstant, FlowCnec flowCnec) {
Expand Down Expand Up @@ -324,12 +324,8 @@ private State lookupState(String contingencyId, Instant instant) {
}

@Override
public void setOptimizationStepsExecuted(OptimizationStepsExecuted optimizationStepsExecuted) {
if (this.optimizationStepsExecuted.equals(OptimizationStepsExecuted.FIRST_PREVENTIVE_ONLY)) {
this.optimizationStepsExecuted = optimizationStepsExecuted;
} else {
throw new OpenRaoException("The RaoResult object should not be modified outside of its usual routine");
}
public void setExecutionDetails(String executionDetails) {
this.executionDetails = executionDetails;
}

private boolean instantHasNoNegativeMargin(Instant optimizedInstant, PhysicalParameter... u) {
Expand Down Expand Up @@ -376,8 +372,8 @@ public boolean isSecure(Instant optimizedInstant, PhysicalParameter... u) {
if (ComputationStatus.FAILURE.equals(getComputationStatus())) {
return false;
}
if (sensitivityStatusPerState.keySet().stream().filter(state -> optimizedInstant.equals(state.getInstant()))
.anyMatch(state -> ComputationStatus.FAILURE.equals(sensitivityStatusPerState.get(state)))) {
if (computationStatusPerState.keySet().stream().filter(state -> optimizedInstant.equals(state.getInstant()))
.anyMatch(state -> ComputationStatus.FAILURE.equals(computationStatusPerState.get(state)))) {
return false;
}
return instantHasNoNegativeMargin(optimizedInstant, u);
Expand All @@ -389,7 +385,7 @@ public boolean isSecure(PhysicalParameter... u) {
}

@Override
public OptimizationStepsExecuted getOptimizationStepsExecuted() {
return optimizationStepsExecuted;
public String getExecutionDetails() {
return executionDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,11 @@ void testCostResults() {
}

@Test
void testOptimizedStepsExecuted() {
void testExecutionDetails() {
setUp();
assertFalse(raoResult.getOptimizationStepsExecuted().hasRunSecondPreventive());
raoResult.setOptimizationStepsExecuted(OptimizationStepsExecuted.FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION);
assertEquals(OptimizationStepsExecuted.FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION, raoResult.getOptimizationStepsExecuted());
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> raoResult.setOptimizationStepsExecuted(OptimizationStepsExecuted.FIRST_PREVENTIVE_ONLY));
assertEquals("The RaoResult object should not be modified outside of its usual routine", exception.getMessage());
exception = assertThrows(OpenRaoException.class, () -> raoResult.setOptimizationStepsExecuted(OptimizationStepsExecuted.SECOND_PREVENTIVE_FELLBACK_TO_FIRST_PREVENTIVE_SITUATION));
assertEquals("The RaoResult object should not be modified outside of its usual routine", exception.getMessage());
exception = assertThrows(OpenRaoException.class, () -> raoResult.setOptimizationStepsExecuted(OptimizationStepsExecuted.FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION));
assertEquals("The RaoResult object should not be modified outside of its usual routine", exception.getMessage());
assertEquals(OptimizationStepsExecuted.FIRST_PREVENTIVE_ONLY, raoResult.getExecutionDetails());
raoResult.setExecutionDetails(OptimizationStepsExecuted.FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION);
assertEquals(OptimizationStepsExecuted.FIRST_PREVENTIVE_FELLBACK_TO_INITIAL_SITUATION, raoResult.getExecutionDetails());
}

@Test
Expand Down
Loading
Loading