Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauline Jean-Marie committed Sep 25, 2024
1 parent 5e72e15 commit 06d212b
Show file tree
Hide file tree
Showing 34 changed files with 1,062 additions and 525 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ private RaoParametersCommons() {
public static final String RANGE_ACTIONS_OPTIMIZATION = "range-actions-optimization";
public static final String RANGE_ACTIONS_OPTIMIZATION_SECTION = "rao-range-actions-optimization";
public static final String MAX_MIP_ITERATIONS = "max-mip-iterations";
public static final String PST_PENALTY_COST = "pst-penalty-cost";
public static final String PST_RA_MIN_IMPACT_THRESHOLD = "pst-ra-min-impact_threshold";
public static final String PST_SENSITIVITY_THRESHOLD = "pst-sensitivity-threshold";
public static final String PST_MODEL = "pst-model";
public static final String HVDC_PENALTY_COST = "hvdc-penalty-cost";
public static final String HVDC_RA_MIN_IMPACT_THRESHOLD = "hvdc-ra-min-impact_threshold";
public static final String HVDC_SENSITIVITY_THRESHOLD = "hvdc-sensitivity-threshold";
public static final String INJECTION_RA_PENALTY_COST = "injection-ra-penalty-cost";
public static final String INJECTION_RA_MIN_IMPACT_THRESHOLD = "injection-ra-min-impact_threshold";
public static final String INJECTION_RA_SENSITIVITY_THRESHOLD = "injection-ra-sensitivity-threshold";
public static final String LINEAR_OPTIMIZATION_SOLVER = "linear-optimization-solver";
public static final String LINEAR_OPTIMIZATION_SOLVER_SECTION = "rao-linear-optimization-solver";
Expand Down Expand Up @@ -120,6 +120,7 @@ private RaoParametersCommons() {
public static final String RELATIVE_MARGINS_SECTION = "rao-relative-margins-parameters";
public static final String PTDF_BOUNDARIES = "ptdf-boundaries";
public static final String PTDF_SUM_LOWER_BOUND = "ptdf-sum-lower-bound";
public static final String SEARCH_TREE_PARAMETERS = "open-rao-search-tree-parameters";

public static PtdfApproximation stringToPtdfApproximation(String string) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,111 +26,30 @@ private JsonRangeActionsOptimizationParameters() {

static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeObjectFieldStart(RANGE_ACTIONS_OPTIMIZATION);
jsonGenerator.writeNumberField(MAX_MIP_ITERATIONS, parameters.getRangeActionsOptimizationParameters().getMaxMipIterations());
jsonGenerator.writeNumberField(PST_PENALTY_COST, parameters.getRangeActionsOptimizationParameters().getPstPenaltyCost());
jsonGenerator.writeNumberField(PST_SENSITIVITY_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstSensitivityThreshold());
jsonGenerator.writeObjectField(PST_MODEL, parameters.getRangeActionsOptimizationParameters().getPstModel());
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());
jsonGenerator.writeStringField(SOLVER_SPECIFIC_PARAMETERS, parameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().getSolverSpecificParameters());
jsonGenerator.writeEndObject();
jsonGenerator.writeNumberField(PST_RA_MIN_IMPACT_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getPstRAMinImpactThreshold());
jsonGenerator.writeNumberField(HVDC_RA_MIN_IMPACT_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getHvdcRAMinImpactThreshold());
jsonGenerator.writeNumberField(INJECTION_RA_MIN_IMPACT_THRESHOLD, parameters.getRangeActionsOptimizationParameters().getInjectionRAMinImpactThreshold());
jsonGenerator.writeEndObject();
}

static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case MAX_MIP_ITERATIONS:
case PST_RA_MIN_IMPACT_THRESHOLD:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setMaxMipIterations(jsonParser.getIntValue());
raoParameters.getRangeActionsOptimizationParameters().setPstRAMinImpactThreshold(jsonParser.getDoubleValue());
break;
case PST_PENALTY_COST:
case HVDC_RA_MIN_IMPACT_THRESHOLD:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setPstPenaltyCost(jsonParser.getDoubleValue());
raoParameters.getRangeActionsOptimizationParameters().setHvdcRAMinImpactThreshold(jsonParser.getDoubleValue());
break;
case PST_SENSITIVITY_THRESHOLD:
case INJECTION_RA_MIN_IMPACT_THRESHOLD:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setPstSensitivityThreshold(jsonParser.getDoubleValue());
break;
case PST_MODEL:
raoParameters.getRangeActionsOptimizationParameters().setPstModel(stringToPstModel(jsonParser.nextTextValue()));
break;
case HVDC_PENALTY_COST:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setHvdcPenaltyCost(jsonParser.getDoubleValue());
break;
case HVDC_SENSITIVITY_THRESHOLD:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setHvdcSensitivityThreshold(jsonParser.getDoubleValue());
break;
case INJECTION_RA_PENALTY_COST:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setInjectionRaPenaltyCost(jsonParser.getDoubleValue());
break;
case INJECTION_RA_SENSITIVITY_THRESHOLD:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().setInjectionRaSensitivityThreshold(jsonParser.getDoubleValue());
break;
case LINEAR_OPTIMIZATION_SOLVER:
jsonParser.nextToken();
deserializeLinearOptimizationSolver(jsonParser, raoParameters);
break;
case RA_RANGE_SHRINKING:
raoParameters.getRangeActionsOptimizationParameters().setRaRangeShrinking(stringToRaRangeShrinking(jsonParser.nextTextValue()));
raoParameters.getRangeActionsOptimizationParameters().setInjectionRAMinImpactThreshold(jsonParser.getDoubleValue());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize range action optimization parameters: unexpected field in %s (%s)", RANGE_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName()));
}
}
}

