com.powsybl.openrao.raoapi.json.JsonSecondPreventiveRaoParameters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of open-rao-rao-api Show documentation
Show all versions of open-rao-rao-api Show documentation
Interface of a RA optimisation task
/*
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.openrao.raoapi.json;
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
import com.powsybl.openrao.raoapi.parameters.SecondPreventiveRaoParameters;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import java.io.IOException;
import static com.powsybl.openrao.raoapi.RaoParametersCommons.*;
/**
* @author Godelaine de Montmorillon {@literal }
*/
final class JsonSecondPreventiveRaoParameters {
private JsonSecondPreventiveRaoParameters() {
}
static void serialize(RaoParameters parameters, JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeObjectFieldStart(SECOND_PREVENTIVE_RAO);
jsonGenerator.writeObjectField(EXECUTION_CONDITION, parameters.getSecondPreventiveRaoParameters().getExecutionCondition());
jsonGenerator.writeBooleanField(RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS, parameters.getSecondPreventiveRaoParameters().getReOptimizeCurativeRangeActions());
jsonGenerator.writeBooleanField(HINT_FROM_FIRST_PREVENTIVE_RAO, parameters.getSecondPreventiveRaoParameters().getHintFromFirstPreventiveRao());
jsonGenerator.writeEndObject();
}
static void deserialize(JsonParser jsonParser, RaoParameters raoParameters) throws IOException {
while (!jsonParser.nextToken().isStructEnd()) {
switch (jsonParser.getCurrentName()) {
case EXECUTION_CONDITION:
raoParameters.getSecondPreventiveRaoParameters().setExecutionCondition(stringToExecutionCondition(jsonParser.nextTextValue()));
break;
case RE_OPTIMIZE_CURATIVE_RANGE_ACTIONS:
jsonParser.nextToken();
raoParameters.getSecondPreventiveRaoParameters().setReOptimizeCurativeRangeActions(jsonParser.getBooleanValue());
break;
case HINT_FROM_FIRST_PREVENTIVE_RAO:
jsonParser.nextToken();
raoParameters.getSecondPreventiveRaoParameters().setHintFromFirstPreventiveRao(jsonParser.getBooleanValue());
break;
default:
throw new OpenRaoException(String.format("Cannot deserialize second preventive rao parameters: unexpected field in %s (%s)", SECOND_PREVENTIVE_RAO, jsonParser.getCurrentName()));
}
}
}
private static SecondPreventiveRaoParameters.ExecutionCondition stringToExecutionCondition(String string) {
try {
return SecondPreventiveRaoParameters.ExecutionCondition.valueOf(string);
} catch (IllegalArgumentException e) {
throw new OpenRaoException(String.format("Unknown execution condition value: %s", string));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy