Skip to content

Commit

Permalink
Refactor alphaCoefficient parameter into activePowerVariationRate.
Browse files Browse the repository at this point in the history
Signed-off-by: parvy <[email protected]>
  • Loading branch information
p-arvy committed Apr 18, 2024
1 parent b49014d commit 325c6fe
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public class OpenReacParameters {

private ReactiveSlackBusesMode reactiveSlackBusesMode = ReactiveSlackBusesMode.NO_GENERATION;

private static final String ALPHA_COEFFICIENT_KEY = "coeff_alpha";
private static final String ACTIVE_POWER_VARIATION_RATE_KEY = "coeff_alpha";

private double alphaCoefficient = 1; // in [0;1]
private double activePowerVariationRate = 1; // in [0;1]

private static final String MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY = "Pnull";

Expand Down Expand Up @@ -295,15 +295,15 @@ public OpenReacParameters setReactiveSlackBusesMode(ReactiveSlackBusesMode react
/**
* @return the weight to favor more/less minimization of active power produced by generators.
*/
public double getAlphaCoefficient() {
return alphaCoefficient;
public double getActivePowerVariationRate() {
return activePowerVariationRate;
}

public OpenReacParameters setAlphaCoefficient(double alphaCoefficient) {
if (Double.isNaN(alphaCoefficient) || alphaCoefficient < 0 || alphaCoefficient > 1) {
throw new IllegalArgumentException("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.");
public OpenReacParameters setActivePowerVariationRate(double activePowerVariationRate) {
if (Double.isNaN(activePowerVariationRate) || activePowerVariationRate < 0 || activePowerVariationRate > 1) {
throw new IllegalArgumentException("Active power variation rate must be defined and between 0 and 1 to be consistent.");
}
this.alphaCoefficient = alphaCoefficient;
this.activePowerVariationRate = activePowerVariationRate;
return this;
}

Expand Down Expand Up @@ -516,7 +516,7 @@ public List<OpenReacAlgoParam> getAllAlgorithmParams() {
allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_LOW_VOLTAGE_LIMIT_KEY, Double.toString(minPlausibleLowVoltageLimit)));
allAlgoParams.add(new OpenReacAlgoParamImpl(MAX_PLAUSIBLE_HIGH_VOLTAGE_LIMIT_KEY, Double.toString(maxPlausibleHighVoltageLimit)));
allAlgoParams.add(reactiveSlackBusesMode.toParam());
allAlgoParams.add(new OpenReacAlgoParamImpl(ALPHA_COEFFICIENT_KEY, Double.toString(alphaCoefficient)));
allAlgoParams.add(new OpenReacAlgoParamImpl(ACTIVE_POWER_VARIATION_RATE_KEY, Double.toString(activePowerVariationRate)));
allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_PLAUSIBLE_ACTIVE_POWER_THRESHOLD_KEY, Double.toString(minPlausibleActivePowerThreshold)));
allAlgoParams.add(new OpenReacAlgoParamImpl(LOW_IMPEDANCE_THRESHOLD_KEY, Double.toString(lowImpedanceThreshold)));
allAlgoParams.add(new OpenReacAlgoParamImpl(MIN_NOMINAL_VOLTAGE_IGNORED_BUS_KEY, Double.toString(minNominalVoltageIgnoredBus)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public OpenReacParameters deserialize(JsonParser parser, DeserializationContext
parser.nextToken();
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.valueOf(parser.getText()));
}
case "alphaCoefficient" -> {
case "activePowerVariationRate" -> {
parser.nextToken();
parameters.setAlphaCoefficient(parser.getValueAsDouble());
parameters.setActivePowerVariationRate(parser.getValueAsDouble());
}
case "minPlausibleActivePowerThreshold" -> {
parser.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void serialize(OpenReacParameters openReacParameters, JsonGenerator jsonG
serializerProvider.defaultSerializeField("minPlausibleLowVoltageLimit", openReacParameters.getMinPlausibleLowVoltageLimit(), jsonGenerator);
serializerProvider.defaultSerializeField("maxPlausibleHighVoltageLimit", openReacParameters.getMaxPlausibleHighVoltageLimit(), jsonGenerator);
serializerProvider.defaultSerializeField("reactiveSlackBusesMode", openReacParameters.getReactiveSlackBusesMode().name(), jsonGenerator);
serializerProvider.defaultSerializeField("alphaCoefficient", openReacParameters.getAlphaCoefficient(), jsonGenerator);
serializerProvider.defaultSerializeField("activePowerVariationRate", openReacParameters.getActivePowerVariationRate(), jsonGenerator);
serializerProvider.defaultSerializeField("minPlausibleActivePowerThreshold", openReacParameters.getMinPlausibleActivePowerThreshold(), jsonGenerator);
serializerProvider.defaultSerializeField("lowImpedanceThreshold", openReacParameters.getLowImpedanceThreshold(), jsonGenerator);
serializerProvider.defaultSerializeField("minNominalVoltageIgnoredBus", openReacParameters.getMinNominalVoltageIgnoredBus(), jsonGenerator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ void testMinMaxVoltageLimitIntegrity() {
}

@Test
void testAlphaCoefficientIntegrity() {
void testActivePowerVariationRateIntegrity() {
OpenReacParameters parameters = new OpenReacParameters();
parameters.setAlphaCoefficient(0); // min value
assertEquals(0., parameters.getAlphaCoefficient());
parameters.setAlphaCoefficient(0.445556);
assertEquals(0.445556, parameters.getAlphaCoefficient());

IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(-1.2));
assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e1.getMessage());
IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(42));
assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e2.getMessage());
IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setAlphaCoefficient(Double.NaN));
assertEquals("Coefficient alpha parameter must be defined and between 0 and 1 to be consistent.", e3.getMessage());
parameters.setActivePowerVariationRate(0); // min value
assertEquals(0., parameters.getActivePowerVariationRate());
parameters.setActivePowerVariationRate(0.445556);
assertEquals(0.445556, parameters.getActivePowerVariationRate());

IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class, () -> parameters.setActivePowerVariationRate(-1.2));
assertEquals("Active power variation rate must be defined and between 0 and 1 to be consistent.", e1.getMessage());
IllegalArgumentException e2 = assertThrows(IllegalArgumentException.class, () -> parameters.setActivePowerVariationRate(42));
assertEquals("Active power variation rate must be defined and between 0 and 1 to be consistent.", e2.getMessage());
IllegalArgumentException e3 = assertThrows(IllegalArgumentException.class, () -> parameters.setActivePowerVariationRate(Double.NaN));
assertEquals("Active power variation rate must be defined and between 0 and 1 to be consistent.", e3.getMessage());
assertTrue(parameters.checkAlgorithmParametersIntegrity());
}

Expand Down Expand Up @@ -310,7 +310,7 @@ void testAlgorithmParams() {
parameters.setMinPlausibleLowVoltageLimit(0.8);
parameters.setMaxPlausibleHighVoltageLimit(1.2);
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL);
parameters.setAlphaCoefficient(0.56);
parameters.setActivePowerVariationRate(0.56);
parameters.setMinPlausibleActivePowerThreshold(0.5);
parameters.setLowImpedanceThreshold(1e-5);
parameters.setMinNominalVoltageIgnoredBus(10);
Expand Down Expand Up @@ -374,7 +374,7 @@ void testDefaultParametersValuesIntegrity() {
assertEquals(0.5, parameters.getMinPlausibleLowVoltageLimit());
assertEquals(1.5, parameters.getMaxPlausibleHighVoltageLimit());
assertEquals(ReactiveSlackBusesMode.NO_GENERATION, parameters.getReactiveSlackBusesMode());
assertEquals(1., parameters.getAlphaCoefficient());
assertEquals(1., parameters.getActivePowerVariationRate());
assertEquals(0.01, parameters.getMinPlausibleActivePowerThreshold());
assertEquals(1e-4, parameters.getLowImpedanceThreshold());
assertEquals(1., parameters.getMinNominalVoltageIgnoredBus());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void testModifiedParamAlgoExport() throws IOException {
.setMinPlausibleLowVoltageLimit(0.7888)
.setMaxPlausibleHighVoltageLimit(1.3455)
.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL)
.setAlphaCoefficient(0.88)
.setActivePowerVariationRate(0.88)
.setMinPlausibleActivePowerThreshold(0.45)
.setLowImpedanceThreshold(1e-5)
.setMinNominalVoltageIgnoredBus(2.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void testOpenReacParametersThresholds() throws IOException {
parameters.setMinPlausibleLowVoltageLimit(0.755);
parameters.setMaxPlausibleHighVoltageLimit(1.236);
parameters.setReactiveSlackBusesMode(ReactiveSlackBusesMode.ALL);
parameters.setAlphaCoefficient(0.56);
parameters.setActivePowerVariationRate(0.56);
parameters.setMinPlausibleActivePowerThreshold(0.5);
parameters.setLowImpedanceThreshold(1e-5);
parameters.setMinNominalVoltageIgnoredBus(10.);
Expand All @@ -108,7 +108,7 @@ void testOpenReacParametersThresholds() throws IOException {
assertEquals(1.236, parameters2.getMaxPlausibleHighVoltageLimit());
assertEquals(ReactiveSlackBusesMode.ALL, parameters2.getReactiveSlackBusesMode());
assertEquals(OpenReacOptimisationObjective.MIN_GENERATION, parameters2.getObjective());
assertEquals(0.56, parameters2.getAlphaCoefficient());
assertEquals(0.56, parameters2.getActivePowerVariationRate());
assertEquals(0.5, parameters2.getMinPlausibleActivePowerThreshold());
assertEquals(1e-5, parameters2.getLowImpedanceThreshold());
assertEquals(10., parameters2.getMinNominalVoltageIgnoredBus());
Expand Down
2 changes: 1 addition & 1 deletion open-reac/src/test/resources/parametersLists.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"minPlausibleLowVoltageLimit" : 0.5,
"maxPlausibleHighVoltageLimit" : 1.5,
"reactiveSlackBusesMode" : "CONFIGURED",
"alphaCoefficient" : 1.0,
"activePowerVariationRate" : 1.0,
"minPlausibleActivePowerThreshold" : 0.01,
"lowImpedanceThreshold" : 1.0E-4,
"minNominalVoltageIgnoredBus" : 1.0,
Expand Down
2 changes: 1 addition & 1 deletion open-reac/src/test/resources/parametersThresholds.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"minPlausibleLowVoltageLimit" : 0.755,
"maxPlausibleHighVoltageLimit" : 1.236,
"reactiveSlackBusesMode" : "ALL",
"alphaCoefficient" : 0.56,
"activePowerVariationRate" : 0.56,
"minPlausibleActivePowerThreshold" : 0.5,
"lowImpedanceThreshold" : 1.0E-5,
"minNominalVoltageIgnoredBus" : 10.0,
Expand Down

0 comments on commit 325c6fe

Please sign in to comment.