private static void deserializeLinearOptimizationSolver(JsonParser jsonParser, RaoParameters raoParameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case SOLVER:
raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolver(stringToSolver(jsonParser.nextTextValue()));
break;
case RELATIVE_MIP_GAP:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setRelativeMipGap(jsonParser.getDoubleValue());
break;
case SOLVER_SPECIFIC_PARAMETERS:
jsonParser.nextToken();
raoParameters.getRangeActionsOptimizationParameters().getLinearOptimizationSolver().setSolverSpecificParameters(jsonParser.getValueAsString());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize linear optimization solver in range action optimization parameters: unexpected field in %s (%s)", LINEAR_OPTIMIZATION_SOLVER, jsonParser.getCurrentName()));
}
}
}

private static RangeActionsOptimizationParameters.PstModel stringToPstModel(String string) {
try {
return RangeActionsOptimizationParameters.PstModel.valueOf(string);
} catch (IllegalArgumentException e) {
throw new OpenRaoException(String.format("Unknown Pst model: %s", string));
}
}

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

private static RangeActionsOptimizationParameters.Solver stringToSolver(String string) {
try {
return RangeActionsOptimizationParameters.Solver.valueOf(string);
} catch (IllegalArgumentException e) {
throw new OpenRaoException(String.format("Unknown solver: %s", string));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,14 @@ private JsonTopoOptimizationParameters() {

static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeObjectFieldStart(TOPOLOGICAL_ACTIONS_OPTIMIZATION);
jsonGenerator.writeNumberField(MAX_PREVENTIVE_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxPreventiveSearchTreeDepth());
jsonGenerator.writeNumberField(MAX_AUTO_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxAutoSearchTreeDepth());
jsonGenerator.writeNumberField(MAX_CURATIVE_SEARCH_TREE_DEPTH, parameters.getTopoOptimizationParameters().getMaxCurativeSearchTreeDepth());
jsonGenerator.writeFieldName(PREDEFINED_COMBINATIONS);
jsonGenerator.writeStartArray();
for (List<String> naIdCombination : parameters.getTopoOptimizationParameters().getPredefinedCombinations()) {
jsonGenerator.writeStartArray();
for (String naId : naIdCombination) {
jsonGenerator.writeString(naId);
}
jsonGenerator.writeEndArray();
}
jsonGenerator.writeEndArray();
jsonGenerator.writeNumberField(RELATIVE_MINIMUM_IMPACT_THRESHOLD, parameters.getTopoOptimizationParameters().getRelativeMinImpactThreshold());
jsonGenerator.writeNumberField(ABSOLUTE_MINIMUM_IMPACT_THRESHOLD, parameters.getTopoOptimizationParameters().getAbsoluteMinImpactThreshold());
jsonGenerator.writeBooleanField(SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT, parameters.getTopoOptimizationParameters().getSkipActionsFarFromMostLimitingElement());
jsonGenerator.writeNumberField(MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS, parameters.getTopoOptimizationParameters().getMaxNumberOfBoundariesForSkippingActions());
jsonGenerator.writeEndObject();
}

static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case MAX_PREVENTIVE_SEARCH_TREE_DEPTH:
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setMaxPreventiveSearchTreeDepth(jsonParser.getIntValue());
break;
case MAX_AUTO_SEARCH_TREE_DEPTH:
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setMaxAutoSearchTreeDepth(jsonParser.getIntValue());
break;
case MAX_CURATIVE_SEARCH_TREE_DEPTH:
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setMaxCurativeSearchTreeDepth(jsonParser.getIntValue());
break;
case PREDEFINED_COMBINATIONS:
raoParameters.getTopoOptimizationParameters().setPredefinedCombinations(readListOfListOfString(jsonParser));
break;
case RELATIVE_MINIMUM_IMPACT_THRESHOLD:
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setRelativeMinImpactThreshold(jsonParser.getDoubleValue());
Expand All @@ -73,26 +43,9 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setAbsoluteMinImpactThreshold(jsonParser.getDoubleValue());
break;
case SKIP_ACTIONS_FAR_FROM_MOST_LIMITING_ELEMENT:
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setSkipActionsFarFromMostLimitingElement(jsonParser.getBooleanValue());
break;
case MAX_NUMBER_OF_BOUNDARIES_FOR_SKIPPING_ACTIONS:
jsonParser.nextToken();
raoParameters.getTopoOptimizationParameters().setMaxNumberOfBoundariesForSkippingActions(jsonParser.getIntValue());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize topological optimization parameters: unexpected field in %s (%s)", TOPOLOGICAL_ACTIONS_OPTIMIZATION, jsonParser.getCurrentName()));
}
}
}

