diff --git a/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/AbstractRemedialAction.java b/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/AbstractRemedialAction.java index 87e262ea5e..d79c765f7f 100644 --- a/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/AbstractRemedialAction.java +++ b/data/crac/crac-impl/src/main/java/com/farao_community/farao/data/crac_impl/AbstractRemedialAction.java @@ -72,20 +72,20 @@ public UsageMethod getUsageMethod(State state) { } } - @Override /** * Evaluates if the remedial action is available depending on its UsageMethod. * If TO_BE_EVALUATED condition has not been evaluated, default behavior is false */ + @Override public boolean isRemedialActionAvailable(State state) { return isRemedialActionAvailable(state, false); } - @Override /** * Evaluates if the remedial action is available depending on its UsageMethod. * When UsageMethod is TO_BE_EVALUATED, condition has to have been evaluated previously */ + @Override public boolean isRemedialActionAvailable(State state, boolean evaluatedCondition) { switch (getUsageMethod(state)) { case AVAILABLE: diff --git a/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/RaoParametersConstants.java b/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/RaoParametersConstants.java index 4c20187eaa..8d02f8bdb1 100644 --- a/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/RaoParametersConstants.java +++ b/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/RaoParametersConstants.java @@ -43,6 +43,7 @@ private RaoParametersConstants() { 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"; + public static final String RA_RANGE_SHRINKING = "ra-range-shrinking"; // topological actions optimization parameters public static final String TOPOLOGICAL_ACTIONS_OPTIMIZATION = "topological-actions-optimization"; diff --git a/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/json/JsonRangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/json/JsonRangeActionsOptimizationParameters.java index 8cdbfe60a6..728f5ea158 100644 --- a/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/json/JsonRangeActionsOptimizationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/json/JsonRangeActionsOptimizationParameters.java @@ -34,6 +34,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr 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()); @@ -80,6 +81,9 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); deserializeLinearOptimizationSolver(jsonParser, raoParameters); break; + case RA_RANGE_SHRINKING: + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(stringToRaRangeShrinking(jsonParser.nextTextValue())); + break; default: throw new FaraoException(String.format("Cannot deserialize range action optimization parameters: unexpected field in %s (%s)", RANGE_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName())); } @@ -114,6 +118,14 @@ private static RangeActionsOptimizationParameters.PstModel stringToPstModel(Stri } } + private static RangeActionsOptimizationParameters.RaRangeShrinking stringToRaRangeShrinking(String string) { + try { + return RangeActionsOptimizationParameters.RaRangeShrinking.valueOf(string); + } catch (IllegalArgumentException e) { + throw new FaraoException(String.format("Unknown Pst variation range shrinking: %s", string)); + } + } + private static RangeActionsOptimizationParameters.Solver stringToSolver(String string) { try { return RangeActionsOptimizationParameters.Solver.valueOf(string); diff --git a/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/parameters/RangeActionsOptimizationParameters.java b/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/parameters/RangeActionsOptimizationParameters.java index f6da21dbf5..9b686c1e65 100644 --- a/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/parameters/RangeActionsOptimizationParameters.java +++ b/ra-optimisation/rao-api/src/main/java/com/farao_community/farao/rao_api/parameters/RangeActionsOptimizationParameters.java @@ -30,6 +30,7 @@ public class RangeActionsOptimizationParameters { private static final double DEFAULT_HVDC_SENSITIVITY_THRESHOLD = 0.0; private static final double DEFAULT_INJECTION_RA_PENALTY_COST = 0.001; private static final double DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD = 0.0; + private static final RaRangeShrinking DEFAULT_RA_RANGE_SHRINKING = RaRangeShrinking.DISABLED; // Attributes private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST; @@ -40,13 +41,19 @@ public class RangeActionsOptimizationParameters { 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; - // Enum 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; @@ -171,6 +178,14 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat 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(); @@ -184,6 +199,7 @@ public static RangeActionsOptimizationParameters load(PlatformConfig platformCon 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.setLinearOptimizationSolver(LinearOptimizationSolver.load(platformConfig)); return parameters; diff --git a/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/json/JsonRaoParametersTest.java b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/json/JsonRaoParametersTest.java index 99c9b03c69..b32f615bb6 100644 --- a/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/json/JsonRaoParametersTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/json/JsonRaoParametersTest.java @@ -68,6 +68,7 @@ void roundTrip() throws IOException { 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); // TopologicalActions optimization parameters parameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(10); parameters.getTopoOptimizationParameters().setRelativeMinImpactThreshold(0.1); diff --git a/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersConfigTest.java b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersConfigTest.java index b2983ff4e6..6de9634e23 100644 --- a/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersConfigTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersConfigTest.java @@ -82,6 +82,7 @@ void checkRangeActionsOptimizationConfig() { 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); diff --git a/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersYamlConfigTest.java b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersYamlConfigTest.java index 874742b613..3e9219a486 100644 --- a/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersYamlConfigTest.java +++ b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersYamlConfigTest.java @@ -52,6 +52,7 @@ void testConfigWithExtensions() throws IOException { 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); @@ -142,6 +143,7 @@ void testConfigWithoutExtensions() throws IOException { 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); @@ -220,6 +222,7 @@ void testConfigWithPartialExtensions() throws IOException { 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); diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json index edaa135596..1ec1863264 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, "injection-ra-sensitivity-threshold" : 0.7, + "ra-range-shrinking" : "ENABLED", "linear-optimization-solver" : { "solver" : "SCIP", "relative-mip-gap" : 1.0E-5, 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 40ab4296cc..06ee719fef 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, "injection-ra-sensitivity-threshold" : 0.0, + "ra-range-shrinking" : "DISABLED", "linear-optimization-solver" : { "solver" : "CBC", "relative-mip-gap" : 1.0E-4, diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withExtensions.json index 22fd8c0450..a94b2959bf 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withExtensions.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withExtensions.json @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.2, "injection-ra-penalty-cost" : 0.003, "injection-ra-sensitivity-threshold" : 0.3, + "ra-range-shrinking" : "DISABLED", "linear-optimization-solver" : { "solver" : "XPRESS", "relative-mip-gap" : 0.004, diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json index ffbf528926..ab458a0468 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, "injection-ra-sensitivity-threshold" : 0.0, + "ra-range-shrinking" : "DISABLED", "linear-optimization-solver" : { "solver" : "CBC", "relative-mip-gap" : 1.0E-4, diff --git a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withPartialExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withPartialExtensions.json index ab884b5d60..b11a84b0bb 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withPartialExtensions.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withPartialExtensions.json @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.2, "injection-ra-penalty-cost" : 0.003, "injection-ra-sensitivity-threshold" : 0.3, + "ra-range-shrinking" : "ENABLED", "linear-optimization-solver" : { "solver" : "CBC", "relative-mip-gap" : 0.004, 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 b6c3df2ed1..9c1c7a200c 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 @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.2, "injection-ra-penalty-cost" : 0.003, "injection-ra-sensitivity-threshold" : 0.3, + "ra-range-shrinking" : "DISABLED", "linear-optimization-solver" : { "solver" : "XPRESS", "relative-mip-gap" : 0.004, 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 f60a3dd40f..3cd2bfc1c8 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -16,6 +16,7 @@ "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, "injection-ra-sensitivity-threshold" : 0.0, + "ra-range-shrinking" : "DISABLED", "linear-optimization-solver" : { "solver" : "CBC", "relative-mip-gap" : 1.0E-4, diff --git a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml index 3404c6240c..85885eacf3 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml @@ -8,6 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS + ra-range-shrinking: ENABLED hvdc-penalty-cost: 0.002 hvdc-sensitivity-threshold: 0.2 injection-ra-penalty-cost: 0.003 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 2dbc805a97..fd401ce323 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml @@ -10,6 +10,7 @@ rao-range-actions-optimization: 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 diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParameters.java index f0f2d208b3..1de79d7b98 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParameters.java @@ -8,6 +8,7 @@ import com.farao_community.farao.commons.FaraoException; import com.farao_community.farao.rao_api.parameters.ObjectiveFunctionParameters; +import com.farao_community.farao.rao_api.parameters.RangeActionsOptimizationParameters; import com.farao_community.farao.rao_api.parameters.RaoParameters; /** @@ -29,15 +30,18 @@ public enum StopCriterion { private final double targetObjectiveValue; private final int maximumSearchDepth; private final int leavesInParallel; + private final boolean raRangeShrinking; public TreeParameters(StopCriterion stopCriterion, - double targetObjectiveValue, - int maximumSearchDepth, - int leavesInParallel) { + double targetObjectiveValue, + int maximumSearchDepth, + int leavesInParallel, + boolean raRangeShrinking) { this.stopCriterion = stopCriterion; this.targetObjectiveValue = targetObjectiveValue; this.maximumSearchDepth = maximumSearchDepth; this.leavesInParallel = leavesInParallel; + this.raRangeShrinking = raRangeShrinking; } public StopCriterion getStopCriterion() { @@ -56,18 +60,27 @@ public int getLeavesInParallel() { return leavesInParallel; } + public boolean getRaRangeShrinking() { + return raRangeShrinking; + } + public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) { + RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking(); + boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || + raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); switch (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()) { case MIN_OBJECTIVE: return new TreeParameters(StopCriterion.MIN_OBJECTIVE, - 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); + 0.0, // value does not matter + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + shouldShrinkRaRange); case SECURE: return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, - 0.0, // secure - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); + 0.0, // secure + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + shouldShrinkRaRange); default: throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); } @@ -96,24 +109,31 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, default: throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion()); } + RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking(); + boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || + raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getCurativeLeavesInParallel()); + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), + shouldShrinkRaRange); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { + boolean raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking().equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE) - && !parameters.getObjectiveFunctionParameters().getCurativeStopCriterion().equals(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE)) { + && !parameters.getObjectiveFunctionParameters().getCurativeStopCriterion().equals(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE)) { return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, - 0.0, // secure - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); + 0.0, // secure + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + raRangeShrinking); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, - 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); + 0.0, // value does not matter + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + raRangeShrinking); } } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizer.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizer.java index fbdf9a584d..f90c68d5da 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizer.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizer.java @@ -21,6 +21,7 @@ import com.farao_community.farao.search_tree_rao.result.impl.LinearProblemResult; import com.farao_community.farao.sensitivity_analysis.AppliedRemedialActions; import com.powsybl.iidm.network.Network; +import org.apache.commons.lang3.tuple.Pair; import java.util.Locale; @@ -44,6 +45,8 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in 0, input.getObjectiveFunction()); + IteratingLinearOptimizationResultImpl previousResult = bestResult; + SensitivityComputer sensitivityComputer = null; LinearProblem linearProblem = LinearProblem.create() @@ -53,6 +56,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in for (int iteration = 1; iteration <= parameters.getMaxNumberOfIterations(); iteration++) { LinearProblemStatus solveStatus = solveLinearProblem(linearProblem, iteration); + bestResult.setNbOfIteration(iteration); if (solveStatus == LinearProblemStatus.FEASIBLE) { TECHNICAL_LOGS.warn("The solver was interrupted. A feasible solution has been produced."); } else if (solveStatus != LinearProblemStatus.OPTIMAL) { @@ -71,7 +75,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in currentRangeActionActivationResult = resolveIfApproximatedPstTaps(bestResult, linearProblem, iteration, currentRangeActionActivationResult, input, parameters); - if (!hasRemedialActionsChanged(currentRangeActionActivationResult, bestResult, input.getOptimizationPerimeter())) { + if (!hasRemedialActionsChanged(currentRangeActionActivationResult, previousResult, input.getOptimizationPerimeter())) { // If the solution has not changed, no need to run a new sensitivity computation and iteration can stop TECHNICAL_LOGS.info("Iteration {}: same results as previous iterations, optimal solution found", iteration); return bestResult; @@ -90,16 +94,14 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in iteration, input.getObjectiveFunction() ); + previousResult = currentResult; - if (currentResult.getCost() >= bestResult.getCost()) { - logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); + Pair mipShouldStop = updateBestResultAndCheckStopCondition(parameters.getRaRangeShrinking(), linearProblem, input, iteration, currentResult, bestResult); + if (mipShouldStop.getRight()) { return bestResult; + } else { + bestResult = mipShouldStop.getLeft(); } - - logBetterResult(iteration, currentResult); - bestResult = currentResult; - linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); return bestResult; @@ -221,6 +223,20 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu ); } + private static Pair updateBestResultAndCheckStopCondition(boolean raRangeShrinking, LinearProblem linearProblem, IteratingLinearOptimizerInput input, int iteration, IteratingLinearOptimizationResultImpl currentResult, IteratingLinearOptimizationResultImpl bestResult) { + if (currentResult.getCost() < bestResult.getCost()) { + logBetterResult(iteration, currentResult); + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); + return Pair.of(currentResult, false); + } + logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); + if (raRangeShrinking) { + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); + } + return Pair.of(bestResult, !raRangeShrinking); + } + private static void logBetterResult(int iteration, ObjectiveFunctionResult currentObjectiveFunctionResult) { TECHNICAL_LOGS.info( "Iteration {}: better solution found with a cost of {} (functional: {})", @@ -231,7 +247,7 @@ private static void logBetterResult(int iteration, ObjectiveFunctionResult curre private static void logWorseResult(int iteration, ObjectiveFunctionResult bestResult, ObjectiveFunctionResult currentResult) { TECHNICAL_LOGS.info( - "Iteration {}: linear optimization found a worse result than previous iteration, with a cost increasing from {} to {} (functional: from {} to {})", + "Iteration {}: linear optimization found a worse result than best iteration, with a cost increasing from {} to {} (functional: from {} to {})", iteration, formatDouble(bestResult.getCost()), formatDouble(currentResult.getCost()), diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFiller.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFiller.java index aa054b5c11..6733c3f8c5 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFiller.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFiller.java @@ -49,6 +49,8 @@ public class CoreProblemFiller implements ProblemFiller { private final RangeActionActivationResult raActivationFromParentLeaf; private final RangeActionsOptimizationParameters rangeActionParameters; private final Unit unit; + private int iteration = 0; + private static final double RANGE_SHRINK_RATE = 0.667; public CoreProblemFiller(OptimizationPerimeter optimizationContext, RangeActionSetpointResult prePerimeterRangeActionSetpoints, @@ -83,6 +85,7 @@ public void fill(LinearProblem linearProblem, FlowResult flowResult, Sensitivity public void updateBetweenSensiIteration(LinearProblem linearProblem, FlowResult flowResult, SensitivityResult sensitivityResult, RangeActionActivationResult rangeActionActivationResult) { // update reference flow and sensitivities of flow constraints updateFlowConstraints(linearProblem, flowResult, sensitivityResult, rangeActionActivationResult); + updateRangeActionConstraints(linearProblem, rangeActionActivationResult); } @Override @@ -240,6 +243,34 @@ private void buildRangeActionConstraints(LinearProblem linearProblem) { ); } + private void updateRangeActionConstraints(LinearProblem linearProblem, RangeActionActivationResult rangeActionActivationResult) { + iteration++; + optimizationContext.getRangeActionsPerState().forEach((state, rangeActionSet) -> rangeActionSet.forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, state, rangeActionActivationResult, iteration) + )); + } + + private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeAction rangeAction, State state, RangeActionActivationResult rangeActionActivationResult, int iteration) { + double previousSetPointValue = rangeActionActivationResult.getOptimizedSetpoint(rangeAction, state); + List minAndMaxAbsoluteAndRelativeSetpoints = getMinAndMaxAbsoluteAndRelativeSetpoints(rangeAction); + double minAbsoluteSetpoint = Math.max(minAndMaxAbsoluteAndRelativeSetpoints.get(0), -LinearProblem.infinity()); + double maxAbsoluteSetpoint = Math.min(minAndMaxAbsoluteAndRelativeSetpoints.get(1), LinearProblem.infinity()); + double constrainedSetPointRange = (maxAbsoluteSetpoint - minAbsoluteSetpoint) * Math.pow(RANGE_SHRINK_RATE, iteration); + FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, LinearProblem.RaRangeShrinking.TRUE); + double lb = previousSetPointValue - constrainedSetPointRange; + double ub = previousSetPointValue + constrainedSetPointRange; + if (iterativeShrink != null) { + iterativeShrink.setLb(lb); + iterativeShrink.setUb(ub); + } else { + FaraoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(rangeAction, state); + if (setPointVariable == null) { + throw new FaraoException(format("Range action variable for %s has not been defined yet.", rangeAction.getId())); + } + iterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(lb, ub, rangeAction, state, LinearProblem.RaRangeShrinking.TRUE); + iterativeShrink.setCoefficient(setPointVariable, 1); + } + } + /** * Build two range action constraints for each RangeAction r. * These constraints link the set point variable of the RangeAction with its absolute @@ -302,7 +333,7 @@ private void buildConstraintsForRangeActionAndState(LinearProblem linearProblem, maxAbsoluteSetpoint = Math.min(maxAbsoluteSetpoint, LinearProblem.infinity()); minRelativeSetpoint = Math.max(minRelativeSetpoint, -LinearProblem.infinity()); maxRelativeSetpoint = Math.min(maxRelativeSetpoint, LinearProblem.infinity()); - FaraoMPConstraint relSetpointConstraint = linearProblem.addRangeActionRelativeSetpointConstraint(minRelativeSetpoint, maxRelativeSetpoint, rangeAction, state); + FaraoMPConstraint 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/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblem.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblem.java index e032cd3800..0b532ead3f 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblem.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblem.java @@ -58,6 +58,22 @@ public enum BoundExtension { UPPER_BOUND } + public enum RaRangeShrinking { + TRUE("iterative-shrink"), + FALSE(""); + + private final String name; + + RaRangeShrinking(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } + public static LinearProblemBuilder create() { return new LinearProblemBuilder(); } @@ -128,8 +144,12 @@ public FaraoMPVariable getRangeActionSetpointVariable(RangeAction rangeAction return solver.getVariable(rangeActionSetpointVariableId(rangeAction, state)); } - public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state) { - return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state)); + public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state, RaRangeShrinking raRangeShrinking) { + return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, raRangeShrinking)); + } + + public FaraoMPConstraint getRangeActionRelativeSetpointConstraint(RangeAction rangeAction, State state, RaRangeShrinking raRangeShrinking) { + return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, raRangeShrinking)); } public FaraoMPVariable addRangeActionVariationBinary(RangeAction rangeAction, State state) { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblemIdGenerator.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblemIdGenerator.java index 2f3a602079..12c1e26598 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblemIdGenerator.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/linear_problem/LinearProblemIdGenerator.java @@ -60,8 +60,8 @@ public static String rangeActionSetpointVariableId(RangeAction rangeAction, S return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + SET_POINT + SEPARATOR + VARIABLE_SUFFIX; } - public static String rangeActionRelativeSetpointConstraintId(RangeAction rangeAction, State state) { - return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + CONSTRAINT_SUFFIX; + public static String rangeActionRelativeSetpointConstraintId(RangeAction rangeAction, State state, LinearProblem.RaRangeShrinking raRangeShrinking) { + return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + raRangeShrinking.toString() + CONSTRAINT_SUFFIX; } public static String pstTapVariableVariationId(RangeAction rangeAction, State state, LinearProblem.VariationDirectionExtension upwardOrDownward) { diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/parameters/IteratingLinearOptimizerParameters.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/parameters/IteratingLinearOptimizerParameters.java index 0c66726409..ae23de9297 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/parameters/IteratingLinearOptimizerParameters.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/linear_optimisation/parameters/IteratingLinearOptimizerParameters.java @@ -32,6 +32,7 @@ public final class IteratingLinearOptimizerParameters { private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; + private final boolean raRangeShrinking; private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction, RangeActionsOptimizationParameters rangeActionParameters, @@ -41,7 +42,8 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective UnoptimizedCnecParameters unoptimizedCnecParameters, RangeActionLimitationParameters raLimitationParameters, RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, - int maxNumberOfIterations) { + int maxNumberOfIterations, + boolean raRangeShrinking) { this.objectiveFunction = objectiveFunction; this.rangeActionParameters = rangeActionParameters; this.mnecParameters = mnecParameters; @@ -51,6 +53,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective this.raLimitationParameters = raLimitationParameters; this.solverParameters = solverParameters; this.maxNumberOfIterations = maxNumberOfIterations; + this.raRangeShrinking = raRangeShrinking; } public ObjectiveFunctionParameters.ObjectiveFunctionType getObjectiveFunction() { @@ -110,6 +113,10 @@ public int getMaxNumberOfIterations() { return maxNumberOfIterations; } + public boolean getRaRangeShrinking() { + return raRangeShrinking; + } + public static LinearOptimizerParametersBuilder create() { return new LinearOptimizerParametersBuilder(); } @@ -125,6 +132,7 @@ public static class LinearOptimizerParametersBuilder { private RangeActionLimitationParameters raLimitationParameters; private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; + private boolean raRangeShrinking; public LinearOptimizerParametersBuilder withObjectiveFunction(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { this.objectiveFunction = objectiveFunction; @@ -171,6 +179,11 @@ public LinearOptimizerParametersBuilder withMaxNumberOfIterations(int maxNumberO return this; } + public LinearOptimizerParametersBuilder withRaRangeShrinking(boolean raRangeShrinking) { + this.raRangeShrinking = raRangeShrinking; + return this; + } + public IteratingLinearOptimizerParameters build() { if (objectiveFunction.relativePositiveMargins() && maxMinRelativeMarginParameters == null) { throw new FaraoException("An objective function with relative margins requires parameters on relative margins."); @@ -185,7 +198,8 @@ public IteratingLinearOptimizerParameters build() { unoptimizedCnecParameters, raLimitationParameters, solverParameters, - maxNumberOfIterations); + maxNumberOfIterations, + raRangeShrinking); } } } diff --git a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/Leaf.java b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/Leaf.java index 84b1cdae21..127e778b61 100644 --- a/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/Leaf.java +++ b/ra-optimisation/search-tree-rao/src/main/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/Leaf.java @@ -215,6 +215,7 @@ void optimize(SearchTreeInput searchTreeInput, SearchTreeParameters parameters) .withRaLimitationParameters(getRaLimitationParameters(searchTreeInput.getOptimizationPerimeter(), parameters)) .withSolverParameters(parameters.getSolverParameters()) .withMaxNumberOfIterations(parameters.getMaxNumberOfIterations()) + .withRaRangeShrinking(parameters.getTreeParameters().getRaRangeShrinking()) .build(); postOptimResult = IteratingLinearOptimizer.optimize(linearOptimizerInput, linearOptimizerParameters); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParametersTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParametersTest.java index 2134ecf1d5..efb472ac78 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParametersTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/commons/parameters/TreeParametersTest.java @@ -7,6 +7,7 @@ package com.farao_community.farao.search_tree_rao.commons.parameters; import com.farao_community.farao.rao_api.parameters.ObjectiveFunctionParameters; +import com.farao_community.farao.rao_api.parameters.RangeActionsOptimizationParameters; import com.farao_community.farao.rao_api.parameters.RaoParameters; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,6 +28,7 @@ public void setUp() { raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(6); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); } @Test @@ -38,41 +40,51 @@ void testPreventive() { assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertFalse(treeParameters.getRaRangeShrinking()); // test with secure, and different values of the parameters raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(15); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); assertEquals(0, treeParameters.getTargetObjectiveValue(), DOUBLE_TOLERANCE); assertEquals(8, treeParameters.getLeavesInParallel()); assertEquals(15, treeParameters.getMaximumSearchDepth()); + assertTrue(treeParameters.getRaRangeShrinking()); + + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); + treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); + assertTrue(treeParameters.getRaRangeShrinking()); } @Test void testCurativeMinObjective() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(2, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertFalse(treeParameters.getRaRangeShrinking()); } @Test void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); + raoParameters.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.getStopCriterion()); assertEquals(0., treeParameters.getTargetObjectiveValue(), DOUBLE_TOLERANCE); assertEquals(16, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - + assertTrue(treeParameters.getRaRangeShrinking()); } @Test @@ -80,12 +92,14 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); assertEquals(65, treeParameters.getTargetObjectiveValue(), DOUBLE_TOLERANCE); assertEquals(2, treeParameters.getLeavesInParallel()); assertEquals(0, treeParameters.getMaximumSearchDepth()); + assertTrue(treeParameters.getRaRangeShrinking()); } @Test @@ -120,30 +134,36 @@ void testSecondPreventive() { // test with min objective raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); TreeParameters treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertFalse(treeParameters.getRaRangeShrinking()); // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); assertEquals(0, treeParameters.getTargetObjectiveValue(), DOUBLE_TOLERANCE); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertFalse(treeParameters.getRaRangeShrinking()); // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertTrue(treeParameters.getRaRangeShrinking()); // still another combination raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizerTest.java index d8671c2605..523d1c10d9 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/IteratingLinearOptimizerTest.java @@ -38,10 +38,7 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -102,6 +99,7 @@ public void setUp() { when(rangeActionParameters.getPstModel()).thenReturn(RangeActionsOptimizationParameters.PstModel.CONTINUOUS); when(parameters.getRangeActionParameters()).thenReturn(rangeActionParameters); when(parameters.getObjectiveFunction()).thenReturn(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN_IN_MEGAWATT); + when(parameters.getRaRangeShrinking()).thenReturn(false); linearProblem = Mockito.mock(LinearProblem.class); network = Mockito.mock(Network.class); @@ -198,7 +196,7 @@ void firstLinearProblemDoesNotChangeSetPoint() { LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); assertEquals(LinearProblemStatus.OPTIMAL, result.getStatus()); - assertEquals(0, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(1, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); assertEquals(100, result.getFunctionalCost(), DOUBLE_TOLERANCE); assertEquals(0, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); } @@ -212,25 +210,55 @@ void secondLinearProblemDoesNotChangeSetPoint() { LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); assertEquals(LinearProblemStatus.OPTIMAL, result.getStatus()); - assertEquals(1, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(2, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); assertEquals(50, result.getFunctionalCost(), DOUBLE_TOLERANCE); assertEquals(1, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); } @Test - void firstLinearProblemChangesSetPointButWorsenFunctionalCost() { - mockLinearProblem(List.of(LinearProblemStatus.OPTIMAL), List.of(1.)); - mockFunctionalCost(100., 140.); + void linearProblemDegradesTheSolutionButKeepsBestIteration() { + when(parameters.getRaRangeShrinking()).thenReturn(true); + mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); + mockFunctionalCost(100., 150., 140., 130., 120., 110.); + prepareLinearProblemBuilder(); + + LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); + + assertEquals(LinearProblemStatus.MAX_ITERATION_REACHED, result.getStatus()); + assertEquals(5, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(100, result.getFunctionalCost(), DOUBLE_TOLERANCE); + assertEquals(0, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); + } + + @Test + void linearProblemDegradesTheSolution() { + mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); + mockFunctionalCost(100., 150., 140., 130., 120., 110.); prepareLinearProblemBuilder(); LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); assertEquals(LinearProblemStatus.OPTIMAL, result.getStatus()); - assertEquals(0, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(1, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); assertEquals(100, result.getFunctionalCost(), DOUBLE_TOLERANCE); assertEquals(0, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); } + @Test + void linearProblemFluctuatesButKeepsBestIteration() { + when(parameters.getRaRangeShrinking()).thenReturn(true); + mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); + mockFunctionalCost(100., 120., 105., 90., 100., 95.); + prepareLinearProblemBuilder(); + + LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); + + assertEquals(LinearProblemStatus.MAX_ITERATION_REACHED, result.getStatus()); + assertEquals(5, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(90, result.getFunctionalCost(), DOUBLE_TOLERANCE); + assertEquals(3, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); + } + @Test void reachMaxIterations() { mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); @@ -254,7 +282,7 @@ void optimizeWithInfeasibility() { LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); assertEquals(LinearProblemStatus.FEASIBLE, result.getStatus()); - assertEquals(1, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(2, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); assertEquals(50, result.getFunctionalCost(), DOUBLE_TOLERANCE); assertEquals(1, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); } @@ -272,17 +300,18 @@ void optimizeWithSensitivityComputationFailure() { LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); assertEquals(LinearProblemStatus.SENSITIVITY_COMPUTATION_FAILED, result.getStatus()); - assertEquals(0, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(1, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); assertEquals(100, result.getFunctionalCost(), DOUBLE_TOLERANCE); assertEquals(0, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); } @Test void testUnapplyRangeAction() { + when(parameters.getRaRangeShrinking()).thenReturn(true); network = NetworkImportsUtil.import12NodesNetwork(); when(input.getNetwork()).thenReturn(network); - mockLinearProblem(List.of(LinearProblemStatus.OPTIMAL, LinearProblemStatus.OPTIMAL), List.of(1., 2.)); - mockFunctionalCost(100., 90., 100.); + mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); + mockFunctionalCost(100., 120., 105., 90., 100., 95.); Crac crac = CracFactory.findDefault().create("test-crac"); rangeAction = crac.newPstRangeAction().withId("test-pst").withNetworkElement("BBE2AA1 BBE3AA1 1") .withInitialTap(0) @@ -295,16 +324,9 @@ void testUnapplyRangeAction() { when(input.getPrePerimeterSetpoints()).thenReturn(rangeActionSetpointResult); rangeActionActivationResult = new RangeActionActivationResultImpl(rangeActionSetpointResult); when(input.getRaActivationFromParentLeaf()).thenReturn(rangeActionActivationResult); - MPVariableMock absVariationMpVarMock = Mockito.mock(MPVariableMock.class); - when(absVariationMpVarMock.solutionValue()).thenReturn(1.); - when(linearProblem.getAbsoluteRangeActionVariationVariable(rangeAction, optimizedState)).thenReturn(absVariationMpVarMock); - MPVariableMock setpointMpVarMock = Mockito.mock(MPVariableMock.class); - when(setpointMpVarMock.solutionValue()).thenReturn(1.); - when(linearProblem.getRangeActionSetpointVariable(rangeAction, optimizedState)).thenReturn(setpointMpVarMock); - network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1").getPhaseTapChanger().setTapPosition(5); prepareLinearProblemBuilder(); - LinearOptimizationResult result = IteratingLinearOptimizer.optimize(input, parameters); - assertEquals(1, network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1").getPhaseTapChanger().getTapPosition()); + IteratingLinearOptimizer.optimize(input, parameters); + assertEquals(3, network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1").getPhaseTapChanger().getTapPosition()); } } diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFillerTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFillerTest.java index accae051a8..4cc575f0ed 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFillerTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/linear_optimisation/algorithms/fillers/CoreProblemFillerTest.java @@ -11,7 +11,6 @@ import com.farao_community.farao.data.crac_api.State; import com.farao_community.farao.data.crac_api.cnec.FlowCnec; import com.farao_community.farao.data.crac_api.cnec.Side; -import com.farao_community.farao.data.crac_api.range_action.PstRangeAction; import com.farao_community.farao.data.crac_api.range_action.RangeAction; import com.farao_community.farao.rao_api.parameters.RangeActionsOptimizationParameters; import com.farao_community.farao.rao_api.parameters.RaoParameters; @@ -400,7 +399,7 @@ void updateTestOnPreventive() { updateLinearProblem(); // some additional data - final double currentAlpha = ((PstRangeAction) pstRangeAction).convertTapToAngle(network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getTapPosition()); + final double currentAlpha = pstRangeAction.convertTapToAngle(network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getTapPosition()); FaraoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, state); @@ -427,14 +426,18 @@ void updateTestOnPreventive() { assertNull(flowConstraint2); // check the number of variables and constraints - // total number of variables 4 : + // total number of variables 3 : // - 1 per CNEC (flow) // - 2 per range action (set-point and variation) // total number of constraints 4 : // - 1 per CNEC (flow constraint) - // - 2 per range action (absolute variation constraints) + // - 3 per range action (absolute variation constraints and iterative relative variation constraint: created before 2nd iteration) assertEquals(3, linearProblem.numVariables()); - assertEquals(3, linearProblem.numConstraints()); + assertEquals(4, linearProblem.numConstraints()); + + // assert that no other constraint is created after 2nd iteration + updateLinearProblem(); + assertEquals(4, linearProblem.numConstraints()); } @Test @@ -445,7 +448,7 @@ void updateTestOnCurative() { updateLinearProblem(); // some additional data - final double currentAlpha = ((PstRangeAction) pstRangeAction).convertTapToAngle(network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getTapPosition()); + final double currentAlpha = pstRangeAction.convertTapToAngle(network.getTwoWindingsTransformer(RANGE_ACTION_ELEMENT_ID).getPhaseTapChanger().getTapPosition()); FaraoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(pstRangeAction, state); @@ -472,14 +475,18 @@ void updateTestOnCurative() { assertEquals(-SENSI_CNEC2_IT2, flowConstraint2.getCoefficient(setPointVariable), DOUBLE_TOLERANCE); // check the number of variables and constraints - // total number of variables 4 : + // total number of variables 3 : // - 1 per CNEC (flow) // - 2 per range action (set-point and variation) // total number of constraints 4 : // - 1 per CNEC (flow constraint) - // - 2 per range action (absolute variation constraints) + // - 3 per range action (absolute variation constraints and iterative relative variation constraint: created before 2nd iteration) assertEquals(3, linearProblem.numVariables()); - assertEquals(3, linearProblem.numConstraints()); + assertEquals(4, linearProblem.numConstraints()); + + // assert that no other constraint is created after 2nd iteration + updateLinearProblem(); + assertEquals(4, linearProblem.numConstraints()); } @Test diff --git a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/LeafTest.java b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/LeafTest.java index da84f0f61d..cc5de41e5b 100644 --- a/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/LeafTest.java +++ b/ra-optimisation/search-tree-rao/src/test/java/com/farao_community/farao/search_tree_rao/search_tree/algorithms/LeafTest.java @@ -25,6 +25,7 @@ import com.farao_community.farao.rao_api.parameters.RaoParameters; import com.farao_community.farao.search_tree_rao.commons.SensitivityComputer; import com.farao_community.farao.search_tree_rao.commons.optimization_perimeters.OptimizationPerimeter; +import com.farao_community.farao.search_tree_rao.commons.parameters.TreeParameters; import com.farao_community.farao.search_tree_rao.linear_optimisation.algorithms.IteratingLinearOptimizer; import com.farao_community.farao.search_tree_rao.commons.objective_function_evaluator.ObjectiveFunction; import com.farao_community.farao.search_tree_rao.commons.NetworkActionCombination; @@ -307,6 +308,7 @@ void optimize() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); rootLeaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(Leaf.Status.OPTIMIZED, rootLeaf.getStatus()); } @@ -352,6 +354,7 @@ void getFlowsAndPtdfsOnFlowCnecAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -420,6 +423,7 @@ void getFunctionalCostAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedFunctionalCost = 3.; @@ -454,6 +458,7 @@ void getVirtualCostAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedVirtualCost = 3.; @@ -497,6 +502,7 @@ void getCostlyAndMostLimitingElementsAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); @@ -573,6 +579,7 @@ void getRangeActionsAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -656,6 +663,7 @@ void getSensitivityStatusAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); leaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(sensitivityStatus, leaf.getSensitivityStatus()); @@ -691,6 +699,7 @@ void getSensitivityValueAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -737,6 +746,7 @@ void getObjectiveFunctionAfterOptimization() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -755,6 +765,7 @@ void testFinalize() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(Mockito.mock(IteratingLinearOptimizationResultImpl.class)); rootLeaf.optimize(searchTreeInput, searchTreeParameters); rootLeaf.finalizeOptimization(); @@ -782,6 +793,7 @@ void testToStringOnRootLeaf() { when(searchTreeInput.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunction.class)); SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); + when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); when(linearOptimizationResult.getCost()).thenReturn(-100.5); diff --git a/util/src/main/java/com/farao_community/farao/util/MultipleNetworkPool.java b/util/src/main/java/com/farao_community/farao/util/MultipleNetworkPool.java index 190dfadeab..5b5e947c8d 100644 --- a/util/src/main/java/com/farao_community/farao/util/MultipleNetworkPool.java +++ b/util/src/main/java/com/farao_community/farao/util/MultipleNetworkPool.java @@ -54,7 +54,7 @@ public void initClones(int desiredNumberOfClones) { return; } - TECHNICAL_LOGS.debug("Filling network pool with '{}' new cop'{}' of network '{}' on variant '{}'", clonesToAdd, clonesToAdd == 1 ? "y" : "ies", network.getId(), targetVariant); + TECHNICAL_LOGS.debug("Filling network pool with {} new cop{} of network {} on variant {}", clonesToAdd, clonesToAdd == 1 ? "y" : "ies", network.getId(), targetVariant); String initialVariant = network.getVariantManager().getWorkingVariantId(); network.getVariantManager().setWorkingVariant(targetVariant);