Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauline Jean-Marie committed Oct 15, 2024
1 parent a41f173 commit a24cff9
Show file tree
Hide file tree
Showing 55 changed files with 1,414 additions and 793 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ private RaoParametersCommons() {
// objective function parameters
public static final String OBJECTIVE_FUNCTION = "objective-function";
public static final String OBJECTIVE_FUNCTION_SECTION = "rao-objective-function";
public static final String ST_OBJECTIVE_FUNCTION_SECTION = "search-tree-objective-function";

public static final String TYPE = "type";
public static final String CURATIVE_MIN_OBJ_IMPROVEMENT = "curative-min-obj-improvement";
public static final String ENFORCE_CURATIVE_SECURITY = "enforce-curative-security";
Expand All @@ -32,12 +34,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 All @@ -61,10 +63,7 @@ private RaoParametersCommons() {
// Multi-threading parameters
public static final String MULTI_THREADING = "multi-threading";
public static final String MULTI_THREADING_SECTION = "rao-multi-threading";
public static final String CONTINGENCY_SCENARIOS_IN_PARALLEL = "contingency-scenarios-in-parallel";
public static final String PREVENTIVE_LEAVES_IN_PARALLEL = "preventive-leaves-in-parallel";
public static final String AUTO_LEAVES_IN_PARALLEL = "auto-leaves-in-parallel";
public static final String CURATIVE_LEAVES_IN_PARALLEL = "curative-leaves-in-parallel";
public static final String AVAILABLE_CPUS = "available-cpus";

// Second Preventive RAO parameters
public static final String SECOND_PREVENTIVE_RAO = "second-preventive-rao";
Expand All @@ -73,29 +72,19 @@ private RaoParametersCommons() {
public static final String RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS = "re-optimize-curative-range-actions";
public static final String HINT_FROM_FIRST_PREVENTIVE_RAO = "hint-from-first-preventive-rao";

// RA usage limits per contingency parameters
public static final String RA_USAGE_LIMITS_PER_CONTINGENCY = "ra-usage-limits-per-contingency";
public static final String RA_USAGE_LIMITS_PER_CONTINGENCY_SECTION = "rao-ra-usage-limits-per-contingency";

public static final String MAX_CURATIVE_RA = "max-curative-ra";
public static final String MAX_CURATIVE_TSO = "max-curative-tso";
public static final String MAX_CURATIVE_TOPO_PER_TSO = "max-curative-topo-per-tso";
public static final String MAX_CURATIVE_PST_PER_TSO = "max-curative-pst-per-tso";
public static final String MAX_CURATIVE_RA_PER_TSO = "max-curative-ra-per-tso";

// Not optimized cnecs parameters
public static final String NOT_OPTIMIZED_CNECS = "not-optimized-cnecs";
public static final String NOT_OPTIMIZED_CNECS_SECTION = "rao-not-optimized-cnecs";
public static final String DO_NOT_OPTIMIZE_CURATIVE_CNECS = "do-not-optimize-curative-cnecs-for-tsos-without-cras";

// Not optimized cnecs parameters
// Load flow and sensitivity parameters
public static final String LOAD_FLOW_AND_SENSITIVITY_COMPUTATION = "load-flow-and-sensitivity-computation";
public static final String LOAD_FLOW_AND_SENSITIVITY_COMPUTATION_SECTION = "rao-load-flow-and-sensitivity-computation";

public static final String LOAD_FLOW_PROVIDER = "load-flow-provider";
public static final String SENSITIVITY_PROVIDER = "sensitivity-provider";
public static final String SENSITIVITY_FAILURE_OVERCOST = "sensitivity-failure-overcost";
public static final String SENSITIVITY_PARAMETERS = "sensitivity-parameters";
public static final String LOAD_FLOW_PARAMETERS = "load-flow-parameters";

// EXTENSIONS
public static final String CONSTRAINT_ADJUSTMENT_COEFFICIENT = "constraint-adjustment-coefficient";
Expand All @@ -119,6 +108,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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@ static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) thr

static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case DO_NOT_OPTIMIZE_CURATIVE_CNECS:
jsonParser.nextToken();
raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(jsonParser.getBooleanValue());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize not optimized cnecs parameters: unexpected field in %s (%s)", NOT_OPTIMIZED_CNECS, jsonParser.getCurrentName()));
if (jsonParser.getCurrentName().equals(DO_NOT_OPTIMIZE_CURATIVE_CNECS)) {
jsonParser.nextToken();
raoParameters.getNotOptimizedCnecsParameters().setDoNotOptimizeCurativeCnecsForTsosWithoutCras(jsonParser.getBooleanValue());
} else {
throw new OpenRaoException(String.format("Cannot deserialize not optimized cnecs parameters: unexpected field in %s (%s)", NOT_OPTIMIZED_CNECS, jsonParser.getCurrentName()));
}
}
}
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.writeNumberField(CURATIVE_MIN_OBJ_IMPROVEMENT, parameters.getObjectiveFunctionParameters().getCurativeMinObjImprovement());
jsonGenerator.writeBooleanField(ENFORCE_CURATIVE_SECURITY, parameters.getObjectiveFunctionParameters().getEnforceCurativeSecurity());
jsonGenerator.writeEndObject();
}
Expand All @@ -38,10 +37,6 @@ static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) thro
case TYPE:
raoParameters.getObjectiveFunctionParameters().setType(stringToObjectiveFunction(jsonParser.nextTextValue()));
break;
case CURATIVE_MIN_OBJ_IMPROVEMENT:
jsonParser.nextToken();
raoParameters.getObjectiveFunctionParameters().setCurativeMinObjImprovement(jsonParser.getValueAsDouble());
break;
case ENFORCE_CURATIVE_SECURITY:
jsonParser.nextToken();
raoParameters.getObjectiveFunctionParameters().setEnforceCurativeSecurity(jsonParser.getBooleanValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.powsybl.openrao.raoapi.json;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.parameters.RangeActionsOptimizationParameters;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
Expand All @@ -26,111 +25,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));
}
}
}
Loading

0 comments on commit a24cff9

Please sign in to comment.