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

[CSA] [Import] Reorder usage rules definition #972

Merged
merged 10 commits into from
Apr 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.contingency.CsaProfileContingencyCreator;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction.CsaProfileRemedialActionsCreator;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction.ElementaryActionsHelper;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction.OnConstraintUsageRuleHelper;
import com.google.auto.service.AutoService;
import com.powsybl.iidm.network.Network;
import com.powsybl.openrao.data.craccreation.creator.csaprofile.parameters.CsaCracCreationParameters;
Expand Down Expand Up @@ -61,12 +60,12 @@ public CsaProfileCracCreationContext createCrac(CsaProfileCrac nativeCrac, Netwo
Map<String, String> overridingData = nativeCrac.getOverridingCracData(offsetDateTime);
PropertyBags contingencies = CsaProfileCracUtils.overrideData(nativeCrac.getContingencies(), overridingData, CsaProfileConstants.OverridingObjectsFields.CONTINGENCY);
PropertyBags assessedElements = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElements(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT);
PropertyBags assessedElementsWithContingencies = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithContingencies(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_CONTINGENCY);
PropertyBags assessedElementWithContingencies = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithContingencies(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_CONTINGENCY);
PropertyBags currentLimits = CsaProfileCracUtils.overrideData(nativeCrac.getCurrentLimits(), overridingData, CsaProfileConstants.OverridingObjectsFields.CURRENT_LIMIT);
PropertyBags voltageLimits = CsaProfileCracUtils.overrideData(nativeCrac.getVoltageLimits(), overridingData, CsaProfileConstants.OverridingObjectsFields.VOLTAGE_LIMIT);
PropertyBags angleLimits = CsaProfileCracUtils.overrideData(nativeCrac.getAngleLimits(), overridingData, CsaProfileConstants.OverridingObjectsFields.VOLTAGE_ANGLE_LIMIT);
PropertyBags assessedElementsWithRemedialAction = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_REMEDIAL_ACTION);
PropertyBags contingenciesWithRemedialAction = CsaProfileCracUtils.overrideData(nativeCrac.getContingencyWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.CONTINGENCY_WITH_REMEDIAL_ACTION);
PropertyBags assessedElementWithRemedialActions = CsaProfileCracUtils.overrideData(nativeCrac.getAssessedElementsWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.ASSESSED_ELEMENT_WITH_REMEDIAL_ACTION);
PropertyBags contingencyWithRemedialActions = CsaProfileCracUtils.overrideData(nativeCrac.getContingencyWithRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.CONTINGENCY_WITH_REMEDIAL_ACTION);
PropertyBags gridStateAlterationRemedialAction = CsaProfileCracUtils.overrideData(nativeCrac.getGridStateAlterationRemedialAction(), overridingData, CsaProfileConstants.OverridingObjectsFields.GRID_STATE_ALTERATION_REMEDIAL_ACTION);
PropertyBags remedialActionSchemes = CsaProfileCracUtils.overrideData(nativeCrac.getRemedialActionScheme(), overridingData, CsaProfileConstants.OverridingObjectsFields.REMEDIAL_ACTION_SCHEME);
PropertyBags gridStateAlterationsCollection = CsaProfileCracUtils.overrideData(nativeCrac.getGridStateAlterationCollection(), overridingData, CsaProfileConstants.OverridingObjectsFields.GRID_STATE_ALTERATION);
Expand All @@ -80,11 +79,10 @@ public CsaProfileCracCreationContext createCrac(CsaProfileCrac nativeCrac, Netwo

createContingencies(contingencies, nativeCrac.getContingencyEquipments());

createCnecs(assessedElements, assessedElementsWithContingencies, currentLimits, voltageLimits, angleLimits, cracCreationParameters.getDefaultMonitoredSides(), regionEicCode);
createCnecs(assessedElements, assessedElementWithContingencies, currentLimits, voltageLimits, angleLimits, cracCreationParameters.getDefaultMonitoredSides(), regionEicCode);

OnConstraintUsageRuleHelper onConstraintUsageRuleAdder = new OnConstraintUsageRuleHelper(creationContext.getCnecCreationContexts(), assessedElements, assessedElementsWithRemedialAction);
ElementaryActionsHelper elementaryActionsHelper = new ElementaryActionsHelper(gridStateAlterationRemedialAction, schemeRemedialActions, remedialActionSchemes, nativeCrac.getStage(), gridStateAlterationsCollection, assessedElementsWithRemedialAction, contingenciesWithRemedialAction, staticPropertyRanges, topologyActions, rotatingMachineActions, shuntCompensatorModifications, tapPositionActions, nativeCrac.getRemedialActionGroups(), remedialActionDependencies);
createRemedialActions(onConstraintUsageRuleAdder, elementaryActionsHelper, spsMaxTimeToImplementThreshold);
ElementaryActionsHelper elementaryActionsHelper = new ElementaryActionsHelper(gridStateAlterationRemedialAction, schemeRemedialActions, remedialActionSchemes, nativeCrac.getStage(), gridStateAlterationsCollection, assessedElementWithRemedialActions, contingencyWithRemedialActions, staticPropertyRanges, topologyActions, rotatingMachineActions, shuntCompensatorModifications, tapPositionActions, nativeCrac.getRemedialActionGroups(), remedialActionDependencies);
createRemedialActions(elementaryActionsHelper, spsMaxTimeToImplementThreshold, assessedElements, assessedElementWithRemedialActions, contingencyWithRemedialActions, creationContext.getCnecCreationContexts());
creationContext.buildCreationReport();
return creationContext.creationSuccess(crac);
}
Expand Down Expand Up @@ -116,8 +114,8 @@ private boolean checkTimeCoherence(PropertyBag header, OffsetDateTime offsetDate
return isValidInterval(offsetDateTime, startTime, endTime);
}

