Skip to content

Commit

Permalink
Merge content of preventive stop criterion into type
Browse files Browse the repository at this point in the history
Signed-off-by: Pauline Jean-Marie <[email protected]>
  • Loading branch information
Pauline Jean-Marie committed Oct 2, 2024
1 parent 7f7e969 commit fd71fe6
Show file tree
Hide file tree
Showing 132 changed files with 192 additions and 275 deletions.
9 changes: 6 additions & 3 deletions python-util/rao_parameter_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@ def obj_function_as_str_lines(new_data, file_type):
def new_rao_param(data: dict, file_path: str, file_type: str) -> dict:
try:
obj_fun = data[tag_by_file_type[file_type]]
if "type" in obj_fun and "MAX_MIN_MARGIN" in obj_fun["type"]:
prev_secure = "preventive-stop-criterion" not in obj_fun or obj_fun["preventive-stop-criterion"] == "SECURE"
if prev_secure and ("type" in obj_fun or "preventive-stop-criterion" in obj_fun):
obj_fun["type"] = "SECURE_FLOW"
elif not prev_secure and "type" not in obj_fun:
obj_fun["type"] = "MAX_MIN_MARGIN"
if "type" in obj_fun and "MAX_MIN_RELATIVE_MARGIN" in obj_fun["type"]:
obj_fun["type"] = "MAX_MIN_RELATIVE_MARGIN"
if "preventive-stop-criterion" in obj_fun:
del obj_fun["preventive-stop-criterion"]
except KeyError as ke:
raise KeyError("in file " + file_path) from ke
data[tag_by_file_type[file_type]] = obj_fun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ private JsonObjectiveFunctionParameters() {
static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeObjectFieldStart(OBJECTIVE_FUNCTION);
jsonGenerator.writeObjectField(TYPE, parameters.getObjectiveFunctionParameters().getType());
jsonGenerator.writeObjectField(PREVENTIVE_STOP_CRITERION, parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion());
jsonGenerator.writeNumberField(CURATIVE_MIN_OBJ_IMPROVEMENT, parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement());
jsonGenerator.writeBooleanField(ENFORCE_CURATIVE_SECURITY, parameters.getObjectiveFunctionParameters().getEnforceCurativeSecurity());
jsonGenerator.writeEndObject();
Expand All @@ -39,9 +38,6 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro
case TYPE:
raoParameters.getObjectiveFunctionParameters().setType(stringToObjectiveFunction(jsonParser.nextTextValue()));
break;
case PREVENTIVE_STOP_CRITERION:
raoParameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(stringToPreventiveStopCriterion(jsonParser.nextTextValue()));
break;
case CURATIVE_MIN_OBJ_IMPROVEMENT:
jsonParser.nextToken();
raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(jsonParser.getValueAsDouble());
Expand All @@ -63,13 +59,4 @@ private static ObjectiveFunctionParameters.ObjectiveFunctionType stringToObjecti
throw new OpenRaoException(String.format("Unknown objective function type value: %s", string));
}
}

