Skip to content

Commit

Permalink
add limit to pst range for sensi changes (#758)
Browse files Browse the repository at this point in the history
* range action movement  modified

* verison qui semble fonctionner malgré log xpres

* stops even when 2 worse iteration have the same result

* fix getValue bug that always returned 0

* fix some tests and update iteration number when finding a worst solution

* increment iteration even when problem fails or is worse

* refactor some tests but one is still not working

* add best result RA on network for each worse MIP iteration

* Update CoreProblemFiller.java

Co-authored-by: Thomas Bouquet <63302082+bqth29@users.noreply.github.com>

* add variable because it is used several times

Co-authored-by: Thomas Bouquet <63302082+bqth29@users.noreply.github.com>

* fix filling network pool log msg

* first draft of new parameters with UTs fixed

* change mip behavior according to new parameter value + fix UTs

* modify Enum names

* change enum names and reduce complexity

* change parameter name in config files

* reduce cognitive complexity to less than 15

* change code according to comments

* change DECREASE to SHRINKING in the code

* remove useless mock in LeafTest.java

* rename

* change parameters serialize order

---------

Co-authored-by: Thomas Bouquet <63302082+bqth29@users.noreply.github.com>
Co-authored-by: Peter Mitri <peter.mitri@rte-france.com>
  • Loading branch information
3 people authored Jun 5, 2023
1 parent 9e20913 commit 51f661f
Show file tree
Hide file tree
Showing 28 changed files with 277 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private RaoParametersConstants() {
public static final String SOLVER = "solver";
public static final String RELATIVE_MIP_GAP = "relative-mip-gap";
public static final String SOLVER_SPECIFIC_PARAMETERS = "solver-specific-parameters";
public static final String RA_RANGE_SHRINKING = "ra-range-shrinking";

// topological actions optimization parameters
public static final String TOPOLOGICAL_ACTIONS_OPTIMIZATION = "topological-actions-optimization";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr
jsonGenerator.writeNumberField(HVDC_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcSensitivityThreshold());
jsonGenerator.writeNumberField(INJECTION_RA_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getInjectionRaPenaltyCost());
jsonGenerator.writeNumberField(INJECTION_RA_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getInjectionRaSensitivityThreshold());
jsonGenerator.writeObjectField(RA_RANGE_SHRINKING, parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking());
jsonGenerator.writeObjectFieldStart(LINEAR_OPTIMIZATION_SOLVER);
jsonGenerator.writeObjectField(SOLVER, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolver());
jsonGenerator.writeNumberField(RELATIVE_MIP_GAP, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getRelativeMipGap());
Expand Down Expand Up @@ -80,6 +81,9 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro
jsonParser.nextToken();
deserializeLinearOptimizationSolver(jsonParser, raoParameters);
break;
case RA_RANGE_SHRINKING:
raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(stringToRaRangeShrinking(jsonParser.nextTextValue()));
break;
default:
throw new FaraoException(String.format("Cannot deserialize range action optimization parameters: unexpected field in %s (%s)", RANGE_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName()));
}
Expand Down Expand Up @@ -114,6 +118,14 @@ private static RangeActionsOptimizationParameters.PstModel stringToPstModel(Stri
}
}

private static RangeActionsOptimizationParameters.RaRangeShrinking stringToRaRangeShrinking(String string) {
try {
return RangeActionsOptimizationParameters.RaRangeShrinking.valueOf(string);
} catch (IllegalArgumentException e) {
throw new FaraoException(String.format("Unknown Pst variation range shrinking: %s", string));
}
}

