From 1579ad14fb3efb02553c6de4fe028aa8afd3567f Mon Sep 17 00:00:00 2001 From: belthlemar Date: Thu, 13 Apr 2023 16:51:34 +0200 Subject: [PATCH 01/22] range action movement modified --- .../algorithms/fillers/CoreProblemFiller.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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..2071425b41 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; + private static final double RANGE_DIMINUTION_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); } @Override @@ -240,6 +243,22 @@ private void buildRangeActionConstraints(LinearProblem linearProblem) { ); } + private void updateRangeActionConstraints(LinearProblem linearProblem) { + optimizationContext.getRangeActionsPerState().entrySet().stream() + .sorted(Comparator.comparingInt(e -> e.getKey().getInstant().getOrder())) + .forEach(entry -> + entry.getValue().forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, entry.getKey()) + ) + ); + } + + private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeAction rangeAction, State state) { + FaraoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(rangeAction, state); + setPointVariable.setLb(setPointVariable.lb() + Math.pow(RANGE_DIMINUTION_RATE, iteration) / 3); + setPointVariable.setUb(setPointVariable.ub() - Math.pow(RANGE_DIMINUTION_RATE, iteration) / 3); + iteration += 1; + } + /** * Build two range action constraints for each RangeAction r. * These constraints link the set point variable of the RangeAction with its absolute From c085cf2193350685cfe5ce15c7aa9a2e68bd0fb4 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Thu, 13 Apr 2023 20:00:03 +0200 Subject: [PATCH 02/22] =?UTF-8?q?verison=20qui=20semble=20fonctionner=20ma?= =?UTF-8?q?lgr=C3=A9=20log=20xpres?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithms/IteratingLinearOptimizer.java | 13 +++++---- .../algorithms/fillers/CoreProblemFiller.java | 27 ++++++++++++++----- .../linear_problem/LinearProblem.java | 8 ++++-- .../LinearProblemIdGenerator.java | 4 +-- 4 files changed, 35 insertions(+), 17 deletions(-) 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..b9e727139c 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 @@ -91,15 +91,14 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in input.getObjectiveFunction() ); - if (currentResult.getCost() >= bestResult.getCost()) { + if (currentResult.getCost() <= bestResult.getCost()) { + logBetterResult(iteration, currentResult); + bestResult = currentResult; + linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); + } else { logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); - return bestResult; + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } - - logBetterResult(iteration, currentResult); - bestResult = currentResult; - linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); return bestResult; 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 2071425b41..566dbf1dcf 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 @@ -244,19 +244,34 @@ private void buildRangeActionConstraints(LinearProblem linearProblem) { } private void updateRangeActionConstraints(LinearProblem linearProblem) { + iteration += 1; optimizationContext.getRangeActionsPerState().entrySet().stream() .sorted(Comparator.comparingInt(e -> e.getKey().getInstant().getOrder())) .forEach(entry -> - entry.getValue().forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, entry.getKey()) + entry.getValue().forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, entry.getKey(), iteration) ) ); } - private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeAction rangeAction, State state) { + private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeAction rangeAction, State state, int iteration) { FaraoMPVariable setPointVariable = linearProblem.getRangeActionSetpointVariable(rangeAction, state); - setPointVariable.setLb(setPointVariable.lb() + Math.pow(RANGE_DIMINUTION_RATE, iteration) / 3); - setPointVariable.setUb(setPointVariable.ub() - Math.pow(RANGE_DIMINUTION_RATE, iteration) / 3); - iteration += 1; + if (setPointVariable == null) { + throw new FaraoException(format("Range action variable for %s has not been defined yet.", rangeAction.getId())); + } + double previousSetPointValue = setPointVariable.solutionValue(); + List minAndMaxAbsoluteAndRelativeSetpoints = getMinAndMaxAbsoluteAndRelativeSetpoints(rangeAction); + double minAbsoluteSetpoint = Math.max(minAndMaxAbsoluteAndRelativeSetpoints.get(0), -LinearProblem.infinity()); + double maxAbsoluteSetpoint = Math.min(minAndMaxAbsoluteAndRelativeSetpoints.get(1), LinearProblem.infinity()); + double setPointRange = Math.abs(minAbsoluteSetpoint) + Math.abs(maxAbsoluteSetpoint); + FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, "iterative_shrink"); + if (iterativeShrink != null) { + iterativeShrink.setLb(previousSetPointValue - setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration)); + iterativeShrink.setUb(previousSetPointValue + setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration)); + } else { + FaraoMPConstraint newIterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(-setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration) + previousSetPointValue, + setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration) + previousSetPointValue, rangeAction, state, "iterative_shrink"); + newIterativeShrink.setCoefficient(setPointVariable, 1); + } } /** @@ -321,7 +336,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, ""); 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..346319f6df 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 @@ -128,8 +128,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, String string) { + return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, string)); + } + + public FaraoMPConstraint getRangeActionRelativeSetpointConstraint(RangeAction rangeAction, State state, String string) { + return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, string)); } 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..e01a39e8e3 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, String string) { + return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + string + CONSTRAINT_SUFFIX; } public static String pstTapVariableVariationId(RangeAction rangeAction, State state, LinearProblem.VariationDirectionExtension upwardOrDownward) { From 0af06ccfb38810263212b88cf7b5a043eba0e0ef Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 14 Apr 2023 13:38:38 +0200 Subject: [PATCH 03/22] stops even when 2 worse iteration have the same result --- .../algorithms/IteratingLinearOptimizer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 b9e727139c..c19bc9ddb7 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 @@ -44,6 +44,8 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in 0, input.getObjectiveFunction()); + IteratingLinearOptimizationResultImpl lastResult = bestResult; + SensitivityComputer sensitivityComputer = null; LinearProblem linearProblem = LinearProblem.create() @@ -71,7 +73,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in currentRangeActionActivationResult = resolveIfApproximatedPstTaps(bestResult, linearProblem, iteration, currentRangeActionActivationResult, input, parameters); - if (!hasRemedialActionsChanged(currentRangeActionActivationResult, bestResult, input.getOptimizationPerimeter())) { + if (!hasRemedialActionsChanged(currentRangeActionActivationResult, lastResult, 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,7 +92,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in iteration, input.getObjectiveFunction() ); - + lastResult = currentResult; if (currentResult.getCost() <= bestResult.getCost()) { logBetterResult(iteration, currentResult); bestResult = currentResult; From 94a07785f460ae7eb00b36f881a813beca0fe94b Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 14 Apr 2023 16:37:34 +0200 Subject: [PATCH 04/22] fix getValue bug that always returned 0 --- .../algorithms/fillers/CoreProblemFiller.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 566dbf1dcf..3fcb580e48 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 @@ -85,7 +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); + updateRangeActionConstraints(linearProblem, rangeActionActivationResult); } @Override @@ -243,22 +243,18 @@ private void buildRangeActionConstraints(LinearProblem linearProblem) { ); } - private void updateRangeActionConstraints(LinearProblem linearProblem) { + private void updateRangeActionConstraints(LinearProblem linearProblem, RangeActionActivationResult rangeActionActivationResult) { iteration += 1; optimizationContext.getRangeActionsPerState().entrySet().stream() .sorted(Comparator.comparingInt(e -> e.getKey().getInstant().getOrder())) .forEach(entry -> - entry.getValue().forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, entry.getKey(), iteration) + entry.getValue().forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, entry.getKey(), rangeActionActivationResult, iteration) ) ); } - private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeAction rangeAction, State state, int iteration) { - 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())); - } - double previousSetPointValue = setPointVariable.solutionValue(); + 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()); @@ -268,6 +264,10 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA iterativeShrink.setLb(previousSetPointValue - setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration)); iterativeShrink.setUb(previousSetPointValue + setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration)); } 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())); + } FaraoMPConstraint newIterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(-setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration) + previousSetPointValue, setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration) + previousSetPointValue, rangeAction, state, "iterative_shrink"); newIterativeShrink.setCoefficient(setPointVariable, 1); From d674860cb0e672c9ea3f47ab85fa61b1fa215608 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 3 May 2023 14:17:16 +0200 Subject: [PATCH 05/22] fix some tests and update iteration number when finding a worst solution --- .../algorithms/IteratingLinearOptimizer.java | 3 ++- .../fillers/CoreProblemFillerTest.java | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) 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 c19bc9ddb7..8dc03df84e 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 @@ -99,6 +99,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); } else { logWorseResult(iteration, bestResult, currentResult); + bestResult.setNbOfIteration(iteration); linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } } @@ -232,7 +233,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/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..629651c657 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,14 @@ 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: 1 more each time the problem is updated) assertEquals(3, linearProblem.numVariables()); - assertEquals(3, linearProblem.numConstraints()); + assertEquals(4, linearProblem.numConstraints()); } @Test @@ -445,7 +444,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 +471,14 @@ 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: 1 more each time the problem is updated) assertEquals(3, linearProblem.numVariables()); - assertEquals(3, linearProblem.numConstraints()); + assertEquals(4, linearProblem.numConstraints()); } @Test From 9f2b8ad1d0f90d0355959618ebcb275029732a0b Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 3 May 2023 15:21:52 +0200 Subject: [PATCH 06/22] increment iteration even when problem fails or is worse --- .../algorithms/IteratingLinearOptimizer.java | 2 +- .../IteratingLinearOptimizerTest.java | 37 ++++++++++++------- 2 files changed, 25 insertions(+), 14 deletions(-) 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 8dc03df84e..171cde4d56 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 @@ -55,6 +55,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) { @@ -99,7 +100,6 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); } else { logWorseResult(iteration, bestResult, currentResult); - bestResult.setNbOfIteration(iteration); linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } } 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..31671181e1 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; @@ -198,7 +195,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 +209,39 @@ 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() { + 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(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 linearProblemFluctuatesButKeepsBestIteration() { + 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 +265,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,7 +283,7 @@ 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); } From 3c02359547da0ba68941c6255886c70b19643c3f Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 3 May 2023 16:54:23 +0200 Subject: [PATCH 07/22] refactor some tests but one is still not working --- .../IteratingLinearOptimizerTest.java | 17 ++++++----------- .../fillers/CoreProblemFillerTest.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 13 deletions(-) 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 31671181e1..ce66c568c7 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 @@ -292,8 +292,8 @@ void optimizeWithSensitivityComputationFailure() { void testUnapplyRangeAction() { 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., 4.4)); + 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) @@ -306,16 +306,11 @@ 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()); + // TODO Should be 3 but isn't ... It's always the last value line 295 + // TODO Ask someone in the team, I don't get it (probably Peter because he wrote this part of the code) } } 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 629651c657..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 @@ -431,9 +431,13 @@ void updateTestOnPreventive() { // - 2 per range action (set-point and variation) // total number of constraints 4 : // - 1 per CNEC (flow constraint) - // - 3 per range action (absolute variation constraints and iterative relative variation constraint: 1 more each time the problem is updated) + // - 3 per range action (absolute variation constraints and iterative relative variation constraint: created before 2nd iteration) assertEquals(3, linearProblem.numVariables()); assertEquals(4, linearProblem.numConstraints()); + + // assert that no other constraint is created after 2nd iteration + updateLinearProblem(); + assertEquals(4, linearProblem.numConstraints()); } @Test @@ -476,9 +480,13 @@ void updateTestOnCurative() { // - 2 per range action (set-point and variation) // total number of constraints 4 : // - 1 per CNEC (flow constraint) - // - 3 per range action (absolute variation constraints and iterative relative variation constraint: 1 more each time the problem is updated) + // - 3 per range action (absolute variation constraints and iterative relative variation constraint: created before 2nd iteration) assertEquals(3, linearProblem.numVariables()); assertEquals(4, linearProblem.numConstraints()); + + // assert that no other constraint is created after 2nd iteration + updateLinearProblem(); + assertEquals(4, linearProblem.numConstraints()); } @Test From 25ccff439992c45010c90970ffed77f568d4b8d5 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 3 May 2023 17:39:41 +0200 Subject: [PATCH 08/22] add best result RA on network for each worse MIP iteration --- .../algorithms/IteratingLinearOptimizer.java | 1 + .../algorithms/IteratingLinearOptimizerTest.java | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) 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 171cde4d56..5a6e86faff 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 @@ -100,6 +100,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); } else { logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } } 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 ce66c568c7..2bec83e9cb 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 @@ -292,7 +292,7 @@ void optimizeWithSensitivityComputationFailure() { void testUnapplyRangeAction() { network = NetworkImportsUtil.import12NodesNetwork(); when(input.getNetwork()).thenReturn(network); - mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 4.4)); + 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") @@ -309,8 +309,6 @@ void testUnapplyRangeAction() { prepareLinearProblemBuilder(); IteratingLinearOptimizer.optimize(input, parameters); - // assertEquals(3, network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1").getPhaseTapChanger().getTapPosition()); - // TODO Should be 3 but isn't ... It's always the last value line 295 - // TODO Ask someone in the team, I don't get it (probably Peter because he wrote this part of the code) + assertEquals(3, network.getTwoWindingsTransformer("BBE2AA1 BBE3AA1 1").getPhaseTapChanger().getTapPosition()); } } From 8873040532786dd71401d8840f47b5da9b59fd75 Mon Sep 17 00:00:00 2001 From: MartinBelthle <102529366+MartinBelthle@users.noreply.github.com> Date: Fri, 5 May 2023 13:25:56 +0200 Subject: [PATCH 09/22] Update CoreProblemFiller.java Co-authored-by: Thomas Bouquet <63302082+bqth29@users.noreply.github.com> --- .../algorithms/fillers/CoreProblemFiller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3fcb580e48..9a873771e5 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 @@ -244,7 +244,7 @@ private void buildRangeActionConstraints(LinearProblem linearProblem) { } private void updateRangeActionConstraints(LinearProblem linearProblem, RangeActionActivationResult rangeActionActivationResult) { - iteration += 1; + iteration++; optimizationContext.getRangeActionsPerState().entrySet().stream() .sorted(Comparator.comparingInt(e -> e.getKey().getInstant().getOrder())) .forEach(entry -> From 20dd31e29e3a0d88f5f5f2a557a5e48f62a75310 Mon Sep 17 00:00:00 2001 From: MartinBelthle <102529366+MartinBelthle@users.noreply.github.com> Date: Fri, 5 May 2023 13:27:43 +0200 Subject: [PATCH 10/22] add variable because it is used several times Co-authored-by: Thomas Bouquet <63302082+bqth29@users.noreply.github.com> --- .../algorithms/fillers/CoreProblemFiller.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 9a873771e5..2bf941d8e5 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 @@ -259,17 +259,18 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA double minAbsoluteSetpoint = Math.max(minAndMaxAbsoluteAndRelativeSetpoints.get(0), -LinearProblem.infinity()); double maxAbsoluteSetpoint = Math.min(minAndMaxAbsoluteAndRelativeSetpoints.get(1), LinearProblem.infinity()); double setPointRange = Math.abs(minAbsoluteSetpoint) + Math.abs(maxAbsoluteSetpoint); + double constrainedSetPointRange = setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration); FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, "iterative_shrink"); if (iterativeShrink != null) { - iterativeShrink.setLb(previousSetPointValue - setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration)); - iterativeShrink.setUb(previousSetPointValue + setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration)); + iterativeShrink.setLb(previousSetPointValue - constrainedSetPointRange); + iterativeShrink.setUb(previousSetPointValue + constrainedSetPointRange); } 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())); } - FaraoMPConstraint newIterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(-setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration) + previousSetPointValue, - setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration) + previousSetPointValue, rangeAction, state, "iterative_shrink"); + FaraoMPConstraint newIterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(-constrainedSetPointRange + previousSetPointValue, + constrainedSetPointRange + previousSetPointValue, rangeAction, state, "iterative_shrink"); newIterativeShrink.setCoefficient(setPointVariable, 1); } } From b2fb72f0eb2019872e7f52ef088c0f80269ad93e Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 5 May 2023 13:32:16 +0200 Subject: [PATCH 11/22] fix filling network pool log msg --- .../com/farao_community/farao/util/MultipleNetworkPool.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 7391315a91ddcefa3dd42fb7bd1978e4aeb0069f Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 May 2023 11:35:22 +0200 Subject: [PATCH 12/22] first draft of new parameters with UTs fixed --- .../farao/rao_api/RaoParametersConstants.java | 1 + .../JsonRangeActionsOptimizationParameters.java | 12 ++++++++++++ .../RangeActionsOptimizationParameters.java | 14 ++++++++++++++ .../farao/rao_api/json/JsonRaoParametersTest.java | 1 + .../parameters/RaoParametersConfigTest.java | 1 + .../parameters/RaoParametersYamlConfigTest.java | 3 +++ .../src/test/resources/RaoParametersSet_v2.json | 1 + .../resources/RaoParametersWithExtension_v2.json | 1 + .../RaoParameters_config_withExtensions.json | 1 + .../RaoParameters_config_withOLFParams.json | 1 + ...RaoParameters_config_withPartialExtensions.json | 1 + .../RaoParameters_config_withoutExtensions.json | 1 + .../src/test/resources/RaoParameters_v2.json | 1 + .../resources/config_withPartialExtensions.yml | 1 + .../test/resources/config_withoutExtensions.yml | 1 + 15 files changed, 41 insertions(+) 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..a03eb27f44 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 MIP_MODEL = "mip-model"; // 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..20a17aaa0f 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 @@ -30,6 +30,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); + jsonGenerator.writeObjectField(MIP_MODEL, parameters.getRangeActionsOptimizationParameters().getMipModel()); jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); @@ -80,6 +81,9 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); deserializeLinearOptimizationSolver(jsonParser, raoParameters); break; + case MIP_MODEL: + raoParameters.getRangeActionsOptimizationParameters().setMipModel(stringToMipModel(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.MipModel stringToMipModel(String string) { + try { + return RangeActionsOptimizationParameters.MipModel.valueOf(string); + } catch (IllegalArgumentException e) { + throw new FaraoException(String.format("Unknown Mip model: %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..70107a3553 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 MipModel DEFAULT_MIP_MODEL = MipModel.DISABLED; // Attributes private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST; @@ -40,6 +41,7 @@ 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 MipModel mipModel = DEFAULT_MIP_MODEL; // Enum public enum PstModel { @@ -47,6 +49,13 @@ public enum PstModel { APPROXIMATED_INTEGERS } + // Refactore these names + public enum MipModel { + DISABLED, + FIRST_PREV_AND_CURATIVE_ONLY, + ALL + } + public static class LinearOptimizationSolver { private static final Solver DEFAULT_SOLVER = Solver.CBC; public static final double DEFAULT_RELATIVE_MIP_GAP = 0.0001; @@ -171,6 +180,10 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat this.linearOptimizationSolver = linearOptimizationSolver; } + public void setMipModel(MipModel mipModel) {this.mipModel = mipModel;} + + public MipModel getMipModel() {return mipModel;} + public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); RangeActionsOptimizationParameters parameters = new RangeActionsOptimizationParameters(); @@ -184,6 +197,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.setMipModel(config.getEnumProperty(MIP_MODEL, MipModel.class, DEFAULT_MIP_MODEL)); }); 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..05d5718ae4 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().setMipModel(RangeActionsOptimizationParameters.MipModel.ALL); // 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..f88d8ba53d 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.MipModel.DISABLED, params.getMipModel()); 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..ac8ce32bde 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.MipModel.DISABLED, rangeActionsOptimizationParameters.getMipModel()); 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.MipModel.DISABLED, rangeActionsOptimizationParameters.getMipModel()); 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.MipModel.ALL, rangeActionsOptimizationParameters.getMipModel()); 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..c168a3b172 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,6 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", + "mip-model" : "ALL", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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..0e997c12b0 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -12,6 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", + "mip-model" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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..cd706d65ae 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 @@ -12,6 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", + "mip-model" : "DISABLED", "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/RaoParameters_config_withOLFParams.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json index ffbf528926..4b6ff8770f 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 @@ -12,6 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", + "mip-model" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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..00916bb515 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 @@ -12,6 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", + "mip-model" : "ALL", "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/RaoParameters_config_withoutExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json index b6c3df2ed1..ed00ac827f 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 @@ -12,6 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", + "mip-model" : "DISABLED", "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/RaoParameters_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json index f60a3dd40f..db30adb0df 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -12,6 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", + "mip-model" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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..7af8519fd1 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 + mip-model: ALL 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..0d556afb18 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 + mip-model: DISABLED hvdc-penalty-cost: 0.002 hvdc-sensitivity-threshold: 0.2 injection-ra-penalty-cost: 0.003 From 9386daaaaa4b7a6dab7787e12daca1c066ee8647 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 May 2023 16:02:28 +0200 Subject: [PATCH 13/22] change mip behavior according to new parameter value + fix UTs --- .../farao/rao_api/RaoParametersConstants.java | 2 +- ...sonRangeActionsOptimizationParameters.java | 12 ++-- .../RangeActionsOptimizationParameters.java | 18 +++--- .../rao_api/json/JsonRaoParametersTest.java | 2 +- .../parameters/RaoParametersConfigTest.java | 2 +- .../RaoParametersYamlConfigTest.java | 6 +- .../test/resources/RaoParametersSet_v2.json | 2 +- .../RaoParametersWithExtension_v2.json | 2 +- .../RaoParameters_config_withExtensions.json | 2 +- .../RaoParameters_config_withOLFParams.json | 2 +- ...rameters_config_withPartialExtensions.json | 2 +- ...aoParameters_config_withoutExtensions.json | 2 +- .../src/test/resources/RaoParameters_v2.json | 2 +- .../config_withPartialExtensions.yml | 2 +- .../resources/config_withoutExtensions.yml | 2 +- .../commons/parameters/TreeParameters.java | 55 +++++++++++-------- .../algorithms/IteratingLinearOptimizer.java | 25 +++++++-- .../IteratingLinearOptimizerParameters.java | 18 +++++- .../search_tree/algorithms/Leaf.java | 1 + .../parameters/TreeParametersTest.java | 22 +++++++- .../IteratingLinearOptimizerTest.java | 18 ++++++ .../search_tree/algorithms/LeafTest.java | 23 ++++++++ 22 files changed, 162 insertions(+), 60 deletions(-) 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 a03eb27f44..c30c8295ce 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,7 +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 MIP_MODEL = "mip-model"; + public static final String PST_VARIATION_GRADUAL_DECREASE = "pst-variation-gradual-decrease"; // 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 20a17aaa0f..76af05d363 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 @@ -30,7 +30,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); - jsonGenerator.writeObjectField(MIP_MODEL, parameters.getRangeActionsOptimizationParameters().getMipModel()); + jsonGenerator.writeObjectField(PST_VARIATION_GRADUAL_DECREASE, parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease()); jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); @@ -81,8 +81,8 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); deserializeLinearOptimizationSolver(jsonParser, raoParameters); break; - case MIP_MODEL: - raoParameters.getRangeActionsOptimizationParameters().setMipModel(stringToMipModel(jsonParser.nextTextValue())); + case PST_VARIATION_GRADUAL_DECREASE: + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(stringToPstVariationGradualDecrease(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())); @@ -118,11 +118,11 @@ private static RangeActionsOptimizationParameters.PstModel stringToPstModel(Stri } } - private static RangeActionsOptimizationParameters.MipModel stringToMipModel(String string) { + private static RangeActionsOptimizationParameters.PstVariationGradualDecrease stringToPstVariationGradualDecrease(String string) { try { - return RangeActionsOptimizationParameters.MipModel.valueOf(string); + return RangeActionsOptimizationParameters.PstVariationGradualDecrease.valueOf(string); } catch (IllegalArgumentException e) { - throw new FaraoException(String.format("Unknown Mip model: %s", string)); + throw new FaraoException(String.format("Unknown Pst variation gradual decrease: %s", 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 70107a3553..6a11677cd1 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,7 +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 MipModel DEFAULT_MIP_MODEL = MipModel.DISABLED; + private static final PstVariationGradualDecrease DEFAULT_PST_DECREASE = PstVariationGradualDecrease.DISABLED; // Attributes private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST; @@ -41,7 +41,7 @@ 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 MipModel mipModel = DEFAULT_MIP_MODEL; + private PstVariationGradualDecrease pstVariationGradualDecrease = DEFAULT_PST_DECREASE; // Enum public enum PstModel { @@ -49,8 +49,8 @@ public enum PstModel { APPROXIMATED_INTEGERS } - // Refactore these names - public enum MipModel { + // Refactor these names + public enum PstVariationGradualDecrease { DISABLED, FIRST_PREV_AND_CURATIVE_ONLY, ALL @@ -180,9 +180,13 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat this.linearOptimizationSolver = linearOptimizationSolver; } - public void setMipModel(MipModel mipModel) {this.mipModel = mipModel;} + public void setPstVariationGradualDecrease(PstVariationGradualDecrease pstVariationGradualDecrease) { + this.pstVariationGradualDecrease = pstVariationGradualDecrease; + } - public MipModel getMipModel() {return mipModel;} + public PstVariationGradualDecrease getPstVariationGradualDecrease() { + return pstVariationGradualDecrease; + } public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { Objects.requireNonNull(platformConfig); @@ -197,7 +201,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.setMipModel(config.getEnumProperty(MIP_MODEL, MipModel.class, DEFAULT_MIP_MODEL)); + parameters.setPstVariationGradualDecrease(config.getEnumProperty(PST_VARIATION_GRADUAL_DECREASE, PstVariationGradualDecrease.class, DEFAULT_PST_DECREASE)); }); 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 05d5718ae4..c698871c3d 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,7 +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().setMipModel(RangeActionsOptimizationParameters.MipModel.ALL); + parameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); // 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 f88d8ba53d..05a0fe1de7 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,7 +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.MipModel.DISABLED, params.getMipModel()); + assertEquals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED, params.getPstVariationGradualDecrease()); 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 ac8ce32bde..a263b6a316 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,7 +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.MipModel.DISABLED, rangeActionsOptimizationParameters.getMipModel()); + assertEquals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -143,7 +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.MipModel.DISABLED, rangeActionsOptimizationParameters.getMipModel()); + assertEquals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -222,7 +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.MipModel.ALL, rangeActionsOptimizationParameters.getMipModel()); + assertEquals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); 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 c168a3b172..b4521c03b3 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "mip-model" : "ALL", + "pst-variation-gradual-decrease" : "ALL", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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 0e997c12b0..4a2012698a 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "mip-model" : "DISABLED", + "pst-variation-gradual-decrease" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 cd706d65ae..bf82275735 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "mip-model" : "DISABLED", + "pst-variation-gradual-decrease" : "DISABLED", "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/RaoParameters_config_withOLFParams.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json index 4b6ff8770f..654f3078fb 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "mip-model" : "DISABLED", + "pst-variation-gradual-decrease" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 00916bb515..8bc7f172e4 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "mip-model" : "ALL", + "pst-variation-gradual-decrease" : "ALL", "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/RaoParameters_config_withoutExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json index ed00ac827f..98cff45079 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "mip-model" : "DISABLED", + "pst-variation-gradual-decrease" : "DISABLED", "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/RaoParameters_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json index db30adb0df..8f4d975af7 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "mip-model" : "DISABLED", + "pst-variation-gradual-decrease" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 7af8519fd1..7216c0ff86 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml @@ -8,7 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - mip-model: ALL + pst-variation-gradual-decrease: ALL 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 0d556afb18..48a10ac948 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml @@ -10,7 +10,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - mip-model: DISABLED + pst-variation-gradual-decrease: 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..2dd292ad59 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 capPstVariation; public TreeParameters(StopCriterion stopCriterion, double targetObjectiveValue, int maximumSearchDepth, - int leavesInParallel) { + int leavesInParallel, + boolean capPstVariation) { this.stopCriterion = stopCriterion; this.targetObjectiveValue = targetObjectiveValue; this.maximumSearchDepth = maximumSearchDepth; this.leavesInParallel = leavesInParallel; + this.capPstVariation = capPstVariation; } public StopCriterion getStopCriterion() { @@ -56,21 +60,23 @@ public int getLeavesInParallel() { return leavesInParallel; } + public boolean getCapPstVariation() { + return capPstVariation; + } + public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) { - 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()); - case SECURE: - return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, - 0.0, // secure - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); - default: - throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); + StopCriterion stopCriterion = StopCriterion.MIN_OBJECTIVE; + if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE)) { + stopCriterion = StopCriterion.AT_TARGET_OBJECTIVE_VALUE; + } else if (!parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE)) { + throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); } + boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); + return new TreeParameters(stopCriterion, + 0.0, + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + capPstVariation); } public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, Double preventiveOptimizedCost) { @@ -96,24 +102,27 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, default: throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion()); } + boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getCurativeLeavesInParallel()); + parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), + capPstVariation); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { + StopCriterion stopCriterion; if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE) && !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()); + stopCriterion = StopCriterion.AT_TARGET_OBJECTIVE_VALUE; } else { - return new TreeParameters(StopCriterion.MIN_OBJECTIVE, - 0.0, // value does not matter - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel()); + stopCriterion = StopCriterion.MIN_OBJECTIVE; } + boolean capPstVariation = parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + return new TreeParameters(stopCriterion, + 0.0, + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + capPstVariation); } } 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 5a6e86faff..d4d290924b 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 @@ -93,15 +93,28 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in iteration, input.getObjectiveFunction() ); - lastResult = currentResult; - if (currentResult.getCost() <= bestResult.getCost()) { + + boolean capPstVariation = parameters.getCapPstVariation(); + if (capPstVariation) { + lastResult = currentResult; + if (currentResult.getCost() <= bestResult.getCost()) { + logBetterResult(iteration, currentResult); + bestResult = currentResult; + linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); + } else { + logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); + } + } else { + if (currentResult.getCost() >= bestResult.getCost()) { + logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); + return bestResult; + } logBetterResult(iteration, currentResult); bestResult = currentResult; linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); - } else { - logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); - linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); 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..3ce0a7db31 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 capPstVariation; 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 capPstVariation) { 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.capPstVariation = capPstVariation; } public ObjectiveFunctionParameters.ObjectiveFunctionType getObjectiveFunction() { @@ -110,6 +113,10 @@ public int getMaxNumberOfIterations() { return maxNumberOfIterations; } + public boolean getCapPstVariation() { + return capPstVariation; + } + 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 capPstVariation; public LinearOptimizerParametersBuilder withObjectiveFunction(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { this.objectiveFunction = objectiveFunction; @@ -171,6 +179,11 @@ public LinearOptimizerParametersBuilder withMaxNumberOfIterations(int maxNumberO return this; } + public LinearOptimizerParametersBuilder withCapPstVariation(boolean capPstVariation) { + this.capPstVariation = capPstVariation; + 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, + capPstVariation); } } } 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..ea59e39166 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()) + .withCapPstVariation(parameters.getTreeParameters().getCapPstVariation()) .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..b03e8b56f3 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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.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.getCapPstVariation()); // 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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.FIRST_PREV_AND_CURATIVE_ONLY); 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.getCapPstVariation()); + + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); + assertTrue(treeParameters.getCapPstVariation()); } @Test void testCurativeMinObjective() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.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.getCapPstVariation()); } @Test void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.FIRST_PREV_AND_CURATIVE_ONLY); 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.getCapPstVariation()); } @Test @@ -80,12 +92,14 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); 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.getCapPstVariation()); } @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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); TreeParameters treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertFalse(treeParameters.getCapPstVariation()); // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.FIRST_PREV_AND_CURATIVE_ONLY); 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.getCapPstVariation()); // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); + assertTrue(treeParameters.getCapPstVariation()); // 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 2bec83e9cb..dcfb9d5d11 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 @@ -99,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.getCapPstVariation()).thenReturn(false); linearProblem = Mockito.mock(LinearProblem.class); network = Mockito.mock(Network.class); @@ -216,6 +217,7 @@ void secondLinearProblemDoesNotChangeSetPoint() { @Test void linearProblemDegradesTheSolutionButKeepsBestIteration() { + when(parameters.getCapPstVariation()).thenReturn(true); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); mockFunctionalCost(100., 150., 140., 130., 120., 110.); prepareLinearProblemBuilder(); @@ -228,8 +230,23 @@ void linearProblemDegradesTheSolutionButKeepsBestIteration() { 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(1, ((IteratingLinearOptimizationResultImpl) result).getNbOfIteration()); + assertEquals(100, result.getFunctionalCost(), DOUBLE_TOLERANCE); + assertEquals(0, result.getOptimizedSetpoint(rangeAction, optimizedState), DOUBLE_TOLERANCE); + } + @Test void linearProblemFluctuatesButKeepsBestIteration() { + when(parameters.getCapPstVariation()).thenReturn(true); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); mockFunctionalCost(100., 120., 105., 90., 100., 95.); prepareLinearProblemBuilder(); @@ -290,6 +307,7 @@ void optimizeWithSensitivityComputationFailure() { @Test void testUnapplyRangeAction() { + when(parameters.getCapPstVariation()).thenReturn(true); network = NetworkImportsUtil.import12NodesNetwork(); when(input.getNetwork()).thenReturn(network); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); 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..ceb4ea21e1 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,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); rootLeaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(Leaf.Status.OPTIMIZED, rootLeaf.getStatus()); } @@ -352,6 +355,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -420,6 +425,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedFunctionalCost = 3.; @@ -454,6 +461,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedVirtualCost = 3.; @@ -497,6 +506,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); @@ -573,6 +584,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -656,6 +669,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); leaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(sensitivityStatus, leaf.getSensitivityStatus()); @@ -691,6 +706,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -737,6 +754,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -755,6 +774,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(Mockito.mock(IteratingLinearOptimizationResultImpl.class)); rootLeaf.optimize(searchTreeInput, searchTreeParameters); rootLeaf.finalizeOptimization(); @@ -782,6 +803,8 @@ 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)); + when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); when(linearOptimizationResult.getCost()).thenReturn(-100.5); From 9b929d6ebe882e8cbbfc65e777faa164c4a83baa Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 May 2023 16:29:01 +0200 Subject: [PATCH 14/22] modify Enum names --- .../RangeActionsOptimizationParameters.java | 4 ++-- .../farao/rao_api/json/JsonRaoParametersTest.java | 2 +- .../parameters/RaoParametersYamlConfigTest.java | 2 +- .../src/test/resources/RaoParametersSet_v2.json | 2 +- .../RaoParameters_config_withPartialExtensions.json | 2 +- .../test/resources/config_withPartialExtensions.yml | 2 +- .../commons/parameters/TreeParameters.java | 2 +- .../commons/parameters/TreeParametersTest.java | 12 ++++++------ 8 files changed, 14 insertions(+), 14 deletions(-) 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 6a11677cd1..51817060c7 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 @@ -52,8 +52,8 @@ public enum PstModel { // Refactor these names public enum PstVariationGradualDecrease { DISABLED, - FIRST_PREV_AND_CURATIVE_ONLY, - ALL + ENABLED_FOR_ALL_STATE, + ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE } public static class LinearOptimizationSolver { 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 c698871c3d..38461d1bb5 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,7 +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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + parameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); // 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/RaoParametersYamlConfigTest.java b/ra-optimisation/rao-api/src/test/java/com/farao_community/farao/rao_api/parameters/RaoParametersYamlConfigTest.java index a263b6a316..04a1038c50 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 @@ -222,7 +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.PstVariationGradualDecrease.ALL, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); 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 b4521c03b3..63fb6c02f1 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "ALL", + "pst-variation-gradual-decrease" : "ENABLED_FOR_ALL_STATE", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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 8bc7f172e4..685e72a629 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "ALL", + "pst-variation-gradual-decrease" : "ENABLED_FOR_ALL_STATE", "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_withPartialExtensions.yml b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml index 7216c0ff86..7598f5dcca 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml @@ -8,7 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-variation-gradual-decrease: ALL + pst-variation-gradual-decrease: ENABLED_FOR_ALL_STATE 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 2dd292ad59..5a08867ede 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 @@ -118,7 +118,7 @@ public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters par } else { stopCriterion = StopCriterion.MIN_OBJECTIVE; } - boolean capPstVariation = parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + boolean capPstVariation = parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); return new TreeParameters(stopCriterion, 0.0, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), 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 b03e8b56f3..cbd6b219ee 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 @@ -46,7 +46,7 @@ void testPreventive() { raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(15); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.FIRST_PREV_AND_CURATIVE_ONLY); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -55,7 +55,7 @@ void testPreventive() { assertEquals(15, treeParameters.getMaximumSearchDepth()); assertTrue(treeParameters.getCapPstVariation()); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertTrue(treeParameters.getCapPstVariation()); } @@ -77,7 +77,7 @@ void testCurativeMinObjective() { void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.FIRST_PREV_AND_CURATIVE_ONLY); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -92,7 +92,7 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -145,7 +145,7 @@ void testSecondPreventive() { // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.FIRST_PREV_AND_CURATIVE_ONLY); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -157,7 +157,7 @@ void testSecondPreventive() { // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ALL); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); From ab3676cb00582b629b79431ba7aa5f2d120ba2b8 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 May 2023 17:24:29 +0200 Subject: [PATCH 15/22] change enum names and reduce complexity --- ...sonRangeActionsOptimizationParameters.java | 4 +-- .../RangeActionsOptimizationParameters.java | 16 ++++++------ .../rao_api/json/JsonRaoParametersTest.java | 2 +- .../parameters/RaoParametersConfigTest.java | 2 +- .../RaoParametersYamlConfigTest.java | 6 ++--- .../test/resources/RaoParametersSet_v2.json | 2 +- ...rameters_config_withPartialExtensions.json | 2 +- .../config_withPartialExtensions.yml | 2 +- .../commons/parameters/TreeParameters.java | 6 ++--- .../algorithms/IteratingLinearOptimizer.java | 25 ++++++++----------- .../parameters/TreeParametersTest.java | 18 ++++++------- 11 files changed, 40 insertions(+), 45 deletions(-) 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 76af05d363..03b601ebc1 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 @@ -118,9 +118,9 @@ private static RangeActionsOptimizationParameters.PstModel stringToPstModel(Stri } } - private static RangeActionsOptimizationParameters.PstVariationGradualDecrease stringToPstVariationGradualDecrease(String string) { + private static RangeActionsOptimizationParameters.PstRangeDecrease stringToPstVariationGradualDecrease(String string) { try { - return RangeActionsOptimizationParameters.PstVariationGradualDecrease.valueOf(string); + return RangeActionsOptimizationParameters.PstRangeDecrease.valueOf(string); } catch (IllegalArgumentException e) { throw new FaraoException(String.format("Unknown Pst variation gradual decrease: %s", 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 51817060c7..9a1d4b0483 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,7 +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 PstVariationGradualDecrease DEFAULT_PST_DECREASE = PstVariationGradualDecrease.DISABLED; + private static final PstRangeDecrease DEFAULT_PST_DECREASE = PstRangeDecrease.DISABLED; // Attributes private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST; @@ -41,7 +41,7 @@ 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 PstVariationGradualDecrease pstVariationGradualDecrease = DEFAULT_PST_DECREASE; + private PstRangeDecrease pstVariationGradualDecrease = DEFAULT_PST_DECREASE; // Enum public enum PstModel { @@ -50,10 +50,10 @@ public enum PstModel { } // Refactor these names - public enum PstVariationGradualDecrease { + public enum PstRangeDecrease { DISABLED, - ENABLED_FOR_ALL_STATE, - ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE + ENABLED, + ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY } public static class LinearOptimizationSolver { @@ -180,11 +180,11 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat this.linearOptimizationSolver = linearOptimizationSolver; } - public void setPstVariationGradualDecrease(PstVariationGradualDecrease pstVariationGradualDecrease) { + public void setPstVariationGradualDecrease(PstRangeDecrease pstVariationGradualDecrease) { this.pstVariationGradualDecrease = pstVariationGradualDecrease; } - public PstVariationGradualDecrease getPstVariationGradualDecrease() { + public PstRangeDecrease getPstVariationGradualDecrease() { return pstVariationGradualDecrease; } @@ -201,7 +201,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.setPstVariationGradualDecrease(config.getEnumProperty(PST_VARIATION_GRADUAL_DECREASE, PstVariationGradualDecrease.class, DEFAULT_PST_DECREASE)); + parameters.setPstVariationGradualDecrease(config.getEnumProperty(PST_VARIATION_GRADUAL_DECREASE, PstRangeDecrease.class, DEFAULT_PST_DECREASE)); }); 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 38461d1bb5..2264246a78 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,7 +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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); + parameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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 05a0fe1de7..f179e1c887 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,7 +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.PstVariationGradualDecrease.DISABLED, params.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED, params.getPstVariationGradualDecrease()); 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 04a1038c50..0699b3c105 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,7 +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.PstVariationGradualDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -143,7 +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.PstVariationGradualDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -222,7 +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.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); 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 63fb6c02f1..2882d1b79e 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "ENABLED_FOR_ALL_STATE", + "pst-variation-gradual-decrease" : "ENABLED", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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 685e72a629..6c92beffd4 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "ENABLED_FOR_ALL_STATE", + "pst-variation-gradual-decrease" : "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_withPartialExtensions.yml b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml index 7598f5dcca..c727429b44 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml @@ -8,7 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-variation-gradual-decrease: ENABLED_FOR_ALL_STATE + pst-variation-gradual-decrease: ENABLED 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 5a08867ede..199d556391 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 @@ -71,7 +71,7 @@ public static TreeParameters buildForPreventivePerimeter(RaoParameters parameter } else if (!parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE)) { throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); } - boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); + boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); return new TreeParameters(stopCriterion, 0.0, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), @@ -102,7 +102,7 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, default: throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion()); } - boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); + boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), @@ -118,7 +118,7 @@ public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters par } else { stopCriterion = StopCriterion.MIN_OBJECTIVE; } - boolean capPstVariation = parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); + boolean capPstVariation = parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); return new TreeParameters(stopCriterion, 0.0, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), 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 d4d290924b..5310c90a4d 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 @@ -97,24 +97,19 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in boolean capPstVariation = parameters.getCapPstVariation(); if (capPstVariation) { lastResult = currentResult; - if (currentResult.getCost() <= bestResult.getCost()) { - logBetterResult(iteration, currentResult); - bestResult = currentResult; - linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); - } else { - logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); - linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); - } - } else { - if (currentResult.getCost() >= bestResult.getCost()) { - logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); - return bestResult; - } + } + if (currentResult.getCost() < bestResult.getCost()) { logBetterResult(iteration, currentResult); bestResult = currentResult; linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); + } else { + logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); + if (capPstVariation) { + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); + } else { + return bestResult; + } } } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); 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 cbd6b219ee..c80384737d 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 @@ -28,7 +28,7 @@ public void setUp() { raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(6); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); } @Test @@ -46,7 +46,7 @@ void testPreventive() { raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(8); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(15); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -55,7 +55,7 @@ void testPreventive() { assertEquals(15, treeParameters.getMaximumSearchDepth()); assertTrue(treeParameters.getCapPstVariation()); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); assertTrue(treeParameters.getCapPstVariation()); } @@ -64,7 +64,7 @@ void testPreventive() { void testCurativeMinObjective() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); @@ -77,7 +77,7 @@ void testCurativeMinObjective() { void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -92,7 +92,7 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); TreeParameters treeParameters = TreeParameters.buildForCurativePerimeter(raoParameters, 100.0); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -134,7 +134,7 @@ void testSecondPreventive() { // test with min objective raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); TreeParameters treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); @@ -145,7 +145,7 @@ void testSecondPreventive() { // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.AT_TARGET_OBJECTIVE_VALUE, treeParameters.getStopCriterion()); @@ -157,7 +157,7 @@ void testSecondPreventive() { // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstVariationGradualDecrease.ENABLED_FOR_ALL_STATE); + raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); From 2df5559c7b46976fa0ce1423f8abeeee71ccaa85 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 May 2023 17:32:57 +0200 Subject: [PATCH 16/22] change parameter name in config files --- .../farao_community/farao/rao_api/RaoParametersConstants.java | 2 +- .../rao-api/src/test/resources/RaoParametersSet_v2.json | 2 +- .../src/test/resources/RaoParametersWithExtension_v2.json | 2 +- .../src/test/resources/RaoParameters_config_withExtensions.json | 2 +- .../src/test/resources/RaoParameters_config_withOLFParams.json | 2 +- .../resources/RaoParameters_config_withPartialExtensions.json | 2 +- .../test/resources/RaoParameters_config_withoutExtensions.json | 2 +- .../rao-api/src/test/resources/RaoParameters_v2.json | 2 +- .../rao-api/src/test/resources/config_withPartialExtensions.yml | 2 +- .../rao-api/src/test/resources/config_withoutExtensions.yml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) 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 c30c8295ce..bb98cd5333 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,7 +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 PST_VARIATION_GRADUAL_DECREASE = "pst-variation-gradual-decrease"; + public static final String PST_VARIATION_GRADUAL_DECREASE = "pst-range-decrease"; // topological actions optimization parameters public static final String TOPOLOGICAL_ACTIONS_OPTIMIZATION = "topological-actions-optimization"; 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 2882d1b79e..0dac631c81 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "ENABLED", + "pst-range-decrease" : "ENABLED", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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 4a2012698a..e5e6d31c80 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-variation-gradual-decrease" : "DISABLED", + "pst-range-decrease" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 bf82275735..41d4687ca5 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "DISABLED", + "pst-range-decrease" : "DISABLED", "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/RaoParameters_config_withOLFParams.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json index 654f3078fb..e3ebb17995 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-variation-gradual-decrease" : "DISABLED", + "pst-range-decrease" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 6c92beffd4..c81a9acd6b 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "ENABLED", + "pst-range-decrease" : "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/RaoParameters_config_withoutExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json index 98cff45079..da187094dd 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-variation-gradual-decrease" : "DISABLED", + "pst-range-decrease" : "DISABLED", "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/RaoParameters_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json index 8f4d975af7..80bfc01058 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-variation-gradual-decrease" : "DISABLED", + "pst-range-decrease" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 c727429b44..da1f47d682 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml @@ -8,7 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-variation-gradual-decrease: ENABLED + pst-range-decrease: 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 48a10ac948..01ce3ee392 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml @@ -10,7 +10,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-variation-gradual-decrease: DISABLED + pst-range-decrease: DISABLED hvdc-penalty-cost: 0.002 hvdc-sensitivity-threshold: 0.2 injection-ra-penalty-cost: 0.003 From 752a2bdfd3060d74c1a5b036256dc1f4ac1bc189 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Wed, 10 May 2023 18:24:51 +0200 Subject: [PATCH 17/22] reduce cognitive complexity to less than 15 --- .../algorithms/IteratingLinearOptimizer.java | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) 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 5310c90a4d..cadca0e8b0 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 @@ -23,6 +23,7 @@ import com.powsybl.iidm.network.Network; import java.util.Locale; +import java.util.Map; import static com.farao_community.farao.commons.logs.FaraoLoggerProvider.*; @@ -93,23 +94,13 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in iteration, input.getObjectiveFunction() ); + lastResult = currentResult; - boolean capPstVariation = parameters.getCapPstVariation(); - if (capPstVariation) { - lastResult = currentResult; - } - if (currentResult.getCost() < bestResult.getCost()) { - logBetterResult(iteration, currentResult); - bestResult = currentResult; - linearProblem.updateBetweenSensiIteration(bestResult.getBranchResult(), bestResult.getSensitivityResult(), bestResult.getRangeActionActivationResult()); + Map mipShouldStop = updateMipAndLogResult(parameters.getCapPstVariation(), linearProblem, input, iteration, currentResult, bestResult); + if (mipShouldStop.containsKey(Boolean.TRUE)) { + return bestResult; } else { - logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); - if (capPstVariation) { - linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); - } else { - return bestResult; - } + bestResult = mipShouldStop.get(Boolean.FALSE); } } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); @@ -232,6 +223,26 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu ); } + private static Map updateMipAndLogResult(boolean capPstVariation, LinearProblem linearProblem, IteratingLinearOptimizerInput input, int iteration, IteratingLinearOptimizationResultImpl currentResult, IteratingLinearOptimizationResultImpl bestResult) { + IteratingLinearOptimizationResultImpl newBestResult; + boolean mipShouldStop = false; + if (currentResult.getCost() < bestResult.getCost()) { + logBetterResult(iteration, currentResult); + newBestResult = currentResult; + linearProblem.updateBetweenSensiIteration(newBestResult.getBranchResult(), newBestResult.getSensitivityResult(), newBestResult.getRangeActionActivationResult()); + } else { + newBestResult = bestResult; + logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); + if (capPstVariation) { + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); + } else { + mipShouldStop = true; + } + } + return Map.of(mipShouldStop, newBestResult); + } + private static void logBetterResult(int iteration, ObjectiveFunctionResult currentObjectiveFunctionResult) { TECHNICAL_LOGS.info( "Iteration {}: better solution found with a cost of {} (functional: {})", From ba98a3689f2ceb97fab7a95fa54951b2bcf9a9d2 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Tue, 30 May 2023 15:13:20 +0200 Subject: [PATCH 18/22] change code according to comments --- .../crac_impl/AbstractRemedialAction.java | 4 +- .../farao/rao_api/RaoParametersConstants.java | 2 +- ...sonRangeActionsOptimizationParameters.java | 6 +- .../RangeActionsOptimizationParameters.java | 8 +-- .../rao_api/json/JsonRaoParametersTest.java | 2 +- .../parameters/RaoParametersConfigTest.java | 2 +- .../RaoParametersYamlConfigTest.java | 6 +- .../test/resources/RaoParametersSet_v2.json | 2 +- .../RaoParametersWithExtension_v2.json | 2 +- .../RaoParameters_config_withExtensions.json | 2 +- .../RaoParameters_config_withOLFParams.json | 2 +- ...rameters_config_withPartialExtensions.json | 2 +- ...aoParameters_config_withoutExtensions.json | 2 +- .../src/test/resources/RaoParameters_v2.json | 2 +- .../config_withPartialExtensions.yml | 2 +- .../resources/config_withoutExtensions.yml | 2 +- .../commons/parameters/TreeParameters.java | 67 +++++++++++-------- .../algorithms/IteratingLinearOptimizer.java | 38 +++++------ .../algorithms/fillers/CoreProblemFiller.java | 22 +++--- .../linear_problem/LinearProblem.java | 24 +++++-- .../LinearProblemIdGenerator.java | 4 +- .../IteratingLinearOptimizerParameters.java | 18 ++--- .../search_tree/algorithms/Leaf.java | 2 +- .../parameters/TreeParametersTest.java | 36 +++++----- .../IteratingLinearOptimizerTest.java | 8 +-- .../search_tree/algorithms/LeafTest.java | 22 +++--- 26 files changed, 155 insertions(+), 134 deletions(-) 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 bb98cd5333..f5b6541a67 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,7 +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 PST_VARIATION_GRADUAL_DECREASE = "pst-range-decrease"; + public static final String PST_RANGE_DECREASE = "pst-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 03b601ebc1..ff995d1ccf 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 @@ -30,7 +30,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); - jsonGenerator.writeObjectField(PST_VARIATION_GRADUAL_DECREASE, parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease()); + jsonGenerator.writeObjectField(PST_RANGE_DECREASE, parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease()); jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); @@ -81,8 +81,8 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); deserializeLinearOptimizationSolver(jsonParser, raoParameters); break; - case PST_VARIATION_GRADUAL_DECREASE: - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(stringToPstVariationGradualDecrease(jsonParser.nextTextValue())); + case PST_RANGE_DECREASE: + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(stringToPstVariationGradualDecrease(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())); 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 9a1d4b0483..050f9e6264 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 @@ -53,7 +53,7 @@ public enum PstModel { public enum PstRangeDecrease { DISABLED, ENABLED, - ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY + ENABLED_IN_FIRST_PRAO_AND_CRAO } public static class LinearOptimizationSolver { @@ -180,11 +180,11 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat this.linearOptimizationSolver = linearOptimizationSolver; } - public void setPstVariationGradualDecrease(PstRangeDecrease pstVariationGradualDecrease) { + public void setPstRangeDecrease(PstRangeDecrease pstVariationGradualDecrease) { this.pstVariationGradualDecrease = pstVariationGradualDecrease; } - public PstRangeDecrease getPstVariationGradualDecrease() { + public PstRangeDecrease getPstRangeDecrease() { return pstVariationGradualDecrease; } @@ -201,7 +201,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.setPstVariationGradualDecrease(config.getEnumProperty(PST_VARIATION_GRADUAL_DECREASE, PstRangeDecrease.class, DEFAULT_PST_DECREASE)); + parameters.setPstRangeDecrease(config.getEnumProperty(PST_RANGE_DECREASE, PstRangeDecrease.class, DEFAULT_PST_DECREASE)); }); 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 2264246a78..8634f84869 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,7 +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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + parameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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 f179e1c887..73a2068381 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,7 +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.PstRangeDecrease.DISABLED, params.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED, params.getPstRangeDecrease()); 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 0699b3c105..7fd8e284a3 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,7 +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.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstRangeDecrease()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -143,7 +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.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstRangeDecrease()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -222,7 +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.PstRangeDecrease.ENABLED, rangeActionsOptimizationParameters.getPstVariationGradualDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED, rangeActionsOptimizationParameters.getPstRangeDecrease()); 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 0dac631c81..b383b8cd3f 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-decrease" : "ENABLED", + "pst-range-shrinking" : "ENABLED", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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 e5e6d31c80..4c8a4ffe83 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-range-decrease" : "DISABLED", + "pst-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 41d4687ca5..39e26d9627 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-decrease" : "DISABLED", + "pst-range-shrinking" : "DISABLED", "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/RaoParameters_config_withOLFParams.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json index e3ebb17995..a9891a69b4 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-range-decrease" : "DISABLED", + "pst-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 c81a9acd6b..50a32ed25e 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-decrease" : "ENABLED", + "pst-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/RaoParameters_config_withoutExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json index da187094dd..858a55f342 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-decrease" : "DISABLED", + "pst-range-shrinking" : "DISABLED", "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/RaoParameters_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json index 80bfc01058..23b500e66c 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-range-decrease" : "DISABLED", + "pst-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 da1f47d682..66a5564284 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withPartialExtensions.yml @@ -8,7 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-range-decrease: ENABLED + pst-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 01ce3ee392..877f0f244f 100644 --- a/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml +++ b/ra-optimisation/rao-api/src/test/resources/config_withoutExtensions.yml @@ -10,7 +10,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-range-decrease: DISABLED + pst-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 199d556391..6bc637dedb 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 @@ -30,18 +30,18 @@ public enum StopCriterion { private final double targetObjectiveValue; private final int maximumSearchDepth; private final int leavesInParallel; - private final boolean capPstVariation; + private final boolean decreasePstRange; public TreeParameters(StopCriterion stopCriterion, double targetObjectiveValue, int maximumSearchDepth, int leavesInParallel, - boolean capPstVariation) { + boolean decreasePstRange) { this.stopCriterion = stopCriterion; this.targetObjectiveValue = targetObjectiveValue; this.maximumSearchDepth = maximumSearchDepth; this.leavesInParallel = leavesInParallel; - this.capPstVariation = capPstVariation; + this.decreasePstRange = decreasePstRange; } public StopCriterion getStopCriterion() { @@ -60,23 +60,30 @@ public int getLeavesInParallel() { return leavesInParallel; } - public boolean getCapPstVariation() { - return capPstVariation; + public boolean getDecreasePstRange() { + return decreasePstRange; } public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) { - StopCriterion stopCriterion = StopCriterion.MIN_OBJECTIVE; - if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE)) { - stopCriterion = StopCriterion.AT_TARGET_OBJECTIVE_VALUE; - } else if (!parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE)) { - throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); + RangeActionsOptimizationParameters.PstRangeDecrease pstRangeDecrease = parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease(); + boolean decreasePstRange = pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO) || + pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.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(), + decreasePstRange); + case SECURE: + return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, + 0.0, // secure + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + decreasePstRange); + default: + throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); } - boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); - return new TreeParameters(stopCriterion, - 0.0, - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - capPstVariation); } public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, Double preventiveOptimizedCost) { @@ -102,27 +109,31 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, default: throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion()); } - boolean capPstVariation = !parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + RangeActionsOptimizationParameters.PstRangeDecrease pstRangeDecrease = parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease(); + boolean decreasePstRange = pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO) || + pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), - capPstVariation); + decreasePstRange); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { - StopCriterion stopCriterion; + boolean decreasePstRange = parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE) - && !parameters.getObjectiveFunctionParameters().getCurativeStopCriterion().equals(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE)) { - stopCriterion = StopCriterion.AT_TARGET_OBJECTIVE_VALUE; + && !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(), + decreasePstRange); } else { - stopCriterion = StopCriterion.MIN_OBJECTIVE; + return new TreeParameters(StopCriterion.MIN_OBJECTIVE, + 0.0, // value does not matter + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), + decreasePstRange); } - boolean capPstVariation = parameters.getRangeActionsOptimizationParameters().getPstVariationGradualDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); - return new TreeParameters(stopCriterion, - 0.0, - parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), - parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - capPstVariation); } } 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 cadca0e8b0..89c59ec21a 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,9 +21,9 @@ 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; -import java.util.Map; import static com.farao_community.farao.commons.logs.FaraoLoggerProvider.*; @@ -45,7 +45,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in 0, input.getObjectiveFunction()); - IteratingLinearOptimizationResultImpl lastResult = bestResult; + IteratingLinearOptimizationResultImpl previousResult = bestResult; SensitivityComputer sensitivityComputer = null; @@ -75,7 +75,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in currentRangeActionActivationResult = resolveIfApproximatedPstTaps(bestResult, linearProblem, iteration, currentRangeActionActivationResult, input, parameters); - if (!hasRemedialActionsChanged(currentRangeActionActivationResult, lastResult, 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; @@ -94,13 +94,13 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in iteration, input.getObjectiveFunction() ); - lastResult = currentResult; + previousResult = currentResult; - Map mipShouldStop = updateMipAndLogResult(parameters.getCapPstVariation(), linearProblem, input, iteration, currentResult, bestResult); - if (mipShouldStop.containsKey(Boolean.TRUE)) { + Pair mipShouldStop = updateBestResultAndCheckStopCondition(parameters.getDecreasePstRange(), linearProblem, input, iteration, currentResult, bestResult); + if (mipShouldStop.getValue().equals(Boolean.TRUE)) { return bestResult; } else { - bestResult = mipShouldStop.get(Boolean.FALSE); + bestResult = mipShouldStop.getKey(); } } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); @@ -223,24 +223,18 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu ); } - private static Map updateMipAndLogResult(boolean capPstVariation, LinearProblem linearProblem, IteratingLinearOptimizerInput input, int iteration, IteratingLinearOptimizationResultImpl currentResult, IteratingLinearOptimizationResultImpl bestResult) { - IteratingLinearOptimizationResultImpl newBestResult; - boolean mipShouldStop = false; + private static Pair updateBestResultAndCheckStopCondition(boolean decreasePstRange, LinearProblem linearProblem, IteratingLinearOptimizerInput input, int iteration, IteratingLinearOptimizationResultImpl currentResult, IteratingLinearOptimizationResultImpl bestResult) { if (currentResult.getCost() < bestResult.getCost()) { logBetterResult(iteration, currentResult); - newBestResult = currentResult; - linearProblem.updateBetweenSensiIteration(newBestResult.getBranchResult(), newBestResult.getSensitivityResult(), newBestResult.getRangeActionActivationResult()); - } else { - newBestResult = bestResult; - logWorseResult(iteration, bestResult, currentResult); - applyRangeActions(bestResult, input); - if (capPstVariation) { - linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); - } else { - mipShouldStop = true; - } + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); + return Pair.of(currentResult, false); + } + logWorseResult(iteration, bestResult, currentResult); + applyRangeActions(bestResult, input); + if (decreasePstRange) { + linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } - return Map.of(mipShouldStop, newBestResult); + return Pair.of(bestResult, !decreasePstRange); } private static void logBetterResult(int iteration, ObjectiveFunctionResult currentObjectiveFunctionResult) { 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 2bf941d8e5..bf0b7cff7c 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,8 +49,8 @@ public class CoreProblemFiller implements ProblemFiller { private final RangeActionActivationResult raActivationFromParentLeaf; private final RangeActionsOptimizationParameters rangeActionParameters; private final Unit unit; - private int iteration; - private static final double RANGE_DIMINUTION_RATE = 0.667; + private int iteration = 0; + private static final double RANGE_DECREASE_RATE = 0.667; public CoreProblemFiller(OptimizationPerimeter optimizationContext, RangeActionSetpointResult prePerimeterRangeActionSetpoints, @@ -258,20 +258,20 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA List minAndMaxAbsoluteAndRelativeSetpoints = getMinAndMaxAbsoluteAndRelativeSetpoints(rangeAction); double minAbsoluteSetpoint = Math.max(minAndMaxAbsoluteAndRelativeSetpoints.get(0), -LinearProblem.infinity()); double maxAbsoluteSetpoint = Math.min(minAndMaxAbsoluteAndRelativeSetpoints.get(1), LinearProblem.infinity()); - double setPointRange = Math.abs(minAbsoluteSetpoint) + Math.abs(maxAbsoluteSetpoint); - double constrainedSetPointRange = setPointRange * Math.pow(RANGE_DIMINUTION_RATE, iteration); - FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, "iterative_shrink"); + double constrainedSetPointRange = (maxAbsoluteSetpoint - minAbsoluteSetpoint) * Math.pow(RANGE_DECREASE_RATE, iteration); + FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, LinearProblem.PstRangeDecrease.TRUE); + double lb = previousSetPointValue - constrainedSetPointRange; + double ub = previousSetPointValue + constrainedSetPointRange; if (iterativeShrink != null) { - iterativeShrink.setLb(previousSetPointValue - constrainedSetPointRange); - iterativeShrink.setUb(previousSetPointValue + constrainedSetPointRange); + 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())); } - FaraoMPConstraint newIterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(-constrainedSetPointRange + previousSetPointValue, - constrainedSetPointRange + previousSetPointValue, rangeAction, state, "iterative_shrink"); - newIterativeShrink.setCoefficient(setPointVariable, 1); + iterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(lb, ub, rangeAction, state, LinearProblem.PstRangeDecrease.TRUE); + iterativeShrink.setCoefficient(setPointVariable, 1); } } @@ -337,7 +337,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.PstRangeDecrease.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 346319f6df..a18e6968a6 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 PstRangeDecrease { + TRUE("iterative-shrink"), + FALSE(""); + + private final String name; + + PstRangeDecrease(String name) { + this.name = name; + } + + @Override + public String toString() { + return name; + } + } + public static LinearProblemBuilder create() { return new LinearProblemBuilder(); } @@ -128,12 +144,12 @@ public FaraoMPVariable getRangeActionSetpointVariable(RangeAction rangeAction return solver.getVariable(rangeActionSetpointVariableId(rangeAction, state)); } - public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state, String string) { - return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, string)); + public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state, PstRangeDecrease pstRangeDecrease) { + return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeDecrease)); } - public FaraoMPConstraint getRangeActionRelativeSetpointConstraint(RangeAction rangeAction, State state, String string) { - return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, string)); + public FaraoMPConstraint getRangeActionRelativeSetpointConstraint(RangeAction rangeAction, State state, PstRangeDecrease pstRangeDecrease) { + return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeDecrease)); } 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 e01a39e8e3..1c70273430 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, String string) { - return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + string + CONSTRAINT_SUFFIX; + public static String rangeActionRelativeSetpointConstraintId(RangeAction rangeAction, State state, LinearProblem.PstRangeDecrease pstRangeDecrease) { + return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + pstRangeDecrease.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 3ce0a7db31..fa59793145 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,7 +32,7 @@ public final class IteratingLinearOptimizerParameters { private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; - private final boolean capPstVariation; + private final boolean decreasePstRange; private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction, RangeActionsOptimizationParameters rangeActionParameters, @@ -43,7 +43,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective RangeActionLimitationParameters raLimitationParameters, RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, int maxNumberOfIterations, - boolean capPstVariation) { + boolean decreasePstRange) { this.objectiveFunction = objectiveFunction; this.rangeActionParameters = rangeActionParameters; this.mnecParameters = mnecParameters; @@ -53,7 +53,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective this.raLimitationParameters = raLimitationParameters; this.solverParameters = solverParameters; this.maxNumberOfIterations = maxNumberOfIterations; - this.capPstVariation = capPstVariation; + this.decreasePstRange = decreasePstRange; } public ObjectiveFunctionParameters.ObjectiveFunctionType getObjectiveFunction() { @@ -113,8 +113,8 @@ public int getMaxNumberOfIterations() { return maxNumberOfIterations; } - public boolean getCapPstVariation() { - return capPstVariation; + public boolean getDecreasePstRange() { + return decreasePstRange; } public static LinearOptimizerParametersBuilder create() { @@ -132,7 +132,7 @@ public static class LinearOptimizerParametersBuilder { private RangeActionLimitationParameters raLimitationParameters; private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; - private boolean capPstVariation; + private boolean decreasePstRange; public LinearOptimizerParametersBuilder withObjectiveFunction(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { this.objectiveFunction = objectiveFunction; @@ -179,8 +179,8 @@ public LinearOptimizerParametersBuilder withMaxNumberOfIterations(int maxNumberO return this; } - public LinearOptimizerParametersBuilder withCapPstVariation(boolean capPstVariation) { - this.capPstVariation = capPstVariation; + public LinearOptimizerParametersBuilder withPstRangeDecrease(boolean decreasePstRange) { + this.decreasePstRange = decreasePstRange; return this; } @@ -199,7 +199,7 @@ public IteratingLinearOptimizerParameters build() { raLimitationParameters, solverParameters, maxNumberOfIterations, - capPstVariation); + decreasePstRange); } } } 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 ea59e39166..c3a6fee818 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,7 +215,7 @@ void optimize(SearchTreeInput searchTreeInput, SearchTreeParameters parameters) .withRaLimitationParameters(getRaLimitationParameters(searchTreeInput.getOptimizationPerimeter(), parameters)) .withSolverParameters(parameters.getSolverParameters()) .withMaxNumberOfIterations(parameters.getMaxNumberOfIterations()) - .withCapPstVariation(parameters.getTreeParameters().getCapPstVariation()) + .withPstRangeDecrease(parameters.getTreeParameters().getDecreasePstRange()) .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 c80384737d..f5a5eb8acd 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 @@ -28,7 +28,7 @@ public void setUp() { raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(6); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); } @Test @@ -40,51 +40,51 @@ void testPreventive() { assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertFalse(treeParameters.getCapPstVariation()); + assertFalse(treeParameters.getDecreasePstRange()); // 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().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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.getCapPstVariation()); + assertTrue(treeParameters.getDecreasePstRange()); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); - assertTrue(treeParameters.getCapPstVariation()); + assertTrue(treeParameters.getDecreasePstRange()); } @Test void testCurativeMinObjective() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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.getCapPstVariation()); + assertFalse(treeParameters.getDecreasePstRange()); } @Test void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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.getCapPstVariation()); + assertTrue(treeParameters.getDecreasePstRange()); } @Test @@ -92,14 +92,14 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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.getCapPstVariation()); + assertTrue(treeParameters.getDecreasePstRange()); } @Test @@ -134,36 +134,36 @@ void testSecondPreventive() { // test with min objective raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); TreeParameters treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertFalse(treeParameters.getCapPstVariation()); + assertFalse(treeParameters.getDecreasePstRange()); // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_FOR_FIRST_PREVENTIVE_AND_CURATIVE_ONLY); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.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.getCapPstVariation()); + assertFalse(treeParameters.getDecreasePstRange()); // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstVariationGradualDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertTrue(treeParameters.getCapPstVariation()); + assertTrue(treeParameters.getDecreasePstRange()); // 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 dcfb9d5d11..377837cc1f 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 @@ -99,7 +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.getCapPstVariation()).thenReturn(false); + when(parameters.getDecreasePstRange()).thenReturn(false); linearProblem = Mockito.mock(LinearProblem.class); network = Mockito.mock(Network.class); @@ -217,7 +217,7 @@ void secondLinearProblemDoesNotChangeSetPoint() { @Test void linearProblemDegradesTheSolutionButKeepsBestIteration() { - when(parameters.getCapPstVariation()).thenReturn(true); + when(parameters.getDecreasePstRange()).thenReturn(true); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); mockFunctionalCost(100., 150., 140., 130., 120., 110.); prepareLinearProblemBuilder(); @@ -246,7 +246,7 @@ void linearProblemDegradesTheSolution() { @Test void linearProblemFluctuatesButKeepsBestIteration() { - when(parameters.getCapPstVariation()).thenReturn(true); + when(parameters.getDecreasePstRange()).thenReturn(true); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); mockFunctionalCost(100., 120., 105., 90., 100., 95.); prepareLinearProblemBuilder(); @@ -307,7 +307,7 @@ void optimizeWithSensitivityComputationFailure() { @Test void testUnapplyRangeAction() { - when(parameters.getCapPstVariation()).thenReturn(true); + when(parameters.getDecreasePstRange()).thenReturn(true); network = NetworkImportsUtil.import12NodesNetwork(); when(input.getNetwork()).thenReturn(network); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); 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 ceb4ea21e1..016eb4b36e 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 @@ -309,7 +309,7 @@ void optimize() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); rootLeaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(Leaf.Status.OPTIMIZED, rootLeaf.getStatus()); } @@ -356,7 +356,7 @@ void getFlowsAndPtdfsOnFlowCnecAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -426,7 +426,7 @@ void getFunctionalCostAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedFunctionalCost = 3.; @@ -462,7 +462,7 @@ void getVirtualCostAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedVirtualCost = 3.; @@ -507,7 +507,7 @@ void getCostlyAndMostLimitingElementsAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); @@ -585,7 +585,7 @@ void getRangeActionsAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -670,7 +670,7 @@ void getSensitivityStatusAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); leaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(sensitivityStatus, leaf.getSensitivityStatus()); @@ -707,7 +707,7 @@ void getSensitivityValueAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -755,7 +755,7 @@ void getObjectiveFunctionAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -775,7 +775,7 @@ void testFinalize() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(Mockito.mock(IteratingLinearOptimizationResultImpl.class)); rootLeaf.optimize(searchTreeInput, searchTreeParameters); rootLeaf.finalizeOptimization(); @@ -804,7 +804,7 @@ void testToStringOnRootLeaf() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getCapPstVariation()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); when(linearOptimizationResult.getCost()).thenReturn(-100.5); From 6171578c61d6c5a28d1a848ad8760fe0db480cc1 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 2 Jun 2023 17:59:59 +0200 Subject: [PATCH 19/22] change DECREASE to SHRINKING in the code --- .../farao/rao_api/RaoParametersConstants.java | 2 +- ...sonRangeActionsOptimizationParameters.java | 12 +++---- .../RangeActionsOptimizationParameters.java | 16 ++++----- .../rao_api/json/JsonRaoParametersTest.java | 2 +- .../parameters/RaoParametersConfigTest.java | 2 +- .../RaoParametersYamlConfigTest.java | 6 ++-- .../commons/parameters/TreeParameters.java | 34 +++++++++--------- .../algorithms/IteratingLinearOptimizer.java | 12 +++---- .../algorithms/fillers/CoreProblemFiller.java | 14 +++----- .../linear_problem/LinearProblem.java | 12 +++---- .../LinearProblemIdGenerator.java | 4 +-- .../IteratingLinearOptimizerParameters.java | 18 +++++----- .../search_tree/algorithms/Leaf.java | 2 +- .../parameters/TreeParametersTest.java | 36 +++++++++---------- .../IteratingLinearOptimizerTest.java | 8 ++--- .../search_tree/algorithms/LeafTest.java | 22 ++++++------ 16 files changed, 99 insertions(+), 103 deletions(-) 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 f5b6541a67..798727a2de 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,7 +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 PST_RANGE_DECREASE = "pst-range-shrinking"; + public static final String PST_RANGE_SHRINKING = "pst-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 ff995d1ccf..62efeb4d91 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 @@ -30,7 +30,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); - jsonGenerator.writeObjectField(PST_RANGE_DECREASE, parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease()); + jsonGenerator.writeObjectField(PST_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking()); jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); @@ -81,8 +81,8 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); deserializeLinearOptimizationSolver(jsonParser, raoParameters); break; - case PST_RANGE_DECREASE: - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(stringToPstVariationGradualDecrease(jsonParser.nextTextValue())); + case PST_RANGE_SHRINKING: + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(stringToPstRangeShrinking(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())); @@ -118,11 +118,11 @@ private static RangeActionsOptimizationParameters.PstModel stringToPstModel(Stri } } - private static RangeActionsOptimizationParameters.PstRangeDecrease stringToPstVariationGradualDecrease(String string) { + private static RangeActionsOptimizationParameters.PstRangeShrinking stringToPstRangeShrinking(String string) { try { - return RangeActionsOptimizationParameters.PstRangeDecrease.valueOf(string); + return RangeActionsOptimizationParameters.PstRangeShrinking.valueOf(string); } catch (IllegalArgumentException e) { - throw new FaraoException(String.format("Unknown Pst variation gradual decrease: %s", string)); + throw new FaraoException(String.format("Unknown Pst variation range shrinking: %s", 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 050f9e6264..0bc79443db 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,7 +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 PstRangeDecrease DEFAULT_PST_DECREASE = PstRangeDecrease.DISABLED; + private static final PstRangeShrinking DEFAULT_PST_RANGE_SHRINKING = PstRangeShrinking.DISABLED; // Attributes private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS; private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST; @@ -41,7 +41,7 @@ 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 PstRangeDecrease pstVariationGradualDecrease = DEFAULT_PST_DECREASE; + private PstRangeShrinking pstRangeShrinking = DEFAULT_PST_RANGE_SHRINKING; // Enum public enum PstModel { @@ -50,7 +50,7 @@ public enum PstModel { } // Refactor these names - public enum PstRangeDecrease { + public enum PstRangeShrinking { DISABLED, ENABLED, ENABLED_IN_FIRST_PRAO_AND_CRAO @@ -180,12 +180,12 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat this.linearOptimizationSolver = linearOptimizationSolver; } - public void setPstRangeDecrease(PstRangeDecrease pstVariationGradualDecrease) { - this.pstVariationGradualDecrease = pstVariationGradualDecrease; + public void setPstRangeShrinking(PstRangeShrinking pstRangeShrinking) { + this.pstRangeShrinking = pstRangeShrinking; } - public PstRangeDecrease getPstRangeDecrease() { - return pstVariationGradualDecrease; + public PstRangeShrinking getPstRangeShrinking() { + return pstRangeShrinking; } public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { @@ -201,7 +201,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.setPstRangeDecrease(config.getEnumProperty(PST_RANGE_DECREASE, PstRangeDecrease.class, DEFAULT_PST_DECREASE)); + parameters.setPstRangeShrinking(config.getEnumProperty(PST_RANGE_SHRINKING, PstRangeShrinking.class, DEFAULT_PST_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 8634f84869..d499c4851c 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,7 +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().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + parameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.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 73a2068381..604fd70e23 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,7 +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.PstRangeDecrease.DISABLED, params.getPstRangeDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED, params.getPstRangeShrinking()); 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 7fd8e284a3..909fa639c7 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,7 +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.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstRangeDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getPstRangeShrinking()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -143,7 +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.PstRangeDecrease.DISABLED, rangeActionsOptimizationParameters.getPstRangeDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getPstRangeShrinking()); assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE); assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE); assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE); @@ -222,7 +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.PstRangeDecrease.ENABLED, rangeActionsOptimizationParameters.getPstRangeDecrease()); + assertEquals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED, rangeActionsOptimizationParameters.getPstRangeShrinking()); 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/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 6bc637dedb..3a6c9947e1 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 @@ -30,18 +30,18 @@ public enum StopCriterion { private final double targetObjectiveValue; private final int maximumSearchDepth; private final int leavesInParallel; - private final boolean decreasePstRange; + private final boolean pstRangeShrinking; public TreeParameters(StopCriterion stopCriterion, double targetObjectiveValue, int maximumSearchDepth, int leavesInParallel, - boolean decreasePstRange) { + boolean pstRangeShrinking) { this.stopCriterion = stopCriterion; this.targetObjectiveValue = targetObjectiveValue; this.maximumSearchDepth = maximumSearchDepth; this.leavesInParallel = leavesInParallel; - this.decreasePstRange = decreasePstRange; + this.pstRangeShrinking = pstRangeShrinking; } public StopCriterion getStopCriterion() { @@ -60,27 +60,27 @@ public int getLeavesInParallel() { return leavesInParallel; } - public boolean getDecreasePstRange() { - return decreasePstRange; + public boolean getPstRangeShrinking() { + return pstRangeShrinking; } public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) { - RangeActionsOptimizationParameters.PstRangeDecrease pstRangeDecrease = parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease(); - boolean decreasePstRange = pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO) || - pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + RangeActionsOptimizationParameters.PstRangeShrinking pstRangeShrinking = parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking(); + boolean shouldShrinkPstRange = pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || + pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.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(), - decreasePstRange); + shouldShrinkPstRange); case SECURE: return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, // secure parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - decreasePstRange); + shouldShrinkPstRange); default: throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); } @@ -109,31 +109,31 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, default: throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion()); } - RangeActionsOptimizationParameters.PstRangeDecrease pstRangeDecrease = parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease(); - boolean decreasePstRange = pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO) || - pstRangeDecrease.equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + RangeActionsOptimizationParameters.PstRangeShrinking pstRangeShrinking = parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking(); + boolean shouldShrinkPstRange = pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || + pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); return new TreeParameters(stopCriterion, targetObjectiveValue, parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), - decreasePstRange); + shouldShrinkPstRange); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { - boolean decreasePstRange = parameters.getRangeActionsOptimizationParameters().getPstRangeDecrease().equals(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + boolean pstRangeShrinking = parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking().equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE) && !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(), - decreasePstRange); + pstRangeShrinking); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - decreasePstRange); + pstRangeShrinking); } } } 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 89c59ec21a..b8154159ba 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 @@ -96,11 +96,11 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in ); previousResult = currentResult; - Pair mipShouldStop = updateBestResultAndCheckStopCondition(parameters.getDecreasePstRange(), linearProblem, input, iteration, currentResult, bestResult); - if (mipShouldStop.getValue().equals(Boolean.TRUE)) { + Pair mipShouldStop = updateBestResultAndCheckStopCondition(parameters.getPstRangeShrinking(), linearProblem, input, iteration, currentResult, bestResult); + if (mipShouldStop.getRight()) { return bestResult; } else { - bestResult = mipShouldStop.getKey(); + bestResult = mipShouldStop.getLeft(); } } bestResult.setStatus(LinearProblemStatus.MAX_ITERATION_REACHED); @@ -223,7 +223,7 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu ); } - private static Pair updateBestResultAndCheckStopCondition(boolean decreasePstRange, LinearProblem linearProblem, IteratingLinearOptimizerInput input, int iteration, IteratingLinearOptimizationResultImpl currentResult, IteratingLinearOptimizationResultImpl bestResult) { + private static Pair updateBestResultAndCheckStopCondition(boolean pstRangeShrinking, 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()); @@ -231,10 +231,10 @@ private static Pair updateBestRe } logWorseResult(iteration, bestResult, currentResult); applyRangeActions(bestResult, input); - if (decreasePstRange) { + if (pstRangeShrinking) { linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } - return Pair.of(bestResult, !decreasePstRange); + return Pair.of(bestResult, !pstRangeShrinking); } private static void logBetterResult(int iteration, ObjectiveFunctionResult currentObjectiveFunctionResult) { 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 bf0b7cff7c..3af71fb969 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 @@ -245,12 +245,8 @@ private void buildRangeActionConstraints(LinearProblem linearProblem) { private void updateRangeActionConstraints(LinearProblem linearProblem, RangeActionActivationResult rangeActionActivationResult) { iteration++; - optimizationContext.getRangeActionsPerState().entrySet().stream() - .sorted(Comparator.comparingInt(e -> e.getKey().getInstant().getOrder())) - .forEach(entry -> - entry.getValue().forEach(rangeAction -> updateConstraintsForRangeAction(linearProblem, rangeAction, entry.getKey(), 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) { @@ -259,7 +255,7 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA 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_DECREASE_RATE, iteration); - FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, LinearProblem.PstRangeDecrease.TRUE); + FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, LinearProblem.PstRangeShrinking.TRUE); double lb = previousSetPointValue - constrainedSetPointRange; double ub = previousSetPointValue + constrainedSetPointRange; if (iterativeShrink != null) { @@ -270,7 +266,7 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA 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.PstRangeDecrease.TRUE); + iterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(lb, ub, rangeAction, state, LinearProblem.PstRangeShrinking.TRUE); iterativeShrink.setCoefficient(setPointVariable, 1); } } @@ -337,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, LinearProblem.PstRangeDecrease.FALSE); + FaraoMPConstraint relSetpointConstraint = linearProblem.addRangeActionRelativeSetpointConstraint(minRelativeSetpoint, maxRelativeSetpoint, rangeAction, state, LinearProblem.PstRangeShrinking.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 a18e6968a6..105d125ea1 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,13 +58,13 @@ public enum BoundExtension { UPPER_BOUND } - public enum PstRangeDecrease { + public enum PstRangeShrinking { TRUE("iterative-shrink"), FALSE(""); private final String name; - PstRangeDecrease(String name) { + PstRangeShrinking(String name) { this.name = name; } @@ -144,12 +144,12 @@ public FaraoMPVariable getRangeActionSetpointVariable(RangeAction rangeAction return solver.getVariable(rangeActionSetpointVariableId(rangeAction, state)); } - public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state, PstRangeDecrease pstRangeDecrease) { - return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeDecrease)); + public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state, PstRangeShrinking pstRangeShrinking) { + return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeShrinking)); } - public FaraoMPConstraint getRangeActionRelativeSetpointConstraint(RangeAction rangeAction, State state, PstRangeDecrease pstRangeDecrease) { - return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeDecrease)); + public FaraoMPConstraint getRangeActionRelativeSetpointConstraint(RangeAction rangeAction, State state, PstRangeShrinking pstRangeShrinking) { + return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeShrinking)); } 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 1c70273430..98fbdb1180 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, LinearProblem.PstRangeDecrease pstRangeDecrease) { - return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + pstRangeDecrease.toString() + CONSTRAINT_SUFFIX; + public static String rangeActionRelativeSetpointConstraintId(RangeAction rangeAction, State state, LinearProblem.PstRangeShrinking pstRangeShrinking) { + return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + pstRangeShrinking.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 fa59793145..7169b5b1c6 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,7 +32,7 @@ public final class IteratingLinearOptimizerParameters { private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; - private final boolean decreasePstRange; + private final boolean pstRangeShrinking; private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction, RangeActionsOptimizationParameters rangeActionParameters, @@ -43,7 +43,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective RangeActionLimitationParameters raLimitationParameters, RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, int maxNumberOfIterations, - boolean decreasePstRange) { + boolean pstRangeShrinking) { this.objectiveFunction = objectiveFunction; this.rangeActionParameters = rangeActionParameters; this.mnecParameters = mnecParameters; @@ -53,7 +53,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective this.raLimitationParameters = raLimitationParameters; this.solverParameters = solverParameters; this.maxNumberOfIterations = maxNumberOfIterations; - this.decreasePstRange = decreasePstRange; + this.pstRangeShrinking = pstRangeShrinking; } public ObjectiveFunctionParameters.ObjectiveFunctionType getObjectiveFunction() { @@ -113,8 +113,8 @@ public int getMaxNumberOfIterations() { return maxNumberOfIterations; } - public boolean getDecreasePstRange() { - return decreasePstRange; + public boolean getPstRangeShrinking() { + return pstRangeShrinking; } public static LinearOptimizerParametersBuilder create() { @@ -132,7 +132,7 @@ public static class LinearOptimizerParametersBuilder { private RangeActionLimitationParameters raLimitationParameters; private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; - private boolean decreasePstRange; + private boolean pstRangeShrinking; public LinearOptimizerParametersBuilder withObjectiveFunction(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { this.objectiveFunction = objectiveFunction; @@ -179,8 +179,8 @@ public LinearOptimizerParametersBuilder withMaxNumberOfIterations(int maxNumberO return this; } - public LinearOptimizerParametersBuilder withPstRangeDecrease(boolean decreasePstRange) { - this.decreasePstRange = decreasePstRange; + public LinearOptimizerParametersBuilder withPstRangeShrinking(boolean pstRangeShrinking) { + this.pstRangeShrinking = pstRangeShrinking; return this; } @@ -199,7 +199,7 @@ public IteratingLinearOptimizerParameters build() { raLimitationParameters, solverParameters, maxNumberOfIterations, - decreasePstRange); + pstRangeShrinking); } } } 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 c3a6fee818..561debd791 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,7 +215,7 @@ void optimize(SearchTreeInput searchTreeInput, SearchTreeParameters parameters) .withRaLimitationParameters(getRaLimitationParameters(searchTreeInput.getOptimizationPerimeter(), parameters)) .withSolverParameters(parameters.getSolverParameters()) .withMaxNumberOfIterations(parameters.getMaxNumberOfIterations()) - .withPstRangeDecrease(parameters.getTreeParameters().getDecreasePstRange()) + .withPstRangeShrinking(parameters.getTreeParameters().getPstRangeShrinking()) .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 f5a5eb8acd..bd2d300c15 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 @@ -28,7 +28,7 @@ public void setUp() { raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(6); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED); } @Test @@ -40,51 +40,51 @@ void testPreventive() { assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertFalse(treeParameters.getDecreasePstRange()); + assertFalse(treeParameters.getPstRangeShrinking()); // 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().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.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.getDecreasePstRange()); + assertTrue(treeParameters.getPstRangeShrinking()); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); - assertTrue(treeParameters.getDecreasePstRange()); + assertTrue(treeParameters.getPstRangeShrinking()); } @Test void testCurativeMinObjective() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.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.getDecreasePstRange()); + assertFalse(treeParameters.getPstRangeShrinking()); } @Test void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.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.getDecreasePstRange()); + assertTrue(treeParameters.getPstRangeShrinking()); } @Test @@ -92,14 +92,14 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.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.getDecreasePstRange()); + assertTrue(treeParameters.getPstRangeShrinking()); } @Test @@ -134,36 +134,36 @@ void testSecondPreventive() { // test with min objective raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED); TreeParameters treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertFalse(treeParameters.getDecreasePstRange()); + assertFalse(treeParameters.getPstRangeShrinking()); // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED_IN_FIRST_PRAO_AND_CRAO); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.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.getDecreasePstRange()); + assertFalse(treeParameters.getPstRangeShrinking()); // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeDecrease(RangeActionsOptimizationParameters.PstRangeDecrease.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForSecondPreventivePerimeter(raoParameters); assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertTrue(treeParameters.getDecreasePstRange()); + assertTrue(treeParameters.getPstRangeShrinking()); // 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 377837cc1f..b73f8ebf73 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 @@ -99,7 +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.getDecreasePstRange()).thenReturn(false); + when(parameters.getPstRangeShrinking()).thenReturn(false); linearProblem = Mockito.mock(LinearProblem.class); network = Mockito.mock(Network.class); @@ -217,7 +217,7 @@ void secondLinearProblemDoesNotChangeSetPoint() { @Test void linearProblemDegradesTheSolutionButKeepsBestIteration() { - when(parameters.getDecreasePstRange()).thenReturn(true); + when(parameters.getPstRangeShrinking()).thenReturn(true); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); mockFunctionalCost(100., 150., 140., 130., 120., 110.); prepareLinearProblemBuilder(); @@ -246,7 +246,7 @@ void linearProblemDegradesTheSolution() { @Test void linearProblemFluctuatesButKeepsBestIteration() { - when(parameters.getDecreasePstRange()).thenReturn(true); + when(parameters.getPstRangeShrinking()).thenReturn(true); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); mockFunctionalCost(100., 120., 105., 90., 100., 95.); prepareLinearProblemBuilder(); @@ -307,7 +307,7 @@ void optimizeWithSensitivityComputationFailure() { @Test void testUnapplyRangeAction() { - when(parameters.getDecreasePstRange()).thenReturn(true); + when(parameters.getPstRangeShrinking()).thenReturn(true); network = NetworkImportsUtil.import12NodesNetwork(); when(input.getNetwork()).thenReturn(network); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); 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 016eb4b36e..bd2a72cf6b 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 @@ -309,7 +309,7 @@ void optimize() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); rootLeaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(Leaf.Status.OPTIMIZED, rootLeaf.getStatus()); } @@ -356,7 +356,7 @@ void getFlowsAndPtdfsOnFlowCnecAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -426,7 +426,7 @@ void getFunctionalCostAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedFunctionalCost = 3.; @@ -462,7 +462,7 @@ void getVirtualCostAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedVirtualCost = 3.; @@ -507,7 +507,7 @@ void getCostlyAndMostLimitingElementsAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); @@ -585,7 +585,7 @@ void getRangeActionsAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -670,7 +670,7 @@ void getSensitivityStatusAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); leaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(sensitivityStatus, leaf.getSensitivityStatus()); @@ -707,7 +707,7 @@ void getSensitivityValueAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -755,7 +755,7 @@ void getObjectiveFunctionAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -775,7 +775,7 @@ void testFinalize() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(Mockito.mock(IteratingLinearOptimizationResultImpl.class)); rootLeaf.optimize(searchTreeInput, searchTreeParameters); rootLeaf.finalizeOptimization(); @@ -804,7 +804,7 @@ void testToStringOnRootLeaf() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getDecreasePstRange()).thenReturn(false); + when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); when(linearOptimizationResult.getCost()).thenReturn(-100.5); From 69a1325167e301d1f7824bf73c8dbce409553dc0 Mon Sep 17 00:00:00 2001 From: belthlemar Date: Fri, 2 Jun 2023 18:14:47 +0200 Subject: [PATCH 20/22] remove useless mock in LeafTest.java --- .../search_tree/algorithms/LeafTest.java | 11 ----------- 1 file changed, 11 deletions(-) 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 bd2a72cf6b..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 @@ -309,7 +309,6 @@ void optimize() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); rootLeaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(Leaf.Status.OPTIMIZED, rootLeaf.getStatus()); } @@ -356,7 +355,6 @@ void getFlowsAndPtdfsOnFlowCnecAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -426,7 +424,6 @@ void getFunctionalCostAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedFunctionalCost = 3.; @@ -462,7 +459,6 @@ void getVirtualCostAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); double expectedVirtualCost = 3.; @@ -507,7 +503,6 @@ void getCostlyAndMostLimitingElementsAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); FlowCnec flowCnec = Mockito.mock(FlowCnec.class); @@ -585,7 +580,6 @@ void getRangeActionsAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -670,7 +664,6 @@ void getSensitivityStatusAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); leaf.optimize(searchTreeInput, searchTreeParameters); assertEquals(sensitivityStatus, leaf.getSensitivityStatus()); @@ -707,7 +700,6 @@ void getSensitivityValueAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -755,7 +747,6 @@ void getObjectiveFunctionAfterOptimization() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); @@ -775,7 +766,6 @@ void testFinalize() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(Mockito.mock(IteratingLinearOptimizationResultImpl.class)); rootLeaf.optimize(searchTreeInput, searchTreeParameters); rootLeaf.finalizeOptimization(); @@ -804,7 +794,6 @@ void testToStringOnRootLeaf() { SearchTreeParameters searchTreeParameters = Mockito.mock(SearchTreeParameters.class); when(searchTreeParameters.getObjectiveFunction()).thenReturn(Mockito.mock(ObjectiveFunctionParameters.ObjectiveFunctionType.class)); when(searchTreeParameters.getTreeParameters()).thenReturn(Mockito.mock(TreeParameters.class)); - when(searchTreeParameters.getTreeParameters().getPstRangeShrinking()).thenReturn(false); prepareLinearProblemBuilder(linearOptimizationResult); leaf.optimize(searchTreeInput, searchTreeParameters); when(linearOptimizationResult.getCost()).thenReturn(-100.5); From 970e9e23036346ff41ed79bd7ffc3ceec4492f34 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Mon, 5 Jun 2023 11:14:58 +0200 Subject: [PATCH 21/22] rename --- .../farao/rao_api/RaoParametersConstants.java | 2 +- ...sonRangeActionsOptimizationParameters.java | 10 ++--- .../RangeActionsOptimizationParameters.java | 18 ++++---- .../rao_api/json/JsonRaoParametersTest.java | 2 +- .../parameters/RaoParametersConfigTest.java | 2 +- .../RaoParametersYamlConfigTest.java | 6 +-- .../test/resources/RaoParametersSet_v2.json | 2 +- .../RaoParametersWithExtension_v2.json | 2 +- .../RaoParameters_config_withExtensions.json | 2 +- .../RaoParameters_config_withOLFParams.json | 2 +- ...rameters_config_withPartialExtensions.json | 2 +- ...aoParameters_config_withoutExtensions.json | 2 +- .../src/test/resources/RaoParameters_v2.json | 2 +- .../config_withPartialExtensions.yml | 2 +- .../resources/config_withoutExtensions.yml | 2 +- .../commons/parameters/TreeParameters.java | 44 +++++++++---------- .../algorithms/IteratingLinearOptimizer.java | 8 ++-- .../algorithms/fillers/CoreProblemFiller.java | 10 ++--- .../linear_problem/LinearProblem.java | 12 ++--- .../LinearProblemIdGenerator.java | 4 +- .../IteratingLinearOptimizerParameters.java | 18 ++++---- .../search_tree/algorithms/Leaf.java | 2 +- .../parameters/TreeParametersTest.java | 36 +++++++-------- .../IteratingLinearOptimizerTest.java | 8 ++-- 24 files changed, 99 insertions(+), 101 deletions(-) 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 798727a2de..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,7 +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 PST_RANGE_SHRINKING = "pst-range-shrinking"; + 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 62efeb4d91..5f4fafe6be 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 @@ -30,7 +30,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); - jsonGenerator.writeObjectField(PST_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking()); + jsonGenerator.writeObjectField(RA_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); @@ -81,8 +81,8 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro jsonParser.nextToken(); deserializeLinearOptimizationSolver(jsonParser, raoParameters); break; - case PST_RANGE_SHRINKING: - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(stringToPstRangeShrinking(jsonParser.nextTextValue())); + 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())); @@ -118,9 +118,9 @@ private static RangeActionsOptimizationParameters.PstModel stringToPstModel(Stri } } - private static RangeActionsOptimizationParameters.PstRangeShrinking stringToPstRangeShrinking(String string) { + private static RangeActionsOptimizationParameters.RaRangeShrinking stringToRaRangeShrinking(String string) { try { - return RangeActionsOptimizationParameters.PstRangeShrinking.valueOf(string); + return RangeActionsOptimizationParameters.RaRangeShrinking.valueOf(string); } catch (IllegalArgumentException e) { throw new FaraoException(String.format("Unknown Pst variation range shrinking: %s", 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 0bc79443db..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,7 +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 PstRangeShrinking DEFAULT_PST_RANGE_SHRINKING = PstRangeShrinking.DISABLED; + 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; @@ -41,16 +41,14 @@ 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 PstRangeShrinking pstRangeShrinking = DEFAULT_PST_RANGE_SHRINKING; + private RaRangeShrinking raRangeShrinking = DEFAULT_RA_RANGE_SHRINKING; - // Enum public enum PstModel { CONTINUOUS, APPROXIMATED_INTEGERS } - // Refactor these names - public enum PstRangeShrinking { + public enum RaRangeShrinking { DISABLED, ENABLED, ENABLED_IN_FIRST_PRAO_AND_CRAO @@ -180,12 +178,12 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat this.linearOptimizationSolver = linearOptimizationSolver; } - public void setPstRangeShrinking(PstRangeShrinking pstRangeShrinking) { - this.pstRangeShrinking = pstRangeShrinking; + public void setRaRangeShrinking(RaRangeShrinking raRangeShrinking) { + this.raRangeShrinking = raRangeShrinking; } - public PstRangeShrinking getPstRangeShrinking() { - return pstRangeShrinking; + public RaRangeShrinking getRaRangeShrinking() { + return raRangeShrinking; } public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) { @@ -201,7 +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.setPstRangeShrinking(config.getEnumProperty(PST_RANGE_SHRINKING, PstRangeShrinking.class, DEFAULT_PST_RANGE_SHRINKING)); + 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 d499c4851c..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,7 +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().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + 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 604fd70e23..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,7 +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.PstRangeShrinking.DISABLED, params.getPstRangeShrinking()); + 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 909fa639c7..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,7 +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.PstRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getPstRangeShrinking()); + 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); @@ -143,7 +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.PstRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getPstRangeShrinking()); + 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); @@ -222,7 +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.PstRangeShrinking.ENABLED, rangeActionsOptimizationParameters.getPstRangeShrinking()); + 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 b383b8cd3f..bf223361de 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-shrinking" : "ENABLED", + "ra-range-shrinking" : "ENABLED", "hvdc-penalty-cost" : 1.0, "hvdc-sensitivity-threshold" : 0.3, "injection-ra-penalty-cost" : 1.2, 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 4c8a4ffe83..0a30a5818e 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-range-shrinking" : "DISABLED", + "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 39e26d9627..2e9e272a1d 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-shrinking" : "DISABLED", + "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/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withOLFParams.json index a9891a69b4..a1e973aba6 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-range-shrinking" : "DISABLED", + "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 50a32ed25e..972257075a 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-shrinking" : "ENABLED", + "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/RaoParameters_config_withoutExtensions.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_config_withoutExtensions.json index 858a55f342..113b72f223 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 @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "pst-range-shrinking" : "DISABLED", + "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/rao-api/src/test/resources/RaoParameters_v2.json b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json index 23b500e66c..8ba921ac14 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -12,7 +12,7 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "pst-range-shrinking" : "DISABLED", + "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "hvdc-sensitivity-threshold" : 0.0, "injection-ra-penalty-cost" : 0.001, 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 66a5564284..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,7 +8,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-range-shrinking: ENABLED + 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 877f0f244f..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,7 +10,7 @@ rao-range-actions-optimization: pst-penalty-cost: 0.02 pst-sensitivity-threshold: 0.2 pst-model: APPROXIMATED_INTEGERS - pst-range-shrinking: DISABLED + 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 3a6c9947e1..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 @@ -30,18 +30,18 @@ public enum StopCriterion { private final double targetObjectiveValue; private final int maximumSearchDepth; private final int leavesInParallel; - private final boolean pstRangeShrinking; + private final boolean raRangeShrinking; public TreeParameters(StopCriterion stopCriterion, - double targetObjectiveValue, - int maximumSearchDepth, - int leavesInParallel, - boolean pstRangeShrinking) { + double targetObjectiveValue, + int maximumSearchDepth, + int leavesInParallel, + boolean raRangeShrinking) { this.stopCriterion = stopCriterion; this.targetObjectiveValue = targetObjectiveValue; this.maximumSearchDepth = maximumSearchDepth; this.leavesInParallel = leavesInParallel; - this.pstRangeShrinking = pstRangeShrinking; + this.raRangeShrinking = raRangeShrinking; } public StopCriterion getStopCriterion() { @@ -60,27 +60,27 @@ public int getLeavesInParallel() { return leavesInParallel; } - public boolean getPstRangeShrinking() { - return pstRangeShrinking; + public boolean getRaRangeShrinking() { + return raRangeShrinking; } public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) { - RangeActionsOptimizationParameters.PstRangeShrinking pstRangeShrinking = parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking(); - boolean shouldShrinkPstRange = pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || - pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + 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(), - shouldShrinkPstRange); + shouldShrinkRaRange); case SECURE: return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, // secure parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - shouldShrinkPstRange); + shouldShrinkRaRange); default: throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()); } @@ -109,31 +109,31 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters, default: throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion()); } - RangeActionsOptimizationParameters.PstRangeShrinking pstRangeShrinking = parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking(); - boolean shouldShrinkPstRange = pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) || - pstRangeShrinking.equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + 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(), - shouldShrinkPstRange); + parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), + parameters.getMultithreadingParameters().getCurativeLeavesInParallel(), + shouldShrinkRaRange); } public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) { - boolean pstRangeShrinking = parameters.getRangeActionsOptimizationParameters().getPstRangeShrinking().equals(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + 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)) { return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE, 0.0, // secure parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - pstRangeShrinking); + raRangeShrinking); } else { return new TreeParameters(StopCriterion.MIN_OBJECTIVE, 0.0, // value does not matter parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(), parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(), - pstRangeShrinking); + 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 b8154159ba..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 @@ -96,7 +96,7 @@ public static LinearOptimizationResult optimize(IteratingLinearOptimizerInput in ); previousResult = currentResult; - Pair mipShouldStop = updateBestResultAndCheckStopCondition(parameters.getPstRangeShrinking(), linearProblem, input, iteration, currentResult, bestResult); + Pair mipShouldStop = updateBestResultAndCheckStopCondition(parameters.getRaRangeShrinking(), linearProblem, input, iteration, currentResult, bestResult); if (mipShouldStop.getRight()) { return bestResult; } else { @@ -223,7 +223,7 @@ private static RangeActionActivationResult roundResult(RangeActionActivationResu ); } - private static Pair updateBestResultAndCheckStopCondition(boolean pstRangeShrinking, LinearProblem linearProblem, IteratingLinearOptimizerInput input, int iteration, IteratingLinearOptimizationResultImpl currentResult, IteratingLinearOptimizationResultImpl bestResult) { + 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()); @@ -231,10 +231,10 @@ private static Pair updateBestRe } logWorseResult(iteration, bestResult, currentResult); applyRangeActions(bestResult, input); - if (pstRangeShrinking) { + if (raRangeShrinking) { linearProblem.updateBetweenSensiIteration(currentResult.getBranchResult(), currentResult.getSensitivityResult(), currentResult.getRangeActionActivationResult()); } - return Pair.of(bestResult, !pstRangeShrinking); + return Pair.of(bestResult, !raRangeShrinking); } private static void logBetterResult(int iteration, ObjectiveFunctionResult currentObjectiveFunctionResult) { 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 3af71fb969..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 @@ -50,7 +50,7 @@ public class CoreProblemFiller implements ProblemFiller { private final RangeActionsOptimizationParameters rangeActionParameters; private final Unit unit; private int iteration = 0; - private static final double RANGE_DECREASE_RATE = 0.667; + private static final double RANGE_SHRINK_RATE = 0.667; public CoreProblemFiller(OptimizationPerimeter optimizationContext, RangeActionSetpointResult prePerimeterRangeActionSetpoints, @@ -254,8 +254,8 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA 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_DECREASE_RATE, iteration); - FaraoMPConstraint iterativeShrink = linearProblem.getRangeActionRelativeSetpointConstraint(rangeAction, state, LinearProblem.PstRangeShrinking.TRUE); + 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) { @@ -266,7 +266,7 @@ private void updateConstraintsForRangeAction(LinearProblem linearProblem, RangeA 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.PstRangeShrinking.TRUE); + iterativeShrink = linearProblem.addRangeActionRelativeSetpointConstraint(lb, ub, rangeAction, state, LinearProblem.RaRangeShrinking.TRUE); iterativeShrink.setCoefficient(setPointVariable, 1); } } @@ -333,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, LinearProblem.PstRangeShrinking.FALSE); + 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 105d125ea1..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,13 +58,13 @@ public enum BoundExtension { UPPER_BOUND } - public enum PstRangeShrinking { + public enum RaRangeShrinking { TRUE("iterative-shrink"), FALSE(""); private final String name; - PstRangeShrinking(String name) { + RaRangeShrinking(String name) { this.name = name; } @@ -144,12 +144,12 @@ public FaraoMPVariable getRangeActionSetpointVariable(RangeAction rangeAction return solver.getVariable(rangeActionSetpointVariableId(rangeAction, state)); } - public FaraoMPConstraint addRangeActionRelativeSetpointConstraint(double lb, double ub, RangeAction rangeAction, State state, PstRangeShrinking pstRangeShrinking) { - return solver.makeConstraint(lb, ub, rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeShrinking)); + 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, PstRangeShrinking pstRangeShrinking) { - return solver.getConstraint(rangeActionRelativeSetpointConstraintId(rangeAction, state, pstRangeShrinking)); + 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 98fbdb1180..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, LinearProblem.PstRangeShrinking pstRangeShrinking) { - return rangeAction.getId() + SEPARATOR + state.getId() + SEPARATOR + RELATIVE + SEPARATOR + SET_POINT + SEPARATOR + pstRangeShrinking.toString() + 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 7169b5b1c6..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,7 +32,7 @@ public final class IteratingLinearOptimizerParameters { private final RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private final int maxNumberOfIterations; - private final boolean pstRangeShrinking; + private final boolean raRangeShrinking; private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction, RangeActionsOptimizationParameters rangeActionParameters, @@ -43,7 +43,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective RangeActionLimitationParameters raLimitationParameters, RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters, int maxNumberOfIterations, - boolean pstRangeShrinking) { + boolean raRangeShrinking) { this.objectiveFunction = objectiveFunction; this.rangeActionParameters = rangeActionParameters; this.mnecParameters = mnecParameters; @@ -53,7 +53,7 @@ private IteratingLinearOptimizerParameters(ObjectiveFunctionParameters.Objective this.raLimitationParameters = raLimitationParameters; this.solverParameters = solverParameters; this.maxNumberOfIterations = maxNumberOfIterations; - this.pstRangeShrinking = pstRangeShrinking; + this.raRangeShrinking = raRangeShrinking; } public ObjectiveFunctionParameters.ObjectiveFunctionType getObjectiveFunction() { @@ -113,8 +113,8 @@ public int getMaxNumberOfIterations() { return maxNumberOfIterations; } - public boolean getPstRangeShrinking() { - return pstRangeShrinking; + public boolean getRaRangeShrinking() { + return raRangeShrinking; } public static LinearOptimizerParametersBuilder create() { @@ -132,7 +132,7 @@ public static class LinearOptimizerParametersBuilder { private RangeActionLimitationParameters raLimitationParameters; private RangeActionsOptimizationParameters.LinearOptimizationSolver solverParameters; private int maxNumberOfIterations; - private boolean pstRangeShrinking; + private boolean raRangeShrinking; public LinearOptimizerParametersBuilder withObjectiveFunction(ObjectiveFunctionParameters.ObjectiveFunctionType objectiveFunction) { this.objectiveFunction = objectiveFunction; @@ -179,8 +179,8 @@ public LinearOptimizerParametersBuilder withMaxNumberOfIterations(int maxNumberO return this; } - public LinearOptimizerParametersBuilder withPstRangeShrinking(boolean pstRangeShrinking) { - this.pstRangeShrinking = pstRangeShrinking; + public LinearOptimizerParametersBuilder withRaRangeShrinking(boolean raRangeShrinking) { + this.raRangeShrinking = raRangeShrinking; return this; } @@ -199,7 +199,7 @@ public IteratingLinearOptimizerParameters build() { raLimitationParameters, solverParameters, maxNumberOfIterations, - pstRangeShrinking); + 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 561debd791..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,7 +215,7 @@ void optimize(SearchTreeInput searchTreeInput, SearchTreeParameters parameters) .withRaLimitationParameters(getRaLimitationParameters(searchTreeInput.getOptimizationPerimeter(), parameters)) .withSolverParameters(parameters.getSolverParameters()) .withMaxNumberOfIterations(parameters.getMaxNumberOfIterations()) - .withPstRangeShrinking(parameters.getTreeParameters().getPstRangeShrinking()) + .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 bd2d300c15..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 @@ -28,7 +28,7 @@ public void setUp() { raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(6); raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(4); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(2); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED); } @Test @@ -40,51 +40,51 @@ void testPreventive() { assertEquals(TreeParameters.StopCriterion.MIN_OBJECTIVE, treeParameters.getStopCriterion()); assertEquals(4, treeParameters.getLeavesInParallel()); assertEquals(6, treeParameters.getMaximumSearchDepth()); - assertFalse(treeParameters.getPstRangeShrinking()); + 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().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + 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.getPstRangeShrinking()); + assertTrue(treeParameters.getRaRangeShrinking()); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED); treeParameters = TreeParameters.buildForPreventivePerimeter(raoParameters); - assertTrue(treeParameters.getPstRangeShrinking()); + assertTrue(treeParameters.getRaRangeShrinking()); } @Test void testCurativeMinObjective() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(false); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED); + 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.getPstRangeShrinking()); + assertFalse(treeParameters.getRaRangeShrinking()); } @Test void testCurativeSecureStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(16); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + 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.getPstRangeShrinking()); + assertTrue(treeParameters.getRaRangeShrinking()); } @Test @@ -92,14 +92,14 @@ void testCurativePreventiveObjectiveStopCriterion() { raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.PREVENTIVE_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(35); raoParameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(0); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + 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.getPstRangeShrinking()); + assertTrue(treeParameters.getRaRangeShrinking()); } @Test @@ -134,36 +134,36 @@ void testSecondPreventive() { // test with min objective raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.DISABLED); + 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.getPstRangeShrinking()); + assertFalse(treeParameters.getRaRangeShrinking()); // test with secure raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.SECURE); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO); + 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.getPstRangeShrinking()); + assertFalse(treeParameters.getRaRangeShrinking()); // other combinations raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE); raoParameters.getObjectiveFunctionParameters().setCurativeStopCriterion(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE); - raoParameters.getRangeActionsOptimizationParameters().setPstRangeShrinking(RangeActionsOptimizationParameters.PstRangeShrinking.ENABLED); + 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.getPstRangeShrinking()); + 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 b73f8ebf73..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 @@ -99,7 +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.getPstRangeShrinking()).thenReturn(false); + when(parameters.getRaRangeShrinking()).thenReturn(false); linearProblem = Mockito.mock(LinearProblem.class); network = Mockito.mock(Network.class); @@ -217,7 +217,7 @@ void secondLinearProblemDoesNotChangeSetPoint() { @Test void linearProblemDegradesTheSolutionButKeepsBestIteration() { - when(parameters.getPstRangeShrinking()).thenReturn(true); + 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(); @@ -246,7 +246,7 @@ void linearProblemDegradesTheSolution() { @Test void linearProblemFluctuatesButKeepsBestIteration() { - when(parameters.getPstRangeShrinking()).thenReturn(true); + 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(); @@ -307,7 +307,7 @@ void optimizeWithSensitivityComputationFailure() { @Test void testUnapplyRangeAction() { - when(parameters.getPstRangeShrinking()).thenReturn(true); + when(parameters.getRaRangeShrinking()).thenReturn(true); network = NetworkImportsUtil.import12NodesNetwork(); when(input.getNetwork()).thenReturn(network); mockLinearProblem(Collections.nCopies(5, LinearProblemStatus.OPTIMAL), List.of(1., 2., 3., 4., 5.)); From ee1f9a9b905cf524069b9a40ad3a1001d8610254 Mon Sep 17 00:00:00 2001 From: Peter Mitri Date: Mon, 5 Jun 2023 11:25:50 +0200 Subject: [PATCH 22/22] change parameters serialize order --- .../rao_api/json/JsonRangeActionsOptimizationParameters.java | 2 +- .../rao-api/src/test/resources/RaoParametersSet_v2.json | 2 +- .../src/test/resources/RaoParametersWithExtension_v2.json | 2 +- .../src/test/resources/RaoParameters_config_withExtensions.json | 2 +- .../src/test/resources/RaoParameters_config_withOLFParams.json | 2 +- .../resources/RaoParameters_config_withPartialExtensions.json | 2 +- .../test/resources/RaoParameters_config_withoutExtensions.json | 2 +- .../rao-api/src/test/resources/RaoParameters_v2.json | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) 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 5f4fafe6be..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 @@ -30,11 +30,11 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost()); jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold()); jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel()); - jsonGenerator.writeObjectField(RA_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); jsonGenerator.writeNumberField(HVDC_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getHvdcPenaltyCost()); jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold()); jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost()); jsonGenerator.writeNumberField(INJECTION_RA_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getInjectionRaSensitivityThreshold()); + jsonGenerator.writeObjectField(RA_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking()); jsonGenerator.writeObjectFieldStart(LINEAR_OPTIMIZATION_SOLVER); jsonGenerator.writeObjectField(SOLVER, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolver()); jsonGenerator.writeNumberField(RELATIVE_MIP_GAP, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getRelativeMipGap()); 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 bf223361de..1ec1863264 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersSet_v2.json @@ -12,11 +12,11 @@ "pst-penalty-cost" : 10.0, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "ra-range-shrinking" : "ENABLED", "hvdc-penalty-cost" : 1.0, "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 0a30a5818e..06ee719fef 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParametersWithExtension_v2.json @@ -12,11 +12,11 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "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 2e9e272a1d..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 @@ -12,11 +12,11 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.002, "hvdc-sensitivity-threshold" : 0.2, "injection-ra-penalty-cost" : 0.003, "injection-ra-sensitivity-threshold" : 0.3, + "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 a1e973aba6..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 @@ -12,11 +12,11 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "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 972257075a..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 @@ -12,11 +12,11 @@ "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, "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 113b72f223..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 @@ -12,11 +12,11 @@ "pst-penalty-cost" : 0.02, "pst-sensitivity-threshold" : 0.2, "pst-model" : "APPROXIMATED_INTEGERS", - "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.002, "hvdc-sensitivity-threshold" : 0.2, "injection-ra-penalty-cost" : 0.003, "injection-ra-sensitivity-threshold" : 0.3, + "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 8ba921ac14..3cd2bfc1c8 100644 --- a/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json +++ b/ra-optimisation/rao-api/src/test/resources/RaoParameters_v2.json @@ -12,11 +12,11 @@ "pst-penalty-cost" : 0.01, "pst-sensitivity-threshold" : 0.0, "pst-model" : "CONTINUOUS", - "ra-range-shrinking" : "DISABLED", "hvdc-penalty-cost" : 0.001, "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,