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 408cf8c35e..2e47df1313 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 @@ -61,10 +61,7 @@ private RaoParametersCommons() { // Multi-threading parameters public static final String MULTI_THREADING = "multi-threading"; public static final String MULTI_THREADING_SECTION = "rao-multi-threading"; - public static final String CONTINGENCY_SCENARIOS_IN_PARALLEL = "contingency-scenarios-in-parallel"; - public static final String PREVENTIVE_LEAVES_IN_PARALLEL = "preventive-leaves-in-parallel"; - public static final String AUTO_LEAVES_IN_PARALLEL = "auto-leaves-in-parallel"; - public static final String CURATIVE_LEAVES_IN_PARALLEL = "curative-leaves-in-parallel"; + public static final String AVAILABLE_CPUS = "available-cpus"; // Second Preventive RAO parameters public static final String SECOND_PREVENTIVE_RAO = "second-preventive-rao"; @@ -73,29 +70,19 @@ private RaoParametersCommons() { public static final String RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS = "re-optimize-curative-range-actions"; public static final String HINT_FROM_FIRST_PREVENTIVE_RAO = "hint-from-first-preventive-rao"; - // RA usage limits per contingency parameters - public static final String RA_USAGE_LIMITS_PER_CONTINGENCY = "ra-usage-limits-per-contingency"; - public static final String RA_USAGE_LIMITS_PER_CONTINGENCY_SECTION = "rao-ra-usage-limits-per-contingency"; - - public static final String MAX_CURATIVE_RA = "max-curative-ra"; - public static final String MAX_CURATIVE_TSO = "max-curative-tso"; - public static final String MAX_CURATIVE_TOPO_PER_TSO = "max-curative-topo-per-tso"; - public static final String MAX_CURATIVE_PST_PER_TSO = "max-curative-pst-per-tso"; - public static final String MAX_CURATIVE_RA_PER_TSO = "max-curative-ra-per-tso"; - // Not optimized cnecs parameters public static final String NOT_OPTIMIZED_CNECS = "not-optimized-cnecs"; public static final String NOT_OPTIMIZED_CNECS_SECTION = "rao-not-optimized-cnecs"; public static final String DO_NOT_OPTIMIZE_CURATIVE_CNECS = "do-not-optimize-curative-cnecs-for-tsos-without-cras"; - // Not optimized cnecs parameters + // Load flow and sensitivity parameters public static final String LOAD_FLOW_AND_SENSITIVITY_COMPUTATION = "load-flow-and-sensitivity-computation"; public static final String LOAD_FLOW_AND_SENSITIVITY_COMPUTATION_SECTION = "rao-load-flow-and-sensitivity-computation"; - public static final String LOAD_FLOW_PROVIDER = "load-flow-provider"; public static final String SENSITIVITY_PROVIDER = "sensitivity-provider"; public static final String SENSITIVITY_FAILURE_OVERCOST = "sensitivity-failure-overcost"; public static final String SENSITIVITY_PARAMETERS = "sensitivity-parameters"; + public static final String LOAD_FLOW_PARAMETERS = "load-flow-parameters"; // EXTENSIONS public static final String CONSTRAINT_ADJUSTMENT_COEFFICIENT = "constraint-adjustment-coefficient"; 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/JsonLoadFlowAndSensitivityComputationParameters.java deleted file mode 100644 index 2e5fee5476..0000000000 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/JsonLoadFlowAndSensitivityComputationParameters.java +++ /dev/null @@ -1,62 +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 com.fasterxml.jackson.databind.SerializerProvider; -import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters; - -import java.io.IOException; - -import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; - -/** - * @author Godelaine de Montmorillon {@literal } - */ -final class JsonLoadFlowAndSensitivityComputationParameters { - - private JsonLoadFlowAndSensitivityComputationParameters() { - } - - static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { - jsonGenerator.writeObjectFieldStart(LOAD_FLOW_AND_SENSITIVITY_COMPUTATION); - jsonGenerator.writeStringField(LOAD_FLOW_PROVIDER, parameters.getLoadFlowAndSensitivityParameters().getLoadFlowProvider()); - jsonGenerator.writeStringField(SENSITIVITY_PROVIDER, parameters.getLoadFlowAndSensitivityParameters().getSensitivityProvider()); - jsonGenerator.writeNumberField(SENSITIVITY_FAILURE_OVERCOST, parameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost()); - jsonGenerator.writeFieldName(SENSITIVITY_PARAMETERS); - serializerProvider.defaultSerializeValue(parameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters(), jsonGenerator); - jsonGenerator.writeEndObject(); - } - - static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException { - while (!jsonParser.nextToken().isStructEnd()) { - switch (jsonParser.getCurrentName()) { - case LOAD_FLOW_PROVIDER: - jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setLoadFlowProvider(jsonParser.getValueAsString()); - break; - case SENSITIVITY_PROVIDER: - jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityProvider(jsonParser.getValueAsString()); - break; - case SENSITIVITY_FAILURE_OVERCOST: - jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityFailureOvercost(jsonParser.getValueAsDouble()); - break; - case SENSITIVITY_PARAMETERS: - jsonParser.nextToken(); - raoParameters.getLoadFlowAndSensitivityParameters().setSensitivityWithLoadFlowParameters(JsonSensitivityAnalysisParameters.createObjectMapper().readerForUpdating(raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters()).readValue(jsonParser)); - break; - default: - throw new OpenRaoException(String.format("Cannot deserialize load flow and sensitivity parameters: unexpected field in %s (%s)", LOAD_FLOW_AND_SENSITIVITY_COMPUTATION, jsonParser.getCurrentName())); - } - } - } -} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/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/RaoParametersDeserializer.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java index a03d12d435..00b1b97461 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersDeserializer.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.powsybl.commons.extensions.Extension; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.loadflow.json.JsonLoadFlowParameters; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.raoapi.parameters.RaoParameters; @@ -63,9 +64,9 @@ public RaoParameters deserialize(JsonParser parser, DeserializationContext deser parser.nextToken(); JsonNotOptimizedCnecsParameters.deserialize(parser, parameters); break; - case LOAD_FLOW_AND_SENSITIVITY_COMPUTATION: + case LOAD_FLOW_PARAMETERS: parser.nextToken(); - JsonLoadFlowAndSensitivityComputationParameters.deserialize(parser, parameters); + JsonLoadFlowParameters.deserialize(parser, deserializationContext, parameters.getLoadFlowParameters()); break; case "extensions": parser.nextToken(); diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java index a3c29ee152..b7e04c7007 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/RaoParametersSerializer.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.powsybl.commons.json.JsonUtil; +import com.powsybl.loadflow.json.JsonLoadFlowParameters; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import java.io.IOException; @@ -34,7 +35,7 @@ public void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, Ser JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator); JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator); JsonNotOptimizedCnecsParameters.serialize(parameters, jsonGenerator); - JsonLoadFlowAndSensitivityComputationParameters.serialize(parameters, jsonGenerator, serializerProvider); + JsonLoadFlowParameters.serialize(parameters.getLoadFlowParameters(), jsonGenerator, serializerProvider); JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonRaoParameters.getExtensionSerializers()); jsonGenerator.writeEndObject(); } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java index 32b7aefa5f..c63ae28e08 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/json/extensions/JsonLoadFlowAndSensitivityComputationParameters.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.SerializerProvider; import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters; @@ -53,7 +52,7 @@ static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searc break; case SENSITIVITY_PARAMETERS: jsonParser.nextToken(); - searchTreeParameters.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 index 3be0a88d6c..2647f28589 100644 --- 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 @@ -8,9 +8,9 @@ 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.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import java.io.IOException; @@ -24,36 +24,23 @@ final class JsonMultiThreadingParameters { private JsonMultiThreadingParameters() { } - static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException { + static void serialize(OpenRaoSearchTreeParameters 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.writeNumberField(AVAILABLE_CPUS, parameters.getMultithreadingParameters().getContingencyScenariosInParallel()); 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 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())); + 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 index 57e14cd99b..7334927b37 100644 --- 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 @@ -9,8 +9,6 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.powsybl.openrao.commons.OpenRaoException; -import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; -import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters; import java.io.IOException; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java deleted file mode 100644 index 0222212b65..0000000000 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/LoadFlowAndSensitivityParameters.java +++ /dev/null @@ -1,62 +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.parameters; - -import com.powsybl.commons.config.PlatformConfig; -import com.powsybl.loadflow.LoadFlowParameters; -import com.powsybl.sensitivity.SensitivityAnalysisParameters; - -import java.util.Objects; -import static com.powsybl.openrao.raoapi.RaoParametersCommons.*; -import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.BUSINESS_WARNS; - -/** - * LoadFlow and sensitivity computation parameters for RAO - * - * @author Godelaine de Montmorillon {@literal } - */ -public class LoadFlowAndSensitivityParameters { - private SensitivityAnalysisParameters sensitivityWithLoadFlowParameters = cleanLoadFlowParameters(new SensitivityAnalysisParameters()); - - // Getters and setters - public SensitivityAnalysisParameters getSensitivityWithLoadFlowParameters() { - return sensitivityWithLoadFlowParameters; - } - - public void setSensitivityWithLoadFlowParameters(SensitivityAnalysisParameters sensitivityWithLoadFlowParameters) { - this.sensitivityWithLoadFlowParameters = cleanLoadFlowParameters(sensitivityWithLoadFlowParameters); - } - - public static LoadFlowAndSensitivityParameters load(PlatformConfig platformConfig) { - Objects.requireNonNull(platformConfig); - LoadFlowAndSensitivityParameters parameters = new LoadFlowAndSensitivityParameters(); - platformConfig.getOptionalModuleConfig(LOAD_FLOW_AND_SENSITIVITY_COMPUTATION_SECTION) - .ifPresent(config -> { - parameters.setLoadFlowProvider(config.getStringProperty(LOAD_FLOW_PROVIDER, DEFAULT_LOADFLOW_PROVIDER)); - parameters.setSensitivityProvider(config.getStringProperty(SENSITIVITY_PROVIDER, DEFAULT_SENSITIVITY_PROVIDER)); - parameters.setSensitivityFailureOvercost(config.getDoubleProperty(SENSITIVITY_FAILURE_OVERCOST, DEFAULT_SENSITIVITY_FAILURE_OVERCOST)); - }); - parameters.setSensitivityWithLoadFlowParameters(SensitivityAnalysisParameters.load(platformConfig)); - return parameters; - } - - private SensitivityAnalysisParameters cleanLoadFlowParameters(SensitivityAnalysisParameters sensitivityAnalysisParameters) { - LoadFlowParameters loadFlowParameters = sensitivityAnalysisParameters.getLoadFlowParameters(); - // we have to clean load flow parameters. - // the slack bus must not be written because it could pollute the sensitivity analyses. - loadFlowParameters.setWriteSlackBus(false); - // in DC, as emulation AC is supported for LF but not for sensitivity analyses, it could - // lead to incoherence. - if (loadFlowParameters.isDc() && loadFlowParameters.isHvdcAcEmulation()) { - BUSINESS_WARNS.warn("The runs are in DC but the HvdcAcEmulation parameter is on: this is not compatible." + - "HvdcAcEmulation parameter set to false."); - loadFlowParameters.setHvdcAcEmulation(false); - } - return sensitivityAnalysisParameters; - } -} diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java index 975a4e850d..b0c9eb3509 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/RaoParameters.java @@ -14,6 +14,7 @@ import com.powsybl.commons.extensions.Extension; import com.powsybl.commons.extensions.ExtensionConfigLoader; import com.powsybl.commons.extensions.ExtensionProviders; +import com.powsybl.loadflow.LoadFlowParameters; import com.powsybl.openrao.raoapi.parameters.extensions.MultithreadingParameters; import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; @@ -30,7 +31,7 @@ public class RaoParameters extends AbstractExtendable { private MultithreadingParameters multithreadingParameters = new MultithreadingParameters(); private SecondPreventiveRaoParameters secondPreventiveRaoParameters = new SecondPreventiveRaoParameters(); private NotOptimizedCnecsParameters notOptimizedCnecsParameters = new NotOptimizedCnecsParameters(); - private LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters = new LoadFlowAndSensitivityParameters(); + private LoadFlowParameters loadFlowParameters = new LoadFlowParameters(); // Getters and setters public void setObjectiveFunctionParameters(ObjectiveFunctionParameters objectiveFunctionParameters) { @@ -57,8 +58,8 @@ public void setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters notOptimi this.notOptimizedCnecsParameters = notOptimizedCnecsParameters; } - public void setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters loadFlowAndSensitivityParameters) { - this.loadFlowAndSensitivityParameters = loadFlowAndSensitivityParameters; + public void setLoadFlowParameters(LoadFlowParameters loadFlowParameters) { + this.loadFlowParameters = loadFlowParameters; } public ObjectiveFunctionParameters getObjectiveFunctionParameters() { @@ -85,8 +86,8 @@ public NotOptimizedCnecsParameters getNotOptimizedCnecsParameters() { return notOptimizedCnecsParameters; } - public LoadFlowAndSensitivityParameters getLoadFlowAndSensitivityParameters() { - return loadFlowAndSensitivityParameters; + public LoadFlowParameters getLoadFlowParameters() { + return loadFlowParameters; } public boolean hasExtension(Class classType) { @@ -132,7 +133,7 @@ public static void load(RaoParameters parameters, PlatformConfig platformConfig) parameters.setMultithreadingParameters(MultithreadingParameters.load(platformConfig)); parameters.setSecondPreventiveRaoParameters(SecondPreventiveRaoParameters.load(platformConfig)); parameters.setNotOptimizedCnecsParameters(NotOptimizedCnecsParameters.load(platformConfig)); - parameters.setLoadFlowAndSensitivityParameters(LoadFlowAndSensitivityParameters.load(platformConfig)); + parameters.setLoadFlowParameters(LoadFlowParameters.load(platformConfig)); } private void loadExtensions(PlatformConfig platformConfig) { @@ -140,6 +141,7 @@ private void loadExtensions(PlatformConfig platformConfig) { if (platformConfig.getOptionalModuleConfig(provider.getExtensionName()).isPresent()) { addExtension(provider.getExtensionClass(), provider.load(platformConfig)); } + // TODO: LoadFlowAndSensitivityParameters hasExtension } } } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java index d46788b53e..b030c1a387 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/LoadFlowAndSensitivityParameters.java @@ -22,9 +22,9 @@ * @author Godelaine de Montmorillon {@literal } */ public class LoadFlowAndSensitivityParameters { - private static final String DEFAULT_LOADFLOW_PROVIDER = "OpenLoadFlow"; + public static final String DEFAULT_LOADFLOW_PROVIDER = "OpenLoadFlow"; private static final String DEFAULT_SENSITIVITY_PROVIDER = "OpenLoadFlow"; - private static final double DEFAULT_SENSITIVITY_FAILURE_OVERCOST = 10000; + public static final double DEFAULT_SENSITIVITY_FAILURE_OVERCOST = 10000; private String loadFlowProvider = DEFAULT_LOADFLOW_PROVIDER; private String sensitivityProvider = DEFAULT_SENSITIVITY_PROVIDER; diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java index 101c164345..c123ae44cc 100644 --- a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/MultithreadingParameters.java @@ -64,11 +64,11 @@ public static MultithreadingParameters load(PlatformConfig platformConfig) { MultithreadingParameters parameters = new MultithreadingParameters(); platformConfig.getOptionalModuleConfig(MULTI_THREADING_SECTION) .ifPresent(config -> { - parameters.setContingencyScenariosInParallel(config.getIntProperty(CONTINGENCY_SCENARIOS_IN_PARALLEL, DEFAULT_CONTINGENCY_SCENARIOS_IN_PARALLEL)); - parameters.setPreventiveLeavesInParallel(config.getIntProperty(PREVENTIVE_LEAVES_IN_PARALLEL, DEFAULT_PREVENTIVE_LEAVES_IN_PARALLEL)); - parameters.setAutoLeavesInParallel(config.getIntProperty(AUTO_LEAVES_IN_PARALLEL, DEFAULT_AUTO_LEAVES_IN_PARALLEL)); - parameters.setCurativeLeavesInParallel(config.getIntProperty(CURATIVE_LEAVES_IN_PARALLEL, DEFAULT_CURATIVE_LEAVES_IN_PARALLEL)); - + int availableCpus = config.getIntProperty(AVAILABLE_CPUS, 1); + parameters.setContingencyScenariosInParallel(availableCpus); + parameters.setPreventiveLeavesInParallel(availableCpus); + parameters.setAutoLeavesInParallel(1); + parameters.setCurativeLeavesInParallel(1); }); return parameters; } diff --git a/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/parameters/extensions/RangeActionsOptimizationParameters.java index 6124501782..1962399058 100644 --- 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 @@ -25,10 +25,10 @@ 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; + public 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; + public static final RaRangeShrinking DEFAULT_RA_RANGE_SHRINKING = RaRangeShrinking.DISABLED; // Attributes private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; private double pstSensitivityThreshold = DEFAULT_PST_SENSITIVITY_THRESHOLD; 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 index 8f2f506048..d3dfed9e34 100644 --- 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 @@ -24,10 +24,10 @@ */ 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; + public static final int DEFAULT_MAX_SEARCH_TREE_DEPTH = Integer.MAX_VALUE; + public static final List> DEFAULT_PREDEFINED_COMBINATIONS = new ArrayList<>(); + public static final boolean DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT = false; + public 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; 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..d24696d759 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 @@ -23,6 +23,7 @@ import com.powsybl.openrao.data.cracapi.usagerule.*; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters; import com.powsybl.openrao.searchtreerao.commons.RaoLogger; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.commons.ToolProvider; @@ -51,6 +52,7 @@ import static com.powsybl.openrao.commons.Unit.MEGAWATT; import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.*; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.DEFAULT_LOADFLOW_PROVIDER; 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.getLoadFlowParameters()); // Next, disable AngleDroopActivePowerControl on HVDCs and set their active power set-points to the value // previously computed by the AngleDroopActivePowerControl. @@ -495,6 +497,13 @@ Pair> disableHvdcAngleDroopActi return Pair.of(result, activePowerSetpoints); } + private String getLoadFlowProvider() { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getLoadFlowProvider(); + } + return DEFAULT_LOADFLOW_PROVIDER; + } + private static Map computeHvdcAngleDroopActivePowerControlValues(Network network, State state, String loadFlowProvider, LoadFlowParameters loadFlowParameters) { // Create a temporary variant to apply contingency and compute load-flow on String initialVariantId = network.getVariantManager().getWorkingVariantId(); 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 92e9dd8005..c409d6633d 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,6 +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.extensions.LoadFlowAndSensitivityParameters; import com.powsybl.openrao.raoapi.parameters.extensions.SecondPreventiveRaoParameters; import com.powsybl.openrao.searchtreerao.commons.NetworkActionCombination; import com.powsybl.openrao.searchtreerao.commons.RaoLogger; @@ -48,6 +49,7 @@ 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.DEFAULT_SENSITIVITY_FAILURE_OVERCOST; import static com.powsybl.openrao.searchtreerao.commons.RaoLogger.formatDouble; import static com.powsybl.openrao.searchtreerao.commons.RaoUtil.applyRemedialActions; @@ -331,7 +333,7 @@ private Object runScenario(Crac crac, RaoParameters raoParameters, StateTree sta Set curativeStates = new HashSet<>(); optimizedScenario.getCurativePerimeters().forEach(perimeter -> curativeStates.addAll(perimeter.getAllStates())); PrePerimeterResult preCurativeResult = prePerimeterSensitivityOutput; - double sensitivityFailureOvercost = raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost(); + double sensitivityFailureOvercost = getSensitivityFailureOvercost(); // Simulate automaton instant boolean autoStateSensiFailed = false; @@ -598,7 +600,7 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, // Specific case : curative state was previously skipped because it led to a sensitivity analysis failure. // Curative state is still a SkippedOptimizationResultImpl, but its computation status must be updated if (entry.getValue() instanceof SkippedOptimizationResultImpl) { - newPostContingencyResults.put(state, new SkippedOptimizationResultImpl(state, new HashSet<>(), new HashSet<>(), postCraSensitivityAnalysisOutput.getSensitivityStatus(entry.getKey()), raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityFailureOvercost())); + newPostContingencyResults.put(state, new SkippedOptimizationResultImpl(state, new HashSet<>(), new HashSet<>(), postCraSensitivityAnalysisOutput.getSensitivityStatus(entry.getKey()), getSensitivityFailureOvercost())); } else { newPostContingencyResults.put(state, new CurativeWithSecondPraoResult(state, entry.getValue(), secondPreventiveRaoResult.perimeterResult(), secondPreventiveRaoResult.remedialActionsExcluded(), postCraSensitivityAnalysisOutput)); } @@ -616,6 +618,13 @@ private RaoResult runSecondPreventiveAndAutoRao(RaoInput raoInput, raoInput.getCrac()); } + private double getSensitivityFailureOvercost() { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getSensitivityFailureOvercost(); + } + return DEFAULT_SENSITIVITY_FAILURE_OVERCOST; + } + private record SecondPreventiveRaoResult(OptimizationResult perimeterResult, PrePerimeterResult postPraSensitivityAnalysisOutput, Set> remedialActionsExcluded, 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..513b887c52 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 @@ -19,8 +19,10 @@ 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.extensions.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; @@ -33,6 +35,8 @@ import java.util.Set; import java.util.stream.Collectors; +import static com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters.DEFAULT_LOADFLOW_PROVIDER; +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.DEFAULT_PST_MODEL; 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), 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); @@ -84,6 +88,20 @@ public static void checkParameters(RaoParameters raoParameters, RaoInput raoInpu } } + private static String getLoadFlowProvider(RaoParameters raoParameters) { + if (raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getLoadFlowProvider(); + } + return DEFAULT_LOADFLOW_PROVIDER; + } + + private static PstModel getPstModel(RaoParameters raoParameters) { + if (raoParameters.hasExtension(RangeActionsOptimizationParameters.class)) { + return raoParameters.getExtension(RangeActionsOptimizationParameters.class).getPstModel(); + } + return DEFAULT_PST_MODEL; + } + public static double getFlowUnitMultiplier(FlowCnec cnec, TwoSides voltageSide, Unit unitFrom, Unit unitTo) { if (unitFrom == unitTo) { return 1; @@ -209,6 +227,6 @@ public static void applyRemedialActions(Network network, OptimizationResult optR } public static Unit getObjectiveFunctionUnit(RaoParameters raoParameters) { - return raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters().getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE; + return raoParameters.getLoadFlowParameters().isDc() ? Unit.MEGAWATT : Unit.AMPERE; } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/commons/ToolProvider.java index 769cc137fb..131494900e 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 @@ -19,6 +19,7 @@ import com.powsybl.openrao.loopflowcomputation.LoopFlowComputationImpl; import com.powsybl.openrao.raoapi.RaoInput; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.LoadFlowAndSensitivityParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; import com.powsybl.openrao.sensitivityanalysis.AppliedRemedialActions; @@ -91,13 +92,18 @@ public SystematicSensitivityInterface getSystematicSensitivityInterface(Set} */ @@ -83,8 +86,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 +140,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(); @@ -157,5 +162,13 @@ public ObjectiveFunction build() { Objects.requireNonNull(functionalCostEvaluator); return new ObjectiveFunction(functionalCostEvaluator, virtualCostEvaluators); } + + private double getSensitivityFailureOvercost(RaoParameters raoParameters) { + if (!raoParameters.hasExtension(LoadFlowAndSensitivityParameters.class)) { + return DEFAULT_SENSITIVITY_FAILURE_OVERCOST; + } else { + return raoParameters.getExtension(LoadFlowAndSensitivityParameters.class).getSensitivityFailureOvercost(); + } + } } } 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..d9528fecb5 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,27 @@ 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)); + } + + private static boolean isSkipActionsFarFromMostLimitingElement(RaoParameters raoParameters) { + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class)) { + return raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class).getSkipActionsFarFromMostLimitingElement(); + } + return DEFAULT_SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT; + } + + private static int getMaxNumberOfBoundariesForSkippingActions(RaoParameters raoParameters) { + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class)) { + return raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class).getMaxNumberOfBoundariesForSkippingActions(); + } + return DEFAULT_MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS; } public void addNetworkActionCombination(NetworkActionCombination networkActionCombination) { @@ -95,8 +112,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); @@ -105,6 +122,13 @@ public static List computePredefinedCombinations(Crac return computedPredefinedCombinations; } + private static List> getPredefinedCombinations(RaoParameters raoParameters) { + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class)) { + return raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.class).getPredefinedCombinations(); + } + return DEFAULT_PREDEFINED_COMBINATIONS; + } + private static Optional computePredefinedCombinationsFromIds(List networkActionIds, Crac crac) { if (networkActionIds.size() < 2) { 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..426a8a0b97 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,8 +7,13 @@ package com.powsybl.openrao.searchtreerao.commons.parameters; import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.RaRangeShrinking; import com.powsybl.openrao.raoapi.parameters.RaoParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters; + +import static com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.DEFAULT_RA_RANGE_SHRINKING; +import static com.powsybl.openrao.raoapi.parameters.extensions.TopoOptimizationParameters.DEFAULT_MAX_SEARCH_TREE_DEPTH; /** * This class contains internal Open RAO parameters used in the SearchTree algorithm. @@ -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(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), shouldShrinkRaRange); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), shouldShrinkRaRange); } } public static TreeParameters buildForAutomatonPerimeter(RaoParameters parameters) { - return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), parameters.getMultithreadingParameters().getAutoLeavesInParallel(), false); + return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, getMaxAutoSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getAutoLeavesInParallel(), false); } public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, Double preventiveOptimizedCost) { @@ -59,30 +64,51 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, targetObjectiveValue = Math.min(targetObjectiveValue, 0); } } - RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking(); + RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = getRaRangeShrinking(parameters); boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, - parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), shouldShrinkRaRange); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { - boolean raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking().equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + boolean raRangeShrinking = getRaRangeShrinking(parameters).equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); if (parameters.getObjectiveFunctionParameters().getType().equals(ObjectiveFunctionParameters.ObjectiveFunctionType.SECURE_FLOW)) { return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, // secure - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), raRangeShrinking); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), + getMaxPreventiveSearchTreeDepth(parameters), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), raRangeShrinking); } } + + private static RaRangeShrinking getRaRangeShrinking(RaoParameters parameters) { + if (parameters.hasExtension(RangeActionsOptimizationParameters.class)) { + return parameters.getExtension(RangeActionsOptimizationParameters.class).getRaRangeShrinking(); + } + return DEFAULT_RA_RANGE_SHRINKING; + } + + private static int getMaxPreventiveSearchTreeDepth(RaoParameters parameters) { + if (parameters.hasExtension(TopoOptimizationParameters.class)) { + return parameters.getExtension(TopoOptimizationParameters.class).getMaxPreventiveSearchTreeDepth(); + } + return DEFAULT_MAX_SEARCH_TREE_DEPTH; + } + + private static int getMaxAutoSearchTreeDepth(RaoParameters parameters) { + if (parameters.hasExtension(TopoOptimizationParameters.class)) { + return parameters.getExtension(TopoOptimizationParameters.class).getMaxAutoSearchTreeDepth(); + } + return DEFAULT_MAX_SEARCH_TREE_DEPTH; + } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java index 3f6cae07c5..c0513032d2 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/IteratingLinearOptimizer.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.raoresultapi.ComputationStatus; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; import com.powsybl.openrao.searchtreerao.commons.SensitivityComputer; import com.powsybl.openrao.searchtreerao.commons.objectivefunctionevaluator.ObjectiveFunction; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.GlobalOptimizationPerimeter; @@ -126,7 +126,7 @@ private static SensitivityComputer runSensitivityAnalysis(SensitivityComputer se private static RangeActionActivationResult resolveIfApproximatedPstTaps(IteratingLinearOptimizationResultImpl bestResult, LinearProblem linearProblem, int iteration, RangeActionActivationResult currentRangeActionActivationResult, IteratingLinearOptimizerInput input, IteratingLinearOptimizerParameters parameters) { LinearProblemStatus solveStatus; RangeActionActivationResult rangeActionActivationResult = currentRangeActionActivationResult; - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { + if (parameters.getRangeActionParametersExtension().getPstModel().equals(PstModel.APPROXIMATED_INTEGERS)) { // if the PST approximation is APPROXIMATED_INTEGERS, we re-solve the optimization problem // but first, we update it, with an adjustment of the PSTs angleToTap conversion factors, to @@ -240,7 +240,7 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu } private static RangeActionActivationResultImpl roundPsts(RangeActionActivationResult linearProblemResult, IteratingLinearOptimizationResultImpl previousResult, IteratingLinearOptimizerInput input, IteratingLinearOptimizerParameters parameters) { - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.CONTINUOUS)) { + if (parameters.getRangeActionParametersExtension().getPstModel().equals(PstModel.CONTINUOUS)) { return BestTapFinder.round( linearProblemResult, input.getNetwork(), diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java index 14bccc300c..1eae9ab1f2 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/fillers/CoreProblemFiller.java @@ -18,6 +18,7 @@ import com.powsybl.openrao.data.cracapi.range.TapRange; import com.powsybl.openrao.data.cracapi.rangeaction.*; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.PstModel; import com.powsybl.openrao.searchtreerao.commons.RaoUtil; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.OptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.linearproblem.OpenRaoMPConstraint; @@ -44,24 +45,28 @@ public class CoreProblemFiller implements ProblemFiller { private final Set flowCnecs; private final RangeActionSetpointResult prePerimeterRangeActionSetpoints; private final RangeActionsOptimizationParameters rangeActionParameters; + private final com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; + private final Unit unit; private int iteration = 0; private static final double RANGE_SHRINK_RATE = 0.667; private final boolean raRangeShrinking; - private final RangeActionsOptimizationParameters.PstModel pstModel; + private final PstModel pstModel; public CoreProblemFiller(OptimizationPerimeter optimizationContext, RangeActionSetpointResult prePerimeterRangeActionSetpoints, RangeActionsOptimizationParameters rangeActionParameters, + com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension, Unit unit, boolean raRangeShrinking, - RangeActionsOptimizationParameters.PstModel pstModel) { + PstModel pstModel) { this.optimizationContext = optimizationContext; this.flowCnecs = new TreeSet<>(Comparator.comparing(Identifiable::getId)); this.flowCnecs.addAll(optimizationContext.getFlowCnecs()); this.prePerimeterRangeActionSetpoints = prePerimeterRangeActionSetpoints; this.rangeActionParameters = rangeActionParameters; + this.rangeActionParametersExtension = rangeActionParametersExtension; this.unit = unit; this.raRangeShrinking = raRangeShrinking; this.pstModel = pstModel; @@ -183,11 +188,11 @@ private void addImpactOfRangeActionOnCnec(LinearProblem linearProblem, Sensitivi private boolean isRangeActionSensitivityAboveThreshold(RangeAction rangeAction, double sensitivity) { if (rangeAction instanceof PstRangeAction) { - return sensitivity >= rangeActionParameters.getPstSensitivityThreshold(); + return sensitivity >= rangeActionParametersExtension.getPstSensitivityThreshold(); } else if (rangeAction instanceof HvdcRangeAction) { - return sensitivity >= rangeActionParameters.getHvdcSensitivityThreshold(); + return sensitivity >= rangeActionParametersExtension.getHvdcSensitivityThreshold(); } else if (rangeAction instanceof InjectionRangeAction) { - return sensitivity >= rangeActionParameters.getInjectionRaSensitivityThreshold(); + return sensitivity >= rangeActionParametersExtension.getInjectionRaSensitivityThreshold(); } else { throw new OpenRaoException("Type of RangeAction not yet handled by the LinearRao."); } @@ -289,7 +294,7 @@ private void buildConstraintsForRangeActionAndState(LinearProblem linearProblem, double maxRelativeSetpoint = minAndMaxAbsoluteAndRelativeSetpoints.get(3); // relative range - if (pstModel.equals(RangeActionsOptimizationParameters.PstModel.CONTINUOUS) || !(rangeAction instanceof PstRangeAction)) { + if (pstModel.equals(PstModel.CONTINUOUS) || !(rangeAction instanceof PstRangeAction)) { OpenRaoMPConstraint relSetpointConstraint = linearProblem.addRangeActionRelativeSetpointConstraint(minRelativeSetpoint, maxRelativeSetpoint, rangeAction, state, LinearProblem.RaRangeShrinking.FALSE); relSetpointConstraint.setCoefficient(setPointVariable, 1); relSetpointConstraint.setCoefficient(previousSetpointVariable, -1); diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java index 67c731a3ff..e4bc0b5772 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblem.java @@ -12,7 +12,7 @@ import com.powsybl.iidm.network.TwoSides; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.fillers.ProblemFiller; import com.powsybl.openrao.searchtreerao.result.api.FlowResult; import com.powsybl.openrao.searchtreerao.result.api.LinearProblemStatus; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java index 7fc5c8a7fc..0516aa9ffe 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/LinearProblemBuilder.java @@ -9,7 +9,7 @@ import com.powsybl.openrao.data.cracapi.State; import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.commons.optimizationperimeters.CurativeOptimizationPerimeter; import com.powsybl.openrao.searchtreerao.linearoptimisation.algorithms.fillers.*; import com.powsybl.openrao.searchtreerao.linearoptimisation.inputs.IteratingLinearOptimizerInput; @@ -37,12 +37,15 @@ public LinearProblem buildFromInputsAndParameters(IteratingLinearOptimizerInput this.inputs = inputs; this.parameters = parameters; - this.withSolver(parameters.getSolverParameters().getSolver()) - .withRelativeMipGap(parameters.getSolverParameters().getRelativeMipGap()) + this.withRelativeMipGap(parameters.getSolverParameters().getRelativeMipGap()) .withSolverSpecificParameters(parameters.getSolverParameters().getSolverSpecificParameters()) .withProblemFiller(buildCoreProblemFiller()) .withInitialRangeActionActivationResult(inputs.getRaActivationFromParentLeaf()); + if (parameters.isRaoWithSolverParameters()) { + this.withSolver(parameters.getSolverParameters().getSolver()); + } + // max.min margin, or max.min relative margin if (parameters.relativePositiveMargins()) { this.withProblemFiller(buildMaxMinRelativeMarginFiller()); @@ -68,7 +71,7 @@ public LinearProblem buildFromInputsAndParameters(IteratingLinearOptimizerInput } // MIP optimization vs. CONTINUOUS optimization - if (parameters.getRangeActionParameters().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { + if (!Objects.isNull(parameters.getRangeActionParametersExtension()) && parameters.getRangeActionParametersExtension().getPstModel().equals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS)) { Map> pstRangeActions = copyOnlyPstRangeActions(inputs.getOptimizationPerimeter().getRangeActionsPerState()); Map>> otherRa = copyWithoutPstRangeActions(inputs.getOptimizationPerimeter().getRangeActionsPerState()); this.withProblemFiller(buildIntegerPstTapFiller(pstRangeActions)); @@ -97,7 +100,7 @@ public LinearProblemBuilder withProblemFiller(ProblemFiller problemFiller) { return this; } - public LinearProblemBuilder withSolver(RangeActionsOptimizationParameters.Solver solver) { + public LinearProblemBuilder withSolver(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.Solver solver) { this.solver = solver; return this; } @@ -121,10 +124,11 @@ private ProblemFiller buildCoreProblemFiller() { return new CoreProblemFiller( inputs.getOptimizationPerimeter(), inputs.getPrePerimeterSetpoints(), - parameters.getRangeActionParameters(), + parameters.getRangeActionParameters(), + parameters.getRangeActionParametersExtension(), parameters.getObjectiveFunctionUnit(), parameters.getRaRangeShrinking(), - parameters.getRangeActionParameters().getPstModel() + Objects.isNull(parameters.getRangeActionParametersExtension()) ? null : parameters.getRangeActionParametersExtension().getPstModel() ); } @@ -193,7 +197,7 @@ private ProblemFiller buildRaUsageLimitsFiller() { inputs.getOptimizationPerimeter().getRangeActionsPerState(), inputs.getPrePerimeterSetpoints(), parameters.getRaLimitationParameters(), - parameters.getRangeActionParameters().getPstModel() == RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, + !Objects.isNull(parameters.getRangeActionParametersExtension()) && parameters.getRangeActionParametersExtension().getPstModel() == RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, inputs.getNetwork()); } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java index b879396ffa..230963404b 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/algorithms/linearproblem/OpenRaoMPSolver.java @@ -12,7 +12,7 @@ import com.google.ortools.linearsolver.MPSolverParameters; import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider; -import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters; import com.powsybl.openrao.searchtreerao.result.api.LinearProblemStatus; import java.util.Map; diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java index dfbdf8cf01..9a1e254071 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/linearoptimisation/parameters/IteratingLinearOptimizerParameters.java @@ -10,6 +10,7 @@ import com.powsybl.openrao.commons.OpenRaoException; import com.powsybl.openrao.commons.Unit; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.LinearOptimizationSolver; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.RelativeMarginsParametersExtension; @@ -23,12 +24,13 @@ public final class IteratingLinearOptimizerParameters { private final Unit objectiveFunctionUnit; private final boolean relativePositiveMargins; private final RangeActionsOptimizationParameters rangeActionParameters; + private final com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; private final MnecParametersExtension mnecParameters; private final RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private final LoopFlowParametersExtension loopFlowParameters; private final UnoptimizedCnecParameters unoptimizedCnecParameters; private final RangeActionLimitationParameters raLimitationParameters; - private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private final LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; private final boolean raRangeShrinking; @@ -36,17 +38,19 @@ public final class IteratingLinearOptimizerParameters { private IteratingLinearOptimizerParameters(Unit objectiveFunctionUnit, boolean relativePositiveMargins, RangeActionsOptimizationParameters rangeActionParameters, + com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension, MnecParametersExtension mnecParameters, RelativeMarginsParametersExtension maxMinRelativeMarginParameters, LoopFlowParametersExtension loopFlowParameters, UnoptimizedCnecParameters unoptimizedCnecParameters, RangeActionLimitationParameters raLimitationParameters, - RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, + LinearOptimizationSolver solverParameters, int maxNumberOfIterations, boolean raRangeShrinking) { this.objectiveFunctionUnit = objectiveFunctionUnit; this.relativePositiveMargins = relativePositiveMargins; this.rangeActionParameters = rangeActionParameters; + this.rangeActionParametersExtension = rangeActionParametersExtension; this.mnecParameters = mnecParameters; this.maxMinRelativeMarginParameters = maxMinRelativeMarginParameters; this.loopFlowParameters = loopFlowParameters; @@ -73,10 +77,18 @@ public boolean isRaoWithMnecLimitation() { return mnecParameters != null; } + public boolean isRaoWithSolverParameters() { + return solverParameters != null; + } + public RangeActionsOptimizationParameters getRangeActionParameters() { return rangeActionParameters; } + public com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters getRangeActionParametersExtension() { + return rangeActionParametersExtension; + } + public MnecParametersExtension getMnecParameters() { return mnecParameters; } @@ -97,7 +109,7 @@ public RangeActionLimitationParameters getRaLimitationParameters() { return raLimitationParameters; } - public RangeActionsOptimizationParameters.LinearOptimizationSolver getSolverParameters() { + public LinearOptimizationSolver getSolverParameters() { return solverParameters; } @@ -118,12 +130,14 @@ public static class LinearOptimizerParametersBuilder { private Unit objectiveFunctionUnit; private boolean relativePositiveMargins; private RangeActionsOptimizationParameters rangeActionParameters; + private com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; + private MnecParametersExtension mnecParameters; private RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private LoopFlowParametersExtension loopFlowParameters; private UnoptimizedCnecParameters unoptimizedCnecParameters; private RangeActionLimitationParameters raLimitationParameters; - private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; private boolean raRangeShrinking; @@ -142,6 +156,11 @@ public LinearOptimizerParametersBuilder withRangeActionParameters(RangeActionsOp return this; } + public LinearOptimizerParametersBuilder withRangeActionParametersExtension(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParameters) { + this.rangeActionParametersExtension = rangeActionParameters; + return this; + } + public LinearOptimizerParametersBuilder withMnecParameters(MnecParametersExtension mnecParameters) { this.mnecParameters = mnecParameters; return this; @@ -167,7 +186,7 @@ public LinearOptimizerParametersBuilder withRaLimitationParameters(RangeActionLi return this; } - public LinearOptimizerParametersBuilder withSolverParameters(RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters) { + public LinearOptimizerParametersBuilder withSolverParameters(LinearOptimizationSolver solverParameters) { this.solverParameters = solverParameters; return this; } @@ -191,6 +210,7 @@ public IteratingLinearOptimizerParameters build() { objectiveFunctionUnit, relativePositiveMargins, rangeActionParameters, + rangeActionParametersExtension, mnecParameters, maxMinRelativeMarginParameters, loopFlowParameters, diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java index e5676b5a2d..95bfba3b21 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/algorithms/Leaf.java @@ -210,6 +210,7 @@ void optimize(SearchTreeInput searchTreeInput, SearchTreeParameters parameters) .withObjectiveFunctionUnit(parameters.getObjectiveFunctionUnit()) .withRelativePositiveMargins(parameters.relativePositiveMargins()) .withRangeActionParameters(parameters.getRangeActionParameters()) + .withRangeActionParametersExtension(parameters.getRangeActionParametersExtension()) .withMnecParameters(parameters.getMnecParameters()) .withMaxMinRelativeMarginParameters(parameters.getMaxMinRelativeMarginParameters()) .withLoopFlowParameters(parameters.getLoopFlowParameters()) diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java index 388d1cecad..f7212c5ee8 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/powsybl/openrao/searchtreerao/searchtree/parameters/SearchTreeParameters.java @@ -14,6 +14,7 @@ import com.powsybl.openrao.data.cracapi.rangeaction.PstRangeAction; import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction; import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters; +import com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.LinearOptimizationSolver; import com.powsybl.openrao.raoapi.parameters.RaoParameters; import com.powsybl.openrao.raoapi.parameters.extensions.LoopFlowParametersExtension; import com.powsybl.openrao.raoapi.parameters.extensions.MnecParametersExtension; @@ -43,11 +44,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 +59,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 +72,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 +105,10 @@ public RangeActionsOptimizationParameters getRangeActionParameters() { return rangeActionParameters; } + public com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters getRangeActionParametersExtension() { + return rangeActionParametersExtension; + } + public MnecParametersExtension getMnecParameters() { return mnecParameters; } @@ -116,7 +125,7 @@ public UnoptimizedCnecParameters getUnoptimizedCnecParameters() { return unoptimizedCnecParameters; } - public RangeActionsOptimizationParameters.LinearOptimizationSolver getSolverParameters() { + public LinearOptimizationSolver getSolverParameters() { return solverParameters; } @@ -249,24 +258,27 @@ public static class SearchTreeParametersBuilder { private NetworkActionParameters networkActionParameters; private Map raLimitationParameters; private RangeActionsOptimizationParameters rangeActionParameters; + private com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters rangeActionParametersExtension; private MnecParametersExtension mnecParameters; private RelativeMarginsParametersExtension maxMinRelativeMarginParameters; private LoopFlowParametersExtension loopFlowParameters; private UnoptimizedCnecParameters unoptimizedCnecParameters; - private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; + private LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; public SearchTreeParametersBuilder withConstantParametersOverAllRao(RaoParameters raoParameters, Crac crac) { this.objectiveFunctionUnit = RaoUtil.getObjectiveFunctionUnit(raoParameters); this.relativePositiveMargins = raoParameters.getObjectiveFunctionParameters().getType().relativePositiveMargins(); - this.networkActionParameters = NetworkActionParameters.buildFromRaoParameters(raoParameters.getTopoOptimizationParameters(), crac); + this.networkActionParameters = NetworkActionParameters.buildFromRaoParameters(raoParameters, crac); this.raLimitationParameters = new HashMap<>(crac.getRaUsageLimitsPerInstant()); this.rangeActionParameters = RangeActionsOptimizationParameters.buildFromRaoParameters(raoParameters); this.mnecParameters = raoParameters.getExtension(MnecParametersExtension.class); this.maxMinRelativeMarginParameters = raoParameters.getExtension(RelativeMarginsParametersExtension.class); this.loopFlowParameters = raoParameters.getExtension(LoopFlowParametersExtension.class); - this.solverParameters = raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver(); - this.maxNumberOfIterations = raoParameters.getRangeActionsOptimizationParameters().getMaxMipIterations(); + if (raoParameters.hasExtension(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.class)) { + this.solverParameters = raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.class).getLinearOptimizationSolver(); + this.maxNumberOfIterations = raoParameters.getExtension(com.powsybl.openrao.raoapi.parameters.extensions.RangeActionsOptimizationParameters.class).getMaxMipIterations(); + } return this; } @@ -320,7 +332,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 +349,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/commons/parameters/NetworkActionParametersTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParametersTest.java index 07207682a5..ead1fd2c79 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParametersTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/powsybl/openrao/searchtreerao/commons/parameters/NetworkActionParametersTest.java @@ -107,7 +107,7 @@ void testNetworkActionCombinations() { List.of("topological-action-1"), // should be filtered (one action only) new ArrayList<>())); // should be filtered - List naCombinations = NetworkActionParameters.computePredefinedCombinations(crac, parameters.getTopoOptimizationParameters()); + List naCombinations = NetworkActionParameters.computePredefinedCombinations(crac, parameters); assertEquals(5, parameters.getTopoOptimizationParameters().getPredefinedCombinations().size()); assertEquals(2, naCombinations.size());