private static List<List<String>> readListOfListOfString(JsonParser jsonParser) throws IOException {
List<List<String>> parsedListOfList = new ArrayList<>();
jsonParser.nextToken();
while (!jsonParser.nextToken().isStructEnd()) {
parsedListOfList.add(jsonParser.readValueAs(ArrayList.class));
}
return parsedListOfList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package com.powsybl.openrao.raoapi.json;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.json.extensions.JsonMultiThreadingParameters;
import com.powsybl.openrao.raoapi.json.extensions.JsonSecondPreventiveRaoParameters;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
Expand Down Expand Up @@ -59,14 +61,6 @@ public RaoParameters deserialize(JsonParser parser, DeserializationContext deser
parser.nextToken();
JsonTopoOptimizationParameters.deserialize(parser, parameters);
break;
case MULTI_THREADING:
parser.nextToken();
JsonMultiThreadingParameters.deserialize(parser, parameters);
break;
case SECOND_PREVENTIVE_RAO:
parser.nextToken();
JsonSecondPreventiveRaoParameters.deserialize(parser, parameters);
break;
case NOT_OPTIMIZED_CNECS:
parser.nextToken();
JsonNotOptimizedCnecsParameters.deserialize(parser, parameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.openrao.raoapi.json;

import com.powsybl.openrao.raoapi.json.extensions.JsonMultiThreadingParameters;
import com.powsybl.openrao.raoapi.json.extensions.JsonSecondPreventiveRaoParameters;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
Expand All @@ -32,10 +34,8 @@ public void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, Ser
JsonObjectiveFunctionParameters.serialize(parameters, jsonGenerator);
JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator);
JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator);
JsonSecondPreventiveRaoParameters.serialize(parameters, jsonGenerator);
JsonNotOptimizedCnecsParameters.serialize(parameters, jsonGenerator);
JsonLoadFlowAndSensitivityComputationParameters.serialize(parameters, jsonGenerator, serializerProvider);
JsonMultiThreadingParameters.serialize(parameters, jsonGenerator);
JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonRaoParameters.getExtensionSerializers());
jsonGenerator.writeEndObject();
}
Expand Down
Loading

0 comments on commit 06d212b

Please sign in to comment.