Skip to content

Commit 35f3506

Browse files
authored
added range type for all ranges (#1672)
* added range type for all ranges --------- Signed-off-by: EDWARDS Philippe <edwardsphi@gm0winl1028.bureau.si.interne>
1 parent 421066b commit 35f3506

15 files changed

Lines changed: 360 additions & 24 deletions

File tree

data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/range/StandardRangeAdder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ public interface StandardRangeAdder<T extends StandardRangeActionAdder<T>> {
1919

2020
StandardRangeAdder<T> withMax(double maxSetpoint);
2121

22+
StandardRangeAdder<T> withRangeType(RangeType rangeType);
23+
2224
T add();
2325
}

data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/StandardRangeAdderImpl.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.powsybl.openrao.data.crac.impl;
99

1010
import com.powsybl.openrao.commons.OpenRaoException;
11+
import com.powsybl.openrao.data.crac.api.range.RangeType;
1112
import com.powsybl.openrao.data.crac.api.range.StandardRange;
1213
import com.powsybl.openrao.data.crac.api.range.StandardRangeAdder;
1314
import com.powsybl.openrao.data.crac.api.rangeaction.StandardRangeActionAdder;
@@ -23,11 +24,13 @@ public class StandardRangeAdderImpl<T extends StandardRangeActionAdder<T>> imple
2324

2425
private Double min;
2526
private Double max;
27+
private RangeType rangeType;
2628

2729
StandardRangeAdderImpl(AbstractStandardRangeActionAdder<T> ownerAdder) {
2830
this.ownerAdder = ownerAdder;
2931
this.min = Double.MIN_VALUE;
3032
this.max = Double.MAX_VALUE;
33+
this.rangeType = RangeType.ABSOLUTE;
3134
}
3235

3336
@Override
@@ -42,22 +45,27 @@ public StandardRangeAdder<T> withMax(double maxSetpoint) {
4245
return this;
4346
}
4447

48+
@Override
49+
public StandardRangeAdder<T> withRangeType(RangeType rangeType) {
50+
this.rangeType = rangeType;
51+
return this;
52+
}
53+
4554
@Override
4655
public T add() {
4756
AdderUtils.assertAttributeNotNull(min, CLASS_NAME, "min value", "withMin()");
4857
AdderUtils.assertAttributeNotNull(max, CLASS_NAME, "max value", "withMax()");
4958

50-
if (max == Double.MAX_VALUE) {
51-
throw new OpenRaoException("StandardRange max value was not defined.");
59+
if (max == Double.MAX_VALUE && rangeType.equals(RangeType.ABSOLUTE)) {
60+
throw new OpenRaoException("StandardRange max value was not defined for absolute range.");
5261
}
53-
if (min == Double.MIN_VALUE) {
54-
throw new OpenRaoException("StandardRange min value was not defined.");
62+
if (min == Double.MIN_VALUE && rangeType.equals(RangeType.ABSOLUTE)) {
63+
throw new OpenRaoException("StandardRange min value was not defined for absolute range.");
5564
}
5665
if (max < min) {
5766
throw new OpenRaoException("Max value of StandardRange must be equal or greater than min value.");
5867
}
59-
60-
StandardRange standardRange = new StandardRangeImpl(min, max);
68+
StandardRange standardRange = new StandardRangeImpl(min, max, rangeType);
6169

6270
ownerAdder.addRange(standardRange);
6371
return (T) ownerAdder;

data/crac/crac-impl/src/main/java/com/powsybl/openrao/data/crac/impl/StandardRangeImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public class StandardRangeImpl extends AbstractRange implements StandardRange {
2020
private final double min;
2121
private final double max;
2222

23-
StandardRangeImpl(double min, double max) {
24-
super(RangeType.ABSOLUTE, Unit.MEGAWATT);
23+
StandardRangeImpl(double min, double max, RangeType rangeType) {
24+
super(rangeType, Unit.MEGAWATT);
2525
this.min = min;
2626
this.max = max;
2727
}

data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/HvdcRangeActionImplTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ void hvdcWithSpecificRange() {
139139
void hvdcWithNoMin() {
140140
StandardRangeAdder<HvdcRangeActionAdder> standardRangeAdder = hvdcRangeActionAdder.newRange().withMax(10);
141141
OpenRaoException exception = assertThrows(OpenRaoException.class, standardRangeAdder::add);
142-
assertEquals("StandardRange min value was not defined.", exception.getMessage());
142+
assertEquals("StandardRange min value was not defined for absolute range.", exception.getMessage());
143143
}
144144

145145
@Test
146146
void hvdcWithNoMax() {
147147
StandardRangeAdder<HvdcRangeActionAdder> standardRangeAdder = hvdcRangeActionAdder.newRange().withMin(10);
148148
OpenRaoException exception = assertThrows(OpenRaoException.class, standardRangeAdder::add);
149-
assertEquals("StandardRange max value was not defined.", exception.getMessage());
149+
assertEquals("StandardRange max value was not defined for absolute range.", exception.getMessage());
150150
}
151151

152152
@Test

data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/StandardRangeAdderImplTest.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ public void setUp() {
3838

3939
@Test
4040
void testOk() {
41-
HvdcRangeAction hvdcRangeAction = hvdcRangeActionAdder.newRange().withMin(-5).withMax(10).add()
42-
.add();
41+
HvdcRangeAction hvdcRangeAction = hvdcRangeActionAdder
42+
.newRange().withMin(-5).withMax(10).add()
43+
.add();
4344

4445
assertEquals(1, hvdcRangeAction.getRanges().size());
4546
assertEquals(-5, hvdcRangeAction.getRanges().get(0).getMin(), 1e-6);
@@ -48,6 +49,19 @@ void testOk() {
4849
assertEquals(Unit.MEGAWATT, hvdcRangeAction.getRanges().get(0).getUnit());
4950
}
5051

52+
@Test
53+
void testRangeActionType() {
54+
HvdcRangeAction hvdcRangeAction = hvdcRangeActionAdder
55+
.newRange().withRangeType(RangeType.RELATIVE_TO_PREVIOUS_INSTANT).withMin(-5).withMax(10).add()
56+
.add();
57+
58+
assertEquals(1, hvdcRangeAction.getRanges().size());
59+
assertEquals(-5, hvdcRangeAction.getRanges().get(0).getMin(), 1e-6);
60+
assertEquals(10, hvdcRangeAction.getRanges().get(0).getMax(), 1e-6);
61+
assertEquals(RangeType.RELATIVE_TO_PREVIOUS_INSTANT, hvdcRangeAction.getRanges().get(0).getRangeType());
62+
assertEquals(Unit.MEGAWATT, hvdcRangeAction.getRanges().get(0).getUnit());
63+
}
64+
5165
@Test
5266
void testNoMin() {
5367
StandardRangeAdder<HvdcRangeActionAdder> standardRangeAdder = hvdcRangeActionAdder.newRange().withMax(16);

data/crac/crac-impl/src/test/java/com/powsybl/openrao/data/crac/impl/StandardRangeImplTest.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ class StandardRangeImplTest {
2323
private final double max = 32;
2424

2525
private StandardRangeImpl fixedRange;
26+
private StandardRangeImpl relativeRange;
2627

2728
@BeforeEach
2829
public void setUp() {
29-
fixedRange = new StandardRangeImpl(min, max);
30+
fixedRange = new StandardRangeImpl(min, max, RangeType.ABSOLUTE);
31+
relativeRange = new StandardRangeImpl(min, max, RangeType.RELATIVE_TO_PREVIOUS_INSTANT);
3032
}
3133

3234
@Test
@@ -42,23 +44,24 @@ void getMaxTest() {
4244
@Test
4345
void getRangeTypeTest() {
4446
assertEquals(RangeType.ABSOLUTE, fixedRange.getRangeType());
47+
assertEquals(RangeType.RELATIVE_TO_PREVIOUS_INSTANT, relativeRange.getRangeType());
4548
}
4649

4750
@Test
4851
void testEquals() {
49-
StandardRangeImpl range1 = new StandardRangeImpl(0, 10);
50-
StandardRangeImpl range2 = new StandardRangeImpl(0, 10);
51-
StandardRangeImpl range3 = new StandardRangeImpl(0, 11);
52+
StandardRangeImpl range1 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
53+
StandardRangeImpl range2 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
54+
StandardRangeImpl range3 = new StandardRangeImpl(0, 11, RangeType.ABSOLUTE);
5255

5356
assertEquals(range1, range2);
5457
assertNotEquals(range1, range3);
5558
}
5659

5760
@Test
5861
void testHashCode() {
59-
StandardRangeImpl range1 = new StandardRangeImpl(0, 10);
60-
StandardRangeImpl range2 = new StandardRangeImpl(0, 10);
61-
StandardRangeImpl range3 = new StandardRangeImpl(0, 11);
62+
StandardRangeImpl range1 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
63+
StandardRangeImpl range2 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
64+
StandardRangeImpl range3 = new StandardRangeImpl(0, 11, RangeType.ABSOLUTE);
6265

6366
assertEquals(range1.hashCode(), range2.hashCode());
6467
assertNotEquals(range1.hashCode(), range3.hashCode());

data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/deserializers/StandardRangeArrayDeserializer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static void deserialize(JsonParser jsonParser, StandardRangeActionAdder<?
3737
jsonParser.nextToken();
3838
adder.withMax(jsonParser.getDoubleValue());
3939
break;
40+
case JsonSerializationConstants.RANGE_TYPE:
41+
adder.withRangeType(JsonSerializationConstants.deserializeRangeType(jsonParser.nextTextValue()));
42+
break;
4043
default:
4144
throw new OpenRaoException("Unexpected field in StandardRange: " + jsonParser.getCurrentName());
4245
}

data/crac/crac-io/crac-io-json/src/main/java/com/powsybl/openrao/data/crac/io/json/serializers/StandardRangeSerializer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public void serialize(StandardRange value, JsonGenerator gen, SerializerProvider
2727
if (value.getMax() < Integer.MAX_VALUE) {
2828
gen.writeNumberField(JsonSerializationConstants.MAX, value.getMax());
2929
}
30+
gen.writeStringField(JsonSerializationConstants.RANGE_TYPE, JsonSerializationConstants.serializeRangeType(value.getRangeType()));
3031
gen.writeEndObject();
3132
}
3233
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema#",
3+
"$id": "resource:/schemas/counter-trade-range-action/counter-trade-range-action-v2.10.json",
4+
"type": "object",
5+
"properties": {
6+
"id": {
7+
"type": "string"
8+
},
9+
"name": {
10+
"type": [
11+
"string",
12+
"null"
13+
]
14+
},
15+
"operator": {
16+
"type": [
17+
"string",
18+
"null"
19+
]
20+
},
21+
"activationCost": "number",
22+
"variationCosts": {
23+
"$ref": "../variation-costs/variation-costs-v2.6.json"
24+
},
25+
"groupId": {
26+
"type": [
27+
"string",
28+
"null"
29+
]
30+
},
31+
"speed": {
32+
"type": "number"
33+
},
34+
"exportingCountry": {
35+
"$ref": "../country/country-v1.3.json"
36+
},
37+
"importingCountry": {
38+
"$ref": "../country/country-v1.3.json"
39+
},
40+
"ranges": {
41+
"type": "array",
42+
"items": {
43+
"type": "object",
44+
"properties": {
45+
"rangeType": {
46+
"$ref": "../range-type/range-type-v2.3.json"
47+
},
48+
"max": {
49+
"type": "number"
50+
},
51+
"min": {
52+
"type": "number"
53+
}
54+
},
55+
"additionalProperties": false
56+
}
57+
},
58+
"onInstantUsageRules": {
59+
"type": "array",
60+
"items": {
61+
"$ref": "../on-instant-usage-rule/on-instant-usage-rule-v2.8.json"
62+
}
63+
},
64+
"onContingencyStateUsageRules": {
65+
"type": "array",
66+
"items": {
67+
"$ref": "../on-contingency-state-usage-rule/on-contingency-state-usage-rule-v2.8.json"
68+
}
69+
},
70+
"onConstraintUsageRules": {
71+
"type": "array",
72+
"items": {
73+
"$ref": "../on-constraint-usage-rule/on-constraint-usage-rule-v2.8.json"
74+
}
75+
},
76+
"onFlowConstraintInCountryUsageRules": {
77+
"type": "array",
78+
"items": {
79+
"$ref": "../on-flow-constraint-in-country-usage-rule/on-flow-constraint-in-country-usage-rule-v2.8.json"
80+
}
81+
}
82+
},
83+
"additionalProperties": false,
84+
"required": [
85+
"id",
86+
"exportingCountry",
87+
"importingCountry",
88+
"ranges"
89+
]
90+
}

data/crac/crac-io/crac-io-json/src/main/resources/schemas/crac/crac-v2.10.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@
8080
"hvdcRangeActions": {
8181
"type": "array",
8282
"items": {
83-
"$ref": "../hvdc-range-action/hvdc-range-action-v2.8.json"
83+
"$ref": "../hvdc-range-action/hvdc-range-action-v2.10.json"
8484
}
8585
},
8686
"injectionRangeActions": {
8787
"type": "array",
8888
"items": {
89-
"$ref": "../injection-range-action/injection-range-action-v2.8.json"
89+
"$ref": "../injection-range-action/injection-range-action-v2.10.json"
9090
}
9191
},
9292
"counterTradeRangeActions": {
9393
"type": "array",
9494
"items": {
95-
"$ref": "../counter-trade-range-action/counter-trade-range-action-v2.8.json"
95+
"$ref": "../counter-trade-range-action/counter-trade-range-action-v2.10.json"
9696
}
9797
},
9898
"networkActions": {

0 commit comments

Comments
 (0)