private void createRemedialActions(OnConstraintUsageRuleHelper onConstraintUsageRuleAdder, ElementaryActionsHelper elementaryActionsHelper, int spsMaxTimeToImplementThreshold) {
new CsaProfileRemedialActionsCreator(crac, network, creationContext, onConstraintUsageRuleAdder, elementaryActionsHelper, spsMaxTimeToImplementThreshold);
private void createRemedialActions(ElementaryActionsHelper elementaryActionsHelper, int spsMaxTimeToImplementThreshold, PropertyBags assessedElements, PropertyBags assessedElementWithRemedialActions, PropertyBags contingencyWithRemedialActions, Set<CsaProfileElementaryCreationContext> cnecCreationContexts) {
new CsaProfileRemedialActionsCreator(crac, network, creationContext, elementaryActionsHelper, spsMaxTimeToImplementThreshold, assessedElements, assessedElementWithRemedialActions, contingencyWithRemedialActions, cnecCreationContexts);
}

private void createContingencies(PropertyBags contingenciesPropertyBags, PropertyBags contingencyEquipmentsPropertyBags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ private CsaProfileCracUtils() {

}

public static Map<String, Set<PropertyBag>> getMappedPropertyBagsSet(PropertyBags propertyBags, String property) {
public static Map<String, Set<PropertyBag>> groupPropertyBagsBy(PropertyBags propertyBags, String groupBy) {
bqth29 marked this conversation as resolved.
Show resolved Hide resolved
Map<String, Set<PropertyBag>> mappedPropertyBags = new HashMap<>();
for (PropertyBag propertyBag : propertyBags) {
String propValue = propertyBag.getId(property);
String propValue = propertyBag.getId(groupBy);
bqth29 marked this conversation as resolved.
Show resolved Hide resolved
Set<PropertyBag> propPropertyBags = mappedPropertyBags.computeIfAbsent(propValue, k -> new HashSet<>());
propPropertyBags.add(propertyBag);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public CsaProfileCnecCreator(Crac crac, Network network, PropertyBags assessedEl
this.crac = crac;
this.network = network;
this.assessedElementsPropertyBags = assessedElementsPropertyBags;
this.assessedElementsWithContingenciesPropertyBags = CsaProfileCracUtils.getMappedPropertyBagsSet(assessedElementsWithContingenciesPropertyBags, CsaProfileConstants.REQUEST_ASSESSED_ELEMENT);
this.currentLimitsPropertyBags = CsaProfileCracUtils.getMappedPropertyBagsSet(currentLimitsPropertyBags, CsaProfileConstants.REQUEST_CURRENT_LIMIT);
this.voltageLimitsPropertyBags = CsaProfileCracUtils.getMappedPropertyBagsSet(voltageLimitsPropertyBags, CsaProfileConstants.REQUEST_VOLTAGE_LIMIT);
this.angleLimitsPropertyBags = CsaProfileCracUtils.getMappedPropertyBagsSet(angleLimitsPropertyBags, CsaProfileConstants.REQUEST_VOLTAGE_ANGLE_LIMIT);
this.assessedElementsWithContingenciesPropertyBags = CsaProfileCracUtils.groupPropertyBagsBy(assessedElementsWithContingenciesPropertyBags, CsaProfileConstants.REQUEST_ASSESSED_ELEMENT);
this.currentLimitsPropertyBags = CsaProfileCracUtils.groupPropertyBagsBy(currentLimitsPropertyBags, CsaProfileConstants.REQUEST_CURRENT_LIMIT);
this.voltageLimitsPropertyBags = CsaProfileCracUtils.groupPropertyBagsBy(voltageLimitsPropertyBags, CsaProfileConstants.REQUEST_VOLTAGE_LIMIT);
this.angleLimitsPropertyBags = CsaProfileCracUtils.groupPropertyBagsBy(angleLimitsPropertyBags, CsaProfileConstants.REQUEST_VOLTAGE_ANGLE_LIMIT);
this.cracCreationContext = cracCreationContext;
this.defaultMonitoredSides = defaultMonitoredSides;
this.regionEic = regionEic;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CsaProfileContingencyCreator(Crac crac, Network network, PropertyBags con
this.crac = crac;
this.network = network;
this.contingenciesPropertyBags = contingenciesPropertyBags;
this.contingencyEquipmentsPropertyBags = CsaProfileCracUtils.getMappedPropertyBagsSet(contingencyEquipmentsPropertyBags, CsaProfileConstants.REQUEST_CONTINGENCY);
this.contingencyEquipmentsPropertyBags = CsaProfileCracUtils.groupPropertyBagsBy(contingencyEquipmentsPropertyBags, CsaProfileConstants.REQUEST_CONTINGENCY);
this.cracCreationContext = cracCreationContext;
this.createAndAddContingencies();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (c) 2024, 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 com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.remedialaction;

import com.powsybl.openrao.data.craccreation.creator.csaprofile.craccreator.CsaProfileConstants;

/**
* @author Thomas Bouquet <thomas.bouquet at rte-france.com>
*/
public record AssociationStatus(boolean isValid,
CsaProfileConstants.ElementCombinationConstraintKind elementCombinationConstraintKind,
String statusDetails) {
}
Loading
Loading