Skip to content

Commit a791e4d

Browse files
authored
All optional attributes in GeneratorConstraints (#1345)
* optional attributes in GeneratorConstraints Signed-off-by: Thomas Bouquet <[email protected]> * coverage Signed-off-by: Thomas Bouquet <[email protected]> * fix test Signed-off-by: Thomas Bouquet <[email protected]> * sonar Signed-off-by: Thomas Bouquet <[email protected]> --------- Signed-off-by: Thomas Bouquet <[email protected]>
1 parent c6c0fd8 commit a791e4d

File tree

2 files changed

+36
-58
lines changed

2 files changed

+36
-58
lines changed

data/generator-constraints/src/main/java/com/powsybl/openrao/data/generatorconstraints/GeneratorConstraints.java

+20-29
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
*/
1919
public final class GeneratorConstraints {
2020
private final String generatorId;
21-
private final double pMin;
22-
private final double pMax;
23-
private final double leadTime;
24-
private final double lagTime;
21+
private final Double pMin;
22+
private final Double pMax;
23+
private final Double leadTime;
24+
private final Double lagTime;
2525
private final Double minUpTime;
2626
private final Double maxUpTime;
2727
private final Double minOffTime;
2828
private final Double upwardPowerGradient;
2929
private final Double downwardPowerGradient;
3030

31-
private GeneratorConstraints(String generatorId, double pMin, double pMax, double leadTime, double lagTime, Double minUpTime, Double maxUpTime, Double minOffTime, Double upwardPowerGradient, Double downwardPowerGradient) {
31+
private GeneratorConstraints(String generatorId, Double pMin, Double pMax, Double leadTime, Double lagTime, Double minUpTime, Double maxUpTime, Double minOffTime, Double upwardPowerGradient, Double downwardPowerGradient) {
3232
this.generatorId = generatorId;
3333
this.pMin = pMin;
3434
this.pMax = pMax;
@@ -53,32 +53,32 @@ public String getGeneratorId() {
5353
* Get the minimal operational power of the generator in MW.
5454
* @return minimal operational power of the generator
5555
*/
56-
public double getPMin() {
57-
return pMin;
56+
public Optional<Double> getPMin() {
57+
return Optional.ofNullable(pMin);
5858
}
5959

6060
/**
6161
* Get the maximal operational power of the generator in MW.
6262
* @return maximal operational power of the generator
6363
*/
64-
public double getPMax() {
65-
return pMax;
64+
public Optional<Double> getPMax() {
65+
return Optional.ofNullable(pMax);
6666
}
6767

6868
/**
6969
* Get the lead time of the generator, i.e. the time required by the power to go from 0 to pMin, in hours.
7070
* @return lead time of the generator
7171
*/
72-
public double getLeadTime() {
73-
return leadTime;
72+
public Optional<Double> getLeadTime() {
73+
return Optional.ofNullable(leadTime);
7474
}
7575

7676
/**
7777
* Get the lag time of the generator, i.e. the time required by the power to go from pMin to 0, in hours.
7878
* @return lag time of the generator
7979
*/
80-
public double getLagTime() {
81-
return lagTime;
80+
public Optional<Double> getLagTime() {
81+
return Optional.ofNullable(lagTime);
8282
}
8383

8484
/**
@@ -198,28 +198,19 @@ public GeneratorConstraints build() {
198198
if (generatorId == null) {
199199
throw new OpenRaoException("The id of the generator is mandatory.");
200200
}
201-
if (pMin == null) {
202-
throw new OpenRaoException("The pMin of the generator is mandatory.");
203-
}
204-
if (pMax == null) {
205-
throw new OpenRaoException("The pMax of the generator is mandatory.");
206-
}
207-
if (leadTime == null) {
208-
throw new OpenRaoException("The lead time of the generator is mandatory.");
209-
}
210-
if (lagTime == null) {
211-
throw new OpenRaoException("The lag time of the generator is mandatory.");
212-
}
213-
if (pMin < 0) {
201+
if (pMin != null && pMin < 0) {
214202
throw new OpenRaoException("The minimal power of the generator must be positive.");
215203
}
216-
if (pMax < pMin) {
204+
if (pMax != null && pMax < 0) {
205+
throw new OpenRaoException("The maximal power of the generator must be positive.");
206+
}
207+
if (pMin != null && pMax != null && pMax < pMin) {
217208
throw new OpenRaoException("The maximal power of the generator must greater than its minimal power.");
218209
}
219-
if (leadTime < 0) {
210+
if (leadTime != null && leadTime < 0) {
220211
throw new OpenRaoException("The lead time of the generator must be positive.");
221212
}
222-
if (lagTime < 0) {
213+
if (lagTime != null && lagTime < 0) {
223214
throw new OpenRaoException("The lag time of the generator must be positive.");
224215
}
225216
if (minUpTime != null && minUpTime < 0) {

data/generator-constraints/src/test/java/com/powsybl/openrao/data/generatorconstraints/GeneratorConstraintsTest.java

+16-29
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ void testBuildSimpleGeneratorConstraints() {
3030
.withLagTime(2.)
3131
.build();
3232
assertEquals("generator", generatorConstraints.getGeneratorId());
33-
assertEquals(400., generatorConstraints.getPMin());
34-
assertEquals(1000., generatorConstraints.getPMax());
35-
assertEquals(1., generatorConstraints.getLeadTime());
36-
assertEquals(2., generatorConstraints.getLagTime());
33+
assertEquals(Optional.of(400.), generatorConstraints.getPMin());
34+
assertEquals(Optional.of(1000.), generatorConstraints.getPMax());
35+
assertEquals(Optional.of(1.), generatorConstraints.getLeadTime());
36+
assertEquals(Optional.of(2.), generatorConstraints.getLagTime());
3737
assertTrue(generatorConstraints.getMinUpTime().isEmpty());
3838
assertTrue(generatorConstraints.getMaxUpTime().isEmpty());
3939
assertTrue(generatorConstraints.getMinOffTime().isEmpty());
@@ -56,10 +56,10 @@ void testBuildComprehensiveGeneratorConstraints() {
5656
.withDownwardPowerGradient(-100.)
5757
.build();
5858
assertEquals("generator", generatorConstraints.getGeneratorId());
59-
assertEquals(400., generatorConstraints.getPMin());
60-
assertEquals(1000., generatorConstraints.getPMax());
61-
assertEquals(1., generatorConstraints.getLeadTime());
62-
assertEquals(2., generatorConstraints.getLagTime());
59+
assertEquals(Optional.of(400.), generatorConstraints.getPMin());
60+
assertEquals(Optional.of(1000.), generatorConstraints.getPMax());
61+
assertEquals(Optional.of(1.), generatorConstraints.getLeadTime());
62+
assertEquals(Optional.of(2.), generatorConstraints.getLagTime());
6363
assertEquals(Optional.of(4.), generatorConstraints.getMinUpTime());
6464
assertEquals(Optional.of(6.5), generatorConstraints.getMaxUpTime());
6565
assertEquals(Optional.of(3.), generatorConstraints.getMinOffTime());
@@ -68,28 +68,9 @@ void testBuildComprehensiveGeneratorConstraints() {
6868
}
6969

7070
@Test
71-
void testBuildWithMissingData() {
72-
OpenRaoException exception;
73-
74-
// missing id
75-
exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withPMin(400.).withPMax(1000.).withLeadTime(1.).withLagTime(1.).build());
71+
void testBuildWithMissingId() {
72+
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withPMin(400.).withPMax(1000.).withLeadTime(1.).withLagTime(1.).build());
7673
assertEquals("The id of the generator is mandatory.", exception.getMessage());
77-
78-
// missing pMin
79-
exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withGeneratorId("generator").withPMax(1000.).withLeadTime(1.).withLagTime(1.).build());
80-
assertEquals("The pMin of the generator is mandatory.", exception.getMessage());
81-
82-
// missing pMax
83-
exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withGeneratorId("generator").withPMin(400.).withLeadTime(1.).withLagTime(1.).build());
84-
assertEquals("The pMax of the generator is mandatory.", exception.getMessage());
85-
86-
// missing lead time
87-
exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withGeneratorId("generator").withPMin(400.).withPMax(1000.).withLagTime(1.).build());
88-
assertEquals("The lead time of the generator is mandatory.", exception.getMessage());
89-
90-
// missing lag time
91-
exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withGeneratorId("generator").withPMin(400.).withPMax(1000.).withLeadTime(1.).build());
92-
assertEquals("The lag time of the generator is mandatory.", exception.getMessage());
9374
}
9475

9576
@Test
@@ -98,6 +79,12 @@ void testNegativePMin() {
9879
assertEquals("The minimal power of the generator must be positive.", exception.getMessage());
9980
}
10081

82+
@Test
83+
void testNegativePMax() {
84+
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withGeneratorId("generator").withPMax(-200.).withLeadTime(1.).withLagTime(1.).build());
85+
assertEquals("The maximal power of the generator must be positive.", exception.getMessage());
86+
}
87+
10188
@Test
10289
void testPMaxLowerThanPMin() {
10390
OpenRaoException exception = assertThrows(OpenRaoException.class, () -> GeneratorConstraints.create().withGeneratorId("generator").withPMin(400.).withPMax(300.).withLeadTime(1.).withLagTime(1.).build());

0 commit comments

Comments
 (0)