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..1afe1d5442 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"; @@ -31,16 +33,18 @@ private RaoParametersCommons() { // range actions optimization parameters 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 ST_RANGE_ACTIONS_OPTIMIZATION_SECTION = "search-tree-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"; + public static final String LINEAR_OPTIMIZATION_SOLVER_SECTION = "search-tree-linear-optimization-solver"; public static final String SOLVER = "solver"; public static final String RELATIVE_MIP_GAP = "relative-mip-gap"; public static final String SOLVER_SPECIFIC_PARAMETERS = "solver-specific-parameters"; @@ -49,6 +53,8 @@ private RaoParametersCommons() { // topological actions optimization parameters public static final String TOPOLOGICAL_ACTIONS_OPTIMIZATION = "topological-actions-optimization"; public static final String TOPOLOGICAL_ACTIONS_OPTIMIZATION_SECTION = "rao-topological-actions-optimization"; + public static final String ST_TOPOLOGICAL_ACTIONS_OPTIMIZATION_SECTION = "search-tree-topological-actions-optimization"; + public static final String MAX_PREVENTIVE_SEARCH_TREE_DEPTH = "max-preventive-search-tree-depth"; public static final String MAX_AUTO_SEARCH_TREE_DEPTH = "max-auto-search-tree-depth"; public static final String MAX_CURATIVE_SEARCH_TREE_DEPTH = "max-curative-search-tree-depth"; @@ -60,38 +66,24 @@ 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 MULTI_THREADING_SECTION = "search-tree-multi-threading"; + public static final String AVAILABLE_CPUS = "available-cpus"; // Second Preventive RAO parameters public static final String SECOND_PREVENTIVE_RAO = "second-preventive-rao"; - public static final String SECOND_PREVENTIVE_RAO_SECTION = "rao-second-preventive-rao"; + public static final String SECOND_PREVENTIVE_RAO_SECTION = "search-tree-second-preventive-rao"; public static final String EXECUTION_CONDITION = "execution-condition"; 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_AND_SENSITIVITY_COMPUTATION_SECTION = "search-tree-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"; @@ -119,6 +111,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..3d88a19ff7 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,14 @@ */ 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.openrao.commons.OpenRaoException; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.io.IOException; import java.util.Collections; @@ -59,22 +59,10 @@ 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: - parser.nextToken(); - JsonLoadFlowAndSensitivityComputationParameters.deserialize(parser, parameters); - break; case "extensions": parser.nextToken(); extensions = JsonUtil.updateExtensions(parser, deserializationContext, JsonRaoParameters.getExtensionSerializers(), parameters); diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java index 4bec9c675f..d475bd65fc 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,11 +6,11 @@ */ 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.openrao.raoapi.parameters.RaoParameters; import java.io.IOException; @@ -32,10 +32,7 @@ public void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, Ser JsonObjectiveFunctionParameters.serialize(parameters, jsonGenerator); JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator); JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator); - JsonSecondPreventiveRaoParameters.serialize(parameters, jsonGenerator); JsonNotOptimizedCnecsParameters.serialize(parameters, jsonGenerator); - JsonLoadFlowAndSensitivityComputationParameters.serialize(parameters, jsonGenerator, serializerProvider); - JsonMultiThreadingParameters.serialize(parameters, jsonGenerator); JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonRaoParameters.getExtensionSerializers()); jsonGenerator.writeEndObject(); } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/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..5c1394916d --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonMultiThreadingParameters.java @@ -0,0 +1,49 @@ +/* + * 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, Math.max( + parameters.getMultithreadingParameters().getContingencyScenariosInParallel(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel())); + 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..3763688efc 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 double getPstRAMinImpactThreshold() { + return pstRAMinImpactThreshold; } - 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 void setPstRAMinImpactThreshold(double pstRAMinImpactThreshold) { + this.pstRAMinImpactThreshold = pstRAMinImpactThreshold; } - public double getHvdcPenaltyCost() { - return hvdcPenaltyCost; + public double getHvdcRAMinImpactThreshold() { + return hvdcRAMinImpactThreshold; } - public void setHvdcPenaltyCost(double hvdcPenaltyCost) { - this.hvdcPenaltyCost = hvdcPenaltyCost; + public void setHvdcRAMinImpactThreshold(double hvdcRAMinImpactThreshold) { + this.hvdcRAMinImpactThreshold = hvdcRAMinImpactThreshold; } - public double getHvdcSensitivityThreshold() { - return hvdcSensitivityThreshold; + public double getInjectionRAMinImpactThreshold() { + return injectionRAMinImpactThreshold; } - 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 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 void setInjectionRAMinImpactThreshold(double injectionRAMinImpactThreshold) { + this.injectionRAMinImpactThreshold = injectionRAMinImpactThreshold; } public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { @@ -201,21 +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; } - - public static RangeActionsOptimizationParameters buildFromRaoParameters(RaoParameters raoParameters) { - return raoParameters.getRangeActionsOptimizationParameters(); - } } 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..ab9d97a98f 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 @@ -25,10 +25,7 @@ public class RaoParameters extends AbstractExtendable { private ObjectiveFunctionParameters objectiveFunctionParameters = new ObjectiveFunctionParameters(); private RangeActionsOptimizationParameters rangeActionsOptimizationParameters = new RangeActionsOptimizationParameters(); private TopoOptimizationParameters topoOptimizationParameters = new TopoOptimizationParameters(); - private MultithreadingParameters multithreadingParameters = new MultithreadingParameters(); - private SecondPreventiveRaoParameters secondPreventiveRaoParameters = new SecondPreventiveRaoParameters(); private NotOptimizedCnecsParameters notOptimizedCnecsParameters = new NotOptimizedCnecsParameters(); - private LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = new LoadFlowAndSensitivityParameters(); // Getters and setters public void setObjectiveFunctionParameters(ObjectiveFunctionParameters objectiveFunctionParameters) { @@ -43,22 +40,10 @@ public void setTopoOptimizationParameters(TopoOptimizationParameters topoOptimiz this.topoOptimizationParameters = topoOptimizationParameters; } - public void setMultithreadingParameters(MultithreadingParameters multithreadingParameters) { - this.multithreadingParameters = multithreadingParameters; - } - - public void setSecondPreventiveRaoParameters(SecondPreventiveRaoParameters secondPreventiveRaoParameters) { - this.secondPreventiveRaoParameters = secondPreventiveRaoParameters; - } - public void setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters notOptimizedCnecsParameters) { this.notOptimizedCnecsParameters = notOptimizedCnecsParameters; } - public void setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters) { - this.loadFlowAndSensitivityParameters = loadFlowAndSensitivityParameters; - } - public ObjectiveFunctionParameters getObjectiveFunctionParameters() { return objectiveFunctionParameters; } @@ -71,26 +56,17 @@ public TopoOptimizationParameters getTopoOptimizationParameters() { return topoOptimizationParameters; } - public MultithreadingParameters getMultithreadingParameters() { - return multithreadingParameters; - } - - public SecondPreventiveRaoParameters getSecondPreventiveRaoParameters() { - return secondPreventiveRaoParameters; - } - public NotOptimizedCnecsParameters getNotOptimizedCnecsParameters() { return notOptimizedCnecsParameters; } - public LoadFlowAndSensitivityParameters getLoadFlowAndSensitivityParameters() { - return loadFlowAndSensitivityParameters; - } - 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 @@ -127,10 +103,7 @@ public static void load(RaoParameters parameters, PlatformConfig platformConfig) parameters.setObjectiveFunctionParameters(ObjectiveFunctionParameters.load(platformConfig)); parameters.setRangeActionsOptimizationParameters(RangeActionsOptimizationParameters.load(platformConfig)); parameters.setTopoOptimizationParameters(TopoOptimizationParameters.load(platformConfig)); - parameters.setMultithreadingParameters(MultithreadingParameters.load(platformConfig)); - parameters.setSecondPreventiveRaoParameters(SecondPreventiveRaoParameters.load(platformConfig)); parameters.setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters.load(platformConfig)); - parameters.setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters.load(platformConfig)); } private void loadExtensions(PlatformConfig platformConfig) { 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 70% 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..7f30ca98b4 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,36 @@ public static LoadFlowAndSensitivityParameters load(PlatformConfig platformConfi return parameters; } - private SensitivityAnalysisParameters cleanLoadFlowParameters(SensitivityAnalysisParameters sensitivityAnalysisParameters) { + public static String getLoadFlowProvider(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters().getLoadFlowProvider(); + } + return DEFAULT_LOADFLOW_PROVIDER; + } + + public static double getSensitivityFailureOvercost(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost(); + } + return DEFAULT_SENSITIVITY_FAILURE_OVERCOST; + } + + public static String getSensitivityProvider(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters().getSensitivityProvider(); + } + return DEFAULT_SENSITIVITY_PROVIDER; + } + + // TODO: do not set if default... + public static SensitivityAnalysisParameters getSensitivityWithLoadFlowParameters(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters(); + } + return cleanLoadFlowParameters(new 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. @@ -88,7 +119,7 @@ private SensitivityAnalysisParameters cleanLoadFlowParameters(SensitivityAnalysi // lead to incoherence. if (loadFlowParameters.isDc() && loadFlowParameters.isHvdcAcEmulation()) { BUSINESS_WARNS.warn("The runs are in DC but the HvdcAcEmulation parameter is on: this is not compatible." + - "HvdcAcEmulation parameter set to false."); + "HvdcAcEmulation parameter set to false."); loadFlowParameters.setHvdcAcEmulation(false); } return sensitivityAnalysisParameters; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/MultithreadingParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java similarity index 57% 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..ed8cd95c22 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,13 +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/. + * 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; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.util.Objects; import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; @@ -63,12 +65,40 @@ 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; } + + public static int getPreventiveLeavesInParallel(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getMultithreadingParameters().getPreventiveLeavesInParallel(); + } + return DEFAULT_PREVENTIVE_LEAVES_IN_PARALLEL; + } + + public static int getCurativeLeavesInParallel(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getMultithreadingParameters().getCurativeLeavesInParallel(); + } + return DEFAULT_CURATIVE_LEAVES_IN_PARALLEL; + } + + public static int getAutoLeavesInParallel(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getMultithreadingParameters().getAutoLeavesInParallel(); + } + return DEFAULT_AUTO_LEAVES_IN_PARALLEL; + } + + public static int getContingencyScenariosInParallel(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getMultithreadingParameters().getContingencyScenariosInParallel(); + } + return DEFAULT_CONTINGENCY_SCENARIOS_IN_PARALLEL; + } } 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..907a04d375 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/ObjectiveFunctionParameters.java @@ -0,0 +1,49 @@ +/* + * 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 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 ObjectiveFunctionParameters load(PlatformConfig platformConfig) { + ObjectiveFunctionParameters parameters = new ObjectiveFunctionParameters(); + platformConfig.getOptionalModuleConfig(ST_OBJECTIVE_FUNCTION_SECTION) + .ifPresent(config -> parameters.setCurativeMinObjImprovement(config.getDoubleProperty(CURATIVE_MIN_OBJ_IMPROVEMENT, DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT))); + 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); + } + + public static double getCurativeMinObjImprovement(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getObjectiveFunctionParameters().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..390e6d3462 --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/OpenRaoSearchTreeParametersConfigLoader.java @@ -0,0 +1,60 @@ +/* + * 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.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; + +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); + List searchTreeParams = Arrays.asList(ST_OBJECTIVE_FUNCTION_SECTION, ST_RANGE_ACTIONS_OPTIMIZATION_SECTION, ST_TOPOLOGICAL_ACTIONS_OPTIMIZATION_SECTION, MULTI_THREADING_SECTION, SECOND_PREVENTIVE_RAO_SECTION, LOAD_FLOW_AND_SENSITIVITY_COMPUTATION_SECTION); + boolean anySearchTreeParams = searchTreeParams.stream().map(platformConfig::getOptionalModuleConfig).anyMatch(Optional::isPresent); + if (!anySearchTreeParams) { + return null; + } + OpenRaoSearchTreeParameters parameters = new OpenRaoSearchTreeParameters(); + parameters.setObjectiveFunctionParameters(ObjectiveFunctionParameters.load(platformConfig)); + parameters.setRangeActionsOptimizationParameters(RangeActionsOptimizationParameters.load(platformConfig)); + parameters.setTopoOptimizationParameters(TopoOptimizationParameters.load(platformConfig)); + parameters.setMultithreadingParameters(MultithreadingParameters.load(platformConfig)); + parameters.setSecondPreventiveRaoParameters(SecondPreventiveRaoParameters.load(platformConfig)); + parameters.setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters.load(platformConfig)); + 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..1b01ad5fbd --- /dev/null +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java @@ -0,0 +1,242 @@ +/* + * 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(ST_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(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().getPstModel(); + } + return DEFAULT_PST_MODEL; + } + + public static RaRangeShrinking getRaRangeShrinking(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().getRaRangeShrinking(); + } + return DEFAULT_RA_RANGE_SHRINKING; + } + + // TODO: do not set if default... + public static LinearOptimizationSolver getLinearOptimizationSolver(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().getLinearOptimizationSolver(); + } + return new LinearOptimizationSolver(); + } + + public static int getMaxMipIterations(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().getMaxMipIterations(); + } + return DEFAULT_MAX_MIP_ITERATIONS; + } + + public static PstModel getPstModel(RangeActionsOptimizationParameters rangeActionsOptimizationParameters) { + if (!Objects.isNull(rangeActionsOptimizationParameters)) { + return rangeActionsOptimizationParameters.getPstModel(); + } + return DEFAULT_PST_MODEL; + } + + public static double getPstSensitivityThreshold(RangeActionsOptimizationParameters rangeActionsOptimizationParameters) { + if (!Objects.isNull(rangeActionsOptimizationParameters)) { + return rangeActionsOptimizationParameters.getPstSensitivityThreshold(); + } + return DEFAULT_PST_SENSITIVITY_THRESHOLD; + } + + public static double getHvdcSensitivityThreshold(RangeActionsOptimizationParameters rangeActionsOptimizationParameters) { + if (!Objects.isNull(rangeActionsOptimizationParameters)) { + return rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(); + } + return DEFAULT_HVDC_SENSITIVITY_THRESHOLD; + } + + public static double getInjectionRaSensitivityThreshold(RangeActionsOptimizationParameters rangeActionsOptimizationParameters) { + if (!Objects.isNull(rangeActionsOptimizationParameters)) { + return rangeActionsOptimizationParameters.getInjectionRaSensitivityThreshold(); + } + return DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD; + } +} 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 70% 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..81a952b059 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,13 +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/. + * 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; +import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.util.Objects; import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; @@ -67,4 +69,25 @@ public static SecondPreventiveRaoParameters load(PlatformConfig platformConfig) }); return parameters; } + + public static ExecutionCondition getExecutionCondition(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getSecondPreventiveRaoParameters().getExecutionCondition(); + } + return DEFAULT_EXECUTION_CONDITION; + } + + public static boolean getReOptimizeCurativeRangeActions(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions(); + } + return DEFAULT_RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS; + } + + public static boolean getHintFromFirstPreventiveRao(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getSecondPreventiveRaoParameters().getHintFromFirstPreventiveRao(); + } + return DEFAULT_HINT_FROM_FIRST_PREVENTIVE_RAO; + } } 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..d06ff35a8c --- /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(ST_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(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(); + } + return DEFAULT_MAX_SEARCH_TREE_DEPTH; + } + + public static int getMaxAutoSearchTreeDepth(RaoParameters parameters) { + if (parameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return parameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(); + } + return DEFAULT_MAX_SEARCH_TREE_DEPTH; + } + + public static boolean isSkipActionsFarFromMostLimitingElement(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement(); + } + return DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT; + } + + public static int getMaxNumberOfBoundariesForSkippingActions(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions(); + } + return DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS; + } + + public static List> getPredefinedCombinations(RaoParameters raoParameters) { + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + return raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getTopoOptimizationParameters().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..13627f1048 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,44 +48,46 @@ void roundTripDefault() throws IOException { @Test void roundTrip() throws IOException { RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); // Objective Function parameters parameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN); - parameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(983); + searchTreeParameters.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); + searchTreeParameters.getRangeActionsOptimizationParameters().setMaxMipIterations(30); + parameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(10); + searchTreeParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(0.2); + parameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(1); + searchTreeParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(0.3); + parameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(1.2); + searchTreeParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(0.7); + searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters("TREEMEMORYLIMIT 20"); + searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(RangeActionsOptimizationParameters.Solver.SCIP); + searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(1e-5); + searchTreeParameters.getRangeActionsOptimizationParameters().setPstModel(PstModel.APPROXIMATED_INTEGERS); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RaRangeShrinking.ENABLED); // TopologicalActions optimization parameters - parameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(10); - parameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(3); - parameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(10); + searchTreeParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(10); + searchTreeParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(3); + searchTreeParameters.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"))); + searchTreeParameters.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); - parameters.getMultithreadingParameters().setAutoLeavesInParallel(30); - parameters.getMultithreadingParameters().setCurativeLeavesInParallel(22); + searchTreeParameters.getMultithreadingParameters().setContingencyScenariosInParallel(15); + searchTreeParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(21); + searchTreeParameters.getMultithreadingParameters().setAutoLeavesInParallel(30); + searchTreeParameters.getMultithreadingParameters().setCurativeLeavesInParallel(22); // Second preventive RAO parameters - parameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); - parameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(true); - parameters.getSecondPreventiveRaoParameters().setHintFromFirstPreventiveRao(true); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); + searchTreeParameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(true); + searchTreeParameters.getSecondPreventiveRaoParameters().setHintFromFirstPreventiveRao(true); // Not optimized cnecs parameters parameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); // LoadFlow and sensitivity parameters - parameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider("OpenLoadFlowProvider"); - parameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider("OpenSensitivityAnalysis"); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider("OpenLoadFlowProvider"); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider("OpenSensitivityAnalysis"); // Extensions // -- LoopFlow parameters parameters.addExtension(LoopFlowParametersExtension.class, new LoopFlowParametersExtension()); @@ -117,23 +116,24 @@ void roundTrip() throws IOException { @Test void update() { RaoParameters parameters = JsonRaoParameters.read(getClass().getResourceAsStream("/RaoParameters_default_v2.json")); - assertEquals(1, parameters.getExtensions().size()); - JsonRaoParameters.update(parameters, getClass().getResourceAsStream("/RaoParameters_update_v2.json")); assertEquals(2, parameters.getExtensions().size()); + JsonRaoParameters.update(parameters, getClass().getResourceAsStream("/RaoParameters_update_v2.json")); + assertEquals(3, 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); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); + assertEquals(5, searchTreeParameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, searchTreeParameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(5, searchTreeParameters.getTopoOptimizationParameters().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()); + assertEquals(8, searchTreeParameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); + assertEquals(1, searchTreeParameters.getMultithreadingParameters().getAutoLeavesInParallel()); + assertEquals(1, searchTreeParameters.getMultithreadingParameters().getCurativeLeavesInParallel()); + assertTrue(searchTreeParameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement()); + assertEquals(2, searchTreeParameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions()); assertTrue(parameters.getNotOptimizedCnecsParameters().getDoNotOptimizeCurativeCnecsForTsosWithoutCras()); - assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE, parameters.getSecondPreventiveRaoParameters().getExecutionCondition()); - assertTrue(parameters.getSecondPreventiveRaoParameters().getHintFromFirstPreventiveRao()); + assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE, searchTreeParameters.getSecondPreventiveRaoParameters().getExecutionCondition()); + assertTrue(searchTreeParameters.getSecondPreventiveRaoParameters().getHintFromFirstPreventiveRao()); // Extensions MnecParametersExtension mnecParameters = parameters.getExtension(MnecParametersExtension.class); assertEquals(888, mnecParameters.getAcceptableMarginDecrease(), DOUBLE_TOLERANCE); 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..cb5c1f02cc 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.*; @@ -42,98 +43,94 @@ public void setUp() { void checkObjectiveFunctionConfig() { MapModuleConfig objectiveFunctionModuleConfig = platformCfg.createModuleConfig("rao-objective-function"); objectiveFunctionModuleConfig.setStringProperty("type", "MAX_MIN_RELATIVE_MARGIN"); - objectiveFunctionModuleConfig.setStringProperty("curative-min-obj-improvement", Objects.toString(123.0)); objectiveFunctionModuleConfig.setStringProperty("enforce-curative-security", "false"); - - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); + MapModuleConfig objectiveFunctionModuleConfigExt = platformCfg.createModuleConfig("search-tree-objective-function"); + objectiveFunctionModuleConfigExt.setStringProperty("curative-min-obj-improvement", Objects.toString(123.0)); + RaoParameters parameters = RaoParameters.load(platformCfg); ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(123, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); + assertEquals(123, getCurativeMinObjImprovement(parameters), DOUBLE_TOLERANCE); assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity()); } @Test void checkRangeActionsOptimizationConfig() { MapModuleConfig rangeActionsOptimizationModuleConfig = platformCfg.createModuleConfig("rao-range-actions-optimization"); - rangeActionsOptimizationModuleConfig.setStringProperty("max-mip-iterations", Objects.toString(4)); - rangeActionsOptimizationModuleConfig.setStringProperty("pst-penalty-cost", Objects.toString(44)); - rangeActionsOptimizationModuleConfig.setStringProperty("pst-sensitivity-threshold", Objects.toString(7)); - rangeActionsOptimizationModuleConfig.setStringProperty("pst-model", "APPROXIMATED_INTEGERS"); - rangeActionsOptimizationModuleConfig.setStringProperty("hvdc-penalty-cost", Objects.toString(33)); - rangeActionsOptimizationModuleConfig.setStringProperty("hvdc-sensitivity-threshold", Objects.toString(8)); - rangeActionsOptimizationModuleConfig.setStringProperty("injection-ra-penalty-cost", Objects.toString(22)); - rangeActionsOptimizationModuleConfig.setStringProperty("injection-ra-sensitivity-threshold", Objects.toString(9)); - MapModuleConfig linearOptimizationSolverModuleConfig = platformCfg.createModuleConfig("rao-linear-optimization-solver"); + rangeActionsOptimizationModuleConfig.setStringProperty("pst-ra-min-impact-threshold", Objects.toString(44)); + rangeActionsOptimizationModuleConfig.setStringProperty("hvdc-ra-min-impact-threshold", Objects.toString(33)); + rangeActionsOptimizationModuleConfig.setStringProperty("injection-ra-min-impact-threshold", Objects.toString(22)); + MapModuleConfig rangeActionsOptimizationModuleConfigExt = platformCfg.createModuleConfig("search-tree-range-actions-optimization"); + rangeActionsOptimizationModuleConfigExt.setStringProperty("max-mip-iterations", Objects.toString(4)); + rangeActionsOptimizationModuleConfigExt.setStringProperty("pst-sensitivity-threshold", Objects.toString(7)); + rangeActionsOptimizationModuleConfigExt.setStringProperty("pst-model", "APPROXIMATED_INTEGERS"); + rangeActionsOptimizationModuleConfigExt.setStringProperty("hvdc-sensitivity-threshold", Objects.toString(8)); + rangeActionsOptimizationModuleConfigExt.setStringProperty("injection-ra-sensitivity-threshold", Objects.toString(9)); + MapModuleConfig linearOptimizationSolverModuleConfig = platformCfg.createModuleConfig("search-tree-linear-optimization-solver"); linearOptimizationSolverModuleConfig.setStringProperty("solver", "XPRESS"); linearOptimizationSolverModuleConfig.setStringProperty("relative-mip-gap", Objects.toString(22)); linearOptimizationSolverModuleConfig.setStringProperty("solver-specific-parameters", "blabla"); - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); + RaoParameters parameters = RaoParameters.load(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 void checkTopoActionsOptimizationConfig() { MapModuleConfig topoActionsModuleConfig = platformCfg.createModuleConfig("rao-topological-actions-optimization"); - topoActionsModuleConfig.setStringProperty("max-preventive-search-tree-depth", Objects.toString(3)); - topoActionsModuleConfig.setStringProperty("max-auto-search-tree-depth", Objects.toString(2)); - topoActionsModuleConfig.setStringProperty("max-curative-search-tree-depth", Objects.toString(3)); - topoActionsModuleConfig.setStringListProperty("predefined-combinations", List.of("{na12} + {na22}", "{na41} + {na5} + {na6}")); topoActionsModuleConfig.setStringProperty("relative-minimum-impact-threshold", Objects.toString(0.9)); topoActionsModuleConfig.setStringProperty("absolute-minimum-impact-threshold", Objects.toString(22)); - topoActionsModuleConfig.setStringProperty("skip-actions-far-from-most-limiting-element", Objects.toString(true)); - topoActionsModuleConfig.setStringProperty("max-number-of-boundaries-for-skipping-actions", Objects.toString(3333)); - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); + MapModuleConfig topoActionsModuleConfigExt = platformCfg.createModuleConfig("search-tree-topological-actions-optimization"); + topoActionsModuleConfigExt.setStringProperty("max-preventive-search-tree-depth", Objects.toString(3)); + topoActionsModuleConfigExt.setStringProperty("max-auto-search-tree-depth", Objects.toString(2)); + topoActionsModuleConfigExt.setStringProperty("max-curative-search-tree-depth", Objects.toString(3)); + topoActionsModuleConfigExt.setStringListProperty("predefined-combinations", List.of("{na12} + {na22}", "{na41} + {na5} + {na6}")); + topoActionsModuleConfigExt.setStringProperty("skip-actions-far-from-most-limiting-element", Objects.toString(true)); + topoActionsModuleConfigExt.setStringProperty("max-number-of-boundaries-for-skipping-actions", Objects.toString(3333)); + RaoParameters parameters = RaoParameters.load(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 void checkMultiThreadingConfig() { - MapModuleConfig multiThreadingModuleConfig = platformCfg.createModuleConfig("rao-multi-threading"); - multiThreadingModuleConfig.setStringProperty("contingency-scenarios-in-parallel", Objects.toString(3)); - multiThreadingModuleConfig.setStringProperty("preventive-leaves-in-parallel", Objects.toString(23)); - multiThreadingModuleConfig.setStringProperty("auto-leaves-in-parallel", Objects.toString(17)); - multiThreadingModuleConfig.setStringProperty("curative-leaves-in-parallel", Objects.toString(43)); - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); - MultithreadingParameters params = parameters.getMultithreadingParameters(); - assertEquals(3, params.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); - assertEquals(23, params.getPreventiveLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(17, params.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(43, params.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); + MapModuleConfig multiThreadingModuleConfig = platformCfg.createModuleConfig("search-tree-multi-threading"); + multiThreadingModuleConfig.setStringProperty("available-cpus", Objects.toString(43)); + RaoParameters parameters = RaoParameters.load(platformCfg); + MultithreadingParameters params = parameters.getExtension(OpenRaoSearchTreeParameters.class).getMultithreadingParameters(); + assertEquals(43, params.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); + assertEquals(43, params.getPreventiveLeavesInParallel(), DOUBLE_TOLERANCE); + assertEquals(1, params.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); + assertEquals(1, params.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); } @Test void checkSecondPreventiveRaoConfig() { - MapModuleConfig secondPreventiveRaoModuleConfig = platformCfg.createModuleConfig("rao-second-preventive-rao"); + MapModuleConfig secondPreventiveRaoModuleConfig = platformCfg.createModuleConfig("search-tree-second-preventive-rao"); secondPreventiveRaoModuleConfig.setStringProperty("execution-condition", "POSSIBLE_CURATIVE_IMPROVEMENT"); secondPreventiveRaoModuleConfig.setStringProperty("re-optimize-curative-range-actions", Objects.toString(false)); secondPreventiveRaoModuleConfig.setStringProperty("hint-from-first-preventive-rao", Objects.toString(true)); - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); - SecondPreventiveRaoParameters params = parameters.getSecondPreventiveRaoParameters(); + RaoParameters parameters = RaoParameters.load(platformCfg); + SecondPreventiveRaoParameters params = parameters.getExtension(OpenRaoSearchTreeParameters.class).getSecondPreventiveRaoParameters(); assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT, params.getExecutionCondition()); assertFalse(params.getReOptimizeCurativeRangeActions()); assertTrue(params.getHintFromFirstPreventiveRao()); @@ -143,24 +140,22 @@ void checkSecondPreventiveRaoConfig() { void checkNotOptimizedCnecsConfig() { MapModuleConfig notOptimizedModuleConfig = platformCfg.createModuleConfig("rao-not-optimized-cnecs"); notOptimizedModuleConfig.setStringProperty("do-not-optimize-curative-cnecs-for-tsos-without-cras", Objects.toString(false)); - RaoParameters parameters = new RaoParameters(); - RaoParameters.load(parameters, platformCfg); + RaoParameters parameters = RaoParameters.load(platformCfg); NotOptimizedCnecsParameters params = parameters.getNotOptimizedCnecsParameters(); assertFalse(params.getDoNotOptimizeCurativeCnecsForTsosWithoutCras()); } @Test void checkLoadFlowParametersConfig() { - MapModuleConfig loadFlowModuleConfig = platformCfg.createModuleConfig("rao-load-flow-and-sensitivity-computation"); + MapModuleConfig loadFlowModuleConfig = platformCfg.createModuleConfig("search-tree-load-flow-and-sensitivity-computation"); loadFlowModuleConfig.setStringProperty("load-flow-provider", "Bonjour"); loadFlowModuleConfig.setStringProperty("sensitivity-provider", "Au revoir"); 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); + RaoParameters parameters = RaoParameters.load(platformCfg); + 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 +208,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))); @@ -228,18 +223,16 @@ void checkMultipleConfigs() { @Test void inconsistentPredefinedCombinations1() { - MapModuleConfig topoActionsModuleConfig = platformCfg.createModuleConfig("rao-topological-actions-optimization"); + MapModuleConfig topoActionsModuleConfig = platformCfg.createModuleConfig("search-tree-topological-actions-optimization"); topoActionsModuleConfig.setStringListProperty("predefined-combinations", List.of("{na12 + {na22}", "{na41} + {na5} + {na6}")); - RaoParameters parameters = new RaoParameters(); - assertThrows(OpenRaoException.class, () -> RaoParameters.load(parameters, platformCfg)); + assertThrows(OpenRaoException.class, () -> RaoParameters.load(platformCfg)); } @Test void inconsistentPredefinedCombinations2() { - MapModuleConfig topoActionsModuleConfig = platformCfg.createModuleConfig("rao-topological-actions-optimization"); + MapModuleConfig topoActionsModuleConfig = platformCfg.createModuleConfig("search-tree-topological-actions-optimization"); topoActionsModuleConfig.setStringListProperty("predefined-combinations", List.of("{na12} - {na22}", "{na41} + {na5} + {na6}")); - RaoParameters parameters = new RaoParameters(); - assertThrows(OpenRaoException.class, () -> RaoParameters.load(parameters, platformCfg)); + assertThrows(OpenRaoException.class, () -> RaoParameters.load(platformCfg)); } @Test 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..877aff0673 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; @@ -41,43 +41,44 @@ public RaoParameters loadRaoParameters(String configFile) { @Test void testConfigWithExtensions() throws IOException { RaoParameters parameters = loadRaoParameters("config_withExtensions"); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); + assertEquals(3, searchTreeParameters.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()); + assertEquals(2, searchTreeParameters.getRangeActionsOptimizationParameters().getMaxMipIterations(), DOUBLE_TOLERANCE); + assertEquals(0.02, rangeActionsOptimizationParameters.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, searchTreeParameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(PstModel.APPROXIMATED_INTEGERS, searchTreeParameters.getRangeActionsOptimizationParameters().getPstModel()); + assertEquals(RaRangeShrinking.DISABLED, searchTreeParameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); + assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, searchTreeParameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.3, searchTreeParameters.getRangeActionsOptimizationParameters().getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(Solver.XPRESS, searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolver()); + assertEquals(0.004, searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("BLABLABLA", searchTreeParameters.getRangeActionsOptimizationParameters().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()); + assertEquals(3, searchTreeParameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, searchTreeParameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(3, searchTreeParameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), searchTreeParameters.getTopoOptimizationParameters().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(searchTreeParameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement()); + assertEquals(3, searchTreeParameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); - MultithreadingParameters multithreadingParameters = parameters.getMultithreadingParameters(); - assertEquals(4, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); + MultithreadingParameters multithreadingParameters = searchTreeParameters.getMultithreadingParameters(); + assertEquals(5, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); assertEquals(5, multithreadingParameters.getPreventiveLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(3, multithreadingParameters.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(6, multithreadingParameters.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); + assertEquals(1, multithreadingParameters.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); + assertEquals(1, multithreadingParameters.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); - SecondPreventiveRaoParameters secondPreventiveRaoParameters = parameters.getSecondPreventiveRaoParameters(); + SecondPreventiveRaoParameters secondPreventiveRaoParameters = searchTreeParameters.getSecondPreventiveRaoParameters(); assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT, secondPreventiveRaoParameters.getExecutionCondition()); assertTrue(secondPreventiveRaoParameters.getReOptimizeCurativeRangeActions()); assertTrue(secondPreventiveRaoParameters.getHintFromFirstPreventiveRao()); @@ -85,13 +86,13 @@ 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); // EXTENSIONS - assertEquals(3, parameters.getExtensions().size()); + assertEquals(4, parameters.getExtensions().size()); LoopFlowParametersExtension loopFlowParameters = parameters.getExtension(LoopFlowParametersExtension.class); assertNotNull(loopFlowParameters); @@ -125,52 +126,20 @@ void testConfigWithoutExtensions() throws IOException { ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(3, objectiveFunctionParameters.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()); + assertEquals(0.02, rangeActionsOptimizationParameters.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); 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()); assertEquals(0.02, topoOptimizationParameters.getRelativeMinImpactThreshold(), DOUBLE_TOLERANCE); assertEquals(2.0, topoOptimizationParameters.getAbsoluteMinImpactThreshold(), DOUBLE_TOLERANCE); - assertTrue(topoOptimizationParameters.getSkipActionsFarFromMostLimitingElement()); - assertEquals(3, topoOptimizationParameters.getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); - - MultithreadingParameters multithreadingParameters = parameters.getMultithreadingParameters(); - assertEquals(4, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); - assertEquals(5, multithreadingParameters.getPreventiveLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(3, multithreadingParameters.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(6, multithreadingParameters.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); - - SecondPreventiveRaoParameters secondPreventiveRaoParameters = parameters.getSecondPreventiveRaoParameters(); - assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT, secondPreventiveRaoParameters.getExecutionCondition()); - assertTrue(secondPreventiveRaoParameters.getReOptimizeCurativeRangeActions()); - assertTrue(secondPreventiveRaoParameters.getHintFromFirstPreventiveRao()); 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); - // EXTENSIONS assertEquals(0, parameters.getExtensions().size()); @@ -190,43 +159,44 @@ void testConfigWithoutExtensions() throws IOException { @Test void testConfigWithPartialExtensions() throws IOException { RaoParameters parameters = loadRaoParameters("config_withPartialExtensions"); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters(); assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType()); - assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE); + assertEquals(3, searchTreeParameters.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()); + assertEquals(10, searchTreeParameters.getRangeActionsOptimizationParameters().getMaxMipIterations(), DOUBLE_TOLERANCE); + assertEquals(0.02, rangeActionsOptimizationParameters.getPstRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, searchTreeParameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(PstModel.APPROXIMATED_INTEGERS, searchTreeParameters.getRangeActionsOptimizationParameters().getPstModel()); + assertEquals(RaRangeShrinking.ENABLED, searchTreeParameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); + assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.2, searchTreeParameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRAMinImpactThreshold(), DOUBLE_TOLERANCE); + assertEquals(0.3, searchTreeParameters.getRangeActionsOptimizationParameters().getInjectionRaSensitivityThreshold(), DOUBLE_TOLERANCE); + assertEquals(Solver.CBC, searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolver()); + assertEquals(0.004, searchTreeParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getRelativeMipGap(), DOUBLE_TOLERANCE); + assertEquals("BLABLABLA", searchTreeParameters.getRangeActionsOptimizationParameters().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()); + assertEquals(3, searchTreeParameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(2, searchTreeParameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(3, searchTreeParameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE); + assertEquals(List.of(List.of("na1", "na2"), List.of("na3", "na4", "na5")), searchTreeParameters.getTopoOptimizationParameters().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(searchTreeParameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement()); + assertEquals(2, searchTreeParameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions(), DOUBLE_TOLERANCE); - MultithreadingParameters multithreadingParameters = parameters.getMultithreadingParameters(); - assertEquals(1, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); + MultithreadingParameters multithreadingParameters = searchTreeParameters.getMultithreadingParameters(); + assertEquals(5, multithreadingParameters.getContingencyScenariosInParallel(), DOUBLE_TOLERANCE); assertEquals(5, multithreadingParameters.getPreventiveLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(2, multithreadingParameters.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); - assertEquals(6, multithreadingParameters.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); + assertEquals(1, multithreadingParameters.getAutoLeavesInParallel(), DOUBLE_TOLERANCE); + assertEquals(1, multithreadingParameters.getCurativeLeavesInParallel(), DOUBLE_TOLERANCE); - SecondPreventiveRaoParameters secondPreventiveRaoParameters = parameters.getSecondPreventiveRaoParameters(); + SecondPreventiveRaoParameters secondPreventiveRaoParameters = searchTreeParameters.getSecondPreventiveRaoParameters(); assertEquals(SecondPreventiveRaoParameters.ExecutionCondition.DISABLED, secondPreventiveRaoParameters.getExecutionCondition()); assertTrue(secondPreventiveRaoParameters.getReOptimizeCurativeRangeActions()); assertTrue(secondPreventiveRaoParameters.getHintFromFirstPreventiveRao()); @@ -234,13 +204,13 @@ 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()); + assertEquals(3, parameters.getExtensions().size()); LoopFlowParametersExtension loopFlowParameters = parameters.getExtension(LoopFlowParametersExtension.class); assertNotNull(loopFlowParameters); @@ -268,11 +238,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/rao-api/src/test/resources/RaoParametersWithExtension_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json index 794884c173..b6fda8ad22 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -17,73 +17,6 @@ "do-not-optimize-curative-cnecs-for-tsos-without-cras" : false }, "extensions" : { - "dummy-extension" : { - - }, - "open-rao-search-tree-parameters" : { - "objective-function" : { - "curative-min-obj-improvement" : 0.0 - }, - "range-actions-optimization" : { - "max-mip-iterations" : 10, - "pst-sensitivity-threshold" : 1.0E-6, - "pst-model" : "CONTINUOUS", - "hvdc-sensitivity-threshold" : 1.0E-6, - "injection-ra-sensitivity-threshold" : 1.0E-6, - "ra-range-shrinking" : "DISABLED", - "linear-optimization-solver" : { - "solver" : "CBC", - "relative-mip-gap" : 1.0E-4, - "solver-specific-parameters" : null - } - }, - "topological-actions-optimization" : { - "max-preventive-search-tree-depth" : 2147483647, - "max-auto-search-tree-depth" : 2147483647, - "max-curative-search-tree-depth" : 2147483647, - "predefined-combinations" : [ ], - "skip-actions-far-from-most-limiting-element" : false, - "max-number-of-boundaries-for-skipping-actions" : 2 - }, - "second-preventive-rao" : { - "execution-condition" : "DISABLED", - "re-optimize-curative-range-actions" : false, - "hint-from-first-preventive-rao" : false - }, - "load-flow-and-sensitivity-computation" : { - "load-flow-provider" : "OpenLoadFlow", - "sensitivity-provider" : "OpenLoadFlow", - "sensitivity-failure-overcost" : 10000.0, - "sensitivity-parameters" : { - "version" : "1.1", - "load-flow-parameters" : { - "version" : "1.9", - "voltageInitMode" : "UNIFORM_VALUES", - "transformerVoltageControlOn" : false, - "phaseShifterRegulationOn" : false, - "useReactiveLimits" : true, - "twtSplitShuntAdmittance" : false, - "shuntCompensatorVoltageControlOn" : false, - "readSlackBus" : true, - "writeSlackBus" : false, - "dc" : false, - "distributedSlack" : true, - "balanceType" : "PROPORTIONAL_TO_GENERATION_P_MAX", - "dcUseTransformerRatio" : true, - "countriesToBalance" : [ ], - "connectedComponentMode" : "MAIN", - "hvdcAcEmulation" : true, - "dcPowerFactor" : 1.0 - }, - "flow-flow-sensitivity-value-threshold" : 0.0, - "voltage-voltage-sensitivity-value-threshold" : 0.0, - "flow-voltage-sensitivity-value-threshold" : 0.0, - "angle-flow-sensitivity-value-threshold" : 0.0 - } - }, - "multi-threading" : { - "available-cpus" : 1 - } - } + "dummy-extension" : { } } } \ No newline at end of file diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithWrongField_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithWrongField_v2.json index cdf31834e6..dc428cc0dd 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithWrongField_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithWrongField_v2.json @@ -72,7 +72,7 @@ } }, "multi-threading" : { - "available-cpus" : 1 + "wrong" : 1 } } } diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json index e111643a71..60524a20bc 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json @@ -15,149 +15,5 @@ }, "not-optimized-cnecs" : { "do-not-optimize-curative-cnecs-for-tsos-without-cras" : false - }, - "extensions" : { - "open-rao-search-tree-parameters" : { - "objective-function" : { - "curative-min-obj-improvement" : 3.0 - }, - "range-actions-optimization" : { - "max-mip-iterations" : 2, - "pst-sensitivity-threshold" : 0.2, - "pst-model" : "APPROXIMATED_INTEGERS", - "hvdc-sensitivity-threshold" : 0.2, - "injection-ra-sensitivity-threshold" : 0.3, - "ra-range-shrinking" : "DISABLED", - "linear-optimization-solver" : { - "solver" : "XPRESS", - "relative-mip-gap" : 0.004, - "solver-specific-parameters" : "BLABLABLA" - } - }, - "topological-actions-optimization" : { - "max-preventive-search-tree-depth" : 3, - "max-auto-search-tree-depth" : 2, - "max-curative-search-tree-depth" : 3, - "predefined-combinations" : [ [ "na1", "na2" ], [ "na3", "na4", "na5" ] ], - "skip-actions-far-from-most-limiting-element" : true, - "max-number-of-boundaries-for-skipping-actions" : 3 - }, - "second-preventive-rao" : { - "execution-condition" : "POSSIBLE_CURATIVE_IMPROVEMENT", - "re-optimize-curative-range-actions" : true, - "hint-from-first-preventive-rao" : true - }, - "load-flow-and-sensitivity-computation" : { - "load-flow-provider" : "LOADFLOW_PROVIDER", - "sensitivity-provider" : "SENSI_PROVIDER", - "sensitivity-failure-overcost" : 2.0, - "sensitivity-parameters" : { - "version" : "1.1", - "load-flow-parameters" : { - "version" : "1.9", - "voltageInitMode" : "UNIFORM_VALUES", - "transformerVoltageControlOn" : false, - "phaseShifterRegulationOn" : false, - "useReactiveLimits" : true, - "twtSplitShuntAdmittance" : false, - "shuntCompensatorVoltageControlOn" : false, - "readSlackBus" : true, - "writeSlackBus" : false, - "dc" : false, - "distributedSlack" : true, - "balanceType" : "PROPORTIONAL_TO_GENERATION_P_MAX", - "dcUseTransformerRatio" : true, - "countriesToBalance" : [ ], - "connectedComponentMode" : "MAIN", - "hvdcAcEmulation" : true, - "dcPowerFactor" : 1.0, - "extensions" : { - "open-load-flow-parameters" : { - "slackBusSelectionMode" : "MOST_MESHED", - "slackBusesIds" : [ ], - "slackDistributionFailureBehavior" : "LEAVE_ON_SLACK_BUS", - "voltageRemoteControl" : true, - "lowImpedanceBranchMode" : "REPLACE_BY_ZERO_IMPEDANCE_LINE", - "loadPowerFactorConstant" : false, - "plausibleActivePowerLimit" : 5000.0, - "newtonRaphsonStoppingCriteriaType" : "UNIFORM_CRITERIA", - "maxActivePowerMismatch" : 0.01, - "maxReactivePowerMismatch" : 0.01, - "maxVoltageMismatch" : 1.0E-4, - "maxAngleMismatch" : 1.0E-5, - "maxRatioMismatch" : 1.0E-5, - "maxSusceptanceMismatch" : 1.0E-4, - "slackBusPMaxMismatch" : 1.0, - "voltagePerReactivePowerControl" : false, - "generatorReactivePowerRemoteControl" : false, - "transformerReactivePowerControl" : false, - "maxNewtonRaphsonIterations" : 15, - "maxOuterLoopIterations" : 20, - "newtonRaphsonConvEpsPerEq" : 1.0E-4, - "voltageInitModeOverride" : "NONE", - "transformerVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL", - "shuntVoltageControlMode" : "WITH_GENERATOR_VOLTAGE_CONTROL", - "minPlausibleTargetVoltage" : 0.8, - "maxPlausibleTargetVoltage" : 1.2, - "minNominalVoltageTargetVoltageCheck" : 20.0, - "minRealisticVoltage" : 0.5, - "maxRealisticVoltage" : 2.0, - "lowImpedanceThreshold" : 1.0E-8, - "reactiveRangeCheckMode" : "MAX", - "networkCacheEnabled" : false, - "svcVoltageMonitoring" : true, - "stateVectorScalingMode" : "NONE", - "maxSlackBusCount" : 1, - "debugDir" : null, - "incrementalTransformerRatioTapControlOuterLoopMaxTapShift" : 3, - "secondaryVoltageControl" : false, - "reactiveLimitsMaxPqPvSwitch" : 3, - "phaseShifterControlMode" : "CONTINUOUS_WITH_DISCRETISATION", - "alwaysUpdateNetwork" : false, - "mostMeshedSlackBusSelectorMaxNominalVoltagePercentile" : 95.0, - "reportedFeatures" : [ ], - "slackBusCountryFilter" : [ ], - "actionableSwitchesIds" : [ ], - "actionableTransformersIds" : [ ], - "asymmetrical" : false, - "reactivePowerDispatchMode" : "Q_EQUAL_PROPORTION", - "outerLoopNames" : null, - "useActiveLimits" : true, - "disableVoltageControlOfGeneratorsOutsideActivePowerLimits" : false, - "lineSearchStateVectorScalingMaxIteration" : 10, - "lineSearchStateVectorScalingStepFold" : 1.3333333333333333, - "maxVoltageChangeStateVectorScalingMaxDv" : 0.1, - "maxVoltageChangeStateVectorScalingMaxDphi" : 0.17453292519943295, - "linePerUnitMode" : "IMPEDANCE", - "useLoadModel" : false, - "dcApproximationType" : "IGNORE_R", - "simulateAutomationSystems" : false, - "acSolverType" : "NEWTON_RAPHSON", - "maxNewtonKrylovIterations" : 100, - "newtonKrylovLineSearch" : false, - "referenceBusSelectionMode" : "FIRST_SLACK", - "writeReferenceTerminals" : true, - "voltageTargetPriorities" : [ "GENERATOR", "TRANSFORMER", "SHUNT" ], - "transformerVoltageControlUseInitialTapPosition" : false, - "generatorVoltageControlMinNominalVoltage" : -1.0, - "fictitiousGeneratorVoltageControlCheckMode" : "FORCED" - } - } - }, - "flow-flow-sensitivity-value-threshold" : 0.0, - "voltage-voltage-sensitivity-value-threshold" : 0.0, - "flow-voltage-sensitivity-value-threshold" : 0.0, - "angle-flow-sensitivity-value-threshold" : 0.0, - "extensions" : { - "open-sensitivity-parameters" : { - "debugDir" : null - } - } - } - }, - "multi-threading" : { - "available-cpus" : 5 - } - } } } \ No newline at end of file diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json index 19e3a27576..4562833d3d 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -15,72 +15,5 @@ }, "not-optimized-cnecs" : { "do-not-optimize-curative-cnecs-for-tsos-without-cras" : false - }, - "extensions" : { - "open-rao-search-tree-parameters" : { - "objective-function" : { - "curative-min-obj-improvement" : 0.0 - }, - "range-actions-optimization" : { - "max-mip-iterations" : 10, - "pst-sensitivity-threshold" : 1.0E-6, - "pst-model" : "CONTINUOUS", - "hvdc-sensitivity-threshold" : 1.0E-6, - "injection-ra-sensitivity-threshold" : 1.0E-6, - "ra-range-shrinking" : "DISABLED", - "linear-optimization-solver" : { - "solver" : "CBC", - "relative-mip-gap" : 1.0E-4, - "solver-specific-parameters" : null - } - }, - "topological-actions-optimization" : { - "max-preventive-search-tree-depth" : 2147483647, - "max-auto-search-tree-depth" : 2147483647, - "max-curative-search-tree-depth" : 2147483647, - "predefined-combinations" : [ ], - "skip-actions-far-from-most-limiting-element" : false, - "max-number-of-boundaries-for-skipping-actions" : 2 - }, - "second-preventive-rao" : { - "execution-condition" : "DISABLED", - "re-optimize-curative-range-actions" : false, - "hint-from-first-preventive-rao" : false - }, - "load-flow-and-sensitivity-computation" : { - "load-flow-provider" : "OpenLoadFlow", - "sensitivity-provider" : "OpenLoadFlow", - "sensitivity-failure-overcost" : 10000.0, - "sensitivity-parameters" : { - "version" : "1.1", - "load-flow-parameters" : { - "version" : "1.9", - "voltageInitMode" : "UNIFORM_VALUES", - "transformerVoltageControlOn" : false, - "phaseShifterRegulationOn" : false, - "useReactiveLimits" : true, - "twtSplitShuntAdmittance" : false, - "shuntCompensatorVoltageControlOn" : false, - "readSlackBus" : true, - "writeSlackBus" : false, - "dc" : false, - "distributedSlack" : true, - "balanceType" : "PROPORTIONAL_TO_GENERATION_P_MAX", - "dcUseTransformerRatio" : true, - "countriesToBalance" : [ ], - "connectedComponentMode" : "MAIN", - "hvdcAcEmulation" : true, - "dcPowerFactor" : 1.0 - }, - "flow-flow-sensitivity-value-threshold" : 0.0, - "voltage-voltage-sensitivity-value-threshold" : 0.0, - "flow-voltage-sensitivity-value-threshold" : 0.0, - "angle-flow-sensitivity-value-threshold" : 0.0 - } - }, - "multi-threading" : { - "available-cpus" : 1 - } - } } } \ No newline at end of file diff --git a/ra-optimisation/rao-api/src/test/resources/config_withOpenLoadFlowExtension.yml b/ra-optimisation/rao-api/src/test/resources/config_withOpenLoadFlowExtension.yml index 6f33c0df49..3571ed2250 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withOpenLoadFlowExtension.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withOpenLoadFlowExtension.yml @@ -1,4 +1,4 @@ -rao-load-flow-and-sensitivity-computation: +search-tree-load-flow-and-sensitivity-computation: load-flow-provider: OpenLoadFlow sensitivity-provider: OpenLoadFlow sensitivity-failure-overcost: 2 diff --git a/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml b/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml index 438d586d69..b668074d0d 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml @@ -12,44 +12,4 @@ rao-topological-actions-optimization: absolute-minimum-impact-threshold: 2.0 rao-not-optimized-cnecs: - do-not-optimize-curative-cnecs-for-tsos-without-cras: false - -search-tree-objective-function: - curative-min-obj-improvement: 3.0 - -search-tree-range-actions-optimization: - max-mip-iterations: 2 - pst-penalty-cost: 0.02 - pst-sensitivity-threshold: 0.2 - pst-model: APPROXIMATED_INTEGERS - ra-range-shrinking: DISABLED - hvdc-penalty-cost: 0.002 - hvdc-sensitivity-threshold: 0.2 - injection-ra-penalty-cost: 0.003 - injection-ra-sensitivity-threshold: 0.3 - -search-tree-linear-optimization-solver: - solver: XPRESS - relative-mip-gap: 0.004 - solver-specific-parameters: BLABLABLA - -search-tree-topological-actions-optimization: - max-preventive-search-tree-depth: 3 - max-auto-search-tree-depth: 2 - max-curative-search-tree-depth: 3 - predefined-combinations: [ "{na1}+{na2}", "{na3}+{na4}+{na5}" ] - skip-actions-far-from-most-limiting-element: true - max-number-of-boundaries-for-skipping-actions: 3 - -search-tree-second-preventive-rao: - execution-condition: POSSIBLE_CURATIVE_IMPROVEMENT - re-optimize-curative-range-actions: true - hint-from-first-preventive-rao: true - -search-tree-load-flow-and-sensitivity-computation: - load-flow-provider: LOADFLOW_PROVIDER - sensitivity-provider: SENSI_PROVIDER - sensitivity-failure-overcost: 2 - -search-tree-multi-threading: - available-cpus: 5 \ No newline at end of file + do-not-optimize-curative-cnecs-for-tsos-without-cras: false \ No newline at end of file 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..f75f2028f6 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,8 @@ 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.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getSensitivityWithLoadFlowParameters; import static com.powsybl.openrao.searchtreerao.commons.RaoUtil.applyRemedialActions; /** @@ -462,7 +464,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), getSensitivityWithLoadFlowParameters(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..fc4cba85bd 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,10 @@ 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.MultithreadingParameters.getContingencyScenariosInParallel; +import static com.powsybl.openrao.raoapi.parameters.extensions.ObjectiveFunctionParameters.getCurativeMinObjImprovement; +import static com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters.*; import static com.powsybl.openrao.searchtreerao.commons.RaoLogger.formatDouble; import static com.powsybl.openrao.searchtreerao.commons.RaoUtil.applyRemedialActions; @@ -303,7 +307,7 @@ private Map optimizeContingencyScenarios(Crac crac, // Create an automaton simulator AutomatonSimulator automatonSimulator = new AutomatonSimulator(crac, raoParameters, toolProvider, initialSensitivityOutput, prePerimeterSensitivityOutput, stateTree.getOperatorsNotSharingCras(), NUMBER_LOGGED_ELEMENTS_DURING_RAO); // Go through all contingency scenarios - try (AbstractNetworkPool networkPool = AbstractNetworkPool.create(network, newVariant, raoParameters.getMultithreadingParameters().getContingencyScenariosInParallel(), true)) { + try (AbstractNetworkPool networkPool = AbstractNetworkPool.create(network, newVariant, getContingencyScenariosInParallel(raoParameters), true)) { AtomicInteger remainingScenarios = new AtomicInteger(stateTree.getContingencyScenarios().size()); List> tasks = stateTree.getContingencyScenarios().stream().map(optimizedScenario -> networkPool.submit(() -> runScenario(crac, raoParameters, stateTree, toolProvider, automatonTreeParameters, curativeTreeParameters, initialSensitivityOutput, prePerimeterSensitivityOutput, automatonsOnly, optimizedScenario, networkPool, automatonSimulator, contingencyScenarioResults, remainingScenarios)) @@ -331,7 +335,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; @@ -487,14 +491,14 @@ static boolean isStopCriterionChecked(ObjectiveFunctionResult result, TreeParame * decision depending on the curative RAO results and the curative RAO stop criterion. */ static boolean shouldRunSecondPreventiveRao(RaoParameters raoParameters, OptimizationResult firstPreventiveResult, Collection curativeRaoResults, RaoResult postFirstRaoResult, java.time.Instant targetEndInstant, long estimatedPreventiveRaoTimeInSeconds, Instant lastCurativeInstant) { - if (raoParameters.getSecondPreventiveRaoParameters().getExecutionCondition().equals(SecondPreventiveRaoParameters.ExecutionCondition.DISABLED)) { + if (getExecutionCondition(raoParameters).equals(SecondPreventiveRaoParameters.ExecutionCondition.DISABLED)) { return false; } if (!Objects.isNull(targetEndInstant) && ChronoUnit.SECONDS.between(java.time.Instant.now(), targetEndInstant) < estimatedPreventiveRaoTimeInSeconds) { BUSINESS_LOGS.info("There is not enough time to run a 2nd preventive RAO (target end time: {}, estimated time needed based on first preventive RAO: {} seconds)", targetEndInstant, estimatedPreventiveRaoTimeInSeconds); return false; } - if (raoParameters.getSecondPreventiveRaoParameters().getExecutionCondition().equals(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE) + if (getExecutionCondition(raoParameters).equals(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE) && postFirstRaoResult.getCost(lastCurativeInstant) <= postFirstRaoResult.getCost(null)) { BUSINESS_LOGS.info("Cost has not increased during RAO, there is no need to run a 2nd preventive RAO."); // it is not necessary to compare initial & post-preventive costs since the preventive RAO cannot increase its own cost @@ -513,7 +517,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); } } @@ -564,7 +568,7 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, // ------ appliedCras from secondPreventiveRaoResult AppliedRemedialActions appliedArasAndCras = secondPreventiveRaoResult.appliedArasAndCras().copyCurative(); // ------ + curative range actions optimized during second preventive with global optimization - if (raoParameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions()) { + if (getReOptimizeCurativeRangeActions(raoParameters)) { for (Map.Entry entry : postContingencyResults.entrySet()) { State state = entry.getKey(); if (!state.getInstant().isCurative()) { @@ -598,7 +602,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)); } @@ -655,7 +659,7 @@ private SecondPreventiveRaoResult runSecondPreventiveRao(RaoInput raoInput, // that the optimal setpoints of the curative results stay coherent with their allowed range and close to // optimality in their perimeters. These range actions will be excluded from 2nd preventive RAO. Set> remedialActionsExcluded = new HashSet<>(); - if (!parameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions()) { // keep old behaviour + if (!getReOptimizeCurativeRangeActions(raoParameters)) { // keep old behaviour remedialActionsExcluded = new HashSet<>(getRangeActionsExcludedFromSecondPreventive(crac, firstPreventiveResult, postContingencyResults)); applyPreventiveResultsForAutoOrCurativeRangeActions(network, firstPreventiveResult, crac); addAppliedRangeActionsPostContingency(crac.getInstants(InstantKind.CURATIVE), appliedArasAndCras, postContingencyResults); @@ -720,7 +724,7 @@ private CompletableFuture optimizeSecondPreventivePer State preventiveState = crac.getPreventiveState(); Set> excludedRangeActions = getRangeActionsExcludedFromSecondPreventive(crac, firstPreventiveResult, postContingencyResults); - if (raoParameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions()) { + if (getReOptimizeCurativeRangeActions(raoParameters)) { optPerimeter = GlobalOptimizationPerimeter.build(crac, raoInput.getNetwork(), raoParameters, prePerimeterResult); } else { Set> rangeActionsFor2p = new HashSet<>(crac.getRangeActions()); @@ -738,13 +742,13 @@ private CompletableFuture optimizeSecondPreventivePer .build(); // update RaUsageLimits with already applied RangeActions - if (!raoParameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions() && searchTreeParameters.getRaLimitationParameters().containsKey(preventiveInstant)) { + if (!getReOptimizeCurativeRangeActions(raoParameters) && searchTreeParameters.getRaLimitationParameters().containsKey(preventiveInstant)) { Set> activatedPreventiveRangeActions = firstPreventiveResult.getActivatedRangeActions(preventiveState); Set> excludedActivatedRangeActions = excludedRangeActions.stream().filter(activatedPreventiveRangeActions::contains).collect(Collectors.toSet()); searchTreeParameters.setRaLimitationsForSecondPreventive(searchTreeParameters.getRaLimitationParameters().get(preventiveInstant), excludedActivatedRangeActions, preventiveInstant); } - if (raoParameters.getSecondPreventiveRaoParameters().getHintFromFirstPreventiveRao()) { + if (getHintFromFirstPreventiveRao(raoParameters)) { // Set the optimal set of network actions decided in 1st preventive RAO as a hint for 2nd preventive RAO searchTreeParameters.getNetworkActionParameters().addNetworkActionCombination(new NetworkActionCombination(firstPreventiveResult.getActivatedNetworkActions(), true)); } 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..466eb59aad 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,9 @@ 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.LoadFlowAndSensitivityParameters.getSensitivityWithLoadFlowParameters; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getPstModel; import static java.lang.String.format; /** @@ -65,7 +69,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), getSensitivityWithLoadFlowParameters(raoParameters).getLoadFlowParameters())); } if (raoParameters.hasExtension(LoopFlowParametersExtension.class) && (Objects.isNull(raoInput.getReferenceProgram()) || Objects.isNull(raoInput.getGlskProvider()))) { @@ -76,7 +80,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 +213,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 getSensitivityWithLoadFlowParameters(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..81dc1afa16 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..716b954285 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,14 @@ 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.MultithreadingParameters.*; +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 +31,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(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + getMaxPreventiveSearchTreeDepth(parameters), + getPreventiveLeavesInParallel(parameters), shouldShrinkRaRange); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + getMaxPreventiveSearchTreeDepth(parameters), + getPreventiveLeavesInParallel(parameters), 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), getAutoLeavesInParallel(parameters), false); } public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, Double preventiveOptimizedCost) { @@ -54,34 +59,34 @@ 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(), - parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), + getMaxPreventiveSearchTreeDepth(parameters), + getCurativeLeavesInParallel(parameters), 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(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + getMaxPreventiveSearchTreeDepth(parameters), + getPreventiveLeavesInParallel(parameters), raRangeShrinking); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + getMaxPreventiveSearchTreeDepth(parameters), + getPreventiveLeavesInParallel(parameters), 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..59c7f167ff 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; @@ -28,6 +28,7 @@ import java.util.Locale; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.*; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getPstModel; /** * @author Joris Mancini {@literal } @@ -126,7 +127,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 (getPstModel(parameters.getRangeActionParametersExtension()).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 +241,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 (getPstModel(parameters.getRangeActionParametersExtension()).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..2b97cde507 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; @@ -32,6 +33,8 @@ import java.util.*; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.*; + /** * @author Pengbo Wang {@literal } * @author Baptiste Seguinot {@literal } @@ -44,24 +47,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 +190,11 @@ private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, Sensitivi private boolean isRangeActionSensitivityAboveThreshold(RangeAction rangeAction, double sensitivity) { if (rangeAction instanceof PstRangeAction) { - return sensitivity >= rangeActionParameters.getPstSensitivityThreshold(); + return sensitivity >= getPstSensitivityThreshold(rangeActionParametersExtension); } else if (rangeAction instanceof HvdcRangeAction) { - return sensitivity >= rangeActionParameters.getHvdcSensitivityThreshold(); + return sensitivity >= getHvdcSensitivityThreshold(rangeActionParametersExtension); } else if (rangeAction instanceof InjectionRangeAction) { - return sensitivity >= rangeActionParameters.getInjectionRaSensitivityThreshold(); + return sensitivity >= getInjectionRaSensitivityThreshold(rangeActionParametersExtension); } else { throw new OpenRaoException("Type of RangeAction not yet handled by the LinearRao."); } @@ -289,7 +296,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 +415,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..1d16af7e96 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; @@ -19,6 +19,8 @@ import java.util.*; import java.util.stream.Collectors; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.getPstModel; + /** * @author Baptiste Seguinot {@literal } */ @@ -68,7 +70,7 @@ public LinearProblem buildFromInputsAndParameters(IteratingLinearOptimizerInput } // MIP optimization vs. CONTINUOUS optimization - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { + if (getPstModel(parameters.getRangeActionParametersExtension()).equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { Map> pstRangeActions = copyOnlyPstRangeActions(inputs.getOptimizationPerimeter().getRangeActionsPerState()); Map>> otherRa = copyWithoutPstRangeActions(inputs.getOptimizationPerimeter().getRangeActionsPerState()); this.withProblemFiller(buildIntegerPstTapFiller(pstRangeActions)); @@ -97,7 +99,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 +123,11 @@ private ProblemFiller buildCoreProblemFiller() { return new CoreProblemFiller( inputs.getOptimizationPerimeter(), inputs.getPrePerimeterSetpoints(), - parameters.getRangeActionParameters(), + parameters.getRangeActionParameters(), + parameters.getRangeActionParametersExtension(), parameters.getObjectiveFunctionUnit(), parameters.getRaRangeShrinking(), - parameters.getRangeActionParameters().getPstModel() + getPstModel(parameters.getRangeActionParametersExtension()) ); } @@ -193,7 +196,7 @@ private ProblemFiller buildRaUsageLimitsFiller() { inputs.getOptimizationPerimeter().getRangeActionsPerState(), inputs.getPrePerimeterSetpoints(), parameters.getRaLimitationParameters(), - parameters.getRangeActionParameters().getPstModel() == RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, + getPstModel(parameters.getRangeActionParametersExtension()) == 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..23f8f9645d 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; @@ -77,6 +81,10 @@ public RangeActionsOptimizationParameters getRangeActionParameters() { return rangeActionParameters; } + public com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters getRangeActionParametersExtension() { + return rangeActionParametersExtension; + } + public MnecParametersExtension getMnecParameters() { return mnecParameters; } @@ -97,7 +105,7 @@ public RangeActionLimitationParameters getRaLimitationParameters() { return raLimitationParameters; } - public RangeActionsOptimizationParameters.LinearOptimizationSolver getSolverParameters() { + public LinearOptimizationSolver getSolverParameters() { return solverParameters; } @@ -118,12 +126,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 +152,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 +182,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 +206,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..ee43e1371c 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,8 @@ 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.OpenRaoSearchTreeParameters; +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 +30,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 +48,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 +63,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 +76,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 +109,10 @@ public RangeActionsOptimizationParameters getRangeActionParameters() { return rangeActionParameters; } + public com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters getRangeActionParametersExtension() { + return rangeActionParametersExtension; + } + public MnecParametersExtension getMnecParameters() { return mnecParameters; } @@ -116,7 +129,7 @@ public UnoptimizedCnecParameters getUnoptimizedCnecParameters() { return unoptimizedCnecParameters; } - public RangeActionsOptimizationParameters.LinearOptimizationSolver getSolverParameters() { + public LinearOptimizationSolver getSolverParameters() { return solverParameters; } @@ -249,24 +262,28 @@ 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.rangeActionParameters = raoParameters.getRangeActionsOptimizationParameters(); + if (raoParameters.hasExtension(OpenRaoSearchTreeParameters.class)) { + this.rangeActionParametersExtension = raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters(); + } 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; } @@ -300,6 +317,11 @@ public SearchTreeParametersBuilder withRangeActionParameters(RangeActionsOptimiz return this; } + public SearchTreeParametersBuilder withRangeActionParametersExtension(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension) { + this.rangeActionParametersExtension = rangeActionParametersExtension; + return this; + } + public SearchTreeParametersBuilder withMnecParameters(MnecParametersExtension mnecParameters) { this.mnecParameters = mnecParameters; return this; @@ -320,7 +342,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 +359,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/AutomatonSimulatorTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java index dc44ccf685..671e280570 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/castor/algorithm/AutomatonSimulatorTest.java @@ -23,6 +23,7 @@ import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.openrao.searchtreerao.commons.ToolProvider; import com.powsybl.openrao.searchtreerao.commons.objectivefunctionevaluator.ObjectiveFunction; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; @@ -228,9 +229,11 @@ public void setup() { autoState = crac.getState(contingency1, autoInstant); RaoParameters raoParameters = new RaoParameters(); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN); - raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().setDc(true); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider("OpenLoadFlow"); + searchTreeParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().setDc(true); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider("OpenLoadFlow"); mockedPreAutoPerimeterSensitivityAnalysis = mock(PrePerimeterSensitivityAnalysis.class); mockedPrePerimeterResult = mock(PrePerimeterResult.class); 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..555d3c1d52 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,8 @@ 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.OpenRaoSearchTreeParameters; +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.*; @@ -96,6 +97,8 @@ public void setup() throws IOException { @Test void testShouldRunSecondPreventiveRaoSimple() { RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); OptimizationResult preventiveResult = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult1 = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult2 = Mockito.mock(OptimizationResult.class); @@ -105,11 +108,11 @@ void testShouldRunSecondPreventiveRaoSimple() { assertFalse(CastorFullOptimization.shouldRunSecondPreventiveRao(parameters, preventiveResult, curativeResults, null, null, 0, crac.getInstant(InstantKind.CURATIVE))); // Deactivated in parameters - parameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.DISABLED); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.DISABLED); assertFalse(CastorFullOptimization.shouldRunSecondPreventiveRao(parameters, preventiveResult, curativeResults, null, null, 0, crac.getInstant(InstantKind.CURATIVE))); // CurativeStopCriterion.MIN_OBJECTIVE - parameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); assertTrue(CastorFullOptimization.shouldRunSecondPreventiveRao(parameters, preventiveResult, curativeResults, null, null, 0, crac.getInstant(InstantKind.CURATIVE))); // CurativeStopCriterion.SECURE, secure case @@ -139,14 +142,16 @@ private void setCost(OptimizationResult optimizationResultMock, double cost) { @Test void testShouldRunSecondPreventiveRaoAdvanced() { RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); OptimizationResult preventiveResult = Mockito.mock(OptimizationResult.class); RaoResult postFirstPreventiveRaoResult = Mockito.mock(RaoResult.class); OptimizationResult optimizationResult1 = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult2 = Mockito.mock(OptimizationResult.class); Collection curativeResults = Set.of(optimizationResult1, optimizationResult2); - parameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); - parameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(10.); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); + searchTreeParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(10.); parameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN); when(preventiveResult.getCost()).thenReturn(-500.); @@ -191,12 +196,14 @@ void testShouldRunSecondPreventiveRaoAdvanced() { @Test void testShouldRunSecondPreventiveRaoTime() { RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); OptimizationResult preventiveResult = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult1 = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult2 = Mockito.mock(OptimizationResult.class); Collection curativeResults = Set.of(optimizationResult1, optimizationResult2); - parameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); // Enough time assertTrue(CastorFullOptimization.shouldRunSecondPreventiveRao(parameters, preventiveResult, curativeResults, null, java.time.Instant.now().plusSeconds(200), 100, crac.getInstant(InstantKind.CURATIVE))); @@ -210,12 +217,14 @@ void testShouldRunSecondPreventiveRaoTime() { @Test void testShouldRunSecondPreventiveRaoCostIncrease() { RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); OptimizationResult preventiveResult = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult1 = Mockito.mock(OptimizationResult.class); OptimizationResult optimizationResult2 = Mockito.mock(OptimizationResult.class); Collection curativeResults = Set.of(optimizationResult1, optimizationResult2); - parameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.COST_INCREASE); RaoResult postFirstRaoResult = Mockito.mock(RaoResult.class); when(postFirstRaoResult.getCost(null)).thenReturn(-100.); @@ -616,9 +625,10 @@ void smallRaoWith2P() throws IOException { crac = Crac.read("small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); // Activate 2P - raoParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); // Run RAO RaoResult raoResult = new CastorFullOptimization(raoInput, raoParameters, null).run().join(); @@ -640,10 +650,11 @@ void smallRaoWithGlobal2P() throws IOException { crac = Crac.read("small-crac-2P.json", getClass().getResourceAsStream("/crac/small-crac-2P.json"), network); RaoInput raoInput = RaoInput.build(network, crac).build(); RaoParameters raoParameters = JsonRaoParameters.read(getClass().getResourceAsStream("/parameters/RaoParameters_2P_v2.json")); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); // Activate global 2P - raoParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); - raoParameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(true); + searchTreeParameters.getSecondPreventiveRaoParameters().setExecutionCondition(SecondPreventiveRaoParameters.ExecutionCondition.POSSIBLE_CURATIVE_IMPROVEMENT); + searchTreeParameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(true); // Run RAO RaoResult raoResult = new CastorFullOptimization(raoInput, raoParameters, null).run().join(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java index f1714d3cb9..12befbb6cf 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/RaoUtilTest.java @@ -24,8 +24,9 @@ import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.openrao.raoapi.RaoInput; 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 com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; @@ -120,10 +121,12 @@ void testExceptionForEmptyBoundariesOnRelativeMargin() { @Test void testAmpereWithDc() { + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); assertEquals(Unit.AMPERE, RaoUtil.getObjectiveFunctionUnit(raoParameters)); - raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().setDc(true); + searchTreeParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().setDc(true); assertEquals(Unit.MEGAWATT, RaoUtil.getObjectiveFunctionUnit(raoParameters)); - raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().setDc(false); + searchTreeParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().setDc(false); assertEquals(Unit.AMPERE, RaoUtil.getObjectiveFunctionUnit(raoParameters)); } @@ -348,7 +351,8 @@ private void assertIsOnFlowInCountryAvailable(RemedialAction ra, State optimi @Test void testElementaryActionsLimitWithNonDiscretePsts() { - raoParameters.getRangeActionsOptimizationParameters().setPstModel(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + raoParameters.getExtension(OpenRaoSearchTreeParameters.class).getRangeActionsOptimizationParameters().setPstModel(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); raoInput.getCrac().newRaUsageLimits(PREVENTIVE_INSTANT_ID).withMaxElementaryActionPerTso(Map.of("TSO", 2)).add(); OpenRaoException exception = assertThrows(OpenRaoException.class, () -> RaoUtil.checkParameters(raoParameters, raoInput)); assertEquals("The PSTs must be approximated as integers to use the limitations of elementary actions as a constraint in the RAO.", exception.getMessage()); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/ObjectiveFunctionTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/ObjectiveFunctionTest.java index 27c9214d62..3ad542ac9d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/ObjectiveFunctionTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/objectivefunctionevaluator/ObjectiveFunctionTest.java @@ -9,6 +9,7 @@ import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.openrao.searchtreerao.result.api.*; import org.apache.commons.lang3.tuple.Pair; import org.junit.jupiter.api.BeforeEach; @@ -128,14 +129,16 @@ void testWithFunctionalAndVirtualCost() { @Test void testBuildForInitialSensitivityComputation() { RaoParameters raoParameters = new RaoParameters(); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(0.); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(0.); ObjectiveFunction objectiveFunction = new ObjectiveFunction.ObjectiveFunctionBuilder().buildForInitialSensitivityComputation( Set.of(cnec1, cnec2), raoParameters ); assertTrue(objectiveFunction.getVirtualCostNames().isEmpty()); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(1.); + searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(1.); objectiveFunction = new ObjectiveFunction.ObjectiveFunctionBuilder().buildForInitialSensitivityComputation( Set.of(cnec1, cnec2), raoParameters ); 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..f67cd7a449 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 @@ -14,6 +14,7 @@ import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod; import com.powsybl.openrao.data.cracimpl.utils.ExhaustiveCracCreation; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.openrao.searchtreerao.commons.NetworkActionCombination; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -37,14 +38,16 @@ class NetworkActionParametersTest { void buildFromRaoParametersTestOk() { crac = ExhaustiveCracCreation.create(); RaoParameters raoParameters = new RaoParameters(); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); - raoParameters.getTopoOptimizationParameters().setPredefinedCombinations(Collections.singletonList(List.of("complexNetworkActionId", "switchPairRaId"))); + searchTreeParameters.getTopoOptimizationParameters().setPredefinedCombinations(Collections.singletonList(List.of("complexNetworkActionId", "switchPairRaId"))); raoParameters.getTopoOptimizationParameters().setAbsoluteMinImpactThreshold(20.); raoParameters.getTopoOptimizationParameters().setRelativeMinImpactThreshold(0.01); - raoParameters.getTopoOptimizationParameters().setSkipActionsFarFromMostLimitingElement(true); - raoParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(4); + searchTreeParameters.getTopoOptimizationParameters().setSkipActionsFarFromMostLimitingElement(true); + searchTreeParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(4); - NetworkActionParameters nap = NetworkActionParameters.buildFromRaoParameters(raoParameters.getTopoOptimizationParameters(), crac); + NetworkActionParameters nap = NetworkActionParameters.buildFromRaoParameters(raoParameters, crac); assertEquals(1, nap.getNetworkActionCombinations().size()); assertEquals(2, nap.getNetworkActionCombinations().get(0).getNetworkActionSet().size()); @@ -99,17 +102,19 @@ void testNetworkActionCombinations() { // test list RaoParameters parameters = new RaoParameters(); + parameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = parameters.getExtension(OpenRaoSearchTreeParameters.class); - parameters.getTopoOptimizationParameters().setPredefinedCombinations(List.of( + searchTreeParameters.getTopoOptimizationParameters().setPredefinedCombinations(List.of( List.of("topological-action-1", "topological-action-2"), // OK List.of("topological-action-1", "topological-action-2", "pst-setpoint"), // OK List.of("topological-action-1", "unknown-na-id"), // should be filtered 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(5, searchTreeParameters.getTopoOptimizationParameters().getPredefinedCombinations().size()); assertEquals(2, naCombinations.size()); assertEquals(2, naCombinations.get(0).getNetworkActionSet().size()); assertEquals(3, naCombinations.get(1).getNetworkActionSet().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..a10741c7c2 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,9 @@ 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 com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,17 +21,21 @@ */ class TreeParametersTest { RaoParameters raoParameters; + OpenRaoSearchTreeParameters searchTreeParameters; + private static final double DOUBLE_TOLERANCE = 1e-6; @BeforeEach public void setUp() { raoParameters = new RaoParameters(); - raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(6); - raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(2); - raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(6); - raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); - raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); + searchTreeParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(6); + searchTreeParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(2); + searchTreeParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(6); + searchTreeParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); + searchTreeParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); } @Test @@ -46,11 +51,11 @@ void testPreventive() { // test with secure, and different values of the parameters raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW); - raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); - raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(15); - raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(5); - raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(15); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + searchTreeParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); + searchTreeParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(15); + searchTreeParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(5); + searchTreeParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(15); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(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); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertTrue(treeParameters.raRangeShrinking()); } @@ -67,8 +72,8 @@ void testPreventive() { @Test void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW); - raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + searchTreeParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -82,11 +87,11 @@ void testCurativeSecureStopCriterion() { void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN); raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(false); - raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); - raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(0); - raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(0); - raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + searchTreeParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); + searchTreeParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(0); + searchTreeParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(0); + searchTreeParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(0); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -100,7 +105,7 @@ void testCurativePreventiveObjectiveStopCriterion() { void testCurativePreventiveObjectiveAndSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN); raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(true); - raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); + searchTreeParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); // limited by secure TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); @@ -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); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(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); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(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); + searchTreeParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.stopCriterion()); @@ -163,10 +168,10 @@ void testSecondPreventive() { // still another combination raoParameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW); raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(true); - raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); - raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(15); - raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(5); - raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(15); + searchTreeParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); + searchTreeParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(15); + searchTreeParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(5); + searchTreeParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(15); 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/IteratingLinearOptimizerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizerTest.java index a072970504..cd2622c624 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizerTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracimpl.utils.NetworkImportsUtil; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.SensitivityComputer; import com.powsybl.openrao.searchtreerao.commons.adapter.BranchResultAdapter; import com.powsybl.openrao.searchtreerao.commons.adapter.SensitivityResultAdapter; @@ -101,7 +101,7 @@ public void setUp() { when(parameters.getMaxNumberOfIterations()).thenReturn(5); RangeActionsOptimizationParameters rangeActionParameters = Mockito.mock(RangeActionsOptimizationParameters.class); when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); - when(parameters.getRangeActionParameters()).thenReturn(rangeActionParameters); + //when(parameters.getRangeActionParameters()).thenReturn(rangeActionParameters); when(parameters.getObjectiveFunctionUnit()).thenReturn(Unit.MEGAWATT); when(parameters.relativePositiveMargins()).thenReturn(false); when(parameters.getRaRangeShrinking()).thenReturn(false); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemBuilderTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemBuilderTest.java index e9add73f88..d76ad89101 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemBuilderTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemBuilderTest.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.data.cracapi.State; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; @@ -40,7 +40,8 @@ class LinearProblemBuilderTest { private IteratingLinearOptimizerInput inputs; private IteratingLinearOptimizerParameters parameters; private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; - private RangeActionsOptimizationParameters rangeActionParameters; + private com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters rangeActionParameters; + private RangeActionsOptimizationParameters rangeActionParametersExtension; private OptimizationPerimeter optimizationPerimeter; @BeforeEach @@ -52,8 +53,10 @@ public void setup() { solverParameters = Mockito.mock(RangeActionsOptimizationParameters.LinearOptimizationSolver.class); when(solverParameters.getSolver()).thenReturn(RangeActionsOptimizationParameters.Solver.SCIP); when(parameters.getSolverParameters()).thenReturn(solverParameters); - rangeActionParameters = Mockito.mock(RangeActionsOptimizationParameters.class); + rangeActionParameters = Mockito.mock(com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters.class); when(parameters.getRangeActionParameters()).thenReturn(rangeActionParameters); + rangeActionParametersExtension = Mockito.mock(RangeActionsOptimizationParameters.class); + when(parameters.getRangeActionParametersExtension()).thenReturn(rangeActionParametersExtension); RelativeMarginsParametersExtension relativeMarginParameters = Mockito.mock(RelativeMarginsParametersExtension.class); when(parameters.getMaxMinRelativeMarginParameters()).thenReturn(relativeMarginParameters); MnecParametersExtension mnecParameters = Mockito.mock(MnecParametersExtension.class); @@ -68,7 +71,7 @@ public void setup() { @Test void testBuildMaxMarginContinuous() { - when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + when(rangeActionParametersExtension.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); when(parameters.getObjectiveFunctionUnit()).thenReturn(Unit.MEGAWATT); when(parameters.relativePositiveMargins()).thenReturn(false); @@ -83,7 +86,7 @@ void testBuildMaxMarginContinuous() { @Test void testBuildMaxMarginDiscrete() { - when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS); + when(rangeActionParametersExtension.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS); when(parameters.getObjectiveFunctionUnit()).thenReturn(Unit.MEGAWATT); when(parameters.relativePositiveMargins()).thenReturn(false); @@ -100,7 +103,7 @@ void testBuildMaxMarginDiscrete() { @Test void testBuildMaxRelativeMarginContinuous() { - when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + when(rangeActionParametersExtension.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); when(parameters.getObjectiveFunctionUnit()).thenReturn(Unit.MEGAWATT); when(parameters.relativePositiveMargins()).thenReturn(true); @@ -115,7 +118,7 @@ void testBuildMaxRelativeMarginContinuous() { @Test void testBuildMaxMarginContinuousMnecLoopflowUnoptimized() { - when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + when(rangeActionParametersExtension.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); when(parameters.getObjectiveFunctionUnit()).thenReturn(Unit.MEGAWATT); when(parameters.relativePositiveMargins()).thenReturn(false); when(parameters.isRaoWithMnecLimitation()).thenReturn(true); @@ -136,7 +139,7 @@ void testBuildMaxMarginContinuousMnecLoopflowUnoptimized() { @Test void testBuildMaxMarginContinuousRaLimitation() { - when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + when(rangeActionParametersExtension.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); when(parameters.getObjectiveFunctionUnit()).thenReturn(Unit.MEGAWATT); when(parameters.relativePositiveMargins()).thenReturn(false); RangeActionLimitationParameters raLimitationParameters = Mockito.mock(RangeActionLimitationParameters.class); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java index defd84f237..40683f2e64 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/LinearProblemTest.java @@ -12,7 +12,7 @@ import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblem; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblemBuilder; import org.junit.jupiter.api.BeforeEach; diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java index 5b34860366..e67cb046a7 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/ContinuousRangeActionGroupFillerTest.java @@ -10,8 +10,8 @@ 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.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPConstraint; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPVariable; @@ -56,12 +56,11 @@ void testFillAndUpdateMethods() throws IOException { rangeActions.put(state, Set.of(pstRa1, pstRa2)); Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(new RaoParameters()); - CoreProblemFiller coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + (new RaoParameters()).getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java index 9c723cadab..c5f04fc54e 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFillerTest.java @@ -13,8 +13,9 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblem; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblemBuilder; @@ -75,7 +76,7 @@ private void initializeForPreventive(double pstSensitivityThreshold, double hvdc initialize(Set.of(cnec1), pstSensitivityThreshold, hvdcSensitivityThreshold, injectionSensitivityThreshold, crac.getPreventiveState(), false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); } - private void initializeForGlobal(RangeActionsOptimizationParameters.PstModel pstModel) { + private void initializeForGlobal(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel pstModel) { initialize(Set.of(cnec1, cnec2), 1e-6, 1e-6, 1e-6, crac.getPreventiveState(), false, pstModel); } @@ -89,15 +90,17 @@ private void initialize(Set cnecs, double pstSensitivityThreshold, dou Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); RaoParameters raoParameters = new RaoParameters(); - raoParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(pstSensitivityThreshold); - raoParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(hvdcSensitivityThreshold); - raoParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(injectionSensitivityThreshold); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters searchTreeParameters = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); + searchTreeParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(pstSensitivityThreshold); + searchTreeParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(hvdcSensitivityThreshold); + searchTreeParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(injectionSensitivityThreshold); coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + raoParameters.getRangeActionsOptimizationParameters(), + searchTreeParameters.getRangeActionsOptimizationParameters(), Unit.MEGAWATT, raRangeShrinking, pstModel); buildLinearProblem(); } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java index 2733f8935e..5ff8c6fc9d 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstGroupFillerTest.java @@ -10,7 +10,8 @@ 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.PstModel; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPConstraint; @@ -58,14 +59,13 @@ void testFillAndUpdateMethods() throws IOException { rangeActions.put(state, Set.of(pstRa1, pstRa2)); Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(new RaoParameters()); - CoreProblemFiller coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + (new RaoParameters()).getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, - false, RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS); + false, PstModel.APPROXIMATED_INTEGERS); Map> pstRangeActions = new HashMap<>(); pstRangeActions.put(state, Set.of(pstRa1, pstRa2)); @@ -82,7 +82,7 @@ void testFillAndUpdateMethods() throws IOException { .withProblemFiller(coreProblemFiller) .withProblemFiller(discretePstTapFiller) .withProblemFiller(discretePstGroupFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .withInitialRangeActionActivationResult(getInitialRangeActionActivationResult()) .build(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java index a04d59981f..b79f528314 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/DiscretePstTapFillerTest.java @@ -11,7 +11,8 @@ import com.powsybl.openrao.data.cracapi.range.RangeType; 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.PstModel; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.LinearProblem; @@ -79,14 +80,13 @@ void setUpAndFill() throws IOException { Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); Mockito.when(optimizationPerimeter.getMainOptimizationState()).thenReturn(preventiveState); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(new RaoParameters()); - CoreProblemFiller coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + (new RaoParameters()).getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, - false, RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS); + false, PstModel.APPROXIMATED_INTEGERS); Map> pstRangeActions = new HashMap<>(); pstRangeActions.put(preventiveState, Set.of(pstRangeAction)); @@ -99,7 +99,7 @@ void setUpAndFill() throws IOException { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(discretePstTapFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .withInitialRangeActionActivationResult(getInitialRangeActionActivationResult()) .build(); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java index ad08691588..e36ae3137f 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/MaxLoopFlowFillerTest.java @@ -14,8 +14,8 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.data.cracloopflowextension.LoopFlowThresholdAdder; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; @@ -73,11 +73,11 @@ public void setUp() throws IOException { rangeActions.put(state, Set.of(pstRangeAction)); Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActions); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(new RaoParameters()); coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + (new RaoParameters()).getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS ); 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..7425195c7b 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 @@ -11,7 +11,6 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPConstraint; @@ -56,17 +55,17 @@ 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); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + raoParameters.getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, - false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + false, com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel.CONTINUOUS); } private void createMaxMinMarginFiller(Unit unit) { @@ -77,7 +76,7 @@ private void buildLinearProblem() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(maxMinMarginFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver.SCIP) .withInitialRangeActionActivationResult(getInitialRangeActionActivationResult()) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -167,7 +166,7 @@ void fillWithMissingFlowVariables() { createMaxMinMarginFiller(Unit.MEGAWATT); linearProblem = new LinearProblemBuilder() .withProblemFiller(maxMinMarginFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver.SCIP) .build(); // AbsoluteRangeActionVariables present, but no the FlowVariables @@ -182,7 +181,7 @@ void fillWithMissingRangeActionVariables() { createMaxMinMarginFiller(Unit.MEGAWATT); linearProblem = new LinearProblemBuilder() .withProblemFiller(maxMinMarginFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver.SCIP) .build(); // FlowVariables present , but not the absoluteRangeActionVariables present, 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..6766938808 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 @@ -12,7 +12,7 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; 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 com.powsybl.openrao.raoapi.parameters.extensions.PtdfApproximation; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; @@ -68,19 +68,19 @@ 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); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); parameters = raoParameters.getExtension(RelativeMarginsParametersExtension.class); coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + raoParameters.getRangeActionsOptimizationParameters(), + null, MEGAWATT, false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); } @@ -100,7 +100,7 @@ private void buildLinearProblem() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(maxMinRelativeMarginFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver.SCIP) .withInitialRangeActionActivationResult(getInitialRangeActionActivationResult()) .build(); linearProblem.fill(flowResult, sensitivityResult); 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..2c2174167f 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 @@ -16,7 +16,8 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; 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.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; @@ -99,17 +100,17 @@ 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); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + raoParameters.getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, - false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + false, PstModel.CONTINUOUS); } private void fillProblemWithFiller(Unit unit) { @@ -130,7 +131,7 @@ private void fillProblemWithFiller(Unit unit) { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(mnecFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); } @@ -231,7 +232,7 @@ void testFilterCnecWithNoInitialFlow() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(mnecFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java index 755f5d8f95..8bf2cb0950 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/RaUsageLimitsFillerTest.java @@ -14,8 +14,9 @@ import com.powsybl.openrao.data.cracapi.rangeaction.InjectionRangeAction; 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.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.commons.parameters.RangeActionLimitationParameters; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.*; @@ -105,14 +106,13 @@ public void setup() throws IOException { rangeActionsPerState.put(state, rangeActions); Mockito.when(optimizationPerimeter.getRangeActionsPerState()).thenReturn(rangeActionsPerState); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(new RaoParameters()); - coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, prePerimeterRangeActionSetpointResult, - rangeActionParameters, + (new RaoParameters()).getRangeActionsOptimizationParameters(), + null, Unit.MEGAWATT, - false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); + false, PstModel.CONTINUOUS); } @Test @@ -127,7 +127,7 @@ void testSkipFiller() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -150,7 +150,7 @@ void testVariationVariableAndConstraints() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -183,7 +183,7 @@ void testVariationVariableAndConstraintsApproxPsts() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -216,7 +216,7 @@ void testSkipConstraints1() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -249,7 +249,7 @@ void testSkipConstraints2() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -271,7 +271,7 @@ void testMaxRa() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -298,7 +298,7 @@ void testSkipLargeMaxRa1() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -321,7 +321,7 @@ void testSkipLargeMaxRa2() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -351,7 +351,7 @@ void testMaxTso() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -384,7 +384,7 @@ void testSkipLargeMaxTso1() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -406,7 +406,7 @@ void testSkipLargeMaxTso2() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -428,7 +428,7 @@ void testMaxTsoWithExclusion() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -456,7 +456,7 @@ void testMaxRaPerTso() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -497,7 +497,7 @@ void testMaxPstPerTso() { linearProblem = new LinearProblemBuilder() .withProblemFiller(coreProblemFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .build(); linearProblem.fill(flowResult, sensitivityResult); @@ -554,7 +554,7 @@ void testMaxElementaryActionsPerTsoConstraint() { .withProblemFiller(coreProblemFiller) .withProblemFiller(discretePstTapFiller) .withProblemFiller(raUsageLimitsFiller) - .withSolver(RangeActionsOptimizationParameters.Solver.SCIP) + .withSolver(Solver.SCIP) .withInitialRangeActionActivationResult(prePerimeterRangeActionActivationResult) .build(); 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..8cc30d4ae5 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 @@ -13,7 +13,7 @@ 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.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; @@ -77,15 +77,15 @@ 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); - RangeActionsOptimizationParameters rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); + raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(0.01); + raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(0.01); coreProblemFiller = new CoreProblemFiller( optimizationPerimeter, initialRangeActionSetpointResult, - rangeActionParameters, + raoParameters.getRangeActionsOptimizationParameters(), + null, MEGAWATT, false, RangeActionsOptimizationParameters.PstModel.CONTINUOUS); } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolverTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolverTest.java index b2dc02b827..631a3dec11 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolverTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolverTest.java @@ -10,7 +10,7 @@ import com.google.ortools.linearsolver.MPSolver; import com.google.ortools.linearsolver.MPVariable; import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.result.api.LinearProblemStatus; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; 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..668f2aead9 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 @@ -16,7 +16,9 @@ import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; +import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.LinearOptimizationSolver; import com.powsybl.openrao.searchtreerao.commons.parameters.*; import com.powsybl.openrao.searchtreerao.result.api.OptimizationResult; import com.powsybl.openrao.searchtreerao.result.api.PrePerimeterResult; @@ -32,6 +34,7 @@ import java.util.Objects; import java.util.Set; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getSensitivityWithLoadFlowParameters; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.when; @@ -49,21 +52,23 @@ public void setup() { @Test void testWithConstantParametersOverAllRao() { RaoParameters raoParameters = new RaoParameters(); + raoParameters.addExtension(OpenRaoSearchTreeParameters.class, new OpenRaoSearchTreeParameters()); + OpenRaoSearchTreeParameters raoParametersExtension = raoParameters.getExtension(OpenRaoSearchTreeParameters.class); Crac crac = Mockito.mock(Crac.class); builder.withConstantParametersOverAllRao(raoParameters, crac); SearchTreeParameters searchTreeParameters = builder.build(); assertNotNull(searchTreeParameters); - assertEquals(raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE, searchTreeParameters.getObjectiveFunctionUnit()); + assertEquals(getSensitivityWithLoadFlowParameters(raoParameters).getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE, searchTreeParameters.getObjectiveFunctionUnit()); assertEquals(raoParameters.getObjectiveFunctionParameters().getType().relativePositiveMargins(), searchTreeParameters.relativePositiveMargins()); - assertEquals(NetworkActionParameters.buildFromRaoParameters(raoParameters.getTopoOptimizationParameters(), crac), searchTreeParameters.getNetworkActionParameters()); + assertEquals(NetworkActionParameters.buildFromRaoParameters(raoParameters, crac), searchTreeParameters.getNetworkActionParameters()); assertEquals(crac.getRaUsageLimitsPerInstant(), searchTreeParameters.getRaLimitationParameters()); - assertEquals(RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters), searchTreeParameters.getRangeActionParameters()); + assertEquals(raoParameters.getRangeActionsOptimizationParameters(), searchTreeParameters.getRangeActionParameters()); 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(raoParametersExtension.getRangeActionsOptimizationParameters().getLinearOptimizationSolver(), searchTreeParameters.getSolverParameters()); + assertEquals(raoParametersExtension.getRangeActionsOptimizationParameters().getMaxMipIterations(), searchTreeParameters.getMaxNumberOfIterations()); } @Test @@ -74,11 +79,12 @@ void testIndividualSetters() { NetworkActionParameters networkActionParameters = Mockito.mock(NetworkActionParameters.class); Map raLimitationParameters = new HashMap<>(); RangeActionsOptimizationParameters rangeActionParameters = Mockito.mock(RangeActionsOptimizationParameters.class); + com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension = Mockito.mock(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.class); MnecParametersExtension mnecParameters = Mockito.mock(MnecParametersExtension.class); RelativeMarginsParametersExtension maxMinRelativeMarginParameters = Mockito.mock(RelativeMarginsParametersExtension.class); LoopFlowParametersExtension loopFlowParameters = Mockito.mock(LoopFlowParametersExtension.class); UnoptimizedCnecParameters unoptimizedCnecParameters = Mockito.mock(UnoptimizedCnecParameters.class); - RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters = Mockito.mock(RangeActionsOptimizationParameters.LinearOptimizationSolver.class); + LinearOptimizationSolver solverParameters = Mockito.mock(LinearOptimizationSolver.class); int maxNumberOfIterations = 3; SearchTreeParameters searchTreeParameters = builder @@ -88,6 +94,7 @@ void testIndividualSetters() { .withNetworkActionParameters(networkActionParameters) .withGlobalRemedialActionLimitationParameters(raLimitationParameters) .withRangeActionParameters(rangeActionParameters) + .withRangeActionParametersExtension(rangeActionParametersExtension) .withMnecParameters(mnecParameters) .withMaxMinRelativeMarginParameters(maxMinRelativeMarginParameters) .withLoopFlowParameters(loopFlowParameters) diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/CommonTestData.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/CommonTestData.java index 9930792bb2..eb366e37bb 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/CommonTestData.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/CommonTestData.java @@ -21,7 +21,6 @@ import com.powsybl.openrao.monitoring.anglemonitoring.AngleMonitoringResult; import com.powsybl.openrao.monitoring.anglemonitoring.RaoResultWithAngleMonitoring; import com.powsybl.openrao.raoapi.json.JsonRaoParameters; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.tests.utils.CoreCcPreprocessor; import com.powsybl.openrao.tests.utils.Helpers; @@ -44,8 +43,6 @@ public final class CommonTestData { private static String dataPrefix = "src/test/resources/files/"; - private static String overrideLinearSolver = null; - private static String networkPath; private static Boolean coreCcNetworkPreprocessing = false; private static Network network; @@ -110,14 +107,6 @@ public static String getResourcesPath() { return dataPrefix; } - public static void setLinearSolver(String solver) { - overrideLinearSolver = solver; - } - - public static void resetLinearSolver() { - overrideLinearSolver = null; - } - @Before // Reset data to null before every scenario public static void reset() { @@ -298,9 +287,6 @@ public static void loadData(String timestamp) throws IOException { } else { raoParameters = buildDefaultConfig(); } - if (overrideLinearSolver != null) { - raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(RangeActionsOptimizationParameters.Solver.valueOf(overrideLinearSolver.toUpperCase())); - } // GLSK // for now, only work with UCTE GLSK files, not CIME GLSK file diff --git a/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java b/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java index faacc611a9..daf2f4e622 100644 --- a/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java +++ b/tests/src/test/java/com/powsybl/openrao/tests/steps/SearchTreeRaoSteps.java @@ -30,6 +30,7 @@ import com.powsybl.openrao.loopflowcomputation.LoopFlowComputationImpl; import com.powsybl.openrao.loopflowcomputation.LoopFlowResult; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.sensitivity.SensitivityAnalysisParameters; import com.powsybl.sensitivity.SensitivityVariableSet; import com.powsybl.openrao.tests.utils.RaoUtils; import io.cucumber.java.en.Then; @@ -44,6 +45,7 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.getSensitivityWithLoadFlowParameters; import static org.junit.jupiter.api.Assertions.*; /** @@ -639,12 +641,13 @@ private void launchLoopflowComputation(String timestamp, String sensitivityProvi network = CommonTestData.getNetwork(); crac = CommonTestData.getCrac(); RaoParameters raoParameters = CommonTestData.getRaoParameters(); - ReferenceProgram referenceProgram = CommonTestData.getReferenceProgram() != null ? CommonTestData.getReferenceProgram() : ReferenceProgramBuilder.buildReferenceProgram(network, loadFlowProvider, raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters()); + SensitivityAnalysisParameters sensitivityAnalysisParameters = getSensitivityWithLoadFlowParameters(raoParameters); + ReferenceProgram referenceProgram = CommonTestData.getReferenceProgram() != null ? CommonTestData.getReferenceProgram() : ReferenceProgramBuilder.buildReferenceProgram(network, loadFlowProvider, sensitivityAnalysisParameters.getLoadFlowParameters()); ZonalData glsks = CommonTestData.getGlsks(); // run loopFlowComputation LoopFlowComputation loopFlowComputation = new LoopFlowComputationImpl(glsks, referenceProgram); - this.loopFlowResult = loopFlowComputation.calculateLoopFlows(network, sensitivityProvider, raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters(), crac.getFlowCnecs(), crac.getOutageInstant()); + this.loopFlowResult = loopFlowComputation.calculateLoopFlows(network, sensitivityProvider, sensitivityAnalysisParameters, crac.getFlowCnecs(), crac.getOutageInstant()); } catch (IOException e) { throw new UncheckedIOException(e);