diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/RaoParametersCommons.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/RaoParametersCommons.java index fa0bcae7af..ad2cb02b6e 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/RaoParametersCommons.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/RaoParametersCommons.java @@ -33,12 +33,12 @@ private RaoParametersCommons() { public static final String RANGE_ACTIONS_OPTIMIZATION = "range-actions-optimization"; public static final String RANGE_ACTIONS_OPTIMIZATION_SECTION = "rao-range-actions-optimization"; public static final String MAX_MIP_ITERATIONS = "max-mip-iterations"; - public static final String PST_PENALTY_COST = "pst-penalty-cost"; + public static final String PST_RA_MIN_IMPACT_THRESHOLD = "pst-ra-min-impact_threshold"; public static final String PST_SENSITIVITY_THRESHOLD = "pst-sensitivity-threshold"; public static final String PST_MODEL = "pst-model"; - public static final String HVDC_PENALTY_COST = "hvdc-penalty-cost"; + public static final String HVDC_RA_MIN_IMPACT_THRESHOLD = "hvdc-ra-min-impact_threshold"; public static final String HVDC_SENSITIVITY_THRESHOLD = "hvdc-sensitivity-threshold"; - public static final String INJECTION_RA_PENALTY_COST = "injection-ra-penalty-cost"; + public static final String INJECTION_RA_MIN_IMPACT_THRESHOLD = "injection-ra-min-impact_threshold"; public static final String INJECTION_RA_SENSITIVITY_THRESHOLD = "injection-ra-sensitivity-threshold"; public static final String LINEAR_OPTIMIZATION_SOLVER = "linear-optimization-solver"; public static final String LINEAR_OPTIMIZATION_SOLVER_SECTION = "rao-linear-optimization-solver"; @@ -120,6 +120,7 @@ private RaoParametersCommons() { public static final String RELATIVE_MARGINS_SECTION = "rao-relative-margins-parameters"; public static final String PTDF_BOUNDARIES = "ptdf-boundaries"; public static final String PTDF_SUM_LOWER_BOUND = "ptdf-sum-lower-bound"; + public static final String SEARCH_TREE_PARAMETERS = "open-rao-search-tree-parameters"; public static PtdfApproximation stringToPtdfApproximation(String string) { try { diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonRangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonRangeActionsOptimizationParameters.java index 90dde1a5e2..f191b2f691 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonRangeActionsOptimizationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonRangeActionsOptimizationParameters.java @@ -26,111 +26,30 @@ private JsonRangeActionsOptimizationParameters() { static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeObjectFieldStart(RANGE_ACTIONS_OPTIMIZATION); - jsonGenerator.writeNumberField(MAX_MIP_ITERATIONS, parameters.getRangeActionsOptimizationParameters().getMaxMipIterations()); - jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); - jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); - jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); - jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); - jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); - jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); - jsonGenerator.writeNumberField(INJECTION_RA_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getInjectionRaSensitivityThreshold()); - jsonGenerator.writeObjectField(RA_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); - jsonGenerator.writeObjectFieldStart(LINEAR_OPTIMIZATION_SOLVER); - jsonGenerator.writeObjectField(SOLVER, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolver()); - jsonGenerator.writeNumberField(RELATIVE_MIP_GAP, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getRelativeMipGap()); - jsonGenerator.writeStringField(SOLVER_SPECIFIC_PARAMETERS, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolverSpecificParameters()); - jsonGenerator.writeEndObject(); + jsonGenerator.writeNumberField(PST_RA_MIN_IMPACT_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstRAMinImpactThreshold()); + jsonGenerator.writeNumberField(HVDC_RA_MIN_IMPACT_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcRAMinImpactThreshold()); + jsonGenerator.writeNumberField(INJECTION_RA_MIN_IMPACT_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getInjectionRAMinImpactThreshold()); jsonGenerator.writeEndObject(); } static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { while (!jsonParser.nextToken().isStructEnd()) { switch (jsonParser.getCurrentName()) { - case MAX_MIP_ITERATIONS: + case PST_RA_MIN_IMPACT_THRESHOLD: jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setMaxMipIterations(jsonParser.getIntValue()); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(jsonParser.getDoubleValue()); break; - case PST_PENALTY_COST: + case HVDC_RA_MIN_IMPACT_THRESHOLD: jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(jsonParser.getDoubleValue()); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(jsonParser.getDoubleValue()); break; - case PST_SENSITIVITY_THRESHOLD: + case INJECTION_RA_MIN_IMPACT_THRESHOLD: jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(jsonParser.getDoubleValue()); - break; - case PST_MODEL: - raoParameters.getRangeActionsOptimizationParameters().setPstModel(stringToPstModel(jsonParser.nextTextValue())); - break; - case HVDC_PENALTY_COST: - jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(jsonParser.getDoubleValue()); - break; - case HVDC_SENSITIVITY_THRESHOLD: - jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(jsonParser.getDoubleValue()); - break; - case INJECTION_RA_PENALTY_COST: - jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(jsonParser.getDoubleValue()); - break; - case INJECTION_RA_SENSITIVITY_THRESHOLD: - jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(jsonParser.getDoubleValue()); - break; - case LINEAR_OPTIMIZATION_SOLVER: - jsonParser.nextToken(); - deserializeLinearOptimizationSolver(jsonParser, raoParameters); - break; - case RA_RANGE_SHRINKING: - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(stringToRaRangeShrinking(jsonParser.nextTextValue())); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(jsonParser.getDoubleValue()); break; default: throw new OpenRaoException(String.format("Cannot deserialize range action optimization parameters: unexpected field in %s (%s)", RANGE_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName())); } } } - - private static void deserializeLinearOptimizationSolver(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { - while (!jsonParser.nextToken().isStructEnd()) { - switch (jsonParser.getCurrentName()) { - case SOLVER: - raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(stringToSolver(jsonParser.nextTextValue())); - break; - case RELATIVE_MIP_GAP: - jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(jsonParser.getDoubleValue()); - break; - case SOLVER_SPECIFIC_PARAMETERS: - jsonParser.nextToken(); - raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters(jsonParser.getValueAsString()); - break; - default: - throw new OpenRaoException(String.format("Cannot deserialize linear optimization solver in range action optimization parameters: unexpected field in %s (%s)", LINEAR_OPTIMIZATION_SOLVER, jsonParser.getCurrentName())); - } - } - } - - private static RangeActionsOptimizationParameters.PstModel stringToPstModel(String string) { - try { - return RangeActionsOptimizationParameters.PstModel.valueOf(string); - } catch (IllegalArgumentException e) { - throw new OpenRaoException(String.format("Unknown Pst model: %s", string)); - } - } - - private static RangeActionsOptimizationParameters.RaRangeShrinking stringToRaRangeShrinking(String string) { - try { - return RangeActionsOptimizationParameters.RaRangeShrinking.valueOf(string); - } catch (IllegalArgumentException e) { - throw new OpenRaoException(String.format("Unknown Pst variation range shrinking: %s", string)); - } - } - - private static RangeActionsOptimizationParameters.Solver stringToSolver(String string) { - try { - return RangeActionsOptimizationParameters.Solver.valueOf(string); - } catch (IllegalArgumentException e) { - throw new OpenRaoException(String.format("Unknown solver: %s", string)); - } - } } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonTopoOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonTopoOptimizationParameters.java index 5e8f170f34..6980231617 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonTopoOptimizationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonTopoOptimizationParameters.java @@ -27,44 +27,14 @@ private JsonTopoOptimizationParameters() { static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeObjectFieldStart(TOPOLOGICAL_ACTIONS_OPTIMIZATION); - jsonGenerator.writeNumberField(MAX_PREVENTIVE_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth()); - jsonGenerator.writeNumberField(MAX_AUTO_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth()); - jsonGenerator.writeNumberField(MAX_CURATIVE_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth()); - jsonGenerator.writeFieldName(PREDEFINED_COMBINATIONS); - jsonGenerator.writeStartArray(); - for (List naIdCombination : parameters.getTopoOptimizationParameters().getPredefinedCombinations()) { - jsonGenerator.writeStartArray(); - for (String naId : naIdCombination) { - jsonGenerator.writeString(naId); - } - jsonGenerator.writeEndArray(); - } - jsonGenerator.writeEndArray(); jsonGenerator.writeNumberField(RELATIVE_MINIMUM_IMPACT_THRESHOLD, parameters.getTopoOptimizationParameters().getRelativeMinImpactThreshold()); jsonGenerator.writeNumberField(ABSOLUTE_MINIMUM_IMPACT_THRESHOLD, parameters.getTopoOptimizationParameters().getAbsoluteMinImpactThreshold()); - jsonGenerator.writeBooleanField(SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT, parameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement()); - jsonGenerator.writeNumberField(MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS, parameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions()); jsonGenerator.writeEndObject(); } static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { while (!jsonParser.nextToken().isStructEnd()) { switch (jsonParser.getCurrentName()) { - case MAX_PREVENTIVE_SEARCH_TREE_DEPTH: - jsonParser.nextToken(); - raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(jsonParser.getIntValue()); - break; - case MAX_AUTO_SEARCH_TREE_DEPTH: - jsonParser.nextToken(); - raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(jsonParser.getIntValue()); - break; - case MAX_CURATIVE_SEARCH_TREE_DEPTH: - jsonParser.nextToken(); - raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(jsonParser.getIntValue()); - break; - case PREDEFINED_COMBINATIONS: - raoParameters.getTopoOptimizationParameters().setPredefinedCombinations(readListOfListOfString(jsonParser)); - break; case RELATIVE_MINIMUM_IMPACT_THRESHOLD: jsonParser.nextToken(); raoParameters.getTopoOptimizationParameters().setRelativeMinImpactThreshold(jsonParser.getDoubleValue()); @@ -73,26 +43,9 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); raoParameters.getTopoOptimizationParameters().setAbsoluteMinImpactThreshold(jsonParser.getDoubleValue()); break; - case SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT: - jsonParser.nextToken(); - raoParameters.getTopoOptimizationParameters().setSkipActionsFarFromMostLimitingElement(jsonParser.getBooleanValue()); - break; - case MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS: - jsonParser.nextToken(); - raoParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(jsonParser.getIntValue()); - break; default: throw new OpenRaoException(String.format("Cannot deserialize topological optimization parameters: unexpected field in %s (%s)", TOPOLOGICAL_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName())); } } } - - private static List> readListOfListOfString(JsonParser jsonParser) throws IOException { - List> parsedListOfList = new ArrayList<>(); - jsonParser.nextToken(); - while (!jsonParser.nextToken().isStructEnd()) { - parsedListOfList.add(jsonParser.readValueAs(ArrayList.class)); - } - return parsedListOfList; - } } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java index 4940b38dc3..9a56750dbb 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java @@ -7,6 +7,8 @@ package com.powsybl.openrao.raoapi.json; import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.json.extensions.JsonMultiThreadingParameters; +import com.powsybl.openrao.raoapi.json.extensions.JsonSecondPreventiveRaoParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; @@ -59,14 +61,6 @@ public RaoParameters deserialize(JsonParser parser, DeserializationContext deser parser.nextToken(); JsonTopoOptimizationParameters.deserialize(parser, parameters); break; - case MULTI_THREADING: - parser.nextToken(); - JsonMultiThreadingParameters.deserialize(parser, parameters); - break; - case SECOND_PREVENTIVE_RAO: - parser.nextToken(); - JsonSecondPreventiveRaoParameters.deserialize(parser, parameters); - break; case NOT_OPTIMIZED_CNECS: parser.nextToken(); JsonNotOptimizedCnecsParameters.deserialize(parser, parameters); diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java index 4bec9c675f..b70f4af6e0 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java @@ -6,6 +6,8 @@ */ package com.powsybl.openrao.raoapi.json; +import com.powsybl.openrao.raoapi.json.extensions.JsonMultiThreadingParameters; +import com.powsybl.openrao.raoapi.json.extensions.JsonSecondPreventiveRaoParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; @@ -32,10 +34,8 @@ public void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, Ser JsonObjectiveFunctionParameters.serialize(parameters, jsonGenerator); JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator); JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator); - JsonSecondPreventiveRaoParameters.serialize(parameters, jsonGenerator); JsonNotOptimizedCnecsParameters.serialize(parameters, jsonGenerator); JsonLoadFlowAndSensitivityComputationParameters.serialize(parameters, jsonGenerator, serializerProvider); - JsonMultiThreadingParameters.serialize(parameters, jsonGenerator); JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonRaoParameters.getExtensionSerializers()); jsonGenerator.writeEndObject(); } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java new file mode 100644 index 0000000000..af30b39925 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023, 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.raoapi.json.extensions; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters; + +import java.io.IOException; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * @author Godelaine de Montmorillon {@literal } + */ +final class JsonLoadFlowAndSensitivityComputationParameters { + + private JsonLoadFlowAndSensitivityComputationParameters() { + } + + static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeObjectFieldStart(LOAD_FLOW_AND_SENSITIVITY_COMPUTATION); + jsonGenerator.writeStringField(LOAD_FLOW_PROVIDER, parameters.getLoadFlowAndSensitivityParameters().getLoadFlowProvider()); + jsonGenerator.writeStringField(SENSITIVITY_PROVIDER, parameters.getLoadFlowAndSensitivityParameters().getSensitivityProvider()); + jsonGenerator.writeNumberField(SENSITIVITY_FAILURE_OVERCOST, parameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost()); + jsonGenerator.writeFieldName(SENSITIVITY_PARAMETERS); + serializerProvider.defaultSerializeValue(parameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters(), jsonGenerator); + jsonGenerator.writeEndObject(); + } + + static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + switch (jsonParser.getCurrentName()) { + case LOAD_FLOW_PROVIDER: + jsonParser.nextToken(); + raoParameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider(jsonParser.getValueAsString()); + break; + case SENSITIVITY_PROVIDER: + jsonParser.nextToken(); + raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider(jsonParser.getValueAsString()); + break; + case SENSITIVITY_FAILURE_OVERCOST: + jsonParser.nextToken(); + raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(jsonParser.getValueAsDouble()); + break; + case SENSITIVITY_PARAMETERS: + jsonParser.nextToken(); + raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityWithLoadFlowParameters(JsonSensitivityAnalysisParameters.createObjectMapper().readerForUpdating(raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters()).readValue(jsonParser)); + break; + default: + throw new OpenRaoException(String.format("Cannot deserialize load flow and sensitivity parameters: unexpected field in %s (%s)", LOAD_FLOW_AND_SENSITIVITY_COMPUTATION, jsonParser.getCurrentName())); + } + } + } +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonMultiThreadingParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java similarity index 91% rename from ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonMultiThreadingParameters.java rename to ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java index 0d3f47b907..3be0a88d6c 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonMultiThreadingParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java @@ -1,10 +1,11 @@ /* - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. + * 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/. + * SPDX-License-Identifier: MPL-2.0 */ -package com.powsybl.openrao.raoapi.json; +package com.powsybl.openrao.raoapi.json.extensions; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.raoapi.parameters.RaoParameters; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonObjectiveFunctionParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonObjectiveFunctionParameters.java new file mode 100644 index 0000000000..4e0c770963 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonObjectiveFunctionParameters.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023, 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.raoapi.json.extensions; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; + +import java.io.IOException; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * @author Godelaine de Montmorillon {@literal } + */ +final class JsonObjectiveFunctionParameters { + + private JsonObjectiveFunctionParameters() { + } + + static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException { + jsonGenerator.writeObjectFieldStart(OBJECTIVE_FUNCTION); + jsonGenerator.writeObjectField(TYPE, parameters.getObjectiveFunctionParameters().getType()); + jsonGenerator.writeNumberField(CURATIVE_MIN_OBJ_IMPROVEMENT, parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement()); + jsonGenerator.writeBooleanField(ENFORCE_CURATIVE_SECURITY, parameters.getObjectiveFunctionParameters().getEnforceCurativeSecurity()); + jsonGenerator.writeEndObject(); + } + + static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + switch (jsonParser.getCurrentName()) { + case TYPE: + raoParameters.getObjectiveFunctionParameters().setType(stringToObjectiveFunction(jsonParser.nextTextValue())); + break; + case CURATIVE_MIN_OBJ_IMPROVEMENT: + jsonParser.nextToken(); + raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(jsonParser.getValueAsDouble()); + break; + case ENFORCE_CURATIVE_SECURITY: + jsonParser.nextToken(); + raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(jsonParser.getBooleanValue()); + break; + default: + throw new OpenRaoException(String.format("Cannot deserialize objective function parameters: unexpected field in %s (%s)", OBJECTIVE_FUNCTION, jsonParser.getCurrentName())); + } + } + } + + private static ObjectiveFunctionParameters.ObjectiveFunctionType stringToObjectiveFunction(String string) { + try { + return ObjectiveFunctionParameters.ObjectiveFunctionType.valueOf(string); + } catch (IllegalArgumentException e) { + throw new OpenRaoException(String.format("Unknown objective function type value: %s", string)); + } + } +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonOpenRaoSearchTreeParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonOpenRaoSearchTreeParameters.java new file mode 100644 index 0000000000..5680612cb5 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonOpenRaoSearchTreeParameters.java @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.openrao.raoapi.json.extensions; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.google.auto.service.AutoService; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.json.*; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; + +import java.io.IOException; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +@AutoService(JsonRaoParameters.ExtensionSerializer.class) +public class JsonOpenRaoSearchTreeParameters implements JsonRaoParameters.ExtensionSerializer { + @Override + public void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeStartObject(); + jsonGenerator.writeStringField(VERSION, RAO_PARAMETERS_VERSION); + JsonObjectiveFunctionParameters.serialize(parameters, jsonGenerator); + JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator); + JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator); + JsonSecondPreventiveRaoParameters.serialize(parameters, jsonGenerator); + JsonNotOptimizedCnecsParameters.serialize(parameters, jsonGenerator); + JsonLoadFlowAndSensitivityComputationParameters.serialize(parameters, jsonGenerator, serializerProvider); + JsonMultiThreadingParameters.serialize(parameters, jsonGenerator); + jsonGenerator.writeEndObject(); + } + + @Override + public OpenRaoSearchTreeParameters deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + return deserializeAndUpdate(jsonParser, deserializationContext, new OpenRaoSearchTreeParameters()); + } + + @Override + public OpenRaoSearchTreeParameters deserializeAndUpdate(JsonParser parser, DeserializationContext deserializationContext, OpenRaoSearchTreeParameters parameters) throws IOException { + while (parser.nextToken() != JsonToken.END_OBJECT) { + switch (parser.getCurrentName()) { + case OBJECTIVE_FUNCTION: + parser.nextToken(); + JsonObjectiveFunctionParameters.deserialize(parser, parameters); + break; + case RANGE_ACTIONS_OPTIMIZATION: + parser.nextToken(); + JsonRangeActionsOptimizationParameters.deserialize(parser, parameters); + break; + case TOPOLOGICAL_ACTIONS_OPTIMIZATION: + parser.nextToken(); + JsonTopoOptimizationParameters.deserialize(parser, parameters); + break; + case MULTI_THREADING: + parser.nextToken(); + JsonMultiThreadingParameters.deserialize(parser, parameters); + break; + case SECOND_PREVENTIVE_RAO: + parser.nextToken(); + JsonSecondPreventiveRaoParameters.deserialize(parser, parameters); + break; + case LOAD_FLOW_AND_SENSITIVITY_COMPUTATION: + parser.nextToken(); + JsonLoadFlowAndSensitivityComputationParameters.deserialize(parser, parameters); + break; + default: + throw new OpenRaoException("Unexpected field in open rao search tree parameters: " + parser.getCurrentName()); + } + } + return parameters; + } + + @Override + public String getExtensionName() { + return SEARCH_TREE_PARAMETERS; + } + + @Override + public String getCategoryName() { + return "rao-parameters"; + } + + @Override + public Class getExtensionClass() { + return OpenRaoSearchTreeParameters.class; + } + +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonRangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonRangeActionsOptimizationParameters.java new file mode 100644 index 0000000000..432980ea2d --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonRangeActionsOptimizationParameters.java @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2023, 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.raoapi.json.extensions; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; + +import java.io.IOException; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * @author Godelaine de Montmorillon {@literal } + */ +final class JsonRangeActionsOptimizationParameters { + + private JsonRangeActionsOptimizationParameters() { + } + + static void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator) throws IOException { + jsonGenerator.writeObjectFieldStart(RANGE_ACTIONS_OPTIMIZATION); + jsonGenerator.writeNumberField(MAX_MIP_ITERATIONS, parameters.getRangeActionsOptimizationParameters().getMaxMipIterations()); + jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); + jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); + jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); + jsonGenerator.writeNumberField(INJECTION_RA_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getInjectionRaSensitivityThreshold()); + jsonGenerator.writeObjectField(RA_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); + jsonGenerator.writeObjectFieldStart(LINEAR_OPTIMIZATION_SOLVER); + jsonGenerator.writeObjectField(SOLVER, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolver()); + jsonGenerator.writeNumberField(RELATIVE_MIP_GAP, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getRelativeMipGap()); + jsonGenerator.writeStringField(SOLVER_SPECIFIC_PARAMETERS, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolverSpecificParameters()); + jsonGenerator.writeEndObject(); + jsonGenerator.writeEndObject(); + } + + static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + switch (jsonParser.getCurrentName()) { + case MAX_MIP_ITERATIONS: + jsonParser.nextToken(); + searchTreeParameters.getRangeActionsOptimizationParameters().setMaxMipIterations(jsonParser.getIntValue()); + break; + case PST_SENSITIVITY_THRESHOLD: + jsonParser.nextToken(); + searchTreeParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(jsonParser.getDoubleValue()); + break; + case PST_MODEL: + searchTreeParameters.getRangeActionsOptimizationParameters().setPstModel(stringToPstModel(jsonParser.nextTextValue())); + break; + case HVDC_SENSITIVITY_THRESHOLD: + jsonParser.nextToken(); + searchTreeParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(jsonParser.getDoubleValue()); + break; + case INJECTION_RA_SENSITIVITY_THRESHOLD: + jsonParser.nextToken(); + searchTreeParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(jsonParser.getDoubleValue()); + break; + case LINEAR_OPTIMIZATION_SOLVER: + jsonParser.nextToken(); + deserializeLinearOptimizationSolver(jsonParser, searchTreeParameters); + break; + case RA_RANGE_SHRINKING: + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(stringToRaRangeShrinking(jsonParser.nextTextValue())); + break; + default: + throw new OpenRaoException(String.format("Cannot deserialize range action optimization parameters: unexpected field in %s (%s)", RANGE_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName())); + } + } + } + + private static void deserializeLinearOptimizationSolver(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + switch (jsonParser.getCurrentName()) { + case SOLVER: + searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(stringToSolver(jsonParser.nextTextValue())); + break; + case RELATIVE_MIP_GAP: + jsonParser.nextToken(); + searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(jsonParser.getDoubleValue()); + break; + case SOLVER_SPECIFIC_PARAMETERS: + jsonParser.nextToken(); + searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters(jsonParser.getValueAsString()); + break; + default: + throw new OpenRaoException(String.format("Cannot deserialize linear optimization solver in range action optimization parameters: unexpected field in %s (%s)", LINEAR_OPTIMIZATION_SOLVER, jsonParser.getCurrentName())); + } + } + } + + private static OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.PstModel stringToPstModel(String string) { + try { + return OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.PstModel.valueOf(string); + } catch (IllegalArgumentException e) { + throw new OpenRaoException(String.format("Unknown Pst model: %s", string)); + } + } + + private static OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking stringToRaRangeShrinking(String string) { + try { + return OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.valueOf(string); + } catch (IllegalArgumentException e) { + throw new OpenRaoException(String.format("Unknown Pst variation range shrinking: %s", string)); + } + } + + private static OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.Solver stringToSolver(String string) { + try { + return OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.Solver.valueOf(string); + } catch (IllegalArgumentException e) { + throw new OpenRaoException(String.format("Unknown solver: %s", string)); + } + } +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonSecondPreventiveRaoParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonSecondPreventiveRaoParameters.java similarity index 66% rename from ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonSecondPreventiveRaoParameters.java rename to ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonSecondPreventiveRaoParameters.java index 57b4252ebe..fc2939fb38 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonSecondPreventiveRaoParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonSecondPreventiveRaoParameters.java @@ -1,14 +1,16 @@ /* - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. + * 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/. + * SPDX-License-Identifier: MPL-2.0 */ -package com.powsybl.openrao.raoapi.json; +package com.powsybl.openrao.raoapi.json.extensions; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.raoapi.parameters.RaoParameters; -import com.powsybl.openrao.raoapi.parameters.SecondPreventiveRaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -24,7 +26,7 @@ final class JsonSecondPreventiveRaoParameters { private JsonSecondPreventiveRaoParameters() { } - static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException { + static void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator) throws IOException { jsonGenerator.writeObjectFieldStart(SECOND_PREVENTIVE_RAO); jsonGenerator.writeObjectField(EXECUTION_CONDITION, parameters.getSecondPreventiveRaoParameters().getExecutionCondition()); jsonGenerator.writeBooleanField(RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS, parameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions()); @@ -32,19 +34,19 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeEndObject(); } - static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { + static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException { while (!jsonParser.nextToken().isStructEnd()) { switch (jsonParser.getCurrentName()) { case EXECUTION_CONDITION: - raoParameters.getSecondPreventiveRaoParameters().setExecutionCondition(stringToExecutionCondition(jsonParser.nextTextValue())); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(stringToExecutionCondition(jsonParser.nextTextValue())); break; case RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS: jsonParser.nextToken(); - raoParameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(jsonParser.getBooleanValue()); + searchTreeParameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(jsonParser.getBooleanValue()); break; case HINT_FROM_FIRST_PREVENTIVE_RAO: jsonParser.nextToken(); - raoParameters.getSecondPreventiveRaoParameters().setHintFromFirstPreventiveRao(jsonParser.getBooleanValue()); + searchTreeParameters.getSecondPreventiveRaoParameters().setHintFromFirstPreventiveRao(jsonParser.getBooleanValue()); break; default: throw new OpenRaoException(String.format("Cannot deserialize second preventive rao parameters: unexpected field in %s (%s)", SECOND_PREVENTIVE_RAO, jsonParser.getCurrentName())); diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonTopoOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonTopoOptimizationParameters.java new file mode 100644 index 0000000000..75170b34e3 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonTopoOptimizationParameters.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2023, 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.raoapi.json.extensions; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * @author Godelaine de Montmorillon {@literal } + */ +final class JsonTopoOptimizationParameters { + + private JsonTopoOptimizationParameters() { + } + + static void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator) throws IOException { + jsonGenerator.writeObjectFieldStart(TOPOLOGICAL_ACTIONS_OPTIMIZATION); + jsonGenerator.writeNumberField(MAX_PREVENTIVE_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth()); + jsonGenerator.writeNumberField(MAX_AUTO_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth()); + jsonGenerator.writeNumberField(MAX_CURATIVE_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth()); + jsonGenerator.writeFieldName(PREDEFINED_COMBINATIONS); + jsonGenerator.writeStartArray(); + for (List naIdCombination : parameters.getTopoOptimizationParameters().getPredefinedCombinations()) { + jsonGenerator.writeStartArray(); + for (String naId : naIdCombination) { + jsonGenerator.writeString(naId); + } + jsonGenerator.writeEndArray(); + } + jsonGenerator.writeEndArray(); + jsonGenerator.writeBooleanField(SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT, parameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement()); + jsonGenerator.writeNumberField(MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS, parameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions()); + jsonGenerator.writeEndObject(); + } + + static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + switch (jsonParser.getCurrentName()) { + case MAX_PREVENTIVE_SEARCH_TREE_DEPTH: + jsonParser.nextToken(); + searchTreeParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(jsonParser.getIntValue()); + break; + case MAX_AUTO_SEARCH_TREE_DEPTH: + jsonParser.nextToken(); + searchTreeParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(jsonParser.getIntValue()); + break; + case MAX_CURATIVE_SEARCH_TREE_DEPTH: + jsonParser.nextToken(); + searchTreeParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(jsonParser.getIntValue()); + break; + case PREDEFINED_COMBINATIONS: + searchTreeParameters.getTopoOptimizationParameters().setPredefinedCombinations(readListOfListOfString(jsonParser)); + break; + case SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT: + jsonParser.nextToken(); + searchTreeParameters.getTopoOptimizationParameters().setSkipActionsFarFromMostLimitingElement(jsonParser.getBooleanValue()); + break; + case MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS: + jsonParser.nextToken(); + searchTreeParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(jsonParser.getIntValue()); + break; + default: + throw new OpenRaoException(String.format("Cannot deserialize topological optimization parameters: unexpected field in %s (%s)", TOPOLOGICAL_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName())); + } + } + } + + private static List> readListOfListOfString(JsonParser jsonParser) throws IOException { + List> parsedListOfList = new ArrayList<>(); + jsonParser.nextToken(); + while (!jsonParser.nextToken().isStructEnd()) { + parsedListOfList.add(jsonParser.readValueAs(ArrayList.class)); + } + return parsedListOfList; + } +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java index f5d290dc93..0222212b65 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java @@ -21,13 +21,6 @@ * @author Godelaine de Montmorillon {@literal } */ public class LoadFlowAndSensitivityParameters { - private static final String DEFAULT_LOADFLOW_PROVIDER = "OpenLoadFlow"; - private static final String DEFAULT_SENSITIVITY_PROVIDER = "OpenLoadFlow"; - private static final double DEFAULT_SENSITIVITY_FAILURE_OVERCOST = 10000; - private String loadFlowProvider = DEFAULT_LOADFLOW_PROVIDER; - private String sensitivityProvider = DEFAULT_SENSITIVITY_PROVIDER; - - private double sensitivityFailureOvercost = DEFAULT_SENSITIVITY_FAILURE_OVERCOST; private SensitivityAnalysisParameters sensitivityWithLoadFlowParameters = cleanLoadFlowParameters(new SensitivityAnalysisParameters()); // Getters and setters @@ -39,33 +32,6 @@ public void setSensitivityWithLoadFlowParameters(SensitivityAnalysisParameters s this.sensitivityWithLoadFlowParameters = cleanLoadFlowParameters(sensitivityWithLoadFlowParameters); } - public String getLoadFlowProvider() { - return loadFlowProvider; - } - - public void setLoadFlowProvider(String loadFlowProvider) { - this.loadFlowProvider = loadFlowProvider; - } - - public String getSensitivityProvider() { - return sensitivityProvider; - } - - public void setSensitivityProvider(String sensitivityProvider) { - this.sensitivityProvider = sensitivityProvider; - } - - public double getSensitivityFailureOvercost() { - return sensitivityFailureOvercost; - } - - public void setSensitivityFailureOvercost(double sensitivityFailureOvercost) { - if (sensitivityFailureOvercost < 0) { - BUSINESS_WARNS.warn("The value {} for `sensitivity-failure-overcost` is smaller than 0. This would encourage the optimizer to make the loadflow diverge. Thus, it will be set to + {}", sensitivityFailureOvercost, -sensitivityFailureOvercost); - } - this.sensitivityFailureOvercost = Math.abs(sensitivityFailureOvercost); - } - public static LoadFlowAndSensitivityParameters load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); LoadFlowAndSensitivityParameters parameters = new LoadFlowAndSensitivityParameters(); diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ParametersUtil.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ParametersUtil.java index a57090d851..ac8e5cf4ea 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ParametersUtil.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ParametersUtil.java @@ -70,7 +70,7 @@ protected static List convertStringIntMapToList(Map map return list; } - protected static List> convertListToListOfList(List stringList) { + public static List> convertListToListOfList(List stringList) { List> listOfList = new ArrayList<>(); stringList.forEach(listEntry -> { String[] splitListEntry = listEntry.split("\\+"); @@ -83,7 +83,7 @@ protected static List> convertListToListOfList(List stringL return listOfList; } - protected static List convertListOfListToList(List> listOfList) { + public static List convertListOfListToList(List> listOfList) { List finalList = new ArrayList<>(); listOfList.forEach(subList -> { if (!subList.isEmpty()) { diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RangeActionsOptimizationParameters.java index 00896bb9d5..e7be5107e9 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RangeActionsOptimizationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RangeActionsOptimizationParameters.java @@ -7,7 +7,6 @@ package com.powsybl.openrao.raoapi.parameters; -import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.commons.config.PlatformConfig; import java.util.Objects; @@ -23,177 +22,37 @@ public class RangeActionsOptimizationParameters { // Default values - private static final int DEFAULT_MAX_MIP_ITERATIONS = 10; - private static final double DEFAULT_PST_PENALTY_COST = 0.01; - private static final double DEFAULT_PST_SENSITIVITY_THRESHOLD = 1e-6; - private static final PstModel DEFAULT_PST_MODEL = PstModel.CONTINUOUS; - private static final double DEFAULT_HVDC_PENALTY_COST = 0.001; - private static final double DEFAULT_HVDC_SENSITIVITY_THRESHOLD = 1e-6; - private static final double DEFAULT_INJECTION_RA_PENALTY_COST = 0.001; - private static final double DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD = 1e-6; - private static final RaRangeShrinking DEFAULT_RA_RANGE_SHRINKING = RaRangeShrinking.DISABLED; + private static final double DEFAULT_PST_RA_MIN_IMPACT_THRESHOLD = 0.01; + private static final double DEFAULT_HVDC_RA_MIN_IMPACT_THRESHOLD = 0.001; + private static final double DEFAULT_INJECTION_RA_MIN_IMPACT_THRESHOLD = 0.001; // Attributes - private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; - private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST; - private double pstSensitivityThreshold = DEFAULT_PST_SENSITIVITY_THRESHOLD; - private PstModel pstModel = DEFAULT_PST_MODEL; - private double hvdcPenaltyCost = DEFAULT_HVDC_PENALTY_COST; - private double hvdcSensitivityThreshold = DEFAULT_HVDC_SENSITIVITY_THRESHOLD; - private double injectionRaPenaltyCost = DEFAULT_INJECTION_RA_PENALTY_COST; - private double injectionRaSensitivityThreshold = DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD; - private LinearOptimizationSolver linearOptimizationSolver = new LinearOptimizationSolver(); - private RaRangeShrinking raRangeShrinking = DEFAULT_RA_RANGE_SHRINKING; - - public enum PstModel { - CONTINUOUS, - APPROXIMATED_INTEGERS - } - - public enum RaRangeShrinking { - DISABLED, - ENABLED, - ENABLED_IN_FIRST_PRAO_AND_CRAO - } - - public static class LinearOptimizationSolver { - private static final Solver DEFAULT_SOLVER = Solver.CBC; - public static final double DEFAULT_RELATIVE_MIP_GAP = 0.0001; - public static final String DEFAULT_SOLVER_SPECIFIC_PARAMETERS = null; - private Solver solver = DEFAULT_SOLVER; - private double relativeMipGap = DEFAULT_RELATIVE_MIP_GAP; - private String solverSpecificParameters = DEFAULT_SOLVER_SPECIFIC_PARAMETERS; - - public Solver getSolver() { - return solver; - } - - public void setSolver(Solver solver) { - this.solver = solver; - } - - public double getRelativeMipGap() { - return relativeMipGap; - } - - public void setRelativeMipGap(double relativeMipGap) { - this.relativeMipGap = relativeMipGap; - } - - public String getSolverSpecificParameters() { - return solverSpecificParameters; - } - - public void setSolverSpecificParameters(String solverSpecificParameters) { - this.solverSpecificParameters = solverSpecificParameters; - } - - public static LinearOptimizationSolver load(PlatformConfig platformConfig) { - Objects.requireNonNull(platformConfig); - LinearOptimizationSolver parameters = new LinearOptimizationSolver(); - platformConfig.getOptionalModuleConfig(LINEAR_OPTIMIZATION_SOLVER_SECTION) - .ifPresent(config -> { - parameters.setSolver(config.getEnumProperty(SOLVER, Solver.class, DEFAULT_SOLVER)); - parameters.setRelativeMipGap(config.getDoubleProperty(RELATIVE_MIP_GAP, DEFAULT_RELATIVE_MIP_GAP)); - parameters.setSolverSpecificParameters(config.getStringProperty(SOLVER_SPECIFIC_PARAMETERS, DEFAULT_SOLVER_SPECIFIC_PARAMETERS)); - }); - return parameters; - } - } - - public enum Solver { - CBC, - SCIP, - XPRESS - } + private double pstRAMinImpactThreshold = DEFAULT_PST_RA_MIN_IMPACT_THRESHOLD; + private double hvdcRAMinImpactThreshold = DEFAULT_HVDC_RA_MIN_IMPACT_THRESHOLD; + private double injectionRAMinImpactThreshold = DEFAULT_INJECTION_RA_MIN_IMPACT_THRESHOLD; // Getters and setters - public int getMaxMipIterations() { - return maxMipIterations; - } - - public void setMaxMipIterations(int maxMipIterations) { - this.maxMipIterations = maxMipIterations; - } - - public double getPstPenaltyCost() { - return pstPenaltyCost; - } - - public void setPstPenaltyCost(double pstPenaltyCost) { - this.pstPenaltyCost = pstPenaltyCost; - } - - public double getPstSensitivityThreshold() { - return pstSensitivityThreshold; - } - - public void setPstSensitivityThreshold(double pstSensitivityThreshold) { - if (pstSensitivityThreshold < 1e-6) { - throw new OpenRaoException("pstSensitivityThreshold should be greater than 1e-6, to avoid numerical issues."); - } - this.pstSensitivityThreshold = pstSensitivityThreshold; - } - - public double getHvdcPenaltyCost() { - return hvdcPenaltyCost; - } - - public void setHvdcPenaltyCost(double hvdcPenaltyCost) { - this.hvdcPenaltyCost = hvdcPenaltyCost; - } - - public double getHvdcSensitivityThreshold() { - return hvdcSensitivityThreshold; - } - - public void setHvdcSensitivityThreshold(double hvdcSensitivityThreshold) { - if (hvdcSensitivityThreshold < 1e-6) { - throw new OpenRaoException("hvdcSensitivityThreshold should be greater than 1e-6, to avoid numerical issues."); - } - this.hvdcSensitivityThreshold = hvdcSensitivityThreshold; - } - - public double getInjectionRaPenaltyCost() { - return injectionRaPenaltyCost; - } - - public void setInjectionRaPenaltyCost(double injectionRaPenaltyCost) { - this.injectionRaPenaltyCost = injectionRaPenaltyCost; - } - - public double getInjectionRaSensitivityThreshold() { - return injectionRaSensitivityThreshold; - } - - public void setInjectionRaSensitivityThreshold(double injectionRaSensitivityThreshold) { - if (injectionRaSensitivityThreshold < 1e-6) { - throw new OpenRaoException("injectionRaSensitivityThreshold should be greater than 1e-6, to avoid numerical issues."); - } - this.injectionRaSensitivityThreshold = injectionRaSensitivityThreshold; - } - - public LinearOptimizationSolver getLinearOptimizationSolver() { - return linearOptimizationSolver; + public double getPstRAMinImpactThreshold() { + return pstRAMinImpactThreshold; } - public void setPstModel(PstModel pstModel) { - this.pstModel = pstModel; + public void setPstRAMinImpactThreshold(double pstRAMinImpactThreshold) { + this.pstRAMinImpactThreshold = pstRAMinImpactThreshold; } - public PstModel getPstModel() { - return pstModel; + public double getHvdcRAMinImpactThreshold() { + return hvdcRAMinImpactThreshold; } - public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizationSolver) { - this.linearOptimizationSolver = linearOptimizationSolver; + public void setHvdcRAMinImpactThreshold(double hvdcRAMinImpactThreshold) { + this.hvdcRAMinImpactThreshold = hvdcRAMinImpactThreshold; } - public void setRaRangeShrinking(RaRangeShrinking raRangeShrinking) { - this.raRangeShrinking = raRangeShrinking; + public double getInjectionRAMinImpactThreshold() { + return injectionRAMinImpactThreshold; } - public RaRangeShrinking getRaRangeShrinking() { - return raRangeShrinking; + public void setInjectionRAMinImpactThreshold(double injectionRAMinImpactThreshold) { + this.injectionRAMinImpactThreshold = injectionRAMinImpactThreshold; } public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { @@ -201,17 +60,10 @@ public static RangeActionsOptimizationParameters load(PlatformConfig platformCon RangeActionsOptimizationParameters parameters = new RangeActionsOptimizationParameters(); platformConfig.getOptionalModuleConfig(RANGE_ACTIONS_OPTIMIZATION_SECTION) .ifPresent(config -> { - parameters.setMaxMipIterations(config.getIntProperty(MAX_MIP_ITERATIONS, DEFAULT_MAX_MIP_ITERATIONS)); - parameters.setPstPenaltyCost(config.getDoubleProperty(PST_PENALTY_COST, DEFAULT_PST_PENALTY_COST)); - parameters.setPstSensitivityThreshold(config.getDoubleProperty(PST_SENSITIVITY_THRESHOLD, DEFAULT_PST_SENSITIVITY_THRESHOLD)); - parameters.setPstModel(config.getEnumProperty(PST_MODEL, PstModel.class, DEFAULT_PST_MODEL)); - parameters.setHvdcPenaltyCost(config.getDoubleProperty(HVDC_PENALTY_COST, DEFAULT_HVDC_PENALTY_COST)); - parameters.setHvdcSensitivityThreshold(config.getDoubleProperty(HVDC_SENSITIVITY_THRESHOLD, DEFAULT_HVDC_SENSITIVITY_THRESHOLD)); - parameters.setInjectionRaPenaltyCost(config.getDoubleProperty(INJECTION_RA_PENALTY_COST, DEFAULT_INJECTION_RA_PENALTY_COST)); - parameters.setInjectionRaSensitivityThreshold(config.getDoubleProperty(INJECTION_RA_SENSITIVITY_THRESHOLD, DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD)); - parameters.setRaRangeShrinking(config.getEnumProperty(RA_RANGE_SHRINKING, RaRangeShrinking.class, DEFAULT_RA_RANGE_SHRINKING)); + parameters.setPstRAMinImpactThreshold(config.getDoubleProperty(PST_RA_MIN_IMPACT_THRESHOLD, DEFAULT_PST_RA_MIN_IMPACT_THRESHOLD)); + parameters.setHvdcRAMinImpactThreshold(config.getDoubleProperty(HVDC_RA_MIN_IMPACT_THRESHOLD, DEFAULT_HVDC_RA_MIN_IMPACT_THRESHOLD)); + parameters.setInjectionRAMinImpactThreshold(config.getDoubleProperty(INJECTION_RA_MIN_IMPACT_THRESHOLD, DEFAULT_INJECTION_RA_MIN_IMPACT_THRESHOLD)); }); - parameters.setLinearOptimizationSolver(LinearOptimizationSolver.load(platformConfig)); return parameters; } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java index 185a710b53..975a4e850d 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java @@ -14,6 +14,8 @@ import com.powsybl.commons.extensions.Extension; import com.powsybl.commons.extensions.ExtensionConfigLoader; import com.powsybl.commons.extensions.ExtensionProviders; +import com.powsybl.openrao.raoapi.parameters.extensions.MultithreadingParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import java.util.Objects; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/TopoOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/TopoOptimizationParameters.java index b66542433c..eeed0592f4 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/TopoOptimizationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/TopoOptimizationParameters.java @@ -21,37 +21,11 @@ */ public class TopoOptimizationParameters { // Default values - private static final int DEFAULT_MAX_SEARCH_TREE_DEPTH = Integer.MAX_VALUE; - private static final List> DEFAULT_PREDEFINED_COMBINATIONS = new ArrayList<>(); private static final double DEFAULT_RELATIVE_MIN_IMPACT_THRESHOLD = 0; private static final double DEFAULT_ABSOLUTE_MIN_IMPACT_THRESHOLD = 0; - private static final boolean DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT = false; - private static final int DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS = 2; // Attributes - private int maxPreventiveSearchTreeDepth = DEFAULT_MAX_SEARCH_TREE_DEPTH; - private int maxAutoSearchTreeDepth = DEFAULT_MAX_SEARCH_TREE_DEPTH; - private int maxCurativeSearchTreeDepth = DEFAULT_MAX_SEARCH_TREE_DEPTH; - private List> predefinedCombinations = DEFAULT_PREDEFINED_COMBINATIONS; private double relativeMinImpactThreshold = DEFAULT_RELATIVE_MIN_IMPACT_THRESHOLD; private double absoluteMinImpactThreshold = DEFAULT_ABSOLUTE_MIN_IMPACT_THRESHOLD; - private boolean skipActionsFarFromMostLimitingElement = DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT; - private int maxNumberOfBoundariesForSkippingActions = DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS; - - public void setMaxPreventiveSearchTreeDepth(int maxPreventiveSearchTreeDepth) { - this.maxPreventiveSearchTreeDepth = maxPreventiveSearchTreeDepth; - } - - public void setMaxAutoSearchTreeDepth(int maxAutoSearchTreeDepth) { - this.maxAutoSearchTreeDepth = maxAutoSearchTreeDepth; - } - - public void setMaxCurativeSearchTreeDepth(int maxCurativeSearchTreeDepth) { - this.maxCurativeSearchTreeDepth = maxCurativeSearchTreeDepth; - } - - public void setPredefinedCombinations(List> predefinedCombinations) { - this.predefinedCombinations = predefinedCombinations; - } public void setRelativeMinImpactThreshold(double relativeMinImpactThreshold) { if (relativeMinImpactThreshold < 0) { @@ -69,31 +43,6 @@ public void setAbsoluteMinImpactThreshold(double absoluteMinImpactThreshold) { this.absoluteMinImpactThreshold = absoluteMinImpactThreshold; } - public void setSkipActionsFarFromMostLimitingElement(boolean skipActionsFarFromMostLimitingElement) { - this.skipActionsFarFromMostLimitingElement = skipActionsFarFromMostLimitingElement; - } - - public void setMaxNumberOfBoundariesForSkippingActions(int maxNumberOfBoundariesForSkippingActions) { - if (maxNumberOfBoundariesForSkippingActions < 0) { - BUSINESS_WARNS.warn("The value {} provided for max number of boundaries for skipping actions is smaller than 0. It will be set to 0.", maxNumberOfBoundariesForSkippingActions); - this.maxNumberOfBoundariesForSkippingActions = 0; - } else { - this.maxNumberOfBoundariesForSkippingActions = maxNumberOfBoundariesForSkippingActions; - } - } - - public int getMaxPreventiveSearchTreeDepth() { - return maxPreventiveSearchTreeDepth; - } - - public int getMaxAutoSearchTreeDepth() { - return maxAutoSearchTreeDepth; - } - - public int getMaxCurativeSearchTreeDepth() { - return maxCurativeSearchTreeDepth; - } - public double getRelativeMinImpactThreshold() { return relativeMinImpactThreshold; } @@ -102,31 +51,13 @@ public double getAbsoluteMinImpactThreshold() { return absoluteMinImpactThreshold; } - public boolean getSkipActionsFarFromMostLimitingElement() { - return skipActionsFarFromMostLimitingElement; - } - - public int getMaxNumberOfBoundariesForSkippingActions() { - return maxNumberOfBoundariesForSkippingActions; - } - - public List> getPredefinedCombinations() { - return predefinedCombinations; - } - public static TopoOptimizationParameters load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); TopoOptimizationParameters parameters = new TopoOptimizationParameters(); platformConfig.getOptionalModuleConfig(TOPOLOGICAL_ACTIONS_OPTIMIZATION_SECTION) .ifPresent(config -> { - parameters.setMaxPreventiveSearchTreeDepth(config.getIntProperty(MAX_PREVENTIVE_SEARCH_TREE_DEPTH, DEFAULT_MAX_SEARCH_TREE_DEPTH)); - parameters.setMaxAutoSearchTreeDepth(config.getIntProperty(MAX_AUTO_SEARCH_TREE_DEPTH, DEFAULT_MAX_SEARCH_TREE_DEPTH)); - parameters.setMaxCurativeSearchTreeDepth(config.getIntProperty(MAX_CURATIVE_SEARCH_TREE_DEPTH, DEFAULT_MAX_SEARCH_TREE_DEPTH)); - parameters.setPredefinedCombinations(ParametersUtil.convertListToListOfList(config.getStringListProperty(PREDEFINED_COMBINATIONS, ParametersUtil.convertListOfListToList(DEFAULT_PREDEFINED_COMBINATIONS)))); parameters.setRelativeMinImpactThreshold(config.getDoubleProperty(RELATIVE_MINIMUM_IMPACT_THRESHOLD, DEFAULT_RELATIVE_MIN_IMPACT_THRESHOLD)); parameters.setAbsoluteMinImpactThreshold(config.getDoubleProperty(ABSOLUTE_MINIMUM_IMPACT_THRESHOLD, DEFAULT_ABSOLUTE_MIN_IMPACT_THRESHOLD)); - parameters.setSkipActionsFarFromMostLimitingElement(config.getBooleanProperty(SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT, DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT)); - parameters.setMaxNumberOfBoundariesForSkippingActions(config.getIntProperty(MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS, DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS)); }); return parameters; } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java new file mode 100644 index 0000000000..d46788b53e --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2023, 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.raoapi.parameters.extensions; + +import com.powsybl.commons.config.PlatformConfig; +import com.powsybl.loadflow.LoadFlowParameters; +import com.powsybl.sensitivity.SensitivityAnalysisParameters; + +import java.util.Objects; + +import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * LoadFlow and sensitivity computation parameters for RAO + * + * @author Godelaine de Montmorillon {@literal } + */ +public class LoadFlowAndSensitivityParameters { + private static final String DEFAULT_LOADFLOW_PROVIDER = "OpenLoadFlow"; + private static final String DEFAULT_SENSITIVITY_PROVIDER = "OpenLoadFlow"; + private static final double DEFAULT_SENSITIVITY_FAILURE_OVERCOST = 10000; + private String loadFlowProvider = DEFAULT_LOADFLOW_PROVIDER; + private String sensitivityProvider = DEFAULT_SENSITIVITY_PROVIDER; + + private double sensitivityFailureOvercost = DEFAULT_SENSITIVITY_FAILURE_OVERCOST; + private SensitivityAnalysisParameters sensitivityWithLoadFlowParameters = cleanLoadFlowParameters(new SensitivityAnalysisParameters()); + + // Getters and setters + public SensitivityAnalysisParameters getSensitivityWithLoadFlowParameters() { + return sensitivityWithLoadFlowParameters; + } + + public void setSensitivityWithLoadFlowParameters(SensitivityAnalysisParameters sensitivityWithLoadFlowParameters) { + this.sensitivityWithLoadFlowParameters = cleanLoadFlowParameters(sensitivityWithLoadFlowParameters); + } + + public String getLoadFlowProvider() { + return loadFlowProvider; + } + + public void setLoadFlowProvider(String loadFlowProvider) { + this.loadFlowProvider = loadFlowProvider; + } + + public String getSensitivityProvider() { + return sensitivityProvider; + } + + public void setSensitivityProvider(String sensitivityProvider) { + this.sensitivityProvider = sensitivityProvider; + } + + public double getSensitivityFailureOvercost() { + return sensitivityFailureOvercost; + } + + public void setSensitivityFailureOvercost(double sensitivityFailureOvercost) { + if (sensitivityFailureOvercost < 0) { + BUSINESS_WARNS.warn("The value {} for `sensitivity-failure-overcost` is smaller than 0. This would encourage the optimizer to make the loadflow diverge. Thus, it will be set to + {}", sensitivityFailureOvercost, -sensitivityFailureOvercost); + } + this.sensitivityFailureOvercost = Math.abs(sensitivityFailureOvercost); + } + + public static LoadFlowAndSensitivityParameters load(PlatformConfig platformConfig) { + Objects.requireNonNull(platformConfig); + LoadFlowAndSensitivityParameters parameters = new LoadFlowAndSensitivityParameters(); + platformConfig.getOptionalModuleConfig(LOAD_FLOW_AND_SENSITIVITY_COMPUTATION_SECTION) + .ifPresent(config -> { + parameters.setLoadFlowProvider(config.getStringProperty(LOAD_FLOW_PROVIDER, DEFAULT_LOADFLOW_PROVIDER)); + parameters.setSensitivityProvider(config.getStringProperty(SENSITIVITY_PROVIDER, DEFAULT_SENSITIVITY_PROVIDER)); + parameters.setSensitivityFailureOvercost(config.getDoubleProperty(SENSITIVITY_FAILURE_OVERCOST, DEFAULT_SENSITIVITY_FAILURE_OVERCOST)); + }); + parameters.setSensitivityWithLoadFlowParameters(SensitivityAnalysisParameters.load(platformConfig)); + return parameters; + } + + private SensitivityAnalysisParameters cleanLoadFlowParameters(SensitivityAnalysisParameters sensitivityAnalysisParameters) { + LoadFlowParameters loadFlowParameters = sensitivityAnalysisParameters.getLoadFlowParameters(); + // we have to clean load flow parameters. + // the slack bus must not be written because it could pollute the sensitivity analyses. + loadFlowParameters.setWriteSlackBus(false); + // in DC, as emulation AC is supported for LF but not for sensitivity analyses, it could + // lead to incoherence. + if (loadFlowParameters.isDc() && loadFlowParameters.isHvdcAcEmulation()) { + BUSINESS_WARNS.warn("The runs are in DC but the HvdcAcEmulation parameter is on: this is not compatible." + + "HvdcAcEmulation parameter set to false."); + loadFlowParameters.setHvdcAcEmulation(false); + } + return sensitivityAnalysisParameters; + } +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/MultithreadingParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java similarity index 95% rename from ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/MultithreadingParameters.java rename to ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java index 70ab475b0b..101c164345 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/MultithreadingParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java @@ -1,11 +1,12 @@ /* - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 */ -package com.powsybl.openrao.raoapi.parameters; +package com.powsybl.openrao.raoapi.parameters.extensions; import com.powsybl.commons.config.PlatformConfig; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParameters.java new file mode 100644 index 0000000000..c70e08a1b3 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParameters.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 + */ + +package com.powsybl.openrao.raoapi.parameters.extensions; + +import com.powsybl.commons.extensions.AbstractExtension; +import com.powsybl.openrao.raoapi.parameters.NotOptimizedCnecsParameters; +import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +public class OpenRaoSearchTreeParameters extends AbstractExtension { + private ObjectiveFunctionParameters objectiveFunctionParameters = new ObjectiveFunctionParameters(); + private RangeActionsOptimizationParameters rangeActionsOptimizationParameters = new RangeActionsOptimizationParameters(); + private TopoOptimizationParameters topoOptimizationParameters = new TopoOptimizationParameters(); + private MultithreadingParameters multithreadingParameters = new MultithreadingParameters(); + private SecondPreventiveRaoParameters secondPreventiveRaoParameters = new SecondPreventiveRaoParameters(); + private NotOptimizedCnecsParameters notOptimizedCnecsParameters = new NotOptimizedCnecsParameters(); + private LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = new LoadFlowAndSensitivityParameters(); + + // Getters and setters + public void setObjectiveFunctionParameters(ObjectiveFunctionParameters objectiveFunctionParameters) { + this.objectiveFunctionParameters = objectiveFunctionParameters; + } + + public void setRangeActionsOptimizationParameters(RangeActionsOptimizationParameters rangeActionsOptimizationParameters) { + this.rangeActionsOptimizationParameters = rangeActionsOptimizationParameters; + } + + public void setTopoOptimizationParameters(TopoOptimizationParameters topoOptimizationParameters) { + this.topoOptimizationParameters = topoOptimizationParameters; + } + + public void setMultithreadingParameters(MultithreadingParameters multithreadingParameters) { + this.multithreadingParameters = multithreadingParameters; + } + + public void setSecondPreventiveRaoParameters(SecondPreventiveRaoParameters secondPreventiveRaoParameters) { + this.secondPreventiveRaoParameters = secondPreventiveRaoParameters; + } + + public void setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters notOptimizedCnecsParameters) { + this.notOptimizedCnecsParameters = notOptimizedCnecsParameters; + } + + public void setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters) { + this.loadFlowAndSensitivityParameters = loadFlowAndSensitivityParameters; + } + + public ObjectiveFunctionParameters getObjectiveFunctionParameters() { + return objectiveFunctionParameters; + } + + public RangeActionsOptimizationParameters getRangeActionsOptimizationParameters() { + return rangeActionsOptimizationParameters; + } + + public TopoOptimizationParameters getTopoOptimizationParameters() { + return topoOptimizationParameters; + } + + public MultithreadingParameters getMultithreadingParameters() { + return multithreadingParameters; + } + + public SecondPreventiveRaoParameters getSecondPreventiveRaoParameters() { + return secondPreventiveRaoParameters; + } + + public NotOptimizedCnecsParameters getNotOptimizedCnecsParameters() { + return notOptimizedCnecsParameters; + } + + public LoadFlowAndSensitivityParameters getLoadFlowAndSensitivityParameters() { + return loadFlowAndSensitivityParameters; + } + + @Override + public String getName() { + return SEARCH_TREE_PARAMETERS; + } + +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java new file mode 100644 index 0000000000..b204e47846 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2023, 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.raoapi.parameters.extensions; + +import com.powsybl.commons.config.PlatformConfig; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; + +import java.util.Objects; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * Range actions optimization parameters for RAO + * + * @author Godelaine de Montmorillon {@literal } + * + */ +public class RangeActionsOptimizationParameters { + + // Default values + private static final int DEFAULT_MAX_MIP_ITERATIONS = 10; + private static final double DEFAULT_PST_SENSITIVITY_THRESHOLD = 1e-6; + private static final PstModel DEFAULT_PST_MODEL = PstModel.CONTINUOUS; + private static final double DEFAULT_HVDC_SENSITIVITY_THRESHOLD = 1e-6; + private static final double DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD = 1e-6; + private static final RaRangeShrinking DEFAULT_RA_RANGE_SHRINKING = RaRangeShrinking.DISABLED; + // Attributes + private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; + private double pstSensitivityThreshold = DEFAULT_PST_SENSITIVITY_THRESHOLD; + private PstModel pstModel = DEFAULT_PST_MODEL; + private double hvdcSensitivityThreshold = DEFAULT_HVDC_SENSITIVITY_THRESHOLD; + private double injectionRaSensitivityThreshold = DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD; + private LinearOptimizationSolver linearOptimizationSolver = new LinearOptimizationSolver(); + private RaRangeShrinking raRangeShrinking = DEFAULT_RA_RANGE_SHRINKING; + + public enum PstModel { + CONTINUOUS, + APPROXIMATED_INTEGERS + } + + public enum RaRangeShrinking { + DISABLED, + ENABLED, + ENABLED_IN_FIRST_PRAO_AND_CRAO + } + + public static class LinearOptimizationSolver { + private static final Solver DEFAULT_SOLVER = Solver.CBC; + public static final double DEFAULT_RELATIVE_MIP_GAP = 0.0001; + public static final String DEFAULT_SOLVER_SPECIFIC_PARAMETERS = null; + private Solver solver = DEFAULT_SOLVER; + private double relativeMipGap = DEFAULT_RELATIVE_MIP_GAP; + private String solverSpecificParameters = DEFAULT_SOLVER_SPECIFIC_PARAMETERS; + + public Solver getSolver() { + return solver; + } + + public void setSolver(Solver solver) { + this.solver = solver; + } + + public double getRelativeMipGap() { + return relativeMipGap; + } + + public void setRelativeMipGap(double relativeMipGap) { + this.relativeMipGap = relativeMipGap; + } + + public String getSolverSpecificParameters() { + return solverSpecificParameters; + } + + public void setSolverSpecificParameters(String solverSpecificParameters) { + this.solverSpecificParameters = solverSpecificParameters; + } + + public static LinearOptimizationSolver load(PlatformConfig platformConfig) { + Objects.requireNonNull(platformConfig); + LinearOptimizationSolver parameters = new LinearOptimizationSolver(); + platformConfig.getOptionalModuleConfig(LINEAR_OPTIMIZATION_SOLVER_SECTION) + .ifPresent(config -> { + parameters.setSolver(config.getEnumProperty(SOLVER, Solver.class, DEFAULT_SOLVER)); + parameters.setRelativeMipGap(config.getDoubleProperty(RELATIVE_MIP_GAP, DEFAULT_RELATIVE_MIP_GAP)); + parameters.setSolverSpecificParameters(config.getStringProperty(SOLVER_SPECIFIC_PARAMETERS, DEFAULT_SOLVER_SPECIFIC_PARAMETERS)); + }); + return parameters; + } + } + + public enum Solver { + CBC, + SCIP, + XPRESS + } + + // Getters and setters + public int getMaxMipIterations() { + return maxMipIterations; + } + + public void setMaxMipIterations(int maxMipIterations) { + this.maxMipIterations = maxMipIterations; + } + + public double getPstSensitivityThreshold() { + return pstSensitivityThreshold; + } + + public void setPstSensitivityThreshold(double pstSensitivityThreshold) { + if (pstSensitivityThreshold < 1e-6) { + throw new OpenRaoException("pstSensitivityThreshold should be greater than 1e-6, to avoid numerical issues."); + } + this.pstSensitivityThreshold = pstSensitivityThreshold; + } + + public double getHvdcSensitivityThreshold() { + return hvdcSensitivityThreshold; + } + + public void setHvdcSensitivityThreshold(double hvdcSensitivityThreshold) { + if (hvdcSensitivityThreshold < 1e-6) { + throw new OpenRaoException("hvdcSensitivityThreshold should be greater than 1e-6, to avoid numerical issues."); + } + this.hvdcSensitivityThreshold = hvdcSensitivityThreshold; + } + + public double getInjectionRaSensitivityThreshold() { + return injectionRaSensitivityThreshold; + } + + public void setInjectionRaSensitivityThreshold(double injectionRaSensitivityThreshold) { + if (injectionRaSensitivityThreshold < 1e-6) { + throw new OpenRaoException("injectionRaSensitivityThreshold should be greater than 1e-6, to avoid numerical issues."); + } + this.injectionRaSensitivityThreshold = injectionRaSensitivityThreshold; + } + + public LinearOptimizationSolver getLinearOptimizationSolver() { + return linearOptimizationSolver; + } + + public void setPstModel(PstModel pstModel) { + this.pstModel = pstModel; + } + + public PstModel getPstModel() { + return pstModel; + } + + public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizationSolver) { + this.linearOptimizationSolver = linearOptimizationSolver; + } + + public void setRaRangeShrinking(RaRangeShrinking raRangeShrinking) { + this.raRangeShrinking = raRangeShrinking; + } + + public RaRangeShrinking getRaRangeShrinking() { + return raRangeShrinking; + } + + public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { + Objects.requireNonNull(platformConfig); + RangeActionsOptimizationParameters parameters = new RangeActionsOptimizationParameters(); + platformConfig.getOptionalModuleConfig(RANGE_ACTIONS_OPTIMIZATION_SECTION) + .ifPresent(config -> { + parameters.setMaxMipIterations(config.getIntProperty(MAX_MIP_ITERATIONS, DEFAULT_MAX_MIP_ITERATIONS)); + parameters.setPstSensitivityThreshold(config.getDoubleProperty(PST_SENSITIVITY_THRESHOLD, DEFAULT_PST_SENSITIVITY_THRESHOLD)); + parameters.setPstModel(config.getEnumProperty(PST_MODEL, PstModel.class, DEFAULT_PST_MODEL)); + parameters.setHvdcSensitivityThreshold(config.getDoubleProperty(HVDC_SENSITIVITY_THRESHOLD, DEFAULT_HVDC_SENSITIVITY_THRESHOLD)); + parameters.setInjectionRaSensitivityThreshold(config.getDoubleProperty(INJECTION_RA_SENSITIVITY_THRESHOLD, DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD)); + parameters.setRaRangeShrinking(config.getEnumProperty(RA_RANGE_SHRINKING, RaRangeShrinking.class, DEFAULT_RA_RANGE_SHRINKING)); + }); + parameters.setLinearOptimizationSolver(LinearOptimizationSolver.load(platformConfig)); + return parameters; + } +} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/SecondPreventiveRaoParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/SecondPreventiveRaoParameters.java similarity index 95% rename from ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/SecondPreventiveRaoParameters.java rename to ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/SecondPreventiveRaoParameters.java index 0b009e7cc9..0119e0cba7 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/SecondPreventiveRaoParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/SecondPreventiveRaoParameters.java @@ -1,11 +1,12 @@ /* - * Copyright (c) 2023, RTE (http://www.rte-france.com) + * Copyright (c) 2024, 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/. + * SPDX-License-Identifier: MPL-2.0 */ -package com.powsybl.openrao.raoapi.parameters; +package com.powsybl.openrao.raoapi.parameters.extensions; import com.powsybl.commons.config.PlatformConfig; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/TopoOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/TopoOptimizationParameters.java new file mode 100644 index 0000000000..8f2f506048 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/TopoOptimizationParameters.java @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2023, 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.raoapi.parameters.extensions; + +import com.powsybl.commons.config.PlatformConfig; +import com.powsybl.openrao.raoapi.parameters.ParametersUtil; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * Topological actions optimization parameters for RAO + * + * @author Godelaine de Montmorillon {@literal } + */ +public class TopoOptimizationParameters { + // Default values + private static final int DEFAULT_MAX_SEARCH_TREE_DEPTH = Integer.MAX_VALUE; + private static final List> DEFAULT_PREDEFINED_COMBINATIONS = new ArrayList<>(); + private static final boolean DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT = false; + private static final int DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS = 2; + // Attributes + private int maxPreventiveSearchTreeDepth = DEFAULT_MAX_SEARCH_TREE_DEPTH; + private int maxAutoSearchTreeDepth = DEFAULT_MAX_SEARCH_TREE_DEPTH; + private int maxCurativeSearchTreeDepth = DEFAULT_MAX_SEARCH_TREE_DEPTH; + private List> predefinedCombinations = DEFAULT_PREDEFINED_COMBINATIONS; + private boolean skipActionsFarFromMostLimitingElement = DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT; + private int maxNumberOfBoundariesForSkippingActions = DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS; + + public void setMaxPreventiveSearchTreeDepth(int maxPreventiveSearchTreeDepth) { + this.maxPreventiveSearchTreeDepth = maxPreventiveSearchTreeDepth; + } + + public void setMaxAutoSearchTreeDepth(int maxAutoSearchTreeDepth) { + this.maxAutoSearchTreeDepth = maxAutoSearchTreeDepth; + } + + public void setMaxCurativeSearchTreeDepth(int maxCurativeSearchTreeDepth) { + this.maxCurativeSearchTreeDepth = maxCurativeSearchTreeDepth; + } + + public void setPredefinedCombinations(List> predefinedCombinations) { + this.predefinedCombinations = predefinedCombinations; + } + + public void setSkipActionsFarFromMostLimitingElement(boolean skipActionsFarFromMostLimitingElement) { + this.skipActionsFarFromMostLimitingElement = skipActionsFarFromMostLimitingElement; + } + + public void setMaxNumberOfBoundariesForSkippingActions(int maxNumberOfBoundariesForSkippingActions) { + if (maxNumberOfBoundariesForSkippingActions < 0) { + BUSINESS_WARNS.warn("The value {} provided for max number of boundaries for skipping actions is smaller than 0. It will be set to 0.", maxNumberOfBoundariesForSkippingActions); + this.maxNumberOfBoundariesForSkippingActions = 0; + } else { + this.maxNumberOfBoundariesForSkippingActions = maxNumberOfBoundariesForSkippingActions; + } + } + + public int getMaxPreventiveSearchTreeDepth() { + return maxPreventiveSearchTreeDepth; + } + + public int getMaxAutoSearchTreeDepth() { + return maxAutoSearchTreeDepth; + } + + public int getMaxCurativeSearchTreeDepth() { + return maxCurativeSearchTreeDepth; + } + + public boolean getSkipActionsFarFromMostLimitingElement() { + return skipActionsFarFromMostLimitingElement; + } + + public int getMaxNumberOfBoundariesForSkippingActions() { + return maxNumberOfBoundariesForSkippingActions; + } + + public List> getPredefinedCombinations() { + return predefinedCombinations; + } + + public static TopoOptimizationParameters load(PlatformConfig platformConfig) { + Objects.requireNonNull(platformConfig); + TopoOptimizationParameters parameters = new TopoOptimizationParameters(); + platformConfig.getOptionalModuleConfig(TOPOLOGICAL_ACTIONS_OPTIMIZATION_SECTION) + .ifPresent(config -> { + parameters.setMaxPreventiveSearchTreeDepth(config.getIntProperty(MAX_PREVENTIVE_SEARCH_TREE_DEPTH, DEFAULT_MAX_SEARCH_TREE_DEPTH)); + parameters.setMaxAutoSearchTreeDepth(config.getIntProperty(MAX_AUTO_SEARCH_TREE_DEPTH, DEFAULT_MAX_SEARCH_TREE_DEPTH)); + parameters.setMaxCurativeSearchTreeDepth(config.getIntProperty(MAX_CURATIVE_SEARCH_TREE_DEPTH, DEFAULT_MAX_SEARCH_TREE_DEPTH)); + parameters.setPredefinedCombinations(ParametersUtil.convertListToListOfList(config.getStringListProperty(PREDEFINED_COMBINATIONS, ParametersUtil.convertListOfListToList(DEFAULT_PREDEFINED_COMBINATIONS)))); + parameters.setSkipActionsFarFromMostLimitingElement(config.getBooleanProperty(SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT, DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT)); + parameters.setMaxNumberOfBoundariesForSkippingActions(config.getIntProperty(MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS, DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS)); + }); + return parameters; + } +} diff --git a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/json/JsonRaoParametersTest.java b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/json/JsonRaoParametersTest.java index 2d40ddcf93..aebbf8fc66 100644 --- a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/json/JsonRaoParametersTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/json/JsonRaoParametersTest.java @@ -10,7 +10,7 @@ import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; -import com.powsybl.openrao.raoapi.parameters.SecondPreventiveRaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation; @@ -57,11 +57,11 @@ void roundTrip() throws IOException { parameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(true); // RangeActionsOptimization parameters parameters.getRangeActionsOptimizationParameters().setMaxMipIterations(30); - parameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(10); + parameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(10); parameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(0.2); - parameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(1); + parameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(1); parameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(0.3); - parameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(1.2); + parameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(1.2); parameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(0.7); parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters("TREEMEMORYLIMIT 20"); parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(RangeActionsOptimizationParameters.Solver.SCIP); diff --git a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConfigTest.java b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConfigTest.java index f5a58d393f..55cf5ddd60 100644 --- a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConfigTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConfigTest.java @@ -73,18 +73,19 @@ void checkRangeActionsOptimizationConfig() { RaoParameters parameters = new RaoParameters(); RaoParameters.load(parameters, platformCfg); RangeActionsOptimizationParameters params = parameters.getRangeActionsOptimizationParameters(); - assertEquals(4, params.getMaxMipIterations(), DOUBLE_TOLERANCE); - assertEquals(44, params.getPstPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(7, params.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, params.getPstModel()); - assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, params.getRaRangeShrinking()); - assertEquals(33, params.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(8, params.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(22, params.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(9, params.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.Solver.XPRESS, params.getLinearOptimizationSolver().getSolver()); - assertEquals(22, params.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); - assertEquals("blabla", params.getLinearOptimizationSolver().getSolverSpecificParameters()); + OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters paramsExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters(); + assertEquals(4, paramsExt.getMaxMipIterations(), DOUBLE_TOLERANCE); + assertEquals(44, params.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(7, paramsExt.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, paramsExt.getPstModel()); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, paramsExt.getRaRangeShrinking()); + assertEquals(33, params.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(8, paramsExt.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(22, params.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(9, paramsExt.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.Solver.XPRESS, paramsExt.getLinearOptimizationSolver().getSolver()); + assertEquals(22, paramsExt.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("blabla", paramsExt.getLinearOptimizationSolver().getSolverSpecificParameters()); } @Test @@ -222,7 +223,7 @@ void checkMultipleConfigs() { RaoParameters.load(parameters, platformCfg); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN, parameters.getObjectiveFunctionParameters().getType()); assertEquals(123, parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement(), 1e-6); - assertEquals(32, parameters.getRangeActionsOptimizationParameters().getMaxMipIterations(), 1e-6); + assertEquals(32, parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().getMaxMipIterations(), 1e-6); assertTrue(Objects.isNull(parameters.getExtension(LoopFlowParametersExtension.class))); assertTrue(Objects.isNull(parameters.getExtension(MnecParametersExtension.class))); assertTrue(Objects.isNull(parameters.getExtension(RelativeMarginsParametersExtension.class))); diff --git a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersYamlConfigTest.java b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersYamlConfigTest.java index 2cd746a6b4..ac4af5aa7e 100644 --- a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersYamlConfigTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersYamlConfigTest.java @@ -7,10 +7,7 @@ package com.powsybl.openrao.raoapi.parameters; import com.powsybl.openrao.raoapi.json.JsonRaoParameters; -import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; -import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; -import com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation; -import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; +import com.powsybl.openrao.raoapi.parameters.extensions.*; import com.powsybl.commons.config.*; import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.iidm.network.Country; @@ -48,18 +45,19 @@ void testConfigWithExtensions() throws IOException { assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity()); RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters(); - assertEquals(2, rangeActionsOptimizationParameters.getMaxMipIterations(), DOUBLE_TOLERANCE); - assertEquals(0.02, rangeActionsOptimizationParameters.getPstPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.2, rangeActionsOptimizationParameters.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParameters.getPstModel()); - assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getRaRangeShrinking()); - assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.3, rangeActionsOptimizationParameters.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.Solver.XPRESS, rangeActionsOptimizationParameters.getLinearOptimizationSolver().getSolver()); - assertEquals(0.004, rangeActionsOptimizationParameters.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); - assertEquals("BLABLABLA", rangeActionsOptimizationParameters.getLinearOptimizationSolver().getSolverSpecificParameters()); + OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters rangeActionsOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters(); + assertEquals(2, rangeActionsOptimizationParametersExt.getMaxMipIterations(), DOUBLE_TOLERANCE); + assertEquals(0.02, rangeActionsOptimizationParameters.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, rangeActionsOptimizationParametersExt.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParametersExt.getPstModel()); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, rangeActionsOptimizationParametersExt.getRaRangeShrinking()); + assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, rangeActionsOptimizationParametersExt.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.3, rangeActionsOptimizationParametersExt.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.Solver.XPRESS, rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getSolver()); + assertEquals(0.004, rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("BLABLABLA", rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getSolverSpecificParameters()); TopoOptimizationParameters topoOptimizationParameters = parameters.getTopoOptimizationParameters(); assertEquals(3, topoOptimizationParameters.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); @@ -129,18 +127,19 @@ void testConfigWithoutExtensions() throws IOException { assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity()); RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters(); - assertEquals(2, rangeActionsOptimizationParameters.getMaxMipIterations(), DOUBLE_TOLERANCE); - assertEquals(0.02, rangeActionsOptimizationParameters.getPstPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.2, rangeActionsOptimizationParameters.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParameters.getPstModel()); - assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getRaRangeShrinking()); - assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.3, rangeActionsOptimizationParameters.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.Solver.XPRESS, rangeActionsOptimizationParameters.getLinearOptimizationSolver().getSolver()); - assertEquals(0.004, rangeActionsOptimizationParameters.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); - assertEquals("BLABLABLA", rangeActionsOptimizationParameters.getLinearOptimizationSolver().getSolverSpecificParameters()); + OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters rangeActionsOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters(); + assertEquals(2, rangeActionsOptimizationParametersExt.getMaxMipIterations(), DOUBLE_TOLERANCE); + assertEquals(0.02, rangeActionsOptimizationParameters.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, rangeActionsOptimizationParametersExt.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParametersExt.getPstModel()); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, rangeActionsOptimizationParametersExt.getRaRangeShrinking()); + assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, rangeActionsOptimizationParametersExt.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.3, rangeActionsOptimizationParametersExt.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.Solver.XPRESS, rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getSolver()); + assertEquals(0.004, rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("BLABLABLA", rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getSolverSpecificParameters()); TopoOptimizationParameters topoOptimizationParameters = parameters.getTopoOptimizationParameters(); assertEquals(3, topoOptimizationParameters.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); @@ -197,18 +196,19 @@ void testConfigWithPartialExtensions() throws IOException { assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity()); RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters(); - assertEquals(10, rangeActionsOptimizationParameters.getMaxMipIterations(), DOUBLE_TOLERANCE); - assertEquals(0.02, rangeActionsOptimizationParameters.getPstPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.2, rangeActionsOptimizationParameters.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParameters.getPstModel()); - assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED, rangeActionsOptimizationParameters.getRaRangeShrinking()); - assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); - assertEquals(0.3, rangeActionsOptimizationParameters.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); - assertEquals(RangeActionsOptimizationParameters.Solver.CBC, rangeActionsOptimizationParameters.getLinearOptimizationSolver().getSolver()); - assertEquals(0.004, rangeActionsOptimizationParameters.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); - assertEquals("BLABLABLA", rangeActionsOptimizationParameters.getLinearOptimizationSolver().getSolverSpecificParameters()); + OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters rangeActionsOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters(); + assertEquals(10, rangeActionsOptimizationParametersExt.getMaxMipIterations(), DOUBLE_TOLERANCE); + assertEquals(0.02, rangeActionsOptimizationParameters.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, rangeActionsOptimizationParametersExt.getPstSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParametersExt.getPstModel()); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED, rangeActionsOptimizationParametersExt.getRaRangeShrinking()); + assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, rangeActionsOptimizationParametersExt.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.3, rangeActionsOptimizationParametersExt.getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.Solver.CBC, rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getSolver()); + assertEquals(0.004, rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("BLABLABLA", rangeActionsOptimizationParametersExt.getLinearOptimizationSolver().getSolverSpecificParameters()); TopoOptimizationParameters topoOptimizationParameters = parameters.getTopoOptimizationParameters(); assertEquals(3, topoOptimizationParameters.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java index c30c25a80b..9a97037425 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimization.java @@ -20,7 +20,7 @@ import com.powsybl.openrao.raoapi.RaoInput; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; -import com.powsybl.openrao.raoapi.parameters.SecondPreventiveRaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import com.powsybl.openrao.searchtreerao.commons.NetworkActionCombination; import com.powsybl.openrao.searchtreerao.commons.RaoLogger; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java index 11f9388e46..a652c3f433 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java @@ -437,11 +437,11 @@ private void fillObjectiveWithRangeActionPenaltyCost(LinearProblem linearProblem // If the range action has been filtered out, then absoluteVariationVariable is null if (absoluteVariationVariable != null && ra instanceof PstRangeAction) { - linearProblem.getObjective().setCoefficient(absoluteVariationVariable, rangeActionParameters.getPstPenaltyCost()); + linearProblem.getObjective().setCoefficient(absoluteVariationVariable, rangeActionParameters.getPstRAMinImpactThreshold()); } else if (absoluteVariationVariable != null && ra instanceof HvdcRangeAction) { - linearProblem.getObjective().setCoefficient(absoluteVariationVariable, rangeActionParameters.getHvdcPenaltyCost()); + linearProblem.getObjective().setCoefficient(absoluteVariationVariable, rangeActionParameters.getHvdcRAMinImpactThreshold()); } else if (absoluteVariationVariable != null && ra instanceof InjectionRangeAction) { - linearProblem.getObjective().setCoefficient(absoluteVariationVariable, rangeActionParameters.getInjectionRaPenaltyCost()); + linearProblem.getObjective().setCoefficient(absoluteVariationVariable, rangeActionParameters.getInjectionRAMinImpactThreshold()); } } )); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java index 1e5e57b6f0..62cd27717e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/CastorFullOptimizationTest.java @@ -32,7 +32,7 @@ import com.powsybl.openrao.raoapi.json.JsonRaoParameters; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; -import com.powsybl.openrao.raoapi.parameters.SecondPreventiveRaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.commons.parameters.TreeParameters; import com.powsybl.openrao.searchtreerao.result.api.*; diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParametersTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParametersTest.java index 253dfab76d..37f8654cc2 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParametersTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParametersTest.java @@ -7,8 +7,8 @@ package com.powsybl.openrao.searchtreerao.commons.parameters; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,6 +20,9 @@ */ class TreeParametersTest { RaoParameters raoParameters; + + OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters raoParametersRangeActionsOptimizationExt; + private static final double DOUBLE_TOLERANCE = 1e-6; @BeforeEach @@ -30,7 +33,9 @@ public void setUp() { raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(6); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + raoParametersRangeActionsOptimizationExt = raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters(); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); } @Test @@ -50,7 +55,7 @@ void testPreventive() { raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(15); raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(5); raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(15); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -59,7 +64,7 @@ void testPreventive() { assertEquals(15, treeParameters.maximumSearchDepth()); assertTrue(treeParameters.raRangeShrinking()); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertTrue(treeParameters.raRangeShrinking()); } @@ -68,7 +73,7 @@ void testPreventive() { void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -86,7 +91,7 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(0); raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(0); raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -129,7 +134,7 @@ void testSecondPreventive() { // test with min objective raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN); raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(false); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); TreeParameters treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.stopCriterion()); @@ -140,7 +145,7 @@ void testSecondPreventive() { // test with secure raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW); raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(false); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -152,7 +157,7 @@ void testSecondPreventive() { // other combinations raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW); raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(false); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + raoParametersRangeActionsOptimizationExt.setRaRangeShrinking(OpenRaoSearchTreeParameters.RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java index fb92fc6e16..61801298e0 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinMarginFillerTest.java @@ -57,9 +57,9 @@ public void setUp() throws IOException { Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); RaoParameters raoParameters = new RaoParameters(); - raoParameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(0.01); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); coreProblemFiller = new CoreProblemFiller( diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java index 13e468136b..8330c11e7e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxMinRelativeMarginFillerTest.java @@ -68,9 +68,9 @@ public void setUp() throws IOException { Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); RaoParameters raoParameters = new RaoParameters(); - raoParameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(0.01); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); raoParameters.addExtension(RelativeMarginsParametersExtension.class, new RelativeMarginsParametersExtension()); raoParameters.getExtension(RelativeMarginsParametersExtension.class).setPtdfSumLowerBound(0.01); raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java index 41c3eca5ab..42e75e6109 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MnecFillerTest.java @@ -100,9 +100,9 @@ public void setUp() throws IOException { when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); RaoParameters raoParameters = new RaoParameters(); - raoParameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(0.01); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); coreProblemFiller = new CoreProblemFiller( diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java index fb5c7460a5..858eb86398 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/UnoptimizedCnecFillerMarginDecreaseRuleTest.java @@ -78,9 +78,9 @@ public void setUp() throws IOException { Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); RaoParameters raoParameters = new RaoParameters(); - raoParameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(0.01); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(0.01); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); coreProblemFiller = new CoreProblemFiller(