Skip to content

[WIP] Run marmot using fast_rao (POC) #1300

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

Open
wants to merge 2 commits into
base: idcc/rao_performance
Choose a base branch
from
Open
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 @@ -31,4 +31,12 @@ public static List<FlowCnec> sortByMargin(Set<FlowCnec> flowCnecs, Unit unit, Ma
.sorted(Comparator.comparingDouble(flowCnec -> marginEvaluator.getMargin(flowResult, flowCnec, unit)))
.toList();
}

public static List<FlowCnec> sortByNegativeMargin(Set<FlowCnec> flowCnecs, Unit unit, MarginEvaluator marginEvaluator, FlowResult flowResult) {
return flowCnecs.stream()
.filter(Cnec::isOptimized)
.filter(flowCnec -> marginEvaluator.getMargin(flowResult, flowCnec, unit) < 0)
.sorted(Comparator.comparingDouble(flowCnec -> marginEvaluator.getMargin(flowResult, flowCnec, unit)))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,35 @@ public static void logSensitivityAnalysisResults(String prefix,
numberOfLoggedLimitingElements);
}

public static void logObjectiveFunctionResult(String prefix,
ObjectiveFunctionResult objectiveFunctionResult,
PrePerimeterResult sensitivityAnalysisResult,
RaoParameters raoParameters,
int numberOfLoggedLimitingElements) {

if (!BUSINESS_LOGS.isInfoEnabled()) {
return;
}

Map<String, Double> virtualCostDetailed = getVirtualCostDetailed(objectiveFunctionResult);

BUSINESS_LOGS.info(prefix + "cost = {} (functional: {}, virtual: {}{})",
formatDoubleBasedOnMargin(objectiveFunctionResult.getCost(), -objectiveFunctionResult.getCost()),
formatDoubleBasedOnMargin(objectiveFunctionResult.getFunctionalCost(), -objectiveFunctionResult.getCost()),
formatDoubleBasedOnMargin(objectiveFunctionResult.getVirtualCost(), -objectiveFunctionResult.getCost()),
virtualCostDetailed.isEmpty() ? "" : " " + virtualCostDetailed);

RaoLogger.logMostLimitingElementsResults(BUSINESS_LOGS,
sensitivityAnalysisResult,
raoParameters.getObjectiveFunctionParameters().getType(),
raoParameters.getObjectiveFunctionParameters().getUnit(),
numberOfLoggedLimitingElements);
}

public static void logRangeActions(OpenRaoLogger logger,
Leaf leaf,
OptimizationPerimeter
optimizationContext, String prefix) {
OptimizationPerimeter optimizationContext,
String prefix) {

boolean globalPstOptimization = optimizationContext instanceof GlobalOptimizationPerimeter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public double getMargin(FlowResult flowResult, FlowCnec flowCnec, TwoSides side,
}

private double computeMargin(FlowCnec flowCnec, double newMargin, double prePerimeterMargin) {
if (countriesNotToOptimize.contains(flowCnec.getOperator()) && newMargin > prePerimeterMargin - .0001 * Math.abs(prePerimeterMargin)) {
if (countriesNotToOptimize.contains(flowCnec.getOperator()) && newMargin > prePerimeterMargin - .0001 * Math.abs(prePerimeterMargin) && flowCnec.getState().getInstant().isCurative()) {
return Double.MAX_VALUE;
}
return newMargin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@
package com.powsybl.openrao.searchtreerao.commons.objectivefunctionevaluator;

import com.powsybl.openrao.commons.Unit;
import com.powsybl.openrao.data.crac.api.State;
import com.powsybl.openrao.data.crac.api.cnec.FlowCnec;
import com.powsybl.openrao.searchtreerao.commons.FlowCnecSorting;
import com.powsybl.openrao.searchtreerao.commons.costevaluatorresult.CostEvaluatorResult;
import com.powsybl.openrao.searchtreerao.commons.costevaluatorresult.MaxCostEvaluatorResult;
import com.powsybl.openrao.searchtreerao.commons.marginevaluator.MarginEvaluator;
import com.powsybl.openrao.searchtreerao.result.api.FlowResult;
import com.powsybl.openrao.searchtreerao.result.api.RemedialActionActivationResult;

import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import static com.powsybl.openrao.searchtreerao.commons.objectivefunctionevaluator.CostEvaluatorUtils.groupFlowCnecsPerState;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
Expand All @@ -33,4 +42,11 @@ public String getName() {
protected double computeCostForState(FlowResult flowResult, Set<FlowCnec> flowCnecsOfState) {
return Math.max(0, super.computeCostForState(flowResult, flowCnecsOfState)) * OVERLOAD_PENALTY;
}

@Override
public CostEvaluatorResult evaluate(FlowResult flowResult, RemedialActionActivationResult remedialActionActivationResult) {
Map<State, Set<FlowCnec>> flowCnecsPerState = groupFlowCnecsPerState(flowCnecs);
Map<State, Double> costPerState = flowCnecsPerState.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> computeCostForState(flowResult, entry.getValue())));
return new MaxCostEvaluatorResult(costPerState, FlowCnecSorting.sortByNegativeMargin(flowCnecs, unit, marginEvaluator, flowResult));
}
}
Loading
Loading