Skip to content

Commit

Permalink
Merge pull request #187 from farao-community/fix-glsk-limitation
Browse files Browse the repository at this point in the history
Change threshold in initial shift for Glsk limitation
  • Loading branch information
kahyami authored May 14, 2024
2 parents 0f7340f + 44e56ab commit 97acc23
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ private static void stackScalableOnLoads(Network network, ZonalData<Scalable> zo

private static double getZoneSumOfActiveLoads(Network network, CseCountry cseCountry) {
return network.getLoadStream()
.filter(load -> isLoadCorrespondingToTheCountry(load, cseCountry))
.map(Load::getP0)
.map(Math::abs)
.filter(load -> isLoadCorrespondingToTheCountry(load, cseCountry)).map(Load::getP0)
.filter(p0 -> p0 > 0)
.reduce(0., Double::sum);
}

Expand All @@ -78,7 +77,7 @@ private static Scalable getStackedScalable(CseCountry cseCountry, Scalable scala
List<Scalable> scalableList = new ArrayList<>();

network.getLoadStream()
.filter(load -> isLoadCorrespondingToTheCountry(load, cseCountry))
.filter(load -> isLoadCorrespondingToTheCountry(load, cseCountry) && load.getP0() > 0)
.forEach(load -> {
percentageList.add(Math.abs(load.getP0() / sum) * 100);
scalableList.add(Scalable.onLoad(load.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ private void shiftNetwork(Map<String, Double> scalingValuesByCountry, CseRequest
ZonalData<Scalable> zonalScalable = getZonalScalableForProcess(cseRequest, network);
String initialVariantId = network.getVariantManager().getWorkingVariantId();
// SecureRandom used to be compliant with sonar
String newVariant = "temporary-working-variant" + new SecureRandom().nextInt(100) + initialVariantId;
network.getVariantManager().cloneVariant(initialVariantId, newVariant);
String newVariant = "temporary-working-variant" + new SecureRandom().nextInt(100);

network.getVariantManager().cloneVariant(initialVariantId, newVariant, true);
network.getVariantManager().setWorkingVariant(newVariant);
ScalingParameters scalingParameters = new ScalingParameters();
scalingParameters.setIterative(true);
Expand All @@ -102,8 +103,8 @@ private void shiftNetwork(Map<String, Double> scalingValuesByCountry, CseRequest
double done = zonalScalable.getData(zoneId).scale(network, asked, scalingParameters);
businessLogger.info(String.format("Applying variation on zone %s (target: %.2f, done: %.2f)", zoneId, asked, done));

if (Math.abs(done - asked) > 1e-3) {
businessLogger.warn(String.format("Glsk limitation : Incomplete variation on zone %s (target: %.2f, done: %.2f)",
if (Math.abs(done - asked) > 1e-2) {
businessLogger.warn(String.format("Glsk limitation : Incomplete variation on zone %s (target: %.3f, done: %.3f)",
zoneId, asked, done));
if (zoneId.equals(new EICode(Country.IT).getAreaCode())) {
double italyGlskLimitationSplittingFactor = done / asked;
Expand All @@ -115,6 +116,10 @@ private void shiftNetwork(Map<String, Double> scalingValuesByCountry, CseRequest
}
}
}
//Save shift in the initial variant
network.getVariantManager().cloneVariant(newVariant, initialVariantId, true);
network.getVariantManager().setWorkingVariant(initialVariantId);
network.getVariantManager().removeVariant(newVariant);

}

Expand Down

0 comments on commit 97acc23

Please sign in to comment.