Skip to content

Commit

Permalink
wip2
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauline Jean-Marie committed Oct 8, 2024
1 parent 1a341e5 commit 01ec4ab
Show file tree
Hide file tree
Showing 30 changed files with 259 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,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 +70,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 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 @@ -12,6 +12,7 @@
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.powsybl.commons.extensions.Extension;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.loadflow.json.JsonLoadFlowParameters;
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;

Expand Down Expand Up @@ -63,9 +64,9 @@ public RaoParameters deserialize(JsonParser parser, DeserializationContext deser
parser.nextToken();
JsonNotOptimizedCnecsParameters.deserialize(parser, parameters);
break;
case LOAD_FLOW_AND_SENSITIVITY_COMPUTATION:
case LOAD_FLOW_PARAMETERS:
parser.nextToken();
JsonLoadFlowAndSensitivityComputationParameters.deserialize(parser, parameters);
JsonLoadFlowParameters.deserialize(parser, deserializationContext, parameters.getLoadFlowParameters());
break;
case "extensions":
parser.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.powsybl.commons.json.JsonUtil;
import com.powsybl.loadflow.json.JsonLoadFlowParameters;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;

import java.io.IOException;
Expand All @@ -34,7 +35,7 @@ public void serialize(RaoParameters parameters, JsonGenerator jsonGenerator, Ser
JsonRangeActionsOptimizationParameters.serialize(parameters, jsonGenerator);
JsonTopoOptimizationParameters.serialize(parameters, jsonGenerator);
JsonNotOptimizedCnecsParameters.serialize(parameters, jsonGenerator);
JsonLoadFlowAndSensitivityComputationParameters.serialize(parameters, jsonGenerator, serializerProvider);
JsonLoadFlowParameters.serialize(parameters.getLoadFlowParameters(), jsonGenerator, serializerProvider);
JsonUtil.writeExtensions(parameters, jsonGenerator, serializerProvider, JsonRaoParameters.getExtensionSerializers());
jsonGenerator.writeEndObject();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters;
import com.powsybl.sensitivity.json.JsonSensitivityAnalysisParameters;

Expand Down Expand Up @@ -53,7 +52,7 @@ static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searc
break;
case SENSITIVITY_PARAMETERS:
jsonParser.nextToken();
searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityWithLoadFlowParameters(JsonSensitivityAnalysisParameters.createObjectMapper().readerForUpdating(raoParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters()).readValue(jsonParser));
searchTreeParameters.getLoadFlowAndSensitivityParameters().setSensitivityWithLoadFlowParameters(JsonSensitivityAnalysisParameters.createObjectMapper().readerForUpdating(searchTreeParameters.getLoadFlowAndSensitivityParameters().getSensitivityWithLoadFlowParameters()).readValue(jsonParser));
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize load flow and sensitivity parameters: unexpected field in %s (%s)", LOAD_FLOW_AND_SENSITIVITY_COMPUTATION, jsonParser.getCurrentName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
package com.powsybl.openrao.raoapi.json.extensions;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters;

import java.io.IOException;

Expand All @@ -24,36 +24,23 @@ final class JsonMultiThreadingParameters {
private JsonMultiThreadingParameters() {
}

static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException {
static void serialize(OpenRaoSearchTreeParameters parameters, JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeObjectFieldStart(MULTI_THREADING);
jsonGenerator.writeNumberField(CONTINGENCY_SCENARIOS_IN_PARALLEL, parameters.getMultithreadingParameters().getContingencyScenariosInParallel());
jsonGenerator.writeNumberField(PREVENTIVE_LEAVES_IN_PARALLEL, parameters.getMultithreadingParameters().getPreventiveLeavesInParallel());
jsonGenerator.writeNumberField(AUTO_LEAVES_IN_PARALLEL, parameters.getMultithreadingParameters().getAutoLeavesInParallel());
jsonGenerator.writeNumberField(CURATIVE_LEAVES_IN_PARALLEL, parameters.getMultithreadingParameters().getCurativeLeavesInParallel());
jsonGenerator.writeNumberField(AVAILABLE_CPUS, parameters.getMultithreadingParameters().getContingencyScenariosInParallel());
jsonGenerator.writeEndObject();
}

static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException {
static void deserialize(JsonParser jsonParser, OpenRaoSearchTreeParameters searchTreeParameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case CONTINGENCY_SCENARIOS_IN_PARALLEL:
jsonParser.nextToken();
raoParameters.getMultithreadingParameters().setContingencyScenariosInParallel(jsonParser.getIntValue());
break;
case PREVENTIVE_LEAVES_IN_PARALLEL:
jsonParser.nextToken();
raoParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(jsonParser.getIntValue());
break;
case AUTO_LEAVES_IN_PARALLEL:
jsonParser.nextToken();
raoParameters.getMultithreadingParameters().setAutoLeavesInParallel(jsonParser.getIntValue());
break;
case CURATIVE_LEAVES_IN_PARALLEL:
jsonParser.nextToken();
raoParameters.getMultithreadingParameters().setCurativeLeavesInParallel(jsonParser.getIntValue());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize multi-threading parameters: unexpected field in %s (%s)", MULTI_THREADING, jsonParser.getCurrentName()));
if (jsonParser.getCurrentName().equals(AVAILABLE_CPUS)) {
jsonParser.nextToken();
int availableCpus = jsonParser.getIntValue();
searchTreeParameters.getMultithreadingParameters().setContingencyScenariosInParallel(availableCpus);
searchTreeParameters.getMultithreadingParameters().setPreventiveLeavesInParallel(availableCpus);
searchTreeParameters.getMultithreadingParameters().setAutoLeavesInParallel(1);
searchTreeParameters.getMultithreadingParameters().setCurativeLeavesInParallel(1);
} else {
throw new OpenRaoException(String.format("Cannot deserialize multi-threading parameters: unexpected field in %s (%s)", MULTI_THREADING, jsonParser.getCurrentName()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.parameters.ObjectiveFunctionParameters;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.powsybl.openrao.raoapi.parameters.extensions.OpenRaoSearchTreeParameters;

import java.io.IOException;
Expand Down

This file was deleted.

Loading

0 comments on commit 01ec4ab

Please sign in to comment.