Skip to content

Commit

Permalink
Fix performance issue when accessing loading limits from IIDM (#1162)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg authored Dec 30, 2024
1 parent c7f69ad commit da71f30
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.function.Supplier;

/**
* @author Geoffroy Jamgotchian {@literal <geoffroy.jamgotchian at rte-france.com>}
Expand Down Expand Up @@ -132,16 +133,22 @@ public LfBus getBus2() {
return bus2;
}

public List<LfLimit> getLimits1(LimitType type, LoadingLimits loadingLimits, LimitReductionManager limitReductionManager) {
public <T extends LoadingLimits> List<LfLimit> getLimits1(LimitType type, Supplier<Optional<T>> loadingLimitsSupplier, LimitReductionManager limitReductionManager) {
// It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
return limits1.computeIfAbsent(type, v -> createSortedLimitsList(loadingLimits, bus1,
getLimitReductions(TwoSides.ONE, limitReductionManager, loadingLimits)));
return limits1.computeIfAbsent(type, v -> {
var loadingLimits = loadingLimitsSupplier.get().orElse(null);
return createSortedLimitsList(loadingLimits, bus1,
getLimitReductions(TwoSides.ONE, limitReductionManager, loadingLimits));
});
}

public List<LfLimit> getLimits2(LimitType type, LoadingLimits loadingLimits, LimitReductionManager limitReductionManager) {
public <T extends LoadingLimits> List<LfLimit> getLimits2(LimitType type, Supplier<Optional<T>> loadingLimitsSupplier, LimitReductionManager limitReductionManager) {
// It is possible to apply the reductions here since the only supported ContingencyContext for LimitReduction is ALL.
return limits2.computeIfAbsent(type, v -> createSortedLimitsList(loadingLimits, bus2,
getLimitReductions(TwoSides.TWO, limitReductionManager, loadingLimits)));
return limits2.computeIfAbsent(type, v -> {
var loadingLimits = loadingLimitsSupplier.get().orElse(null);
return createSortedLimitsList(loadingLimits, bus2,
getLimitReductions(TwoSides.TWO, limitReductionManager, loadingLimits));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
var branch = getBranch();
switch (type) {
case ACTIVE_POWER:
return getLimits1(type, branch.getActivePowerLimits1().orElse(null), limitReductionManager);
return getLimits1(type, branch::getActivePowerLimits1, limitReductionManager);
case APPARENT_POWER:
return getLimits1(type, branch.getApparentPowerLimits1().orElse(null), limitReductionManager);
return getLimits1(type, branch::getApparentPowerLimits1, limitReductionManager);
case CURRENT:
return getLimits1(type, branch.getCurrentLimits1().orElse(null), limitReductionManager);
return getLimits1(type, branch::getCurrentLimits1, limitReductionManager);
case VOLTAGE:
default:
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
Expand All @@ -253,11 +253,11 @@ public List<LfLimit> getLimits2(final LimitType type, LimitReductionManager limi
var branch = getBranch();
switch (type) {
case ACTIVE_POWER:
return getLimits2(type, branch.getActivePowerLimits2().orElse(null), limitReductionManager);
return getLimits2(type, branch::getActivePowerLimits2, limitReductionManager);
case APPARENT_POWER:
return getLimits2(type, branch.getApparentPowerLimits2().orElse(null), limitReductionManager);
return getLimits2(type, branch::getApparentPowerLimits2, limitReductionManager);
case CURRENT:
return getLimits2(type, branch.getCurrentLimits2().orElse(null), limitReductionManager);
return getLimits2(type, branch::getCurrentLimits2, limitReductionManager);
case VOLTAGE:
default:
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
var danglingLine = getDanglingLine();
switch (type) {
case ACTIVE_POWER:
return getLimits1(type, danglingLine.getActivePowerLimits().orElse(null), limitReductionManager);
return getLimits1(type, danglingLine::getActivePowerLimits, limitReductionManager);
case APPARENT_POWER:
return getLimits1(type, danglingLine.getApparentPowerLimits().orElse(null), limitReductionManager);
return getLimits1(type, danglingLine::getApparentPowerLimits, limitReductionManager);
case CURRENT:
return getLimits1(type, danglingLine.getCurrentLimits().orElse(null), limitReductionManager);
return getLimits1(type, danglingLine::getCurrentLimits, limitReductionManager);
case VOLTAGE:
default:
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
var leg = getLeg();
switch (type) {
case ACTIVE_POWER:
return getLimits1(type, leg.getActivePowerLimits().orElse(null), limitReductionManager);
return getLimits1(type, leg::getActivePowerLimits, limitReductionManager);
case APPARENT_POWER:
return getLimits1(type, leg.getApparentPowerLimits().orElse(null), limitReductionManager);
return getLimits1(type, leg::getApparentPowerLimits, limitReductionManager);
case CURRENT:
return getLimits1(type, leg.getCurrentLimits().orElse(null), limitReductionManager);
return getLimits1(type, leg::getCurrentLimits, limitReductionManager);
case VOLTAGE:
default:
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ public List<BranchResult> createBranchResult(double preContingencyBranchP1, doub
public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limitReductionManager) {
switch (type) {
case ACTIVE_POWER:
return getLimits1(type, getHalf1().getActivePowerLimits().orElse(null), limitReductionManager);
return getLimits1(type, getHalf1()::getActivePowerLimits, limitReductionManager);
case APPARENT_POWER:
return getLimits1(type, getHalf1().getApparentPowerLimits().orElse(null), limitReductionManager);
return getLimits1(type, getHalf1()::getApparentPowerLimits, limitReductionManager);
case CURRENT:
return getLimits1(type, getHalf1().getCurrentLimits().orElse(null), limitReductionManager);
return getLimits1(type, getHalf1()::getCurrentLimits, limitReductionManager);
case VOLTAGE:
default:
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
Expand All @@ -120,11 +120,11 @@ public List<LfLimit> getLimits1(final LimitType type, LimitReductionManager limi
public List<LfLimit> getLimits2(final LimitType type, LimitReductionManager limitReductionManager) {
switch (type) {
case ACTIVE_POWER:
return getLimits2(type, getHalf2().getActivePowerLimits().orElse(null), limitReductionManager);
return getLimits2(type, getHalf2()::getActivePowerLimits, limitReductionManager);
case APPARENT_POWER:
return getLimits2(type, getHalf2().getApparentPowerLimits().orElse(null), limitReductionManager);
return getLimits2(type, getHalf2()::getApparentPowerLimits, limitReductionManager);
case CURRENT:
return getLimits2(type, getHalf2().getCurrentLimits().orElse(null), limitReductionManager);
return getLimits2(type, getHalf2()::getCurrentLimits, limitReductionManager);
case VOLTAGE:
default:
throw new UnsupportedOperationException(String.format("Getting %s limits is not supported.", type.name()));
Expand Down

0 comments on commit da71f30

Please sign in to comment.