Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable rescale if AC does not converge #56

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ DecomposedFlow rescale(DecomposedFlow decomposedFlow) {
Country country1 = decomposedFlow.getCountry1();
Country country2 = decomposedFlow.getCountry2();
double internalFlow = decomposedFlow.getInternalFlow();
if (Double.isNaN(acReferenceFlow)) {
return decomposedFlow;
}
double deltaToRescale = acReferenceFlow * Math.signum(acReferenceFlow) - decomposedFlow.getTotalFlow();
double sumOfReLUFlows = reLU(allocatedFlow) + reLU(pstFlow) + loopFlows.values().stream().mapToDouble(this::reLU).sum() + reLU(internalFlow);
Map<String, Double> rescaledLoopFlows = loopFlows.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Map;
import java.util.TreeMap;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Sebastien Murgey {@literal <sebastien.murgey at rte-france.com>}
Expand Down Expand Up @@ -144,11 +144,11 @@ void testNoNormalizationWithFlowDecompositionResultsWithPstNetwork() {
static void testNormalizationWithFlowDecompositionResults(String networkFileName, boolean enableRescaledResults) {
Network network = AllocatedFlowTests.importNetwork(networkFileName);

FlowDecompositionParameters flowDecompositionParameters = new FlowDecompositionParameters();
flowDecompositionParameters.setEnableLossesCompensation(FlowDecompositionParameters.ENABLE_LOSSES_COMPENSATION);
flowDecompositionParameters.setLossesCompensationEpsilon(FlowDecompositionParameters.DISABLE_LOSSES_COMPENSATION_EPSILON);
flowDecompositionParameters.setSensitivityEpsilon(FlowDecompositionParameters.DISABLE_SENSITIVITY_EPSILON);
flowDecompositionParameters.setRescaleEnabled(enableRescaledResults);
FlowDecompositionParameters flowDecompositionParameters = new FlowDecompositionParameters()
.setEnableLossesCompensation(FlowDecompositionParameters.ENABLE_LOSSES_COMPENSATION)
.setLossesCompensationEpsilon(FlowDecompositionParameters.DISABLE_LOSSES_COMPENSATION_EPSILON)
.setSensitivityEpsilon(FlowDecompositionParameters.DISABLE_SENSITIVITY_EPSILON)
.setRescaleEnabled(enableRescaledResults);

FlowDecompositionComputer flowDecompositionComputer = new FlowDecompositionComputer(flowDecompositionParameters);
FlowDecompositionResults flowDecompositionResults = flowDecompositionComputer.run(network);
Expand All @@ -162,4 +162,26 @@ static void testNormalizationWithFlowDecompositionResults(String networkFileName
}
}
}

@Test
void testRescalingDoesNotOccurWhenAcDiverge() {
String networkFileName = "NETWORK_LOOP_FLOW_WITH_COUNTRIES.uct";
Network network = AllocatedFlowTests.importNetwork(networkFileName);

FlowDecompositionParameters flowDecompositionParameters = new FlowDecompositionParameters()
.setEnableLossesCompensation(FlowDecompositionParameters.ENABLE_LOSSES_COMPENSATION)
.setLossesCompensationEpsilon(FlowDecompositionParameters.DISABLE_LOSSES_COMPENSATION_EPSILON)
.setSensitivityEpsilon(FlowDecompositionParameters.DISABLE_SENSITIVITY_EPSILON)
.setRescaleEnabled(FlowDecompositionParameters.ENABLE_RESCALED_RESULTS);

FlowDecompositionComputer flowDecompositionComputer = new FlowDecompositionComputer(flowDecompositionParameters);
FlowDecompositionResults flowDecompositionResults = flowDecompositionComputer.run(network);

String xnecId = "BLOAD 11 FLOAD 11 1";
assertTrue(Double.isNaN(flowDecompositionResults.getDecomposedFlowMapBeforeRescaling().get(xnecId).getAcReferenceFlow()));
assertFalse(Double.isNaN(flowDecompositionResults.getDecomposedFlowMapBeforeRescaling().get(xnecId).getAllocatedFlow()));
assertTrue(Double.isNaN(flowDecompositionResults.getDecomposedFlowMap().get(xnecId).getAcReferenceFlow()));
assertFalse(Double.isNaN(flowDecompositionResults.getDecomposedFlowMap().get(xnecId).getAllocatedFlow()));

}
}