Skip to content

Commit d3d7537

Browse files
authored
Merge branch 'main' into other_ptdf_sum_fix
2 parents db5730a + e5495f8 commit d3d7537

55 files changed

Lines changed: 1096 additions & 702 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Open RAO
22

3-
[![Actions Status](https://github.com/powsybl/powsybl-core/workflows/CI/badge.svg)](https://github.com/powsybl/powsybl-open-rao/actions)
3+
[![Actions Status](https://github.com/powsybl/powsybl-open-rao/actions/workflows/build_and_test.yml/badge.svg?branch=main)](https://github.com/powsybl/powsybl-open-rao/actions)
44
[![Coverage Status](https://sonarcloud.io/api/project_badges/measure?project=com.powsybl%3Aopen-rao&metric=coverage)](https://sonarcloud.io/component_measures?id=com.powsybl%3Aopen-rao&metric=coverage)
55
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.powsybl%3Aopen-rao&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.powsybl%3Aopen-rao)
66
[![MPL-2.0 License](https://img.shields.io/badge/license-MPL_2.0-blue.svg)](https://www.mozilla.org/en-US/MPL/2.0/)

commons/src/test/java/com/powsybl/openrao/commons/AbstractToolTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.junit.jupiter.api.Assertions.assertNotNull;
3838

3939
/**
40-
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
40+
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
4141
*/
4242
public abstract class AbstractToolTest {
4343

data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/usagerule/OnConstraint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import com.powsybl.openrao.data.crac.api.cnec.Cnec;
1010

1111
/**
12-
* @author Thomas Bouquet <thomas.bouquet at rte-france.com>
12+
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
1313
*/
1414
public interface OnConstraint<T extends Cnec<?>> extends UsageRule {
1515
/**

data/crac/crac-api/src/main/java/com/powsybl/openrao/data/crac/api/usagerule/OnConstraintAdder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import com.powsybl.openrao.data.crac.api.cnec.Cnec;
1111

1212
/**
13-
* @author Thomas Bouquet <thomas.bouquet at rte-france.com>
13+
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
1414
*/
1515
public interface OnConstraintAdder<T extends RemedialActionAdder<T>, S extends Cnec<?>> {
1616
OnConstraintAdder<T, S> withInstant(String instantId);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import static com.powsybl.openrao.data.crac.impl.AdderUtils.assertAttributeNotNull;
1919

2020
/**
21-
* @author Thomas Bouquet <thomas.bouquet at rte-france.com>
21+
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
2222
*/
2323
public class OnConstraintAdderImpl<T extends AbstractRemedialActionAdder<T>, S extends Cnec<?>> implements OnConstraintAdder<T, S> {
2424
public static final String ON_CONSTRAINT = "OnConstraint";

data/crac/crac-io/crac-io-commons/src/main/java/com/powsybl/openrao/data/crac/io/commons/ucte/UcteConnectable.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ enum Side {
6161
this.type = ConnectableType.getType(iidmConnectable);
6262
}
6363

64-
boolean doesMatch(String from, String to, String suffix, ConnectableType... connectableTypes) {
65-
return matchSuffix(suffix) && matchFromTo(from, to) && matchType(connectableTypes);
64+
boolean doesMatchWithOrderCode(String from, String to, String suffix, ConnectableType... connectableTypes) {
65+
return ucteOrderCodeMatchesSuffix(suffix) && matchFromTo(from, to) && matchType(connectableTypes);
6666
}
6767

68-
UcteMatchingResult getUcteMatchingResult(String from, String to, String suffix, ConnectableType... connectableTypes) {
69-
if (!doesMatch(from, to, suffix, connectableTypes)) {
70-
return UcteMatchingResult.notFound();
71-
} else {
72-
return UcteMatchingResult.found(iidmSide, isIidmConventionInverted, iidmIdentifiable);
73-
}
68+
boolean doesMatchWithElementName(String from, String to, String suffix, ConnectableType... connectableTypes) {
69+
return elementNameMatchesSuffix(suffix) && matchFromTo(from, to) && matchType(connectableTypes);
70+
}
71+
72+
UcteMatchingResult getUcteMatchingResult() {
73+
return UcteMatchingResult.found(iidmSide, isIidmConventionInverted, iidmIdentifiable);
7474
}
7575

7676
@Override
@@ -105,9 +105,12 @@ private boolean matchFromTo(String from, String to) {
105105
return UcteUtils.matchNodeNames(from, this.ucteFromNode) && UcteUtils.matchNodeNames(to, this.ucteToNode);
106106
}
107107

108-
private boolean matchSuffix(String suffix) {
109-
return suffix.equals(ucteOrderCode)
110-
|| ucteElementNames != null && ucteElementNames.contains(suffix);
108+
private boolean ucteOrderCodeMatchesSuffix(String suffix) {
109+
return suffix.equals(ucteOrderCode);
110+
}
111+
112+
private boolean elementNameMatchesSuffix(String suffix) {
113+
return ucteElementNames != null && ucteElementNames.contains(suffix);
111114
}
112115

113116
private boolean matchType(ConnectableType... connectableTypes) {

data/crac/crac-io/crac-io-commons/src/main/java/com/powsybl/openrao/data/crac/io/commons/ucte/UcteConnectableCollection.java

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package com.powsybl.openrao.data.crac.io.commons.ucte;
88

9+
import com.powsybl.openrao.commons.OpenRaoException;
910
import com.powsybl.openrao.data.crac.io.commons.ConnectableType;
1011
import com.google.common.collect.Ordering;
1112
import com.google.common.collect.TreeMultimap;
@@ -39,7 +40,7 @@ class UcteConnectableCollection {
3940
addHvdcs(network);
4041
}
4142

42-
UcteMatchingResult lookForConnectable(String fromNodeId, String toNodeId, String suffix, UcteNetworkAnalyzerProperties.BusIdMatchPolicy policy, ConnectableType... connectableTypes) {
43+
UcteMatchingResult lookForConnectable(String fromNodeId, String toNodeId, String suffix, UcteNetworkAnalyzerProperties ucteNetworkAnalyzerProperties, ConnectableType... connectableTypes) {
4344

4445
/*
4546
priority is given to the search with the from/to direction given in argument
@@ -55,17 +56,17 @@ UcteMatchingResult lookForConnectable(String fromNodeId, String toNodeId, String
5556
method returns the connectable with the id in the same order as the ones given in argument of the method.
5657
*/
5758

58-
UcteMatchingResult ucteMatchingResult = lookForMatch(fromNodeId, toNodeId, suffix, connectableTypes);
59+
UcteMatchingResult ucteMatchingResult = lookForMatch(fromNodeId, toNodeId, suffix, ucteNetworkAnalyzerProperties, connectableTypes);
5960

6061
if (!ucteMatchingResult.getStatus().equals(UcteMatchingResult.MatchStatus.NOT_FOUND)) {
6162
return ucteMatchingResult;
6263
}
6364

6465
// if no result has been found in the direction in argument, look for an inverted one
65-
ucteMatchingResult = lookForMatch(toNodeId, fromNodeId, suffix, connectableTypes);
66+
ucteMatchingResult = lookForMatch(toNodeId, fromNodeId, suffix, ucteNetworkAnalyzerProperties, connectableTypes);
6667

6768
if (!ucteMatchingResult.getStatus().equals(UcteMatchingResult.MatchStatus.NOT_FOUND)
68-
|| !policy.equals(UcteNetworkAnalyzerProperties.BusIdMatchPolicy.REPLACE_8TH_CHARACTER_WITH_WILDCARD)) {
69+
|| !ucteNetworkAnalyzerProperties.getBusIdMatchPolicy().equals(UcteNetworkAnalyzerProperties.BusIdMatchPolicy.REPLACE_8TH_CHARACTER_WITH_WILDCARD)) {
6970
return ucteMatchingResult.invert();
7071
}
7172

@@ -75,24 +76,25 @@ UcteMatchingResult lookForConnectable(String fromNodeId, String toNodeId, String
7576
String toWildcard = String.format("%1$-7s", toNodeId).substring(0, 7) + UcteUtils.WILDCARD_CHARACTER;
7677

7778
// with the direction in argument ...
78-
ucteMatchingResult = lookForMatch(fromWildcard, toWildcard, suffix, connectableTypes);
79+
ucteMatchingResult = lookForMatch(fromWildcard, toWildcard, suffix, ucteNetworkAnalyzerProperties, connectableTypes);
7980

8081
if (!ucteMatchingResult.getStatus().equals(UcteMatchingResult.MatchStatus.NOT_FOUND)) {
8182
return ucteMatchingResult;
8283
}
8384

8485
// or, if not found, with the inverted direction
85-
return lookForMatch(toWildcard, fromWildcard, suffix, connectableTypes).invert();
86+
return lookForMatch(toWildcard, fromWildcard, suffix, ucteNetworkAnalyzerProperties, connectableTypes).invert();
8687

8788
}
8889

89-
private UcteMatchingResult lookForMatch(String fromNodeId, String toNodeId, String suffix, ConnectableType... types) {
90+
private UcteMatchingResult lookForMatch(String fromNodeId, String toNodeId, String suffix,
91+
UcteNetworkAnalyzerProperties ucteNetworkAnalyzerProperties, ConnectableType... types) {
9092

9193
if (!fromNodeId.endsWith(UcteUtils.WILDCARD_CHARACTER)) {
9294

9395
// if the from node contains no wildcard, directly look for the entry of the TreeMultimap with the fromNode id
9496
Collection<UcteConnectable> ucteElements = connectables.asMap().getOrDefault(fromNodeId, Collections.emptyList());
95-
return lookForMatchWithinCollection(fromNodeId, toNodeId, suffix, ucteElements, types);
97+
return lookForMatchWithinCollection(fromNodeId, toNodeId, suffix, ucteElements, ucteNetworkAnalyzerProperties, types);
9698

9799
} else {
98100

@@ -106,37 +108,71 @@ private UcteMatchingResult lookForMatch(String fromNodeId, String toNodeId, Stri
106108
.flatMap(Collection::stream)
107109
.toList();
108110

109-
return lookForMatchWithinCollection(fromNodeId, toNodeId, suffix, ucteElements, types);
111+
return lookForMatchWithinCollection(fromNodeId, toNodeId, suffix, ucteElements, ucteNetworkAnalyzerProperties, types);
110112
}
111113
}
112114

113-
private UcteMatchingResult lookForMatchWithinCollection(String fromNodeId, String toNodeId, String suffix, Collection<UcteConnectable> ucteConnectables, ConnectableType... connectableTypes) {
115+
private UcteMatchingResult lookForMatchWithinCollection(String fromNodeId, String toNodeId, String suffix,
116+
Collection<UcteConnectable> ucteConnectables,
117+
UcteNetworkAnalyzerProperties ucteNetworkAnalyzerProperties,
118+
ConnectableType... connectableTypes) {
114119

115-
if (fromNodeId.endsWith(UcteUtils.WILDCARD_CHARACTER) || toNodeId.endsWith(UcteUtils.WILDCARD_CHARACTER)) {
116-
// if the nodes contains wildCards, we have to look for all possible match
120+
List<UcteMatchingResult> matchedConnectables = getUcteMatchingResultsWithPriority(fromNodeId, toNodeId, suffix,
121+
ucteConnectables, ucteNetworkAnalyzerProperties.getSuffixMatchPriority(), connectableTypes);
117122

118-
List<UcteMatchingResult> matchedConnectables = ucteConnectables.stream()
119-
.filter(ucteConnectable -> ucteConnectable.doesMatch(fromNodeId, toNodeId, suffix, connectableTypes))
120-
.map(ucteConnectable -> ucteConnectable.getUcteMatchingResult(fromNodeId, toNodeId, suffix, connectableTypes))
121-
.toList();
122-
123-
if (matchedConnectables.size() == 1) {
124-
return matchedConnectables.get(0);
125-
} else if (matchedConnectables.size() == 2) {
126-
return UcteMatchingResult.severalPossibleMatch();
127-
} else if (matchedConnectables.size() > 2) {
128-
return UcteMatchingResult.severalPossibleMatch();
129-
} else {
130-
return UcteMatchingResult.notFound();
131-
}
123+
if (matchedConnectables.size() == 1) {
124+
return matchedConnectables.get(0);
125+
} else if (matchedConnectables.size() == 2) {
126+
return UcteMatchingResult.severalPossibleMatch();
127+
} else if (matchedConnectables.size() > 2) {
128+
return UcteMatchingResult.severalPossibleMatch();
132129
} else {
130+
return UcteMatchingResult.notFound();
131+
}
132+
}
133133

134-
// if the nodes contains no wildCards, speed up the search by using findAny() instead of looking for all possible matches
135-
return ucteConnectables.stream()
136-
.filter(ucteConnectable -> ucteConnectable.doesMatch(fromNodeId, toNodeId, suffix, connectableTypes))
137-
.map(ucteConnectable -> ucteConnectable.getUcteMatchingResult(fromNodeId, toNodeId, suffix, connectableTypes))
138-
.findAny().orElse(UcteMatchingResult.notFound());
134+
private static List<UcteMatchingResult> getUcteMatchingResultsWithPriority(String fromNodeId, String toNodeId, String suffix,
135+
Collection<UcteConnectable> ucteConnectables,
136+
UcteNetworkAnalyzerProperties.SuffixMatchPriority suffixMatchPriority,
137+
ConnectableType[] connectableTypes) {
138+
List<UcteMatchingResult> matchedConnectables;
139+
140+
switch (suffixMatchPriority) {
141+
case ALL:
142+
matchedConnectables = ucteConnectables.stream()
143+
.filter(ucteConnectable -> ucteConnectable.doesMatchWithElementName(fromNodeId, toNodeId, suffix, connectableTypes)
144+
|| ucteConnectable.doesMatchWithOrderCode(fromNodeId, toNodeId, suffix, connectableTypes))
145+
.map(UcteConnectable::getUcteMatchingResult)
146+
.toList();
147+
break;
148+
case ORDERCODE_BEFORE_NAME:
149+
matchedConnectables = ucteConnectables.stream()
150+
.filter(ucteConnectable -> ucteConnectable.doesMatchWithOrderCode(fromNodeId, toNodeId, suffix, connectableTypes))
151+
.map(UcteConnectable::getUcteMatchingResult)
152+
.toList();
153+
if (matchedConnectables.isEmpty()) {
154+
matchedConnectables = ucteConnectables.stream()
155+
.filter(ucteConnectable -> ucteConnectable.doesMatchWithElementName(fromNodeId, toNodeId, suffix, connectableTypes))
156+
.map(UcteConnectable::getUcteMatchingResult)
157+
.toList();
158+
}
159+
break;
160+
case NAME_BEFORE_ORDERCODE:
161+
matchedConnectables = ucteConnectables.stream()
162+
.filter(ucteConnectable -> ucteConnectable.doesMatchWithElementName(fromNodeId, toNodeId, suffix, connectableTypes))
163+
.map(UcteConnectable::getUcteMatchingResult)
164+
.toList();
165+
if (matchedConnectables.isEmpty()) {
166+
matchedConnectables = ucteConnectables.stream()
167+
.filter(ucteConnectable -> ucteConnectable.doesMatchWithOrderCode(fromNodeId, toNodeId, suffix, connectableTypes))
168+
.map(UcteConnectable::getUcteMatchingResult)
169+
.toList();
170+
}
171+
break;
172+
default:
173+
throw new OpenRaoException(String.format("SuffixMatchPriority %s is not handled", suffixMatchPriority));
139174
}
175+
return matchedConnectables;
140176
}
141177

142178
private void addBranches(Network network) {

data/crac/crac-io/crac-io-commons/src/main/java/com/powsybl/openrao/data/crac/io/commons/ucte/UcteNetworkAnalyzer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@ public UcteNetworkAnalyzerProperties getProperties() {
4040
}
4141

4242
UcteMatchingResult findContingencyElement(String from, String to, String suffix) {
43-
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties.getBusIdMatchPolicy(),
44-
ConnectableType.INTERNAL_LINE, ConnectableType.TIE_LINE, ConnectableType.DANGLING_LINE, ConnectableType.VOLTAGE_TRANSFORMER, ConnectableType.PST, ConnectableType.HVDC);
43+
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties,
44+
ConnectableType.INTERNAL_LINE, ConnectableType.TIE_LINE, ConnectableType.DANGLING_LINE, ConnectableType.VOLTAGE_TRANSFORMER, ConnectableType.PST, ConnectableType.HVDC, ConnectableType.SWITCH);
4545
}
4646

4747
UcteMatchingResult findFlowElement(String from, String to, String suffix) {
48-
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties.getBusIdMatchPolicy(),
48+
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties,
4949
ConnectableType.INTERNAL_LINE, ConnectableType.TIE_LINE, ConnectableType.DANGLING_LINE, ConnectableType.VOLTAGE_TRANSFORMER, ConnectableType.PST);
5050
}
5151

5252
UcteMatchingResult findTopologicalElement(String from, String to, String suffix) {
53-
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties.getBusIdMatchPolicy(),
53+
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties,
5454
ConnectableType.INTERNAL_LINE, ConnectableType.TIE_LINE, ConnectableType.DANGLING_LINE, ConnectableType.VOLTAGE_TRANSFORMER, ConnectableType.PST, ConnectableType.SWITCH);
5555
}
5656

5757
UcteMatchingResult findPstElement(String from, String to, String suffix) {
58-
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties.getBusIdMatchPolicy(), ConnectableType.PST);
58+
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties, ConnectableType.PST);
5959
}
6060

6161
UcteMatchingResult findHvdcElement(String from, String to, String suffix) {
62-
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties.getBusIdMatchPolicy(), ConnectableType.HVDC);
62+
return connectablesInNetwork.lookForConnectable(completeNodeName(from), completeNodeName(to), suffix, properties, ConnectableType.HVDC);
6363
}
6464

6565
private String completeNodeName(String nodeName) {

data/crac/crac-io/crac-io-commons/src/main/java/com/powsybl/openrao/data/crac/io/commons/ucte/UcteNetworkAnalyzerProperties.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,32 @@ public enum BusIdMatchPolicy {
2121
REPLACE_8TH_CHARACTER_WITH_WILDCARD
2222
}
2323

24-
private BusIdMatchPolicy busIdMatchPolicy;
24+
public enum SuffixMatchPriority {
25+
ORDERCODE_BEFORE_NAME,
26+
NAME_BEFORE_ORDERCODE,
27+
ALL
28+
}
29+
30+
private static final SuffixMatchPriority DEFAULT_SUFFIX_MATCH_PRIORITY = SuffixMatchPriority.ALL;
31+
32+
private final BusIdMatchPolicy busIdMatchPolicy;
33+
private final SuffixMatchPriority suffixMatchPriority;
2534

2635
public UcteNetworkAnalyzerProperties(BusIdMatchPolicy busIdMatchPolicy) {
36+
this(busIdMatchPolicy, DEFAULT_SUFFIX_MATCH_PRIORITY);
37+
}
38+
39+
public UcteNetworkAnalyzerProperties(BusIdMatchPolicy busIdMatchPolicy, SuffixMatchPriority suffixMatchPriority) {
2740
this.busIdMatchPolicy = busIdMatchPolicy;
41+
this.suffixMatchPriority = suffixMatchPriority;
2842
}
2943

3044
public BusIdMatchPolicy getBusIdMatchPolicy() {
3145
return busIdMatchPolicy;
3246
}
47+
48+
public SuffixMatchPriority getSuffixMatchPriority() {
49+
return suffixMatchPriority;
50+
}
51+
3352
}

0 commit comments

Comments
 (0)