private static ObjectiveFunctionParameters.PreventiveStopCriterion stringToPreventiveStopCriterion(String string) {
try {
return ObjectiveFunctionParameters.PreventiveStopCriterion.valueOf(string);
} catch (IllegalArgumentException e) {
throw new OpenRaoException(String.format("Unknown preventive stop criterion: %s", string));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@
*/
public class ObjectiveFunctionParameters {
// Default values
private static final ObjectiveFunctionType DEFAULT_OBJECTIVE_FUNCTION = ObjectiveFunctionType.MAX_MIN_MARGIN;
private static final ObjectiveFunctionType DEFAULT_OBJECTIVE_FUNCTION = ObjectiveFunctionType.SECURE_FLOW;
private static final double DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT = 0;
private static final PreventiveStopCriterion DEFAULT_PREVENTIVE_STOP_CRITERION = PreventiveStopCriterion.SECURE;
private static final boolean DEFAULT_ENFORCE_CURATIVE_SECURITY = false;
// Attributes
private ObjectiveFunctionType type = DEFAULT_OBJECTIVE_FUNCTION;
private double curativeMinObjImprovement = DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT;
private PreventiveStopCriterion preventiveStopCriterion = DEFAULT_PREVENTIVE_STOP_CRITERION;
private boolean enforceCurativeSecurity = DEFAULT_ENFORCE_CURATIVE_SECURITY;

// Enum
public enum ObjectiveFunctionType {
SECURE_FLOW,
MAX_MIN_MARGIN,
MAX_MIN_RELATIVE_MARGIN;

Expand All @@ -40,11 +39,6 @@ public boolean relativePositiveMargins() {
}
}

public enum PreventiveStopCriterion {
MIN_OBJECTIVE,
SECURE
}

// Getters and setters
public ObjectiveFunctionType getType() {
return type;
Expand All @@ -54,18 +48,10 @@ public void setType(ObjectiveFunctionType type) {
this.type = type;
}

public void setPreventiveStopCriterion(PreventiveStopCriterion preventiveStopCriterion) {
this.preventiveStopCriterion = preventiveStopCriterion;
}

public double getCurativeMinObjImprovement() {
return curativeMinObjImprovement;
}

public PreventiveStopCriterion getPreventiveStopCriterion() {
return preventiveStopCriterion;
}

public boolean getEnforceCurativeSecurity() {
return enforceCurativeSecurity;
}
Expand All @@ -82,8 +68,6 @@ public static ObjectiveFunctionParameters load(PlatformConfig platformConfig) {
parameters.setType(config.getEnumProperty(TYPE, ObjectiveFunctionType.class,
DEFAULT_OBJECTIVE_FUNCTION));
parameters.setCurativeMinObjImprovement(config.getDoubleProperty(CURATIVE_MIN_OBJ_IMPROVEMENT, DEFAULT_CURATIVE_MIN_OBJ_IMPROVEMENT));
parameters.setPreventiveStopCriterion(config.getEnumProperty(PREVENTIVE_STOP_CRITERION, PreventiveStopCriterion.class,
DEFAULT_PREVENTIVE_STOP_CRITERION));
parameters.setEnforceCurativeSecurity(config.getBooleanProperty(ENFORCE_CURATIVE_SECURITY, DEFAULT_ENFORCE_CURATIVE_SECURITY));
});
return parameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ void roundTrip() throws IOException {
RaoParameters parameters = new RaoParameters();
// Objective Function parameters
parameters.getObjectiveFunctionParameters().setType(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN);
parameters.getObjectiveFunctionParameters().setPreventiveStopCriterion(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE);
parameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(983);
parameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(true);
// RangeActionsOptimization parameters
Expand Down Expand Up @@ -121,7 +120,7 @@ void update() {
assertEquals(1, parameters.getExtensions().size());
JsonRaoParameters.update(parameters, getClass().getResourceAsStream("/RaoParameters_update_v2.json"));
assertEquals(2, parameters.getExtensions().size());
assertEquals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE, parameters.getObjectiveFunctionParameters().getPreventiveStopCriterion());
assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, parameters.getObjectiveFunctionParameters().getType());
assertEquals(5, parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth(), DOUBLE_TOLERANCE);
assertEquals(2, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth(), DOUBLE_TOLERANCE);
assertEquals(5, parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth(), DOUBLE_TOLERANCE);
Expand Down Expand Up @@ -175,7 +174,7 @@ void testFailOnOldVersion() {
}

@ParameterizedTest
@ValueSource(strings = {"LoopFlowError", "PrevStopCriterionError", "WrongField"})
@ValueSource(strings = {"LoopFlowError", "ObjFuncTypeError", "WrongField"})
void importNokTest(String source) {
InputStream inputStream = getClass().getResourceAsStream("/RaoParametersWith" + source + "_v2.json");
assertThrows(OpenRaoException.class, () -> JsonRaoParameters.read(inputStream));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ void checkObjectiveFunctionConfig() {
ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters();
assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_RELATIVE_MARGIN, objectiveFunctionParameters.getType());
assertEquals(123, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE);
assertEquals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE, objectiveFunctionParameters.getPreventiveStopCriterion());
assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ void testConfigWithExtensions() throws IOException {
ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters();
assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType());
assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE);
assertEquals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE, objectiveFunctionParameters.getPreventiveStopCriterion());
assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity());

RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters();
Expand Down Expand Up @@ -127,7 +126,6 @@ void testConfigWithoutExtensions() throws IOException {
ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters();
assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType());
assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE);
assertEquals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE, objectiveFunctionParameters.getPreventiveStopCriterion());
assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity());

RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters();
Expand Down Expand Up @@ -196,7 +194,6 @@ void testConfigWithPartialExtensions() throws IOException {
ObjectiveFunctionParameters objectiveFunctionParameters = parameters.getObjectiveFunctionParameters();
assertEquals(ObjectiveFunctionParameters.ObjectiveFunctionType.MAX_MIN_MARGIN, objectiveFunctionParameters.getType());
assertEquals(3, objectiveFunctionParameters.getCurativeMinObjImprovement(), DOUBLE_TOLERANCE);
assertEquals(ObjectiveFunctionParameters.PreventiveStopCriterion.MIN_OBJECTIVE, objectiveFunctionParameters.getPreventiveStopCriterion());
assertFalse(objectiveFunctionParameters.getEnforceCurativeSecurity());

RangeActionsOptimizationParameters rangeActionsOptimizationParameters = parameters.getRangeActionsOptimizationParameters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "MIN_OBJECTIVE",
"curative-min-obj-improvement" : 983.0,
"enforce-curative-security" : true
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "SECURE",
"type" : "SECURE_FLOW",
"curative-min-obj-improvement" : 0.0,
"enforce-curative-security" : false
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "SECURE",
"type" : "SECURE_FLOW",
"curative-min-obj-improvement" : 0.0
},
"range-actions-optimization" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "WRONG",
"curative-min-obj-improvement" : 0.0
},
"range-actions-optimization" : {
"max-mip-iterations" : 10,
"pst-penalty-cost" : 0.01,
"pst-sensitivity-threshold" : 1.0E-6,
"pst-model" : "CONTINUOUS",
"hvdc-penalty-cost" : 0.001,
"hvdc-sensitivity-threshold" : 1.0E-6,
"injection-ra-penalty-cost" : 0.001,
"injection-ra-sensitivity-threshold" : 1.0E-6,
"linear-optimization-solver" : {
"solver" : "CBC",
"relative-mip-gap" : 1.0E-4,
"solver-specific-parameters" : null
}
},
"topological-actions-optimization" : {
"max-preventive-search-tree-depth" : 2147483647,
"max-auto-search-tree-depth" : 2147483647,
"max-curative-search-tree-depth" : 2147483647,
"predefined-combinations" : [ ],
"relative-minimum-impact-threshold" : 0.0,
"absolute-minimum-impact-threshold" : 0.0,
"skip-actions-far-from-most-limiting-element" : false,
"max-number-of-boundaries-for-skipping-actions" : 2
},
"second-preventive-rao" : {
"execution-condition" : "DISABLED",
"re-optimize-curative-range-actions" : false,
"hint-from-first-preventive-rao" : false
},
"not-optimized-cnecs" : {
"do-not-optimize-curative-cnecs-for-tsos-without-cras" : false
},
"load-flow-and-sensitivity-computation" : {
"load-flow-provider" : "OpenLoadFlow",
"sensitivity-provider" : "OpenLoadFlow",
"sensitivity-failure-overcost" : 10000.0,
"sensitivity-parameters" : {
"version" : "1.0",
"load-flow-parameters" : {
"version" : "1.8",
"voltageInitMode" : "UNIFORM_VALUES",
"transformerVoltageControlOn" : false,
"phaseShifterRegulationOn" : false,
"useReactiveLimits" : true,
"twtSplitShuntAdmittance" : false,
"shuntCompensatorVoltageControlOn" : false,
"readSlackBus" : true,
"writeSlackBus" : true,
"dc" : false,
"distributedSlack" : true,
"balanceType" : "PROPORTIONAL_TO_GENERATION_P_MAX",
"dcUseTransformerRatio" : true,
"countriesToBalance" : [ ],
"connectedComponentMode" : "MAIN",
"hvdcAcEmulation" : true
}
}
},
"multi-threading" : {
"contingency-scenarios-in-parallel" : 1,
"preventive-leaves-in-parallel" : 1,
"auto-leaves-in-parallel" : 1,
"curative-leaves-in-parallel" : 1
},
"extensions" : {
"loop-flow-parameters" : {
"acceptable-increase" : 0.0,
"ptdf-approximation" : "FIXED_PTDF",
"constraint-adjustment-coefficient" : 0.0,
"violation-cost" : 0.0,
"countries" : [ ]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "WRONG",
"curative-min-obj-improvement" : 0.0
},
"range-actions-optimization" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "SECURE",
"type" : "SECURE_FLOW",
"curative-min-obj-improvement" : 0.0
},
"range-actions-optimization" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "MIN_OBJECTIVE",
"curative-min-obj-improvement" : 3.0,
"enforce-curative-security" : false
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "SECURE",
"type" : "SECURE_FLOW",
"curative-min-obj-improvement" : 0.0,
"enforce-curative-security" : false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "MIN_OBJECTIVE",
"curative-min-obj-improvement" : 3.0,
"enforce-curative-security" : false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "MIN_OBJECTIVE",
"curative-min-obj-improvement" : 3.0,
"enforce-curative-security" : false
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "SECURE"
"type" : "SECURE_FLOW"
},
"range-actions-optimization" : {
"max-mip-iterations" : 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "MIN_OBJECTIVE",
"enforce-curative-security" : false
},
"range-actions-optimization" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"version" : "2.5",
"objective-function" : {
"type" : "MAX_MIN_MARGIN",
"preventive-stop-criterion" : "SECURE",
"type" : "SECURE_FLOW",
"curative-min-obj-improvement" : 0.0,
"enforce-curative-security" : false
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
rao-objective-function:
type: MAX_MIN_MARGIN
preventive-stop-criterion: MIN_OBJECTIVE
curative-min-obj-improvement: 3.0

rao-range-actions-optimization:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
rao-objective-function:
preventive-stop-criterion: MIN_OBJECTIVE
type: MAX_MIN_MARGIN
curative-min-obj-improvement: 3.0

rao-range-actions-optimization:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
rao-objective-function:
type: MAX_MIN_MARGIN
preventive-stop-criterion: MIN_OBJECTIVE
curative-min-obj-improvement: 3.0
optimize-curative-if-preventive-unsecure: true

Expand Down
Loading

0 comments on commit fd71fe6

Please sign in to comment.