From a24cff91e7648a267e386f0116b905ece756f6e3 Mon Sep 17 00:00:00 2001 From: Pauline Jean-Marie Date: Wed, 25 Sep 2024 15:29:43 +0200 Subject: [PATCH] wip --- .../openrao/raoapi/RaoParametersCommons.java | 28 +-- .../json/JsonMultiThreadingParameters.java | 59 ----- .../json/JsonNotOptimizedCnecsParameters.java | 12 +- .../json/JsonObjectiveFunctionParameters.java | 5 - ...sonRangeActionsOptimizationParameters.java | 100 +------- .../json/JsonTopoOptimizationParameters.java | 53 +---- .../json/RaoParametersDeserializer.java | 17 +- .../raoapi/json/RaoParametersSerializer.java | 10 +- ...owAndSensitivityComputationParameters.java | 18 +- .../JsonMultiThreadingParameters.java | 47 ++++ .../JsonObjectiveFunctionParameters.java | 42 ++++ .../JsonOpenRaoSearchTreeParameters.java | 94 ++++++++ ...sonRangeActionsOptimizationParameters.java | 121 ++++++++++ .../JsonSecondPreventiveRaoParameters.java | 23 +- .../JsonTopoOptimizationParameters.java | 88 ++++++++ .../ObjectiveFunctionParameters.java | 15 -- .../raoapi/parameters/ParametersUtil.java | 4 +- .../RangeActionsOptimizationParameters.java | 190 ++-------------- .../raoapi/parameters/RaoParameters.java | 19 +- .../TopoOptimizationParameters.java | 69 ------ .../LoadFlowAndSensitivityParameters.java | 36 ++- .../MultithreadingParameters.java | 15 +- .../ObjectiveFunctionParameters.java | 52 +++++ .../OpenRaoSearchTreeParameters.java | 78 +++++++ ...enRaoSearchTreeParametersConfigLoader.java | 47 ++++ .../RangeActionsOptimizationParameters.java | 213 ++++++++++++++++++ .../SecondPreventiveRaoParameters.java | 5 +- .../TopoOptimizationParameters.java | 142 ++++++++++++ .../raoapi/json/JsonRaoParametersTest.java | 60 ++--- .../parameters/RaoParametersConfigTest.java | 83 ++++--- .../RaoParametersConsistencyTest.java | 45 ++-- .../RaoParametersYamlConfigTest.java | 156 +++++++------ .../castor/algorithm/AutomatonSimulator.java | 3 +- .../algorithm/CastorFullOptimization.java | 10 +- .../searchtreerao/commons/RaoUtil.java | 17 +- .../searchtreerao/commons/ToolProvider.java | 9 +- .../ObjectiveFunction.java | 12 +- .../parameters/NetworkActionParameters.java | 15 +- .../commons/parameters/TreeParameters.java | 26 ++- .../algorithms/IteratingLinearOptimizer.java | 6 +- .../algorithms/fillers/CoreProblemFiller.java | 23 +- .../linearproblem/LinearProblem.java | 2 +- .../linearproblem/LinearProblemBuilder.java | 20 +- .../linearproblem/OpenRaoMPSolver.java | 2 +- .../IteratingLinearOptimizerParameters.java | 30 ++- .../searchtree/algorithms/Leaf.java | 1 + .../parameters/SearchTreeParameters.java | 30 ++- .../algorithm/CastorFullOptimizationTest.java | 2 +- .../NetworkActionParametersTest.java | 2 +- .../parameters/TreeParametersTest.java | 23 +- .../fillers/MaxMinMarginFillerTest.java | 6 +- .../MaxMinRelativeMarginFillerTest.java | 6 +- .../algorithms/fillers/MnecFillerTest.java | 6 +- ...mizedCnecFillerMarginDecreaseRuleTest.java | 6 +- .../parameters/SearchTreeParametersTest.java | 4 +- 55 files changed, 1414 insertions(+), 793 deletions(-) delete mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonMultiThreadingParameters.java rename ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/{ => extensions}/JsonLoadFlowAndSensitivityComputationParameters.java (68%) create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonObjectiveFunctionParameters.java create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonOpenRaoSearchTreeParameters.java create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonRangeActionsOptimizationParameters.java rename ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/{ => extensions}/JsonSecondPreventiveRaoParameters.java (65%) create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonTopoOptimizationParameters.java rename ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/{ => extensions}/LoadFlowAndSensitivityParameters.java (73%) rename ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/{ => extensions}/MultithreadingParameters.java (80%) create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/ObjectiveFunctionParameters.java create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParameters.java create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParametersConfigLoader.java create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java rename ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/{ => extensions}/SecondPreventiveRaoParameters.java (95%) create mode 100644 ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/TopoOptimizationParameters.java 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 39c2376957..4f4f3f26ec 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 @@ -24,6 +24,8 @@ private RaoParametersCommons() { // objective function parameters public static final String OBJECTIVE_FUNCTION = "objective-function"; public static final String OBJECTIVE_FUNCTION_SECTION = "rao-objective-function"; + public static final String ST_OBJECTIVE_FUNCTION_SECTION = "search-tree-objective-function"; + public static final String TYPE = "type"; public static final String CURATIVE_MIN_OBJ_IMPROVEMENT = "curative-min-obj-improvement"; public static final String ENFORCE_CURATIVE_SECURITY = "enforce-curative-security"; @@ -32,12 +34,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"; @@ -61,10 +63,7 @@ private RaoParametersCommons() { // Multi-threading parameters public static final String MULTI_THREADING = "multi-threading"; public static final String MULTI_THREADING_SECTION = "rao-multi-threading"; - public static final String CONTINGENCY_SCENARIOS_IN_PARALLEL = "contingency-scenarios-in-parallel"; - public static final String PREVENTIVE_LEAVES_IN_PARALLEL = "preventive-leaves-in-parallel"; - public static final String AUTO_LEAVES_IN_PARALLEL = "auto-leaves-in-parallel"; - public static final String CURATIVE_LEAVES_IN_PARALLEL = "curative-leaves-in-parallel"; + public static final String AVAILABLE_CPUS = "available-cpus"; // Second Preventive RAO parameters public static final String SECOND_PREVENTIVE_RAO = "second-preventive-rao"; @@ -73,29 +72,19 @@ private RaoParametersCommons() { public static final String RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS = "re-optimize-curative-range-actions"; public static final String HINT_FROM_FIRST_PREVENTIVE_RAO = "hint-from-first-preventive-rao"; - // RA usage limits per contingency parameters - public static final String RA_USAGE_LIMITS_PER_CONTINGENCY = "ra-usage-limits-per-contingency"; - public static final String RA_USAGE_LIMITS_PER_CONTINGENCY_SECTION = "rao-ra-usage-limits-per-contingency"; - - public static final String MAX_CURATIVE_RA = "max-curative-ra"; - public static final String MAX_CURATIVE_TSO = "max-curative-tso"; - public static final String MAX_CURATIVE_TOPO_PER_TSO = "max-curative-topo-per-tso"; - public static final String MAX_CURATIVE_PST_PER_TSO = "max-curative-pst-per-tso"; - public static final String MAX_CURATIVE_RA_PER_TSO = "max-curative-ra-per-tso"; - // Not optimized cnecs parameters public static final String NOT_OPTIMIZED_CNECS = "not-optimized-cnecs"; public static final String NOT_OPTIMIZED_CNECS_SECTION = "rao-not-optimized-cnecs"; public static final String DO_NOT_OPTIMIZE_CURATIVE_CNECS = "do-not-optimize-curative-cnecs-for-tsos-without-cras"; - // Not optimized cnecs parameters + // Load flow and sensitivity parameters public static final String LOAD_FLOW_AND_SENSITIVITY_COMPUTATION = "load-flow-and-sensitivity-computation"; public static final String LOAD_FLOW_AND_SENSITIVITY_COMPUTATION_SECTION = "rao-load-flow-and-sensitivity-computation"; - public static final String LOAD_FLOW_PROVIDER = "load-flow-provider"; public static final String SENSITIVITY_PROVIDER = "sensitivity-provider"; public static final String SENSITIVITY_FAILURE_OVERCOST = "sensitivity-failure-overcost"; public static final String SENSITIVITY_PARAMETERS = "sensitivity-parameters"; + public static final String LOAD_FLOW_PARAMETERS = "load-flow-parameters"; // EXTENSIONS public static final String CONSTRAINT_ADJUSTMENT_COEFFICIENT = "constraint-adjustment-coefficient"; @@ -119,6 +108,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/JsonMultiThreadingParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonMultiThreadingParameters.java deleted file mode 100644 index 0d3f47b907..0000000000 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonMultiThreadingParameters.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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; - -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; -import com.fasterxml.jackson.core.JsonGenerator; -import com.fasterxml.jackson.core.JsonParser; - -import java.io.IOException; - -import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; - -/** - * @author Godelaine de Montmorillon {@literal } - */ -final class JsonMultiThreadingParameters { - - private JsonMultiThreadingParameters() { - } - - static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException { - jsonGenerator.writeObjectFieldStart(MULTI_THREADING); - jsonGenerator.writeNumberField(CONTINGENCY_SCENARIOS_IN_PARALLEL, parameters.getMultithreadingParameters().getContingencyScenariosInParallel()); - jsonGenerator.writeNumberField(PREVENTIVE_LEAVES_IN_PARALLEL, parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); - jsonGenerator.writeNumberField(AUTO_LEAVES_IN_PARALLEL, parameters.getMultithreadingParameters().getAutoLeavesInParallel()); - jsonGenerator.writeNumberField(CURATIVE_LEAVES_IN_PARALLEL, parameters.getMultithreadingParameters().getCurativeLeavesInParallel()); - jsonGenerator.writeEndObject(); - } - - static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { - while (!jsonParser.nextToken().isStructEnd()) { - switch (jsonParser.getCurrentName()) { - case CONTINGENCY_SCENARIOS_IN_PARALLEL: - jsonParser.nextToken(); - raoParameters.getMultithreadingParameters().setContingencyScenariosInParallel(jsonParser.getIntValue()); - break; - case PREVENTIVE_LEAVES_IN_PARALLEL: - jsonParser.nextToken(); - raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(jsonParser.getIntValue()); - break; - case AUTO_LEAVES_IN_PARALLEL: - jsonParser.nextToken(); - raoParameters.getMultithreadingParameters().setAutoLeavesInParallel(jsonParser.getIntValue()); - break; - case CURATIVE_LEAVES_IN_PARALLEL: - jsonParser.nextToken(); - raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(jsonParser.getIntValue()); - break; - default: - throw new OpenRaoException(String.format("Cannot deserialize multi-threading parameters: unexpected field in %s (%s)", MULTI_THREADING, jsonParser.getCurrentName())); - } - } - } -} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonNotOptimizedCnecsParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonNotOptimizedCnecsParameters.java index 649361b3cf..59de6f89ad 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonNotOptimizedCnecsParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonNotOptimizedCnecsParameters.java @@ -31,13 +31,11 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { while (!jsonParser.nextToken().isStructEnd()) { - switch (jsonParser.getCurrentName()) { - case DO_NOT_OPTIMIZE_CURATIVE_CNECS: - jsonParser.nextToken(); - raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(jsonParser.getBooleanValue()); - break; - default: - throw new OpenRaoException(String.format("Cannot deserialize not optimized cnecs parameters: unexpected field in %s (%s)", NOT_OPTIMIZED_CNECS, jsonParser.getCurrentName())); + if (jsonParser.getCurrentName().equals(DO_NOT_OPTIMIZE_CURATIVE_CNECS)) { + jsonParser.nextToken(); + raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(jsonParser.getBooleanValue()); + } else { + throw new OpenRaoException(String.format("Cannot deserialize not optimized cnecs parameters: unexpected field in %s (%s)", NOT_OPTIMIZED_CNECS, jsonParser.getCurrentName())); } } } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonObjectiveFunctionParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonObjectiveFunctionParameters.java index 20561a0647..3f21542c3c 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonObjectiveFunctionParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonObjectiveFunctionParameters.java @@ -27,7 +27,6 @@ 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(); } @@ -38,10 +37,6 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro 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()); 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..6d628c1ce9 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 @@ -7,7 +7,6 @@ package com.powsybl.openrao.raoapi.json; import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; @@ -26,111 +25,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..90ba2ee400 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 @@ -6,14 +6,12 @@ */ package com.powsybl.openrao.raoapi.json; -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; 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 java.io.IOException; -import java.util.ArrayList; -import java.util.List; import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; @@ -27,44 +25,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 +41,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..00b1b97461 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 @@ -6,14 +6,15 @@ */ package com.powsybl.openrao.raoapi.json; -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.powsybl.commons.extensions.Extension; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.loadflow.json.JsonLoadFlowParameters; +import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.io.IOException; import java.util.Collections; @@ -59,21 +60,13 @@ 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); break; - case LOAD_FLOW_AND_SENSITIVITY_COMPUTATION: + case LOAD_FLOW_PARAMETERS: parser.nextToken(); - JsonLoadFlowAndSensitivityComputationParameters.deserialize(parser, parameters); + JsonLoadFlowParameters.deserialize(parser, deserializationContext, parameters.getLoadFlowParameters()); break; case "extensions": parser.nextToken(); 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..b7e04c7007 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,15 +6,17 @@ */ package com.powsybl.openrao.raoapi.json; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.loadflow.json.JsonLoadFlowParameters; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.io.IOException; -import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; +import static com.powsybl.openrao.raoapi.RaoParametersCommons.RAO_PARAMETERS_VERSION; +import static com.powsybl.openrao.raoapi.RaoParametersCommons.VERSION; /** * @author Baptiste Seguinot {@literal } @@ -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); + JsonLoadFlowParameters.serialize(parameters.getLoadFlowParameters(), jsonGenerator, serializerProvider); JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonRaoParameters.getExtensionSerializers()); jsonGenerator.writeEndObject(); } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonLoadFlowAndSensitivityComputationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java similarity index 68% rename from ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonLoadFlowAndSensitivityComputationParameters.java rename to ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java index 2e5fee5476..c63ae28e08 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonLoadFlowAndSensitivityComputationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java @@ -4,13 +4,13 @@ * 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; +package com.powsybl.openrao.raoapi.json.extensions; -import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; 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.extensions.OpenRaoSearchTreeParameters; import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters; import java.io.IOException; @@ -25,7 +25,7 @@ final class JsonLoadFlowAndSensitivityComputationParameters { private JsonLoadFlowAndSensitivityComputationParameters() { } - static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + static void serialize(OpenRaoSearchTreeParameters 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()); @@ -35,24 +35,24 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, Ser 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 LOAD_FLOW_PROVIDER: jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider(jsonParser.getValueAsString()); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider(jsonParser.getValueAsString()); break; case SENSITIVITY_PROVIDER: jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider(jsonParser.getValueAsString()); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider(jsonParser.getValueAsString()); break; case SENSITIVITY_FAILURE_OVERCOST: jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(jsonParser.getValueAsDouble()); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(jsonParser.getValueAsDouble()); break; case SENSITIVITY_PARAMETERS: jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityWithLoadFlowParameters(JsonSensitivityAnalysisParameters.createObjectMapper().readerForUpdating(raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters()).readValue(jsonParser)); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityWithLoadFlowParameters(JsonSensitivityAnalysisParameters.createObjectMapper().readerForUpdating(searchTreeParameters.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/extensions/JsonMultiThreadingParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java new file mode 100644 index 0000000000..2647f28589 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java @@ -0,0 +1,47 @@ +/* + * 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.powsybl.openrao.commons.OpenRaoException; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +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 JsonMultiThreadingParameters { + + private JsonMultiThreadingParameters() { + } + + static void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator) throws IOException { + jsonGenerator.writeObjectFieldStart(MULTI_THREADING); + jsonGenerator.writeNumberField(AVAILABLE_CPUS, parameters.getMultithreadingParameters().getContingencyScenariosInParallel()); + jsonGenerator.writeEndObject(); + } + + static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + if (jsonParser.getCurrentName().equals(AVAILABLE_CPUS)) { + jsonParser.nextToken(); + int availableCpus = jsonParser.getIntValue(); + searchTreeParameters.getMultithreadingParameters().setContingencyScenariosInParallel(availableCpus); + searchTreeParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(availableCpus); + searchTreeParameters.getMultithreadingParameters().setAutoLeavesInParallel(1); + searchTreeParameters.getMultithreadingParameters().setCurativeLeavesInParallel(1); + } else { + throw new OpenRaoException(String.format("Cannot deserialize multi-threading parameters: unexpected field in %s (%s)", MULTI_THREADING, jsonParser.getCurrentName())); + } + } + } +} 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..7334927b37 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonObjectiveFunctionParameters.java @@ -0,0 +1,42 @@ +/* + * 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.extensions.OpenRaoSearchTreeParameters; + +import java.io.IOException; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * @author Godelaine de Montmorillon {@literal } + */ +final class JsonObjectiveFunctionParameters { + + private JsonObjectiveFunctionParameters() { + } + + static void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator) throws IOException { + jsonGenerator.writeObjectFieldStart(OBJECTIVE_FUNCTION); + jsonGenerator.writeNumberField(CURATIVE_MIN_OBJ_IMPROVEMENT, parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement()); + jsonGenerator.writeEndObject(); + } + + static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException { + while (!jsonParser.nextToken().isStructEnd()) { + if (jsonParser.getCurrentName().equals(CURATIVE_MIN_OBJ_IMPROVEMENT)) { + jsonParser.nextToken(); + searchTreeParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(jsonParser.getValueAsDouble()); + } else { + throw new OpenRaoException(String.format("Cannot deserialize objective function parameters: unexpected field in %s (%s)", OBJECTIVE_FUNCTION, jsonParser.getCurrentName())); + } + } + } +} 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..36e37a625b --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonOpenRaoSearchTreeParameters.java @@ -0,0 +1,94 @@ +/* + * 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(); + JsonObjectiveFunctionParameters.serialize(parameters, jsonGenerator); + JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator); + JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator); + JsonSecondPreventiveRaoParameters.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..217c89760c --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonRangeActionsOptimizationParameters.java @@ -0,0 +1,121 @@ +/* + * 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.extensions.OpenRaoSearchTreeParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; + +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 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/JsonSecondPreventiveRaoParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonSecondPreventiveRaoParameters.java similarity index 65% 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..37f50cd3f4 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,15 @@ /* - * 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 +25,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 +33,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..38eeef6b89 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonTopoOptimizationParameters.java @@ -0,0 +1,88 @@ +/* + * 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.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/ObjectiveFunctionParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ObjectiveFunctionParameters.java index 9f3da0edb4..bfdf4b1642 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ObjectiveFunctionParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/ObjectiveFunctionParameters.java @@ -11,7 +11,6 @@ import java.util.Objects; -import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; /** * Objective function parameters for RAO @@ -21,11 +20,9 @@ public class ObjectiveFunctionParameters { // Default values private static final ObjectiveFunctionType DEFAULT_OBJECTIVE_FUNCTION = ObjectiveFunctionType.SECURE_FLOW; - private static final double DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT = 0; private static final boolean DEFAULT_ENFORCE_CURATIVE_SECURITY = false; // Attributes private ObjectiveFunctionType type = DEFAULT_OBJECTIVE_FUNCTION; - private double curativeMinObjImprovement = DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT; private boolean enforceCurativeSecurity = DEFAULT_ENFORCE_CURATIVE_SECURITY; // Enum @@ -48,10 +45,6 @@ public void setType(ObjectiveFunctionType type) { this.type = type; } - public double getCurativeMinObjImprovement() { - return curativeMinObjImprovement; - } - public boolean getEnforceCurativeSecurity() { return enforceCurativeSecurity; } @@ -67,16 +60,8 @@ public static ObjectiveFunctionParameters load(PlatformConfig platformConfig) { .ifPresent(config -> { parameters.setType(config.getEnumProperty(TYPE, ObjectiveFunctionType.class, DEFAULT_OBJECTIVE_FUNCTION)); - parameters.setCurativeMinObjImprovement(config.getDoubleProperty(CURATIVE_MIN_OBJ_IMPROVEMENT, DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT)); parameters.setEnforceCurativeSecurity(config.getBooleanProperty(ENFORCE_CURATIVE_SECURITY, DEFAULT_ENFORCE_CURATIVE_SECURITY)); }); return parameters; } - - public void setCurativeMinObjImprovement(double curativeRaoMinObjImprovement) { - if (curativeRaoMinObjImprovement < 0) { - BUSINESS_WARNS.warn("The value {} provided for curative RAO minimum objective improvement is smaller than 0. It will be set to + {}", curativeRaoMinObjImprovement, -curativeRaoMinObjImprovement); - } - this.curativeMinObjImprovement = Math.abs(curativeRaoMinObjImprovement); - } } 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 60684e2382..fff381c354 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,9 @@ import com.powsybl.commons.extensions.Extension; import com.powsybl.commons.extensions.ExtensionConfigLoader; import com.powsybl.commons.extensions.ExtensionProviders; +import com.powsybl.loadflow.LoadFlowParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.MultithreadingParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import java.util.Objects; @@ -28,7 +31,7 @@ public class RaoParameters extends AbstractExtendable { private MultithreadingParameters multithreadingParameters = new MultithreadingParameters(); private SecondPreventiveRaoParameters secondPreventiveRaoParameters = new SecondPreventiveRaoParameters(); private NotOptimizedCnecsParameters notOptimizedCnecsParameters = new NotOptimizedCnecsParameters(); - private LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = new LoadFlowAndSensitivityParameters(); + private LoadFlowParameters loadFlowParameters = new LoadFlowParameters(); // Getters and setters public void setObjectiveFunctionParameters(ObjectiveFunctionParameters objectiveFunctionParameters) { @@ -55,8 +58,8 @@ public void setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters notOptimi this.notOptimizedCnecsParameters = notOptimizedCnecsParameters; } - public void setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters) { - this.loadFlowAndSensitivityParameters = loadFlowAndSensitivityParameters; + public void setLoadFlowParameters(LoadFlowParameters loadFlowParameters) { + this.loadFlowParameters = loadFlowParameters; } public ObjectiveFunctionParameters getObjectiveFunctionParameters() { @@ -83,14 +86,17 @@ public NotOptimizedCnecsParameters getNotOptimizedCnecsParameters() { return notOptimizedCnecsParameters; } - public LoadFlowAndSensitivityParameters getLoadFlowAndSensitivityParameters() { - return loadFlowAndSensitivityParameters; + public LoadFlowParameters getLoadFlowParameters() { + return loadFlowParameters; } public boolean hasExtension(Class classType) { return Objects.nonNull(this.getExtension(classType)); } + public void addExtension(Class rangeActionsOptimizationParametersClass) { + } + // ConfigLoader /** * A configuration loader interface for the RaoParameters extensions loaded from the platform configuration @@ -130,7 +136,7 @@ public static void load(RaoParameters parameters, PlatformConfig platformConfig) parameters.setMultithreadingParameters(MultithreadingParameters.load(platformConfig)); parameters.setSecondPreventiveRaoParameters(SecondPreventiveRaoParameters.load(platformConfig)); parameters.setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters.load(platformConfig)); - parameters.setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters.load(platformConfig)); + parameters.setLoadFlowParameters(LoadFlowParameters.load(platformConfig)); } private void loadExtensions(PlatformConfig platformConfig) { @@ -139,6 +145,7 @@ private void loadExtensions(PlatformConfig platformConfig) { if (extension != null) { addExtension(provider.getExtensionClass(), extension); } + // TODO: LoadFlowAndSensitivityParameters hasExtension } } } 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/LoadFlowAndSensitivityParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java similarity index 73% rename from ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java rename to ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java index f5d290dc93..d854511884 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/extensions/LoadFlowAndSensitivityParameters.java @@ -5,15 +5,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -package com.powsybl.openrao.raoapi.parameters; +package com.powsybl.openrao.raoapi.parameters.extensions; import com.powsybl.commons.config.PlatformConfig; import com.powsybl.loadflow.LoadFlowParameters; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.sensitivity.SensitivityAnalysisParameters; import java.util.Objects; -import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; /** * LoadFlow and sensitivity computation parameters for RAO @@ -79,7 +81,7 @@ public static LoadFlowAndSensitivityParameters load(PlatformConfig platformConfi return parameters; } - private SensitivityAnalysisParameters cleanLoadFlowParameters(SensitivityAnalysisParameters sensitivityAnalysisParameters) { + private static 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. @@ -93,4 +95,32 @@ private SensitivityAnalysisParameters cleanLoadFlowParameters(SensitivityAnalysi } return sensitivityAnalysisParameters; } + + public static String getLoadFlowProvider(RaoParameters raoParameters) { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getLoadFlowProvider(); + } + return DEFAULT_LOADFLOW_PROVIDER; + } + + public static double getSensitivityFailureOvercost(RaoParameters raoParameters) { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getSensitivityFailureOvercost(); + } + return DEFAULT_SENSITIVITY_FAILURE_OVERCOST; + } + + public static String getSensitivityProvider(RaoParameters raoParameters) { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getSensitivityProvider(); + } + return DEFAULT_SENSITIVITY_PROVIDER; + } + + public static SensitivityAnalysisParameters getSensitivityWithLoadFlowParameters(RaoParameters raoParameters) { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getSensitivityWithLoadFlowParameters(); + } + return cleanLoadFlowParameters(new 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 80% 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..c123ae44cc 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; @@ -63,11 +64,11 @@ public static MultithreadingParameters load(PlatformConfig platformConfig) { MultithreadingParameters parameters = new MultithreadingParameters(); platformConfig.getOptionalModuleConfig(MULTI_THREADING_SECTION) .ifPresent(config -> { - parameters.setContingencyScenariosInParallel(config.getIntProperty(CONTINGENCY_SCENARIOS_IN_PARALLEL, DEFAULT_CONTINGENCY_SCENARIOS_IN_PARALLEL)); - parameters.setPreventiveLeavesInParallel(config.getIntProperty(PREVENTIVE_LEAVES_IN_PARALLEL, DEFAULT_PREVENTIVE_LEAVES_IN_PARALLEL)); - parameters.setAutoLeavesInParallel(config.getIntProperty(AUTO_LEAVES_IN_PARALLEL, DEFAULT_AUTO_LEAVES_IN_PARALLEL)); - parameters.setCurativeLeavesInParallel(config.getIntProperty(CURATIVE_LEAVES_IN_PARALLEL, DEFAULT_CURATIVE_LEAVES_IN_PARALLEL)); - + int availableCpus = config.getIntProperty(AVAILABLE_CPUS, 1); + parameters.setContingencyScenariosInParallel(availableCpus); + parameters.setPreventiveLeavesInParallel(availableCpus); + parameters.setAutoLeavesInParallel(1); + parameters.setCurativeLeavesInParallel(1); }); return parameters; } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/ObjectiveFunctionParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/ObjectiveFunctionParameters.java new file mode 100644 index 0000000000..0d117f7eab --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/ObjectiveFunctionParameters.java @@ -0,0 +1,52 @@ +/* + * 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.RaoParameters; + +import java.util.Optional; + +import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + +/** + * Objective function parameters for RAO + * + * @author Godelaine de Montmorillon {@literal } + */ +public class ObjectiveFunctionParameters { + private static final double DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT = 0; + private double curativeMinObjImprovement = DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT; + + public double getCurativeMinObjImprovement() { + return curativeMinObjImprovement; + } + + public static Optional load(PlatformConfig platformConfig) { + return platformConfig.getOptionalModuleConfig(ST_OBJECTIVE_FUNCTION_SECTION).map(config -> { + ObjectiveFunctionParameters params = new ObjectiveFunctionParameters(); + params.setCurativeMinObjImprovement(config.getDoubleProperty(CURATIVE_MIN_OBJ_IMPROVEMENT, DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT)); + return params; + }); + } + + public void setCurativeMinObjImprovement(double curativeRaoMinObjImprovement) { + if (curativeRaoMinObjImprovement < 0) { + BUSINESS_WARNS.warn("The value {} provided for curative RAO minimum objective improvement is smaller than 0. It will be set to + {}", curativeRaoMinObjImprovement, -curativeRaoMinObjImprovement); + } + this.curativeMinObjImprovement = Math.abs(curativeRaoMinObjImprovement); + } + + public static double getCurativeMinObjImprovement(RaoParameters parameters) { + if (parameters.hasExtension(ObjectiveFunctionParameters.class)) { + return parameters.getExtension(ObjectiveFunctionParameters.class).getCurativeMinObjImprovement(); + } + return DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT; + } +} 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..0f9ca7dfd5 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParameters.java @@ -0,0 +1,78 @@ +/* + * 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.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 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 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 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/OpenRaoSearchTreeParametersConfigLoader.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParametersConfigLoader.java new file mode 100644 index 0000000000..f29ab65cb1 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParametersConfigLoader.java @@ -0,0 +1,47 @@ +/* + * 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.google.auto.service.AutoService; +import com.powsybl.commons.config.PlatformConfig; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; + +import java.util.Objects; + +import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; + + +/** + * @author Pauline JEAN-MARIE {@literal } + */ +@AutoService(RaoParameters.ConfigLoader.class) +public class OpenRaoSearchTreeParametersConfigLoader implements RaoParameters.ConfigLoader { + + @Override + public OpenRaoSearchTreeParameters load(PlatformConfig platformConfig) { + Objects.requireNonNull(platformConfig); + OpenRaoSearchTreeParameters parameters = new OpenRaoSearchTreeParameters(); + ObjectiveFunctionParameters.load(platformConfig).ifPresent(parameters::setObjectiveFunctionParameters); + 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/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..31214693fb --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java @@ -0,0 +1,213 @@ +/* + * 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; + } + + public static PstModel getPstModel(RaoParameters raoParameters) { + if (raoParameters.hasExtension(RangeActionsOptimizationParameters.class)) { + return raoParameters.getExtension(RangeActionsOptimizationParameters.class).getPstModel(); + } + return DEFAULT_PST_MODEL; + } + + public static RaRangeShrinking getRaRangeShrinking(RaoParameters parameters) { + if (parameters.hasExtension(RangeActionsOptimizationParameters.class)) { + return parameters.getExtension(RangeActionsOptimizationParameters.class).getRaRangeShrinking(); + } + return DEFAULT_RA_RANGE_SHRINKING; + } + + public static LinearOptimizationSolver getLinearOptimizationSolver(RaoParameters parameters) { + if (parameters.hasExtension(RangeActionsOptimizationParameters.class)) { + return parameters.getExtension(RangeActionsOptimizationParameters.class).getLinearOptimizationSolver(); + } + return new LinearOptimizationSolver(); + } + + public static int getMaxMipIterations(RaoParameters parameters) { + if (parameters.hasExtension(RangeActionsOptimizationParameters.class)) { + return parameters.getExtension(RangeActionsOptimizationParameters.class).getMaxMipIterations(); + } + return DEFAULT_MAX_MIP_ITERATIONS; + } +} 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..dab94e69b4 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/TopoOptimizationParameters.java @@ -0,0 +1,142 @@ +/* + * 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 com.powsybl.openrao.raoapi.parameters.RaoParameters; + +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; + } + + public static int getMaxPreventiveSearchTreeDepth(RaoParameters parameters) { + if (parameters.hasExtension(TopoOptimizationParameters.class)) { + return parameters.getExtension(TopoOptimizationParameters.class).getMaxPreventiveSearchTreeDepth(); + } + return DEFAULT_MAX_SEARCH_TREE_DEPTH; + } + + public static int getMaxAutoSearchTreeDepth(RaoParameters parameters) { + if (parameters.hasExtension(TopoOptimizationParameters.class)) { + return parameters.getExtension(TopoOptimizationParameters.class).getMaxAutoSearchTreeDepth(); + } + return DEFAULT_MAX_SEARCH_TREE_DEPTH; + } + + public static boolean isSkipActionsFarFromMostLimitingElement(RaoParameters raoParameters) { + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class)) { + return raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class).getSkipActionsFarFromMostLimitingElement(); + } + return DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT; + } + + public static int getMaxNumberOfBoundariesForSkippingActions(RaoParameters raoParameters) { + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class)) { + return raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class).getMaxNumberOfBoundariesForSkippingActions(); + } + return DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS; + } + + public static List> getPredefinedCombinations(RaoParameters raoParameters) { + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class)) { + return raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class).getPredefinedCombinations(); + } + return DEFAULT_PREDEFINED_COMBINATIONS; + } +} 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..1f3be31416 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 @@ -8,13 +8,10 @@ import com.powsybl.openrao.commons.OpenRaoException; 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.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.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.RaRangeShrinking; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; @@ -51,30 +48,32 @@ void roundTripDefault() throws IOException { @Test void roundTrip() throws IOException { RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters openRaoSTParams = parameters.getExtension(OpenRaoSearchTreeParameters.class); // Objective Function parameters parameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN); - parameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(983); + openRaoSTParams.getObjectiveFunctionParameters().setCurativeMinObjImprovement(983); parameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(true); // RangeActionsOptimization parameters - parameters.getRangeActionsOptimizationParameters().setMaxMipIterations(30); - parameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(10); - parameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(0.2); - parameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(1); - parameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(0.3); - parameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(1.2); - parameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(0.7); - parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters("TREEMEMORYLIMIT 20"); - parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(RangeActionsOptimizationParameters.Solver.SCIP); - parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(1e-5); - parameters.getRangeActionsOptimizationParameters().setPstModel(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS); - parameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + openRaoSTParams.getRangeActionsOptimizationParameters().setMaxMipIterations(30); + parameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(10); + openRaoSTParams.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(0.2); + parameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(1); + openRaoSTParams.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(0.3); + parameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(1.2); + openRaoSTParams.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(0.7); + openRaoSTParams.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters("TREEMEMORYLIMIT 20"); + openRaoSTParams.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(RangeActionsOptimizationParameters.Solver.SCIP); + openRaoSTParams.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(1e-5); + openRaoSTParams.getRangeActionsOptimizationParameters().setPstModel(PstModel.APPROXIMATED_INTEGERS); + openRaoSTParams.getRangeActionsOptimizationParameters().setRaRangeShrinking(RaRangeShrinking.ENABLED); // TopologicalActions optimization parameters - parameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(10); - parameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(3); - parameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(10); + openRaoSTParams.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(10); + openRaoSTParams.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(3); + openRaoSTParams.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(10); parameters.getTopoOptimizationParameters().setRelativeMinImpactThreshold(0.1); parameters.getTopoOptimizationParameters().setAbsoluteMinImpactThreshold(20); - parameters.getTopoOptimizationParameters().setPredefinedCombinations(List.of(List.of("na-id-1", "na-id-2"), List.of("na-id-1", "na-id-3", "na-id-4"))); + openRaoSTParams.getTopoOptimizationParameters().setPredefinedCombinations(List.of(List.of("na-id-1", "na-id-2"), List.of("na-id-1", "na-id-3", "na-id-4"))); // Multi-threading parameters parameters.getMultithreadingParameters().setContingencyScenariosInParallel(15); parameters.getMultithreadingParameters().setPreventiveLeavesInParallel(21); @@ -87,8 +86,8 @@ void roundTrip() throws IOException { // Not optimized cnecs parameters parameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); // LoadFlow and sensitivity parameters - parameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider("OpenLoadFlowProvider"); - parameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider("OpenSensitivityAnalysis"); + openRaoSTParams.getLoadFlowAndSensitivityParameters().setLoadFlowProvider("OpenLoadFlowProvider"); + openRaoSTParams.getLoadFlowAndSensitivityParameters().setSensitivityProvider("OpenSensitivityAnalysis"); // Extensions // -- LoopFlow parameters parameters.addExtension(LoopFlowParametersExtension.class, new LoopFlowParametersExtension()); @@ -121,16 +120,17 @@ void update() { JsonRaoParameters.update(parameters, getClass().getResourceAsStream("/RaoParameters_update_v2.json")); assertEquals(2, parameters.getExtensions().size()); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, parameters.getObjectiveFunctionParameters().getType()); - assertEquals(5, parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(2, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(5, parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + TopoOptimizationParameters topoOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters(); + assertEquals(5, topoOptimizationParametersExt.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, topoOptimizationParametersExt.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(5, topoOptimizationParametersExt.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); assertEquals(0, parameters.getTopoOptimizationParameters().getRelativeMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(1, parameters.getTopoOptimizationParameters().getAbsoluteMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(8, parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); assertEquals(4, parameters.getMultithreadingParameters().getAutoLeavesInParallel()); assertEquals(3, parameters.getMultithreadingParameters().getCurativeLeavesInParallel()); - assertTrue(parameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement()); - assertEquals(2, parameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions()); + assertTrue(topoOptimizationParametersExt.getSkipActionsFarFromMostLimitingElement()); + assertEquals(2, topoOptimizationParametersExt.getMaxNumberOfBoundariesForSkippingActions()); assertTrue(parameters.getNotOptimizedCnecsParameters().getDoNotOptimizeCurativeCnecsForTsosWithoutCras()); assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE, parameters.getSecondPreventiveRaoParameters().getExecutionCondition()); assertTrue(parameters.getSecondPreventiveRaoParameters().getHintFromFirstPreventiveRao()); 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 19a8101a16..4e8360485f 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 @@ -19,6 +19,7 @@ import java.nio.file.FileSystem; import java.util.*; +import static com.powsybl.openrao.raoapi.parameters.extensions.ObjectiveFunctionParameters.getCurativeMinObjImprovement; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.*; @@ -49,10 +50,30 @@ void checkObjectiveFunctionConfig() { RaoParameters.load(parameters, platformCfg); ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(123, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity()); } + @Test + void checkSearchTreeObjectiveFunctionConfig() { + //ModuleConfig mnecModuleConfig = Mockito.mock(ModuleConfig.class); + //Mockito.when(mnecModuleConfig.getDoubleProperty(eq("acceptable-margin-decrease"), anyDouble())).thenReturn(32.); + //Mockito.when(mnecModuleConfig.getDoubleProperty(eq("violation-cost"), anyDouble())).thenReturn(43.); + //Mockito.when(mnecModuleConfig.getDoubleProperty(eq("constraint-adjustment-coefficient"), anyDouble())).thenReturn(45.); + //Mockito.when(mockedPlatformConfig.getOptionalModuleConfig("rao-mnec-parameters")).thenReturn(Optional.of(mnecModuleConfig)); + //MnecParametersConfigLoader configLoader = new MnecParametersConfigLoader(); + //MnecParametersExtension parameters = configLoader.load(mockedPlatformConfig); + //assertEquals(32, parameters.getAcceptableMarginDecrease(), DOUBLE_TOLERANCE); + //assertEquals(43, parameters.getViolationCost(), DOUBLE_TOLERANCE); + //assertEquals(45, parameters.getConstraintAdjustmentCoefficient(), DOUBLE_TOLERANCE); + + MapModuleConfig objectiveFunctionModuleConfig = platformCfg.createModuleConfig("search-tree-objective-function"); + objectiveFunctionModuleConfig.setStringProperty("curative-min-obj-improvement", Objects.toString(123.0)); + + RaoParameters parameters = RaoParameters.load(platformCfg); + getCurativeMinObjImprovement(parameters); + assertEquals(123, getCurativeMinObjImprovement(parameters), DOUBLE_TOLERANCE); + } + @Test void checkRangeActionsOptimizationConfig() { MapModuleConfig rangeActionsOptimizationModuleConfig = platformCfg.createModuleConfig("rao-range-actions-optimization"); @@ -71,18 +92,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()); + com.powsybl.openrao.raoapi.parameters.extensions.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(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, paramsExt.getPstModel()); + assertEquals(com.powsybl.openrao.raoapi.parameters.extensions.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(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver.XPRESS, paramsExt.getLinearOptimizationSolver().getSolver()); + assertEquals(22, paramsExt.getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("blabla", paramsExt.getLinearOptimizationSolver().getSolverSpecificParameters()); } @Test @@ -99,14 +121,15 @@ void checkTopoActionsOptimizationConfig() { RaoParameters parameters = new RaoParameters(); RaoParameters.load(parameters, platformCfg); TopoOptimizationParameters params = parameters.getTopoOptimizationParameters(); - assertEquals(3, params.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(2, params.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(3, params.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(List.of(List.of("na12", "na22"), List.of("na41", "na5", "na6")), params.getPredefinedCombinations()); + com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters paramsExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters(); + assertEquals(3, paramsExt.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, paramsExt.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(3, paramsExt.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(List.of(List.of("na12", "na22"), List.of("na41", "na5", "na6")), paramsExt.getPredefinedCombinations()); assertEquals(0.9, params.getRelativeMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(22, params.getAbsoluteMinImpactThreshold(), DOUBLE_TOLERANCE); - assertTrue(params.getSkipActionsFarFromMostLimitingElement()); - assertEquals(3333, params.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); + assertTrue(paramsExt.getSkipActionsFarFromMostLimitingElement()); + assertEquals(3333, paramsExt.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); } @Test @@ -157,10 +180,10 @@ void checkLoadFlowParametersConfig() { loadFlowModuleConfig.setStringProperty("sensitivity-failure-overcost", Objects.toString(32)); RaoParameters parameters = new RaoParameters(); RaoParameters.load(parameters, platformCfg); - LoadFlowAndSensitivityParameters params = parameters.getLoadFlowAndSensitivityParameters(); - assertEquals("Bonjour", params.getLoadFlowProvider()); - assertEquals("Au revoir", params.getSensitivityProvider()); - assertEquals(32, params.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); + LoadFlowAndSensitivityParameters paramsExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters(); + assertEquals("Bonjour", paramsExt.getLoadFlowProvider()); + assertEquals("Au revoir", paramsExt.getSensitivityProvider()); + assertEquals(32, paramsExt.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); } @Test @@ -213,14 +236,14 @@ void checkRelativeMarginsConfig() { void checkMultipleConfigs() { MapModuleConfig objectiveFunctionModuleConfig = platformCfg.createModuleConfig("rao-objective-function"); objectiveFunctionModuleConfig.setStringProperty("type", "MAX_MIN_RELATIVE_MARGIN"); - objectiveFunctionModuleConfig.setStringProperty("curative-min-obj-improvement", Objects.toString(123.0)); - MapModuleConfig rangeActionsOptimizationModuleConfig = platformCfg.createModuleConfig("rao-range-actions-optimization"); - rangeActionsOptimizationModuleConfig.setStringProperty("max-mip-iterations", Objects.toString(32)); - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); + MapModuleConfig objectiveFunctionExtModuleConfig = platformCfg.createModuleConfig("search-tree-objective-function"); + objectiveFunctionExtModuleConfig.setStringProperty("curative-min-obj-improvement", Objects.toString(123.0)); + MapModuleConfig rangeActionsOptimizationExtModuleConfig = platformCfg.createModuleConfig("search-tree-range-actions-optimization"); + rangeActionsOptimizationExtModuleConfig.setStringProperty("max-mip-iterations", Objects.toString(32)); + RaoParameters parameters = RaoParameters.load(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); + // TODO assertEquals(123, parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement(), 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/RaoParametersConsistencyTest.java b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConsistencyTest.java index 863dec5233..06d0a9d8f1 100644 --- a/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConsistencyTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/parameters/RaoParametersConsistencyTest.java @@ -8,9 +8,12 @@ import com.powsybl.openrao.commons.EICode; import com.powsybl.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; import com.powsybl.iidm.network.Country; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; + import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -20,6 +23,13 @@ */ class RaoParametersConsistencyTest { private final RaoParameters parameters = new RaoParameters(); + private OpenRaoSearchTreeParameters stParameters; + + @BeforeEach + public void generalSetUp() { + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + stParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); + } @Test void testSetBoundariesFromCountryCodes() { @@ -76,42 +86,37 @@ void testRelativeNetworkActionMinimumImpactThresholdBounds() { @Test void testMaxNumberOfBoundariesForSkippingNetworkActionsBounds() { - TopoOptimizationParameters topoOptimizationParameters = parameters.getTopoOptimizationParameters(); - topoOptimizationParameters.setMaxNumberOfBoundariesForSkippingActions(300); - assertEquals(300, topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions()); - topoOptimizationParameters.setMaxNumberOfBoundariesForSkippingActions(-2); - assertEquals(0, topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions()); + stParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(300); + assertEquals(300, stParameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions()); + stParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(-2); + assertEquals(0, stParameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions()); } @Test void testNegativeCurativeRaoMinObjImprovement() { - ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); - objectiveFunctionParameters.setCurativeMinObjImprovement(100); - assertEquals(100, objectiveFunctionParameters.getCurativeMinObjImprovement(), 1e-6); - objectiveFunctionParameters.setCurativeMinObjImprovement(-100); - assertEquals(100, objectiveFunctionParameters.getCurativeMinObjImprovement(), 1e-6); + stParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(100); + assertEquals(100, stParameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement(), 1e-6); + stParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(-100); + assertEquals(100, stParameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement(), 1e-6); } @Test void testNegativeSensitivityFailureOverCost() { - LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = parameters.getLoadFlowAndSensitivityParameters(); - loadFlowAndSensitivityParameters.setSensitivityFailureOvercost(60000); - assertEquals(60000, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), 1e-6); - loadFlowAndSensitivityParameters.setSensitivityFailureOvercost(-20000); - assertEquals(20000, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), 1e-6); + stParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(60000); + assertEquals(60000, stParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost(), 1e-6); + stParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(-20000); + assertEquals(20000, stParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost(), 1e-6); } @Test void testFailsOnLowSensitivityThreshold() { - RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters(); - - Exception e = assertThrows(OpenRaoException.class, () -> rangeActionsOptimizationParameters.setPstSensitivityThreshold(0.)); + Exception e = assertThrows(OpenRaoException.class, () -> stParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(0.)); assertEquals("pstSensitivityThreshold should be greater than 1e-6, to avoid numerical issues.", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> rangeActionsOptimizationParameters.setHvdcSensitivityThreshold(1e-7)); + e = assertThrows(OpenRaoException.class, () -> stParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(1e-7)); assertEquals("hvdcSensitivityThreshold should be greater than 1e-6, to avoid numerical issues.", e.getMessage()); - e = assertThrows(OpenRaoException.class, () -> rangeActionsOptimizationParameters.setInjectionRaSensitivityThreshold(0.)); + e = assertThrows(OpenRaoException.class, () -> stParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(0.)); assertEquals("injectionRaSensitivityThreshold should be greater than 1e-6, to avoid numerical issues.", e.getMessage()); } } 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..2c87bccd7e 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,10 @@ 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.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.RaRangeShrinking; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver; import com.powsybl.commons.config.*; import com.powsybl.commons.test.AbstractSerDeTest; import com.powsybl.iidm.network.Country; @@ -44,32 +44,34 @@ void testConfigWithExtensions() throws IOException { ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); + assertEquals(3, parameters.getExtension(OpenRaoSearchTreeParameters.class).getObjectiveFunctionParameters().getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); 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()); + com.powsybl.openrao.raoapi.parameters.extensions.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(PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParametersExt.getPstModel()); + assertEquals(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(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); - assertEquals(2, topoOptimizationParameters.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(3, topoOptimizationParameters.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), topoOptimizationParameters.getPredefinedCombinations()); + com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters topoOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters(); + assertEquals(3, topoOptimizationParametersExt.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, topoOptimizationParametersExt.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(3, topoOptimizationParametersExt.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), topoOptimizationParametersExt.getPredefinedCombinations()); assertEquals(0.02, topoOptimizationParameters.getRelativeMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(2.0, topoOptimizationParameters.getAbsoluteMinImpactThreshold(), DOUBLE_TOLERANCE); - assertTrue(topoOptimizationParameters.getSkipActionsFarFromMostLimitingElement()); - assertEquals(3, topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); + assertTrue(topoOptimizationParametersExt.getSkipActionsFarFromMostLimitingElement()); + assertEquals(3, topoOptimizationParametersExt.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); MultithreadingParameters multithreadingParameters = parameters.getMultithreadingParameters(); assertEquals(4, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); @@ -85,7 +87,7 @@ void testConfigWithExtensions() throws IOException { NotOptimizedCnecsParameters notOptimizedCnecsParameters = parameters.getNotOptimizedCnecsParameters(); assertFalse(notOptimizedCnecsParameters.getDoNotOptimizeCurativeCnecsForTsosWithoutCras()); - LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = parameters.getLoadFlowAndSensitivityParameters(); + LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters(); assertEquals("LOADFLOW_PROVIDER", loadFlowAndSensitivityParameters.getLoadFlowProvider()); assertEquals("SENSI_PROVIDER", loadFlowAndSensitivityParameters.getSensitivityProvider()); assertEquals(2, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); @@ -125,32 +127,34 @@ void testConfigWithoutExtensions() throws IOException { ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); + assertEquals(3, parameters.getExtension(OpenRaoSearchTreeParameters.class).getObjectiveFunctionParameters().getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); 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()); + com.powsybl.openrao.raoapi.parameters.extensions.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(PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParametersExt.getPstModel()); + assertEquals(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(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); - assertEquals(2, topoOptimizationParameters.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(3, topoOptimizationParameters.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), topoOptimizationParameters.getPredefinedCombinations()); + com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters topoOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters(); + assertEquals(3, topoOptimizationParametersExt.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, topoOptimizationParametersExt.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(3, topoOptimizationParametersExt.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), topoOptimizationParametersExt.getPredefinedCombinations()); assertEquals(0.02, topoOptimizationParameters.getRelativeMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(2.0, topoOptimizationParameters.getAbsoluteMinImpactThreshold(), DOUBLE_TOLERANCE); - assertTrue(topoOptimizationParameters.getSkipActionsFarFromMostLimitingElement()); - assertEquals(3, topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); + assertTrue(topoOptimizationParametersExt.getSkipActionsFarFromMostLimitingElement()); + assertEquals(3, topoOptimizationParametersExt.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); MultithreadingParameters multithreadingParameters = parameters.getMultithreadingParameters(); assertEquals(4, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); @@ -166,10 +170,10 @@ void testConfigWithoutExtensions() throws IOException { NotOptimizedCnecsParameters notOptimizedCnecsParameters = parameters.getNotOptimizedCnecsParameters(); assertFalse(notOptimizedCnecsParameters.getDoNotOptimizeCurativeCnecsForTsosWithoutCras()); - LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = parameters.getLoadFlowAndSensitivityParameters(); - assertEquals("LOADFLOW_PROVIDER", loadFlowAndSensitivityParameters.getLoadFlowProvider()); - assertEquals("SENSI_PROVIDER", loadFlowAndSensitivityParameters.getSensitivityProvider()); - assertEquals(2, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); + LoadFlowAndSensitivityParameters loadFlowAndSensitivityParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters(); + assertEquals("LOADFLOW_PROVIDER", loadFlowAndSensitivityParametersExt.getLoadFlowProvider()); + assertEquals("SENSI_PROVIDER", loadFlowAndSensitivityParametersExt.getSensitivityProvider()); + assertEquals(2, loadFlowAndSensitivityParametersExt.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); // EXTENSIONS assertEquals(0, parameters.getExtensions().size()); @@ -193,32 +197,34 @@ void testConfigWithPartialExtensions() throws IOException { ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); + assertEquals(3, parameters.getExtension(OpenRaoSearchTreeParameters.class).getObjectiveFunctionParameters().getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); 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()); + com.powsybl.openrao.raoapi.parameters.extensions.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(PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParametersExt.getPstModel()); + assertEquals(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(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); - assertEquals(2, topoOptimizationParameters.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(3, topoOptimizationParameters.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); - assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), topoOptimizationParameters.getPredefinedCombinations()); + com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters topoOptimizationParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters(); + assertEquals(3, topoOptimizationParametersExt.getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, topoOptimizationParametersExt.getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(3, topoOptimizationParametersExt.getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), topoOptimizationParametersExt.getPredefinedCombinations()); assertEquals(0.02, topoOptimizationParameters.getRelativeMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(2.0, topoOptimizationParameters.getAbsoluteMinImpactThreshold(), DOUBLE_TOLERANCE); - assertTrue(topoOptimizationParameters.getSkipActionsFarFromMostLimitingElement()); - assertEquals(2, topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); + assertTrue(topoOptimizationParametersExt.getSkipActionsFarFromMostLimitingElement()); + assertEquals(2, topoOptimizationParametersExt.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); MultithreadingParameters multithreadingParameters = parameters.getMultithreadingParameters(); assertEquals(1, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); @@ -234,10 +240,10 @@ void testConfigWithPartialExtensions() throws IOException { NotOptimizedCnecsParameters notOptimizedCnecsParameters = parameters.getNotOptimizedCnecsParameters(); assertFalse(notOptimizedCnecsParameters.getDoNotOptimizeCurativeCnecsForTsosWithoutCras()); - LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = parameters.getLoadFlowAndSensitivityParameters(); - assertEquals("OpenLoadFlow", loadFlowAndSensitivityParameters.getLoadFlowProvider()); - assertEquals("SENSI_PROVIDER", loadFlowAndSensitivityParameters.getSensitivityProvider()); - assertEquals(2, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); + LoadFlowAndSensitivityParameters loadFlowAndSensitivityParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters(); + assertEquals("OpenLoadFlow", loadFlowAndSensitivityParametersExt.getLoadFlowProvider()); + assertEquals("SENSI_PROVIDER", loadFlowAndSensitivityParametersExt.getSensitivityProvider()); + assertEquals(2, loadFlowAndSensitivityParametersExt.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); // EXTENSIONS assertEquals(2, parameters.getExtensions().size()); @@ -268,11 +274,11 @@ void testConfigWithPartialExtensions() throws IOException { @Test void testConfigWithOpenLoadFlowExtension() throws IOException { RaoParameters parameters = loadRaoParameters("config_withOpenLoadFlowExtension"); - LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = parameters.getLoadFlowAndSensitivityParameters(); - assertEquals("OpenLoadFlow", loadFlowAndSensitivityParameters.getLoadFlowProvider()); - assertEquals("OpenLoadFlow", loadFlowAndSensitivityParameters.getSensitivityProvider()); - assertEquals(2, loadFlowAndSensitivityParameters.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); - OpenLoadFlowParameters olfParams = loadFlowAndSensitivityParameters.getSensitivityWithLoadFlowParameters().getLoadFlowParameters().getExtension(OpenLoadFlowParameters.class); + LoadFlowAndSensitivityParameters loadFlowAndSensitivityParametersExt = parameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters(); + assertEquals("OpenLoadFlow", loadFlowAndSensitivityParametersExt.getLoadFlowProvider()); + assertEquals("OpenLoadFlow", loadFlowAndSensitivityParametersExt.getSensitivityProvider()); + assertEquals(2, loadFlowAndSensitivityParametersExt.getSensitivityFailureOvercost(), DOUBLE_TOLERANCE); + OpenLoadFlowParameters olfParams = loadFlowAndSensitivityParametersExt.getSensitivityWithLoadFlowParameters().getLoadFlowParameters().getExtension(OpenLoadFlowParameters.class); assertNotNull(olfParams); assertEquals(0.444, olfParams.getMinPlausibleTargetVoltage(), DOUBLE_TOLERANCE); assertEquals(1.444, olfParams.getMaxPlausibleTargetVoltage(), DOUBLE_TOLERANCE); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java index c6604c5bd9..e20a63db6b 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulator.java @@ -51,6 +51,7 @@ import static com.powsybl.openrao.commons.Unit.MEGAWATT; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.*; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getLoadFlowProvider; import static com.powsybl.openrao.searchtreerao.commons.RaoUtil.applyRemedialActions; /** @@ -462,7 +463,7 @@ Pair> disableHvdcAngleDroopActi } TECHNICAL_LOGS.debug("Running load-flow computation to access HvdcAngleDroopActivePowerControl set-point values."); - Map controls = computeHvdcAngleDroopActivePowerControlValues(network, automatonState, raoParameters.getLoadFlowAndSensitivityParameters().getLoadFlowProvider(), raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters()); + Map controls = computeHvdcAngleDroopActivePowerControlValues(network, automatonState, getLoadFlowProvider(raoParameters), raoParameters.getLoadFlowParameters()); // Next, disable AngleDroopActivePowerControl on HVDCs and set their active power set-points to the value // previously computed by the AngleDroopActivePowerControl. 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 3b13941b6a..10eced941f 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; @@ -48,6 +48,8 @@ import static com.powsybl.openrao.data.cracapi.range.RangeType.RELATIVE_TO_PREVIOUS_INSTANT; import static com.powsybl.openrao.data.raoresultapi.ComputationStatus.DEFAULT; import static com.powsybl.openrao.data.raoresultapi.ComputationStatus.FAILURE; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getSensitivityFailureOvercost; +import static com.powsybl.openrao.raoapi.parameters.extensions.ObjectiveFunctionParameters.getCurativeMinObjImprovement; import static com.powsybl.openrao.searchtreerao.commons.RaoLogger.formatDouble; import static com.powsybl.openrao.searchtreerao.commons.RaoUtil.applyRemedialActions; @@ -331,7 +333,7 @@ private Object runScenario(Crac crac, RaoParameters raoParameters, StateTree sta Set curativeStates = new HashSet<>(); optimizedScenario.getCurativePerimeters().forEach(perimeter -> curativeStates.addAll(perimeter.getAllStates())); PrePerimeterResult preCurativeResult = prePerimeterSensitivityOutput; - double sensitivityFailureOvercost = raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost(); + double sensitivityFailureOvercost = getSensitivityFailureOvercost(raoParameters); // Simulate automaton instant boolean autoStateSensiFailed = false; @@ -513,7 +515,7 @@ static boolean shouldRunSecondPreventiveRao(RaoParameters raoParameters, Optimiz return isAnyResultUnsecure(curativeRaoResults); } else { // MIN OBJECTIVE // Run 2nd preventive RAO if the final result has a worse cost than the preventive perimeter - return isFinalCostWorseThanPreventive(raoParameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement(), firstPreventiveResult, postFirstRaoResult, lastCurativeInstant); + return isFinalCostWorseThanPreventive(getCurativeMinObjImprovement(raoParameters), firstPreventiveResult, postFirstRaoResult, lastCurativeInstant); } } @@ -598,7 +600,7 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, // Specific case : curative state was previously skipped because it led to a sensitivity analysis failure. // Curative state is still a SkippedOptimizationResultImpl, but its computation status must be updated if (entry.getValue() instanceof SkippedOptimizationResultImpl) { - newPostContingencyResults.put(state, new SkippedOptimizationResultImpl(state, new HashSet<>(), new HashSet<>(), postCraSensitivityAnalysisOutput.getSensitivityStatus(entry.getKey()), raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost())); + newPostContingencyResults.put(state, new SkippedOptimizationResultImpl(state, new HashSet<>(), new HashSet<>(), postCraSensitivityAnalysisOutput.getSensitivityStatus(entry.getKey()), getSensitivityFailureOvercost(raoParameters))); } else { newPostContingencyResults.put(state, new CurativeWithSecondPraoResult(state, entry.getValue(), secondPreventiveRaoResult.perimeterResult(), secondPreventiveRaoResult.remedialActionsExcluded(), postCraSensitivityAnalysisOutput)); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java index 185558e598..3205a64454 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/RaoUtil.java @@ -7,6 +7,8 @@ package com.powsybl.openrao.searchtreerao.commons; +import com.powsybl.iidm.network.Network; +import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider; @@ -14,18 +16,17 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.cnec.Cnec; import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; -import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracapi.usagerule.*; import com.powsybl.openrao.data.refprog.referenceprogram.ReferenceProgramBuilder; import com.powsybl.openrao.raoapi.RaoInput; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; -import com.powsybl.openrao.searchtreerao.result.api.*; -import com.powsybl.iidm.network.Network; +import com.powsybl.openrao.searchtreerao.result.api.FlowResult; +import com.powsybl.openrao.searchtreerao.result.api.OptimizationResult; import org.apache.commons.lang3.tuple.Pair; import java.util.Objects; @@ -33,6 +34,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getLoadFlowProvider; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getPstModel; import static java.lang.String.format; /** @@ -65,7 +68,7 @@ public static void checkParameters(RaoParameters raoParameters, RaoInput raoInpu || raoParameters.getObjectiveFunctionParameters().getType().relativePositiveMargins()) && (Objects.isNull(raoInput.getReferenceProgram()))) { OpenRaoLoggerProvider.BUSINESS_WARNS.warn("No ReferenceProgram provided. A ReferenceProgram will be generated using information in the network file."); - raoInput.setReferenceProgram(ReferenceProgramBuilder.buildReferenceProgram(raoInput.getNetwork(), raoParameters.getLoadFlowAndSensitivityParameters().getLoadFlowProvider(), raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters())); + raoInput.setReferenceProgram(ReferenceProgramBuilder.buildReferenceProgram(raoInput.getNetwork(), getLoadFlowProvider(raoParameters), raoParameters.getLoadFlowParameters())); } if (raoParameters.hasExtension(LoopFlowParametersExtension.class) && (Objects.isNull(raoInput.getReferenceProgram()) || Objects.isNull(raoInput.getGlskProvider()))) { @@ -76,7 +79,7 @@ public static void checkParameters(RaoParameters raoParameters, RaoInput raoInpu throw new OpenRaoException(msg); } - if (!RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS.equals(raoParameters.getRangeActionsOptimizationParameters().getPstModel()) + if (!PstModel.APPROXIMATED_INTEGERS.equals(getPstModel(raoParameters)) && raoInput.getCrac().getRaUsageLimitsPerInstant().values().stream().anyMatch(raUsageLimits -> !raUsageLimits.getMaxElementaryActionsPerTso().isEmpty())) { String msg = "The PSTs must be approximated as integers to use the limitations of elementary actions as a constraint in the RAO."; OpenRaoLoggerProvider.BUSINESS_LOGS.error(msg); @@ -209,6 +212,6 @@ public static void applyRemedialActions(Network network, OptimizationResult optR } public static Unit getObjectiveFunctionUnit(RaoParameters raoParameters) { - return raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE; + return raoParameters.getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE; } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java index 769cc137fb..5f1b0671bb 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java @@ -32,6 +32,9 @@ import java.util.*; import java.util.stream.Collectors; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getSensitivityProvider; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getSensitivityWithLoadFlowParameters; + /** * @author Joris Mancini {@literal } */ @@ -91,13 +94,13 @@ public SystematicSensitivityInterface getSystematicSensitivityInterface(Set} */ @@ -83,8 +85,9 @@ public ObjectiveFunction buildForInitialSensitivityComputation(Set flo // sensitivity failure over-cost should be computed on initial sensitivity result too // (this allows the RAO to prefer RAs that can remove sensitivity failures) - if (raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost() > 0) { - this.withVirtualCostEvaluator(new SensitivityFailureOvercostEvaluator(flowCnecs, raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost())); + double sensitivityFailureOvercost = getSensitivityFailureOvercost(raoParameters); + if (sensitivityFailureOvercost > 0) { + this.withVirtualCostEvaluator(new SensitivityFailureOvercostEvaluator(flowCnecs, sensitivityFailureOvercost)); } return this.build(); @@ -136,8 +139,9 @@ public ObjectiveFunction build(Set flowCnecs, // If sensi failed, create a high virtual cost via SensitivityFailureOvercostEvaluator // to ensure that corresponding leaf is not selected - if (raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost() > 0) { - this.withVirtualCostEvaluator(new SensitivityFailureOvercostEvaluator(flowCnecs, raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost())); + double sensitivityFailureOvercost = getSensitivityFailureOvercost(raoParameters); + if (sensitivityFailureOvercost > 0) { + this.withVirtualCostEvaluator(new SensitivityFailureOvercostEvaluator(flowCnecs, sensitivityFailureOvercost)); } return this.build(); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParameters.java index 06adeb68c0..43be8dfd7c 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParameters.java @@ -8,12 +8,14 @@ import com.powsybl.openrao.data.cracapi.Crac; import com.powsybl.openrao.data.cracapi.networkaction.NetworkAction; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.TopoOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.NetworkActionCombination; import java.util.*; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; +import static com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.*; /** * @author Baptiste Seguinot {@literal } @@ -60,12 +62,13 @@ public int getMaxNumberOfBoundariesForSkippingNetworkActions() { return maxNumberOfBoundariesForSkippingNetworkActions; } - public static NetworkActionParameters buildFromRaoParameters(TopoOptimizationParameters topoOptimizationParameters, Crac crac) { - return new NetworkActionParameters(computePredefinedCombinations(crac, topoOptimizationParameters), + public static NetworkActionParameters buildFromRaoParameters(RaoParameters raoParameters, Crac crac) { + TopoOptimizationParameters topoOptimizationParameters = raoParameters.getTopoOptimizationParameters(); + return new NetworkActionParameters(computePredefinedCombinations(crac, raoParameters), topoOptimizationParameters.getAbsoluteMinImpactThreshold(), topoOptimizationParameters.getRelativeMinImpactThreshold(), - topoOptimizationParameters.getSkipActionsFarFromMostLimitingElement(), - topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions()); + isSkipActionsFarFromMostLimitingElement(raoParameters), + getMaxNumberOfBoundariesForSkippingActions(raoParameters)); } public void addNetworkActionCombination(NetworkActionCombination networkActionCombination) { @@ -95,8 +98,8 @@ public int hashCode() { return Objects.hash(predefinedCombinations, absoluteNetworkActionMinimumImpactThreshold, relativeNetworkActionMinimumImpactThreshold, skipNetworkActionFarFromMostLimitingElements, maxNumberOfBoundariesForSkippingNetworkActions); } - public static List computePredefinedCombinations(Crac crac, TopoOptimizationParameters topoOptimizationParameters) { - List> predefinedCombinationsIds = topoOptimizationParameters.getPredefinedCombinations(); + public static List computePredefinedCombinations(Crac crac, RaoParameters raoParameters) { + List> predefinedCombinationsIds = getPredefinedCombinations(raoParameters); List computedPredefinedCombinations = new ArrayList<>(); predefinedCombinationsIds.forEach(networkActionIds -> { Optional optNaCombination = computePredefinedCombinationsFromIds(networkActionIds, crac); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParameters.java index e9755308a8..f4d6b16e03 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/parameters/TreeParameters.java @@ -7,9 +7,13 @@ 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.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import static com.powsybl.openrao.raoapi.parameters.extensions.ObjectiveFunctionParameters.getCurativeMinObjImprovement; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getRaRangeShrinking; +import static com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.*; + /** * This class contains internal Open RAO parameters used in the SearchTree algorithm. * These parameters are dynamically generated by the SearchTreeRaoProvider depending on the context and on @@ -26,26 +30,26 @@ public enum StopCriterion { } public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) { - RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking(); + RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = getRaRangeShrinking(parameters); boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); if (parameters.getObjectiveFunctionParameters().getType() == ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW) { return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, // secure - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), shouldShrinkRaRange); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), shouldShrinkRaRange); } } public static TreeParameters buildForAutomatonPerimeter(RaoParameters parameters) { - return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), parameters.getMultithreadingParameters().getAutoLeavesInParallel(), false); + return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, getMaxAutoSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getAutoLeavesInParallel(), false); } public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, Double preventiveOptimizedCost) { @@ -54,33 +58,33 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, if (parameters.getObjectiveFunctionParameters().getType() == ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW) { targetObjectiveValue = 0.0; } else { - targetObjectiveValue = preventiveOptimizedCost - parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement(); + targetObjectiveValue = preventiveOptimizedCost - getCurativeMinObjImprovement(parameters); if (parameters.getObjectiveFunctionParameters().getEnforceCurativeSecurity()) { targetObjectiveValue = Math.min(targetObjectiveValue, 0); } } - RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking(); + RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = getRaRangeShrinking(parameters); boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, - parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), shouldShrinkRaRange); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { - boolean raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking().equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + boolean raRangeShrinking = getRaRangeShrinking(parameters).equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); if (parameters.getObjectiveFunctionParameters().getType().equals(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW)) { return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, // secure - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), raRangeShrinking); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), raRangeShrinking); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java index 3f6cae07c5..c0513032d2 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; import com.powsybl.openrao.searchtreerao.commons.SensitivityComputer; import com.powsybl.openrao.searchtreerao.commons.objectivefunctionevaluator.ObjectiveFunction; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.GlobalOptimizationPerimeter; @@ -126,7 +126,7 @@ private static SensitivityComputer runSensitivityAnalysis(SensitivityComputer se private static RangeActionActivationResult resolveIfApproximatedPstTaps(IteratingLinearOptimizationResultImpl bestResult, LinearProblem linearProblem, int iteration, RangeActionActivationResult currentRangeActionActivationResult, IteratingLinearOptimizerInput input, IteratingLinearOptimizerParameters parameters) { LinearProblemStatus solveStatus; RangeActionActivationResult rangeActionActivationResult = currentRangeActionActivationResult; - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { + if (parameters.getRangeActionParametersExtension().getPstModel().equals(PstModel.APPROXIMATED_INTEGERS)) { // if the PST approximation is APPROXIMATED_INTEGERS, we re-solve the optimization problem // but first, we update it, with an adjustment of the PSTs angleToTap conversion factors, to @@ -240,7 +240,7 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu } private static RangeActionActivationResultImpl roundPsts(RangeActionActivationResult linearProblemResult, IteratingLinearOptimizationResultImpl previousResult, IteratingLinearOptimizerInput input, IteratingLinearOptimizerParameters parameters) { - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.CONTINUOUS)) { + if (parameters.getRangeActionParametersExtension().getPstModel().equals(PstModel.CONTINUOUS)) { return BestTapFinder.round( linearProblemResult, input.getNetwork(), 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 9781309c97..1eae9ab1f2 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 @@ -18,6 +18,7 @@ import com.powsybl.openrao.data.cracapi.range.TapRange; import com.powsybl.openrao.data.cracapi.rangeaction.*; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPConstraint; @@ -44,24 +45,28 @@ public class CoreProblemFiller implements ProblemFiller { private final Set flowCnecs; private final RangeActionSetpointResult prePerimeterRangeActionSetpoints; private final RangeActionsOptimizationParameters rangeActionParameters; + private final com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; + private final Unit unit; private int iteration = 0; private static final double RANGE_SHRINK_RATE = 0.667; private final boolean raRangeShrinking; - private final RangeActionsOptimizationParameters.PstModel pstModel; + private final PstModel pstModel; public CoreProblemFiller(OptimizationPerimeter optimizationContext, RangeActionSetpointResult prePerimeterRangeActionSetpoints, RangeActionsOptimizationParameters rangeActionParameters, + com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension, Unit unit, boolean raRangeShrinking, - RangeActionsOptimizationParameters.PstModel pstModel) { + PstModel pstModel) { this.optimizationContext = optimizationContext; this.flowCnecs = new TreeSet<>(Comparator.comparing(Identifiable::getId)); this.flowCnecs.addAll(optimizationContext.getFlowCnecs()); this.prePerimeterRangeActionSetpoints = prePerimeterRangeActionSetpoints; this.rangeActionParameters = rangeActionParameters; + this.rangeActionParametersExtension = rangeActionParametersExtension; this.unit = unit; this.raRangeShrinking = raRangeShrinking; this.pstModel = pstModel; @@ -183,11 +188,11 @@ private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, Sensitivi private boolean isRangeActionSensitivityAboveThreshold(RangeAction rangeAction, double sensitivity) { if (rangeAction instanceof PstRangeAction) { - return sensitivity >= rangeActionParameters.getPstSensitivityThreshold(); + return sensitivity >= rangeActionParametersExtension.getPstSensitivityThreshold(); } else if (rangeAction instanceof HvdcRangeAction) { - return sensitivity >= rangeActionParameters.getHvdcSensitivityThreshold(); + return sensitivity >= rangeActionParametersExtension.getHvdcSensitivityThreshold(); } else if (rangeAction instanceof InjectionRangeAction) { - return sensitivity >= rangeActionParameters.getInjectionRaSensitivityThreshold(); + return sensitivity >= rangeActionParametersExtension.getInjectionRaSensitivityThreshold(); } else { throw new OpenRaoException("Type of RangeAction not yet handled by the LinearRao."); } @@ -289,7 +294,7 @@ private void buildConstraintsForRangeActionAndState(LinearProblem linearProblem, double maxRelativeSetpoint = minAndMaxAbsoluteAndRelativeSetpoints.get(3); // relative range - if (pstModel.equals(RangeActionsOptimizationParameters.PstModel.CONTINUOUS) || !(rangeAction instanceof PstRangeAction)) { + if (pstModel.equals(PstModel.CONTINUOUS) || !(rangeAction instanceof PstRangeAction)) { OpenRaoMPConstraint relSetpointConstraint = linearProblem.addRangeActionRelativeSetpointConstraint(minRelativeSetpoint, maxRelativeSetpoint, rangeAction, state, LinearProblem.RaRangeShrinking.FALSE); relSetpointConstraint.setCoefficient(setPointVariable, 1); relSetpointConstraint.setCoefficient(previousSetpointVariable, -1); @@ -408,11 +413,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/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java index 67c731a3ff..e4bc0b5772 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java @@ -12,7 +12,7 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.fillers.ProblemFiller; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.LinearProblemStatus; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java index 7fc5c8a7fc..0516aa9ffe 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.CurativeOptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.fillers.*; import com.powsybl.openrao.searchtreerao.linearoptimisation.inputs.IteratingLinearOptimizerInput; @@ -37,12 +37,15 @@ public LinearProblem buildFromInputsAndParameters(IteratingLinearOptimizerInput this.inputs = inputs; this.parameters = parameters; - this.withSolver(parameters.getSolverParameters().getSolver()) - .withRelativeMipGap(parameters.getSolverParameters().getRelativeMipGap()) + this.withRelativeMipGap(parameters.getSolverParameters().getRelativeMipGap()) .withSolverSpecificParameters(parameters.getSolverParameters().getSolverSpecificParameters()) .withProblemFiller(buildCoreProblemFiller()) .withInitialRangeActionActivationResult(inputs.getRaActivationFromParentLeaf()); + if (parameters.isRaoWithSolverParameters()) { + this.withSolver(parameters.getSolverParameters().getSolver()); + } + // max.min margin, or max.min relative margin if (parameters.relativePositiveMargins()) { this.withProblemFiller(buildMaxMinRelativeMarginFiller()); @@ -68,7 +71,7 @@ public LinearProblem buildFromInputsAndParameters(IteratingLinearOptimizerInput } // MIP optimization vs. CONTINUOUS optimization - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { + if (!Objects.isNull(parameters.getRangeActionParametersExtension()) && parameters.getRangeActionParametersExtension().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { Map> pstRangeActions = copyOnlyPstRangeActions(inputs.getOptimizationPerimeter().getRangeActionsPerState()); Map>> otherRa = copyWithoutPstRangeActions(inputs.getOptimizationPerimeter().getRangeActionsPerState()); this.withProblemFiller(buildIntegerPstTapFiller(pstRangeActions)); @@ -97,7 +100,7 @@ public LinearProblemBuilder withProblemFiller(ProblemFiller problemFiller) { return this; } - public LinearProblemBuilder withSolver(RangeActionsOptimizationParameters.Solver solver) { + public LinearProblemBuilder withSolver(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver solver) { this.solver = solver; return this; } @@ -121,10 +124,11 @@ private ProblemFiller buildCoreProblemFiller() { return new CoreProblemFiller( inputs.getOptimizationPerimeter(), inputs.getPrePerimeterSetpoints(), - parameters.getRangeActionParameters(), + parameters.getRangeActionParameters(), + parameters.getRangeActionParametersExtension(), parameters.getObjectiveFunctionUnit(), parameters.getRaRangeShrinking(), - parameters.getRangeActionParameters().getPstModel() + Objects.isNull(parameters.getRangeActionParametersExtension()) ? null : parameters.getRangeActionParametersExtension().getPstModel() ); } @@ -193,7 +197,7 @@ private ProblemFiller buildRaUsageLimitsFiller() { inputs.getOptimizationPerimeter().getRangeActionsPerState(), inputs.getPrePerimeterSetpoints(), parameters.getRaLimitationParameters(), - parameters.getRangeActionParameters().getPstModel() == RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, + !Objects.isNull(parameters.getRangeActionParametersExtension()) && parameters.getRangeActionParametersExtension().getPstModel() == RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, inputs.getNetwork()); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java index b879396ffa..230963404b 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java @@ -12,7 +12,7 @@ import com.google.ortools.linearsolver.MPSolverParameters; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.result.api.LinearProblemStatus; import java.util.Map; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java index dfbdf8cf01..9a1e254071 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java @@ -10,6 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.LinearOptimizationSolver; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; @@ -23,12 +24,13 @@ public final class IteratingLinearOptimizerParameters { private final Unit objectiveFunctionUnit; private final boolean relativePositiveMargins; private final RangeActionsOptimizationParameters rangeActionParameters; + private final com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; private final MnecParametersExtension mnecParameters; private final RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private final LoopFlowParametersExtension loopFlowParameters; private final UnoptimizedCnecParameters unoptimizedCnecParameters; private final RangeActionLimitationParameters raLimitationParameters; - private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private final LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; private final boolean raRangeShrinking; @@ -36,17 +38,19 @@ public final class IteratingLinearOptimizerParameters { private IteratingLinearOptimizerParameters(Unit objectiveFunctionUnit, boolean relativePositiveMargins, RangeActionsOptimizationParameters rangeActionParameters, + com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension, MnecParametersExtension mnecParameters, RelativeMarginsParametersExtension maxMinRelativeMarginParameters, LoopFlowParametersExtension loopFlowParameters, UnoptimizedCnecParameters unoptimizedCnecParameters, RangeActionLimitationParameters raLimitationParameters, - RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, + LinearOptimizationSolver solverParameters, int maxNumberOfIterations, boolean raRangeShrinking) { this.objectiveFunctionUnit = objectiveFunctionUnit; this.relativePositiveMargins = relativePositiveMargins; this.rangeActionParameters = rangeActionParameters; + this.rangeActionParametersExtension = rangeActionParametersExtension; this.mnecParameters = mnecParameters; this.maxMinRelativeMarginParameters = maxMinRelativeMarginParameters; this.loopFlowParameters = loopFlowParameters; @@ -73,10 +77,18 @@ public boolean isRaoWithMnecLimitation() { return mnecParameters != null; } + public boolean isRaoWithSolverParameters() { + return solverParameters != null; + } + public RangeActionsOptimizationParameters getRangeActionParameters() { return rangeActionParameters; } + public com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters getRangeActionParametersExtension() { + return rangeActionParametersExtension; + } + public MnecParametersExtension getMnecParameters() { return mnecParameters; } @@ -97,7 +109,7 @@ public RangeActionLimitationParameters getRaLimitationParameters() { return raLimitationParameters; } - public RangeActionsOptimizationParameters.LinearOptimizationSolver getSolverParameters() { + public LinearOptimizationSolver getSolverParameters() { return solverParameters; } @@ -118,12 +130,14 @@ public static class LinearOptimizerParametersBuilder { private Unit objectiveFunctionUnit; private boolean relativePositiveMargins; private RangeActionsOptimizationParameters rangeActionParameters; + private com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; + private MnecParametersExtension mnecParameters; private RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private LoopFlowParametersExtension loopFlowParameters; private UnoptimizedCnecParameters unoptimizedCnecParameters; private RangeActionLimitationParameters raLimitationParameters; - private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; private boolean raRangeShrinking; @@ -142,6 +156,11 @@ public LinearOptimizerParametersBuilder withRangeActionParameters(RangeActionsOp return this; } + public LinearOptimizerParametersBuilder withRangeActionParametersExtension(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParameters) { + this.rangeActionParametersExtension = rangeActionParameters; + return this; + } + public LinearOptimizerParametersBuilder withMnecParameters(MnecParametersExtension mnecParameters) { this.mnecParameters = mnecParameters; return this; @@ -167,7 +186,7 @@ public LinearOptimizerParametersBuilder withRaLimitationParameters(RangeActionLi return this; } - public LinearOptimizerParametersBuilder withSolverParameters(RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters) { + public LinearOptimizerParametersBuilder withSolverParameters(LinearOptimizationSolver solverParameters) { this.solverParameters = solverParameters; return this; } @@ -191,6 +210,7 @@ public IteratingLinearOptimizerParameters build() { objectiveFunctionUnit, relativePositiveMargins, rangeActionParameters, + rangeActionParametersExtension, mnecParameters, maxMinRelativeMarginParameters, loopFlowParameters, diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java index e5676b5a2d..95bfba3b21 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java @@ -210,6 +210,7 @@ void optimize(SearchTreeInput searchTreeInput, SearchTreeParameters parameters) .withObjectiveFunctionUnit(parameters.getObjectiveFunctionUnit()) .withRelativePositiveMargins(parameters.relativePositiveMargins()) .withRangeActionParameters(parameters.getRangeActionParameters()) + .withRangeActionParametersExtension(parameters.getRangeActionParametersExtension()) .withMnecParameters(parameters.getMnecParameters()) .withMaxMinRelativeMarginParameters(parameters.getMaxMinRelativeMarginParameters()) .withLoopFlowParameters(parameters.getLoopFlowParameters()) diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java index 388d1cecad..5312d4fa97 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java @@ -14,6 +14,7 @@ import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.LinearOptimizationSolver; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; @@ -28,6 +29,9 @@ import java.util.Map; import java.util.Set; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getLinearOptimizationSolver; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getMaxMipIterations; + /** * @author Baptiste Seguinot {@literal } */ @@ -43,11 +47,13 @@ public class SearchTreeParameters { // required for sub-module iterating linear optimizer private final RangeActionsOptimizationParameters rangeActionParameters; + private final com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; + private final MnecParametersExtension mnecParameters; private final RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private final LoopFlowParametersExtension loopFlowParameters; private final UnoptimizedCnecParameters unoptimizedCnecParameters; - private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private final LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; public SearchTreeParameters(Unit objectiveFunctionUnit, @@ -56,11 +62,12 @@ public SearchTreeParameters(Unit objectiveFunctionUnit, NetworkActionParameters networkActionParameters, Map raLimitationParameters, RangeActionsOptimizationParameters rangeActionParameters, + com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension, MnecParametersExtension mnecParameters, RelativeMarginsParametersExtension maxMinRelativeMarginParameters, LoopFlowParametersExtension loopFlowParameters, UnoptimizedCnecParameters unoptimizedCnecParameters, - RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, + LinearOptimizationSolver solverParameters, int maxNumberOfIterations) { this.objectiveFunctionUnit = objectiveFunctionUnit; this.relativePositiveMargins = relativePositiveMargins; @@ -68,6 +75,7 @@ public SearchTreeParameters(Unit objectiveFunctionUnit, this.networkActionParameters = networkActionParameters; this.raLimitationParameters = raLimitationParameters; this.rangeActionParameters = rangeActionParameters; + this.rangeActionParametersExtension = rangeActionParametersExtension; this.mnecParameters = mnecParameters; this.maxMinRelativeMarginParameters = maxMinRelativeMarginParameters; this.loopFlowParameters = loopFlowParameters; @@ -100,6 +108,10 @@ public RangeActionsOptimizationParameters getRangeActionParameters() { return rangeActionParameters; } + public com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters getRangeActionParametersExtension() { + return rangeActionParametersExtension; + } + public MnecParametersExtension getMnecParameters() { return mnecParameters; } @@ -116,7 +128,7 @@ public UnoptimizedCnecParameters getUnoptimizedCnecParameters() { return unoptimizedCnecParameters; } - public RangeActionsOptimizationParameters.LinearOptimizationSolver getSolverParameters() { + public LinearOptimizationSolver getSolverParameters() { return solverParameters; } @@ -249,24 +261,25 @@ public static class SearchTreeParametersBuilder { private NetworkActionParameters networkActionParameters; private Map raLimitationParameters; private RangeActionsOptimizationParameters rangeActionParameters; + private com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; private MnecParametersExtension mnecParameters; private RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private LoopFlowParametersExtension loopFlowParameters; private UnoptimizedCnecParameters unoptimizedCnecParameters; - private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; public SearchTreeParametersBuilder withConstantParametersOverAllRao(RaoParameters raoParameters, Crac crac) { this.objectiveFunctionUnit = RaoUtil.getObjectiveFunctionUnit(raoParameters); this.relativePositiveMargins = raoParameters.getObjectiveFunctionParameters().getType().relativePositiveMargins(); - this.networkActionParameters = NetworkActionParameters.buildFromRaoParameters(raoParameters.getTopoOptimizationParameters(), crac); + this.networkActionParameters = NetworkActionParameters.buildFromRaoParameters(raoParameters, crac); this.raLimitationParameters = new HashMap<>(crac.getRaUsageLimitsPerInstant()); this.rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); this.mnecParameters = raoParameters.getExtension(MnecParametersExtension.class); this.maxMinRelativeMarginParameters = raoParameters.getExtension(RelativeMarginsParametersExtension.class); this.loopFlowParameters = raoParameters.getExtension(LoopFlowParametersExtension.class); - this.solverParameters = raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver(); - this.maxNumberOfIterations = raoParameters.getRangeActionsOptimizationParameters().getMaxMipIterations(); + this.solverParameters = getLinearOptimizationSolver(raoParameters); + this.maxNumberOfIterations = getMaxMipIterations(raoParameters); return this; } @@ -320,7 +333,7 @@ public SearchTreeParametersBuilder withUnoptimizedCnecParameters(UnoptimizedCnec return this; } - public SearchTreeParametersBuilder withSolverParameters(RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters) { + public SearchTreeParametersBuilder withSolverParameters(LinearOptimizationSolver solverParameters) { this.solverParameters = solverParameters; return this; } @@ -337,6 +350,7 @@ public SearchTreeParameters build() { networkActionParameters, raLimitationParameters, rangeActionParameters, + rangeActionParametersExtension, mnecParameters, maxMinRelativeMarginParameters, loopFlowParameters, 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 20c7daef22..1ae562fa94 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/NetworkActionParametersTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParametersTest.java index 07207682a5..ead1fd2c79 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParametersTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParametersTest.java @@ -107,7 +107,7 @@ void testNetworkActionCombinations() { List.of("topological-action-1"), // should be filtered (one action only) new ArrayList<>())); // should be filtered - List naCombinations = NetworkActionParameters.computePredefinedCombinations(crac, parameters.getTopoOptimizationParameters()); + List naCombinations = NetworkActionParameters.computePredefinedCombinations(crac, parameters); assertEquals(5, parameters.getTopoOptimizationParameters().getPredefinedCombinations().size()); assertEquals(2, naCombinations.size()); 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 c4fb72342b..114b0896a2 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 @@ -56,9 +56,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 08663f5905..e6e6733136 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 65b723189d..6455a0f46f 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 @@ -99,9 +99,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 e13a1dc988..651804d746 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 @@ -77,9 +77,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/searchtree/parameters/SearchTreeParametersTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java index 2ff6a241c1..736478c928 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParametersTest.java @@ -62,8 +62,8 @@ void testWithConstantParametersOverAllRao() { assertEquals(raoParameters.getExtension(MnecParametersExtension.class), searchTreeParameters.getMnecParameters()); assertEquals(raoParameters.getExtension(RelativeMarginsParametersExtension.class), searchTreeParameters.getMaxMinRelativeMarginParameters()); assertEquals(raoParameters.getExtension(LoopFlowParametersExtension.class), searchTreeParameters.getLoopFlowParameters()); - assertEquals(raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver(), searchTreeParameters.getSolverParameters()); - assertEquals(raoParameters.getRangeActionsOptimizationParameters().getMaxMipIterations(), searchTreeParameters.getMaxNumberOfIterations()); + assertEquals(raoParameters.getExtension(RangeActionsOptimizationParameters.class).getLinearOptimizationSolver(), searchTreeParameters.getSolverParameters()); + assertEquals(raoParameters.getExtension(RangeActionsOptimizationParameters.class).getMaxMipIterations(), searchTreeParameters.getMaxNumberOfIterations()); } @Test