-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experiment/objective function result (#1199)
* simplify objective function Signed-off-by: Thomas Bouquet <[email protected]> * define cost evaluator results Signed-off-by: Thomas Bouquet <[email protected]> * split modules Signed-off-by: Thomas Bouquet <[email protected]> * remove useless method Signed-off-by: Thomas Bouquet <[email protected]> * refactor evaluator results Signed-off-by: Thomas Bouquet <[email protected]> * refactor evaluators based on ranking of cnecs Signed-off-by: Thomas Bouquet <[email protected]> * linter Signed-off-by: Thomas Bouquet <[email protected]> * fix sensi test mocks Signed-off-by: Thomas Bouquet <[email protected]> --------- Signed-off-by: Thomas Bouquet <[email protected]>
- Loading branch information
Showing
42 changed files
with
638 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...owsybl/openrao/searchtreerao/commons/costevaluatorresult/AbsoluteCostEvaluatorResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.searchtreerao.commons.costevaluatorresult; | ||
|
||
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public class AbsoluteCostEvaluatorResult implements CostEvaluatorResult { | ||
private final double cost; | ||
|
||
public AbsoluteCostEvaluatorResult(double cost) { | ||
this.cost = cost; | ||
} | ||
|
||
@Override | ||
public double getCost(Set<String> contingenciesToExclude) { | ||
return cost; | ||
} | ||
|
||
@Override | ||
public List<FlowCnec> getCostlyElements(Set<String> contingenciesToExclude) { | ||
return new ArrayList<>(); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
...enrao/searchtreerao/commons/costevaluatorresult/AbstractStateWiseCostEvaluatorResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.searchtreerao.commons.costevaluatorresult; | ||
|
||
import com.powsybl.contingency.Contingency; | ||
import com.powsybl.openrao.data.cracapi.State; | ||
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
import java.util.stream.DoubleStream; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public abstract class AbstractStateWiseCostEvaluatorResult implements CostEvaluatorResult { | ||
private final Map<State, Double> costPerState; | ||
private final List<FlowCnec> costlyElements; | ||
|
||
protected AbstractStateWiseCostEvaluatorResult(Map<State, Double> costPerState, List<FlowCnec> costlyElements) { | ||
this.costPerState = costPerState; | ||
this.costlyElements = costlyElements; | ||
} | ||
|
||
private DoubleStream filterCostsOnContingency(Set<String> contingenciesToExclude) { | ||
return costPerState.entrySet().stream().filter(entry -> filterStateOnContingency(entry.getKey(), contingenciesToExclude)).mapToDouble(Map.Entry::getValue); | ||
} | ||
|
||
@Override | ||
public double getCost(Set<String> contingenciesToExclude) { | ||
return evaluateResultsWithSpecificStrategy(filterCostsOnContingency(contingenciesToExclude)); | ||
} | ||
|
||
protected abstract double evaluateResultsWithSpecificStrategy(DoubleStream filteredCostsStream); | ||
|
||
@Override | ||
public List<FlowCnec> getCostlyElements(Set<String> contingenciesToExclude) { | ||
return costlyElements.stream().filter(flowCnec -> filterFlowCnecOnContingency(flowCnec, contingenciesToExclude)).toList(); | ||
} | ||
|
||
private static boolean filterStateOnContingency(State state, Set<String> contingenciesToExclude) { | ||
Optional<Contingency> contingency = state.getContingency(); | ||
return contingency.isEmpty() || !contingenciesToExclude.contains(contingency.get().getId()); | ||
} | ||
|
||
private static boolean filterFlowCnecOnContingency(FlowCnec flowCnec, Set<String> contingenciesToExclude) { | ||
return filterStateOnContingency(flowCnec.getState(), contingenciesToExclude); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...com/powsybl/openrao/searchtreerao/commons/costevaluatorresult/MaxCostEvaluatorResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.searchtreerao.commons.costevaluatorresult; | ||
|
||
import com.powsybl.openrao.data.cracapi.State; | ||
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.DoubleStream; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public class MaxCostEvaluatorResult extends AbstractStateWiseCostEvaluatorResult { | ||
public MaxCostEvaluatorResult(Map<State, Double> costPerState, List<FlowCnec> costlyElements) { | ||
super(costPerState, costlyElements); | ||
} | ||
|
||
@Override | ||
protected double evaluateResultsWithSpecificStrategy(DoubleStream filteredCostsStream) { | ||
return filteredCostsStream.max().orElse(-Double.MAX_VALUE); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...com/powsybl/openrao/searchtreerao/commons/costevaluatorresult/SumCostEvaluatorResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.searchtreerao.commons.costevaluatorresult; | ||
|
||
import com.powsybl.openrao.data.cracapi.State; | ||
import com.powsybl.openrao.data.cracapi.cnec.FlowCnec; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.DoubleStream; | ||
|
||
/** | ||
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>} | ||
*/ | ||
public class SumCostEvaluatorResult extends AbstractStateWiseCostEvaluatorResult { | ||
public SumCostEvaluatorResult(Map<State, Double> costPerState, List<FlowCnec> costlyElements) { | ||
super(costPerState, costlyElements); | ||
} | ||
|
||
@Override | ||
protected double evaluateResultsWithSpecificStrategy(DoubleStream filteredCostsStream) { | ||
return filteredCostsStream.sum(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.