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

Fix NPE in AutomatonPerimeterResultImpl #1195

Merged
merged 5 commits into from
Dec 2, 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 @@ -95,16 +95,16 @@ public AutomatonSimulator(Crac crac, RaoParameters raoParameters, ToolProvider t
*/
AutomatonPerimeterResultImpl simulateAutomatonState(State automatonState, Set<State> curativeStates, Network network, StateTree stateTree, TreeParameters automatonTreeParameters) {
TECHNICAL_LOGS.info("Optimizing automaton state {}.", automatonState.getId());
TECHNICAL_LOGS.info("Initial situation:");
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, prePerimeterSensitivityOutput, Set.of(automatonState), raoParameters.getObjectiveFunctionParameters().getType(), numberLoggedElementsDuringRao);

PrePerimeterSensitivityAnalysis preAutoPstOptimizationSensitivityAnalysis = getPreAutoPerimeterSensitivityAnalysis(automatonState, curativeStates);

// Sensitivity analysis failed :
if (prePerimeterSensitivityOutput.getSensitivityStatus(automatonState) == ComputationStatus.FAILURE) {
return createFailedAutomatonPerimeterResult(automatonState, prePerimeterSensitivityOutput, new HashSet<>(), "before");
}

TECHNICAL_LOGS.info("Initial situation:");
RaoLogger.logMostLimitingElementsResults(TECHNICAL_LOGS, prePerimeterSensitivityOutput, Set.of(automatonState), raoParameters.getObjectiveFunctionParameters().getType(), numberLoggedElementsDuringRao);

// I) Simulate FORCED topological automatons
TopoAutomatonSimulationResult topoSimulationResult = simulateTopologicalAutomatons(automatonState, network, preAutoPstOptimizationSensitivityAnalysis);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ private static Map<State, Map<RangeAction<?>, Double>> buildSetPointResultsMap(C
correspondanceMap.forEach((pra, associatedCras) -> {
setPointResults.get(preventiveState).put(pra, firstPreventiveResult.getOptimizedSetpoint(pra, preventiveState));
associatedCras.forEach(cra -> contingencyResults.forEach((state, result) -> {
if (crac.isRangeActionAvailableInState(cra, state)) {
if (crac.isRangeActionAvailableInState(cra, state) && result.getComputationStatus() != FAILURE) {
setPointResults.putIfAbsent(state, new HashMap<>());
setPointResults.get(state).put(pra, result.getOptimizedSetpoint(cra, state));
}
Expand All @@ -470,7 +470,7 @@ private static Map<State, Map<RangeAction<?>, Double>> buildSetPointResultsMap(C
multipleInstantRangeActions.forEach(ra -> {
setPointResults.get(preventiveState).put(ra, firstPreventiveResult.getOptimizedSetpoint(ra, preventiveState));
contingencyResults.forEach((state, result) -> {
if (crac.isRangeActionAvailableInState(ra, state)) {
if (crac.isRangeActionAvailableInState(ra, state) && result.getComputationStatus() != FAILURE) {
setPointResults.putIfAbsent(state, new HashMap<>());
setPointResults.get(state).put(ra, result.getOptimizedSetpoint(ra, state));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Map<PstRangeAction, Integer> getOptimizedTapsOnState(State state) {

@Override
public ComputationStatus getSensitivityStatus() {
return postAutomatonSensitivityAnalysisOutput.getSensitivityStatus();
return postAutomatonSensitivityAnalysisOutput.getSensitivityStatus(optimizedState);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public Map<PstRangeAction, Integer> getOptimizedTapsOnState(State state) {

@Override
public ComputationStatus getSensitivityStatus() {
return postCraSensitivitySensitivityResult.getSensitivityStatus();
return postCraSensitivitySensitivityResult.getSensitivityStatus(state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void testWrongState() {

@Test
void testGetSensitivityStatus() {
when(postAutoSensitivity.getSensitivityStatus()).thenReturn(ComputationStatus.DEFAULT);
when(postAutoSensitivity.getSensitivityStatus(state1)).thenReturn(ComputationStatus.DEFAULT);
assertEquals(ComputationStatus.DEFAULT, result.getSensitivityStatus());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ public SensitivityComputationStatus getStatus() {
}

public SensitivityComputationStatus getStatus(State state) {
if (status == SensitivityComputationStatus.FAILURE) {
return status;
}
Optional<Contingency> optionalContingency = state.getContingency();
if (optionalContingency.isPresent()) {
List<Integer> possibleInstants = postContingencyResults.keySet().stream()
Expand Down