private static RangeActionsOptimizationParameters.Solver stringToSolver(String string) {
try {
return RangeActionsOptimizationParameters.Solver.valueOf(string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class RangeActionsOptimizationParameters {
private static final double DEFAULT_HVDC_SENSITIVITY_THRESHOLD = 0.0;
private static final double DEFAULT_INJECTION_RA_PENALTY_COST = 0.001;
private static final double DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD = 0.0;
private static final RaRangeShrinking DEFAULT_RA_RANGE_SHRINKING = RaRangeShrinking.DISABLED;
// Attributes
private int maxMipIterations = DEFAULT_MAX_MIP_ITERATIONS;
private double pstPenaltyCost = DEFAULT_PST_PENALTY_COST;
Expand All @@ -40,13 +41,19 @@ public class RangeActionsOptimizationParameters {
private double injectionRaPenaltyCost = DEFAULT_INJECTION_RA_PENALTY_COST;
private double injectionRaSensitivityThreshold = DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD;
private LinearOptimizationSolver linearOptimizationSolver = new LinearOptimizationSolver();
private RaRangeShrinking raRangeShrinking = DEFAULT_RA_RANGE_SHRINKING;

// Enum
public enum PstModel {
CONTINUOUS,
APPROXIMATED_INTEGERS
}

public enum RaRangeShrinking {
DISABLED,
ENABLED,
ENABLED_IN_FIRST_PRAO_AND_CRAO
}

public static class LinearOptimizationSolver {
private static final Solver DEFAULT_SOLVER = Solver.CBC;
public static final double DEFAULT_RELATIVE_MIP_GAP = 0.0001;
Expand Down Expand Up @@ -171,6 +178,14 @@ public void setLinearOptimizationSolver(LinearOptimizationSolver linearOptimizat
this.linearOptimizationSolver = linearOptimizationSolver;
}

public void setRaRangeShrinking(RaRangeShrinking raRangeShrinking) {
this.raRangeShrinking = raRangeShrinking;
}

public RaRangeShrinking getRaRangeShrinking() {
return raRangeShrinking;
}

public static RangeActionsOptimizationParameters load(PlatformConfig platformConfig) {
Objects.requireNonNull(platformConfig);
RangeActionsOptimizationParameters parameters = new RangeActionsOptimizationParameters();
Expand All @@ -184,6 +199,7 @@ public static RangeActionsOptimizationParameters load(PlatformConfig platformCon
parameters.setHvdcSensitivityThreshold(config.getDoubleProperty(HVDC_SENSITIVITY_THRESHOLD, DEFAULT_HVDC_SENSITIVITY_THRESHOLD));
parameters.setInjectionRaPenaltyCost(config.getDoubleProperty(INJECTION_RA_PENALTY_COST, DEFAULT_INJECTION_RA_PENALTY_COST));
parameters.setInjectionRaSensitivityThreshold(config.getDoubleProperty(INJECTION_RA_SENSITIVITY_THRESHOLD, DEFAULT_INJECTION_RA_SENSITIVITY_THRESHOLD));
parameters.setRaRangeShrinking(config.getEnumProperty(RA_RANGE_SHRINKING, RaRangeShrinking.class, DEFAULT_RA_RANGE_SHRINKING));
});
parameters.setLinearOptimizationSolver(LinearOptimizationSolver.load(platformConfig));
return parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void roundTrip() throws IOException {
parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(RangeActionsOptimizationParameters.Solver.SCIP);
parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(1e-5);
parameters.getRangeActionsOptimizationParameters().setPstModel(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS);
parameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED);
// TopologicalActions optimization parameters
parameters.getTopoOptimizationParameters().setMaxSearchTreeDepth(10);
parameters.getTopoOptimizationParameters().setRelativeMinImpactThreshold(0.1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void checkRangeActionsOptimizationConfig() {
assertEquals(44, params.getPstPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(7, params.getPstSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, params.getPstModel());
assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, params.getRaRangeShrinking());
assertEquals(33, params.getHvdcPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(8, params.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(22, params.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void testConfigWithExtensions() throws IOException {
assertEquals(0.02, rangeActionsOptimizationParameters.getPstPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(0.2, rangeActionsOptimizationParameters.getPstSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParameters.getPstModel());
assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getRaRangeShrinking());
assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE);
Expand Down Expand Up @@ -142,6 +143,7 @@ void testConfigWithoutExtensions() throws IOException {
assertEquals(0.02, rangeActionsOptimizationParameters.getPstPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(0.2, rangeActionsOptimizationParameters.getPstSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParameters.getPstModel());
assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.DISABLED, rangeActionsOptimizationParameters.getRaRangeShrinking());
assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE);
Expand Down Expand Up @@ -220,6 +222,7 @@ void testConfigWithPartialExtensions() throws IOException {
assertEquals(0.02, rangeActionsOptimizationParameters.getPstPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(0.2, rangeActionsOptimizationParameters.getPstSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(RangeActionsOptimizationParameters.PstModel.APPROXIMATED_INTEGERS, rangeActionsOptimizationParameters.getPstModel());
assertEquals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED, rangeActionsOptimizationParameters.getRaRangeShrinking());
assertEquals(0.002, rangeActionsOptimizationParameters.getHvdcPenaltyCost(), DOUBLE_TOLERANCE);
assertEquals(0.2, rangeActionsOptimizationParameters.getHvdcSensitivityThreshold(), DOUBLE_TOLERANCE);
assertEquals(0.003, rangeActionsOptimizationParameters.getInjectionRaPenaltyCost(), DOUBLE_TOLERANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.3,
"injection-ra-penalty-cost" : 1.2,
"injection-ra-sensitivity-threshold" : 0.7,
"ra-range-shrinking" : "ENABLED",
"linear-optimization-solver" : {
"solver" : "SCIP",
"relative-mip-gap" : 1.0E-5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.0,
"injection-ra-penalty-cost" : 0.001,
"injection-ra-sensitivity-threshold" : 0.0,
"ra-range-shrinking" : "DISABLED",
"linear-optimization-solver" : {
"solver" : "CBC",
"relative-mip-gap" : 1.0E-4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.2,
"injection-ra-penalty-cost" : 0.003,
"injection-ra-sensitivity-threshold" : 0.3,
"ra-range-shrinking" : "DISABLED",
"linear-optimization-solver" : {
"solver" : "XPRESS",
"relative-mip-gap" : 0.004,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.0,
"injection-ra-penalty-cost" : 0.001,
"injection-ra-sensitivity-threshold" : 0.0,
"ra-range-shrinking" : "DISABLED",
"linear-optimization-solver" : {
"solver" : "CBC",
"relative-mip-gap" : 1.0E-4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.2,
"injection-ra-penalty-cost" : 0.003,
"injection-ra-sensitivity-threshold" : 0.3,
"ra-range-shrinking" : "ENABLED",
"linear-optimization-solver" : {
"solver" : "CBC",
"relative-mip-gap" : 0.004,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.2,
"injection-ra-penalty-cost" : 0.003,
"injection-ra-sensitivity-threshold" : 0.3,
"ra-range-shrinking" : "DISABLED",
"linear-optimization-solver" : {
"solver" : "XPRESS",
"relative-mip-gap" : 0.004,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"hvdc-sensitivity-threshold" : 0.0,
"injection-ra-penalty-cost" : 0.001,
"injection-ra-sensitivity-threshold" : 0.0,
"ra-range-shrinking" : "DISABLED",
"linear-optimization-solver" : {
"solver" : "CBC",
"relative-mip-gap" : 1.0E-4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rao-range-actions-optimization:
pst-penalty-cost: 0.02
pst-sensitivity-threshold: 0.2
pst-model: APPROXIMATED_INTEGERS
ra-range-shrinking: ENABLED
hvdc-penalty-cost: 0.002
hvdc-sensitivity-threshold: 0.2
injection-ra-penalty-cost: 0.003
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rao-range-actions-optimization:
pst-penalty-cost: 0.02
pst-sensitivity-threshold: 0.2
pst-model: APPROXIMATED_INTEGERS
ra-range-shrinking: DISABLED
hvdc-penalty-cost: 0.002
hvdc-sensitivity-threshold: 0.2
injection-ra-penalty-cost: 0.003
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -29,15 +30,18 @@ public enum StopCriterion {
private final double targetObjectiveValue;
private final int maximumSearchDepth;
private final int leavesInParallel;
private final boolean raRangeShrinking;

public TreeParameters(StopCriterion stopCriterion,
double targetObjectiveValue,
int maximumSearchDepth,
int leavesInParallel) {
double targetObjectiveValue,
int maximumSearchDepth,
int leavesInParallel,
boolean raRangeShrinking) {
this.stopCriterion = stopCriterion;
this.targetObjectiveValue = targetObjectiveValue;
this.maximumSearchDepth = maximumSearchDepth;
this.leavesInParallel = leavesInParallel;
this.raRangeShrinking = raRangeShrinking;
}

public StopCriterion getStopCriterion() {
Expand All @@ -56,18 +60,27 @@ public int getLeavesInParallel() {
return leavesInParallel;
}

public boolean getRaRangeShrinking() {
return raRangeShrinking;
}

public static TreeParameters buildForPreventivePerimeter(RaoParameters parameters) {
RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking();
boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) ||
raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED);
switch (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion()) {
case MIN_OBJECTIVE:
return new TreeParameters(StopCriterion.MIN_OBJECTIVE,
0.0, // value does not matter
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel());
0.0, // value does not matter
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(),
shouldShrinkRaRange);
case SECURE:
return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE,
0.0, // secure
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel());
0.0, // secure
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(),
shouldShrinkRaRange);
default:
throw new FaraoException("Unknown preventive stop criterion: " + parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion());
}
Expand Down Expand Up @@ -96,24 +109,31 @@ public static TreeParameters buildForCurativePerimeter(RaoParameters parameters,
default:
throw new FaraoException("Unknown curative stop criterion: " + parameters.getObjectiveFunctionParameters().getCurativeStopCriterion());
}
RangeActionsOptimizationParameters.RaRangeShrinking raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking();
boolean shouldShrinkRaRange = raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED_IN_FIRST_PRAO_AND_CRAO) ||
raRangeShrinking.equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED);
return new TreeParameters(stopCriterion,
targetObjectiveValue,
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getCurativeLeavesInParallel());
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getCurativeLeavesInParallel(),
shouldShrinkRaRange);
}

public static TreeParameters buildForSecondPreventivePerimeter(RaoParameters parameters) {
boolean raRangeShrinking = parameters.getRangeActionsOptimizationParameters().getRaRangeShrinking().equals(RangeActionsOptimizationParameters.RaRangeShrinking.ENABLED);
if (parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion().equals(ObjectiveFunctionParameters.PreventiveStopCriterion.SECURE)
&& !parameters.getObjectiveFunctionParameters().getCurativeStopCriterion().equals(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE)) {
&& !parameters.getObjectiveFunctionParameters().getCurativeStopCriterion().equals(ObjectiveFunctionParameters.CurativeStopCriterion.MIN_OBJECTIVE)) {
return new TreeParameters(StopCriterion.AT_TARGET_OBJECTIVE_VALUE,
0.0, // secure
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel());
0.0, // secure
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(),
raRangeShrinking);
} else {
return new TreeParameters(StopCriterion.MIN_OBJECTIVE,
0.0, // value does not matter
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel());
0.0, // value does not matter
parameters.getTopoOptimizationParameters().getMaxSearchTreeDepth(),
parameters.getMultithreadingParameters().getPreventiveLeavesInParallel(),
raRangeShrinking);
}
}
}
Loading

0 comments on commit 51f661f

Please sign in to comment.