Skip to content

Commit

Permalink
Sort the dangling lines when creating a tie line to ensure reproducib…
Browse files Browse the repository at this point in the history
…ility (#2874)

Signed-off-by: Olivier Perrin <olivier.perrin@rte-france.com>
  • Loading branch information
olperr1 authored Jan 26, 2024
1 parent b44532e commit 251d866
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,11 @@ private void pairDanglingLines(List<DanglingLinePair> danglingLinePairs, Danglin
((DanglingLineImpl) dl2).replaceId(l.dl2Id + "_2");
l.dl1Id = dl1.getId();
l.dl2Id = dl2.getId();
} else if (l.dl1Id.compareTo(l.dl2Id) > 0) {
// Invert the ids to always have them in lexicographical order (to ensure reproducibility)
var tmp = l.dl1Id;
l.dl1Id = l.dl2Id;
l.dl2Id = tmp;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public void testMergeAndDetach() {
assertNotNull(tieLine);
assertEquals("dl1_name + dl2_name", tieLine.getOptionalName().orElse(null));
assertEquals("dl1_name + dl2_name", tieLine.getNameOrId());
assertEquals("dl1", tieLine.getDanglingLine1().getId());
assertEquals("dl2", tieLine.getDanglingLine2().getId());
assertEquals(0.0, tieLine.getDanglingLine1().getP0());
assertEquals(0.0, tieLine.getDanglingLine1().getQ0());
assertEquals(0.0, tieLine.getDanglingLine2().getP0());
Expand Down Expand Up @@ -624,6 +626,18 @@ public void mergeThenCloneVariantBug() {
assertEquals(0, ld2.getP0(), 0);
}

@Test
public void invertDanglingLinesWhenCreatingATieLine() {
addCommonSubstationsAndVoltageLevels();
addCommonDanglingLines("dl2", "code", "dl1", "code");
Network merge = Network.merge(n1, n2);
assertEquals(1, merge.getTieLineCount());
TieLine tieLine = merge.getTieLine("dl1 + dl2");
assertNotNull(tieLine);
assertEquals("dl1", tieLine.getDanglingLine1().getId());
assertEquals("dl2", tieLine.getDanglingLine2().getId());
}

@Test
public void dontCreateATieLineWithAlreadyMergedDanglingLinesInMergedNetwork() {
// The code is not the same if the dangling line with the duplicate pairing key is in the current network
Expand Down

0 comments on commit 251d866

Please sign in to comment.