-
Notifications
You must be signed in to change notification settings - Fork 19
/
BranchParallelIndexes.java
87 lines (78 loc) · 3.3 KB
/
BranchParallelIndexes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Copyright (c) 2016, All partners of the iTesla project (http://www.itesla-project.eu/consortium)
* Copyright (c) 2017, 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 eu.itesla_project.iidm.eurostag.export;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap;
import eu.itesla_project.iidm.network.*;
import java.util.*;
/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
*/
public class BranchParallelIndexes {
private final Map<String, Character> parallelIndexes;
public static BranchParallelIndexes build(Network network, EurostagEchExportConfig config, EurostagFakeNodes fakeNodes) {
Multimap<String, Identifiable> map = HashMultimap.create();
for (Branch branch : Iterables.concat(network.getLines(), network.getTwoWindingsTransformers())) {
ConnectionBus bus1 = ConnectionBus.fromTerminal(branch.getTerminal1(), config, fakeNodes);
ConnectionBus bus2 = ConnectionBus.fromTerminal(branch.getTerminal2(), config, fakeNodes);
if (bus1.getId().compareTo(bus2.getId()) < 0) {
map.put(bus1.getId() + bus2.getId(), branch);
} else {
map.put(bus2.getId() + bus1.getId(), branch);
}
}
for (VoltageLevel vl : network.getVoltageLevels()) {
for (Switch s : EchUtil.getSwitches(vl, config)) {
Bus bus1 = EchUtil.getBus1(vl, s.getId(), config);
Bus bus2 = EchUtil.getBus2(vl, s.getId(), config);
if (bus1.getId().compareTo(bus2.getId()) < 0) {
map.put(bus1.getId() + bus2.getId(), s);
} else {
map.put(bus2.getId() + bus1.getId(), s);
}
}
}
Map<String, Character> parallelIndexes = new HashMap<>();
for (Map.Entry<String, Collection<Identifiable>> entry : map.asMap().entrySet()) {
List<Identifiable> eqs = new ArrayList<>(entry.getValue());
Collections.sort(eqs, (o1, o2) -> o1.getId().compareTo(o2.getId()));
if (eqs.size() >= 2) {
char index = '0';
for (Identifiable l : eqs) {
index = incParallelIndex(index);
parallelIndexes.put(l.getId(), index);
}
}
}
return new BranchParallelIndexes(parallelIndexes);
}
private BranchParallelIndexes(Map<String, Character> parallelIndexes) {
this.parallelIndexes = parallelIndexes;
}
private static char incParallelIndex(char index) {
if (index == 'Z') {
throw new RuntimeException("Number max of parallel index reached");
}
if (index == '9') {
return 'A';
} else {
return ++index;
}
}
public char getParallelIndex(String iidmId) {
Character index = parallelIndexes.get(iidmId);
if (index == null) {
return '1';
}
return index;
}
public Map<String, Character> toMap() {
return parallelIndexes;
}
}