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

Add remedial actions' activation cost and range actions' variation costs in API #1182

Open
wants to merge 6 commits into
base: main
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 @@ -55,6 +55,11 @@ public interface RemedialAction<I extends RemedialAction<I>> extends Identifiabl
*/
Optional<Integer> getSpeed();

/**
* Get the cost to spend to activate the remedial action.
*/
Optional<Double> getActivationCost();

Set<FlowCnec> getFlowCnecsConstrainingUsageRules(Set<FlowCnec> perimeterCnecs, Network network, State optimizedState);

Set<FlowCnec> getFlowCnecsConstrainingForOneUsageRule(UsageRule usageRule, Set<FlowCnec> perimeterCnecs, Network network);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public interface RemedialActionAdder<T extends RemedialActionAdder<T>> extends I

T withSpeed(Integer speed);

T withActivationCost(Double activationCost);

RemedialAction<?> add();

OnInstantAdder<T> newOnInstantUsageRule();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public interface PstRangeActionAdder extends RemedialActionAdder<PstRangeActionA

PstRangeActionAdder withTapToAngleConversionMap(Map<Integer, Double> tapToAngleConversionMap);

PstRangeActionAdder withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection);

TapRangeAdder newTapRange();

PstRangeAction add();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

/**
* Remedial action interface specifying an action of type range.
*
* <p>
* When applying a Range Action, a setpoint (double value) must be set. This setpoint
* must be included within a range, delimited by minimum and maximum values.
*
* <p>
* The apply method therefore involves a {@link Network} and a setpoint (double value).
* The presence of this double in the apply() method explains why this interface
* has been designed besides the {@link NetworkAction} interface
Expand Down Expand Up @@ -54,4 +54,10 @@ public interface RangeAction<T extends RangeAction<T>> extends RemedialAction<T>
*/
Optional<String> getGroupId();

Optional<Double> getVariationCost(VariationDirection variationDirection);

enum VariationDirection {
UP, DOWN
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public interface StandardRangeActionAdder<T extends StandardRangeActionAdder<T>>

T withInitialSetpoint(double initialSetpoint);

T withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection);

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public OnContingencyStateAdderToRemedialAction<NetworkAction> newOnStateUsageRul
return null;
}

@Override
public Optional<Double> getActivationCost() {
return Optional.empty();
}

@Override
public boolean hasImpactOnNetwork(Network network) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction;
import com.powsybl.openrao.data.cracapi.usagerule.UsageRule;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

Expand All @@ -18,17 +20,24 @@
public abstract class AbstractRangeAction<T extends RangeAction<T>> extends AbstractRemedialAction<T> implements RangeAction<T> {

protected String groupId = null;
protected Map<VariationDirection, Double> variationCosts;

AbstractRangeAction(String id, String name, String operator, Set<UsageRule> usageRules, String groupId, Integer speed) {
super(id, name, operator, usageRules, speed);
AbstractRangeAction(String id, String name, String operator, Set<UsageRule> usageRules, String groupId, Integer speed, Double activationCost, Map<VariationDirection, Double> variationCosts) {
super(id, name, operator, usageRules, speed, activationCost);
this.groupId = groupId;
this.variationCosts = variationCosts == null ? new HashMap<>() : new HashMap<>(variationCosts);
}

@Override
public Optional<String> getGroupId() {
return Optional.ofNullable(groupId);
}

@Override
public Optional<Double> getVariationCost(VariationDirection variationDirection) {
return Optional.ofNullable(variationCosts.get(variationDirection));
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ public abstract class AbstractRemedialAction<I extends RemedialAction<I>> extend
protected String operator;
protected Set<UsageRule> usageRules;
protected Integer speed;
protected Double activationCost;
private boolean computedUsageMethods = false;
private Map<State, UsageMethod> usageMethodPerState;
private Map<Instant, UsageMethod> usageMethodPerInstant;

protected AbstractRemedialAction(String id, String name, String operator, Set<UsageRule> usageRules, Integer speed) {
protected AbstractRemedialAction(String id, String name, String operator, Set<UsageRule> usageRules, Integer speed, Double activationCost) {
super(id, name);
this.operator = operator;
this.usageRules = usageRules;
this.speed = speed;
this.activationCost = activationCost;
}

void addUsageRule(UsageRule usageRule) {
Expand Down Expand Up @@ -65,6 +67,11 @@ public Optional<Integer> getSpeed() {
return Optional.ofNullable(speed);
}

@Override
public Optional<Double> getActivationCost() {
return Optional.ofNullable(activationCost);
}

@Override
public UsageMethod getUsageMethod(State state) {
if (!computedUsageMethods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public abstract class AbstractRemedialActionAdder<T extends RemedialActionAdder<

protected String operator;
protected Integer speed;
protected Double activationCost;
protected Set<UsageRule> usageRules = new HashSet<>();
private final CracImpl crac;

Expand All @@ -42,6 +43,12 @@ public T withSpeed(Integer speed) {
return (T) this;
}

@Override
public T withActivationCost(Double activationCost) {
this.activationCost = activationCost;
return (T) this;
}

@Override
public OnInstantAdder<T> newOnInstantUsageRule() {
return new OnInstantAdderImpl(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.data.cracapi.range.StandardRange;
import com.powsybl.openrao.data.cracapi.range.StandardRangeAdder;
import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction;
import com.powsybl.openrao.data.cracapi.rangeaction.StandardRangeActionAdder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
Expand All @@ -23,10 +26,12 @@ public abstract class AbstractStandardRangeActionAdder<T extends StandardRangeAc
protected String groupId;
protected double initialSetpoint;
protected List<StandardRange> ranges;
protected Map<RangeAction.VariationDirection, Double> variationCosts;

AbstractStandardRangeActionAdder(CracImpl crac) {
super(crac);
this.ranges = new ArrayList<>();
this.variationCosts = new HashMap<>();
}

@Override
Expand All @@ -41,6 +46,12 @@ public T withInitialSetpoint(double initialSetpoint) {
return (T) this;
}

@Override
public T withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection) {
this.variationCosts.put(variationDirection, variationCost);
return (T) this;
}

@Override
public StandardRangeAdder<T> newRange() {
return new StandardRangeAdderImpl<>(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CounterTradeRangeAction add() {
BUSINESS_WARNS.warn("CounterTradeRangeAction {} does not contain any usage rule, by default it will never be available", id);
}

CounterTradeRangeAction counterTradeRangeAction = new CounterTradeRangeActionImpl(this.id, this.name, this.operator, this.groupId, this.usageRules, this.ranges, this.initialSetpoint, speed, this.exportingCountry, this.importingCountry);
CounterTradeRangeAction counterTradeRangeAction = new CounterTradeRangeActionImpl(this.id, this.name, this.operator, this.groupId, this.usageRules, this.ranges, this.initialSetpoint, speed, activationCost, variationCosts, this.exportingCountry, this.importingCountry);
getCrac().addCounterTradeRangeAction(counterTradeRangeAction);
return counterTradeRangeAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
Expand All @@ -29,8 +30,8 @@ public class CounterTradeRangeActionImpl extends AbstractRangeAction<CounterTrad
private final double initialSetpoint;

CounterTradeRangeActionImpl(String id, String name, String operator, String groupId, Set<UsageRule> usageRules,
List<StandardRange> ranges, double initialSetpoint, Integer speed, Country exportingCountry, Country importingCountry) {
super(id, name, operator, usageRules, groupId, speed);
List<StandardRange> ranges, double initialSetpoint, Integer speed, Double activationCost, Map<VariationDirection, Double> variationCosts, Country exportingCountry, Country importingCountry) {
super(id, name, operator, usageRules, groupId, speed, activationCost, variationCosts);
this.ranges = ranges;
this.initialSetpoint = initialSetpoint;
this.exportingCountry = exportingCountry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public HvdcRangeAction add() {
}

NetworkElement networkElement = this.getCrac().addNetworkElement(networkElementId, networkElementName);
HvdcRangeActionImpl hvdcWithRange = new HvdcRangeActionImpl(this.id, this.name, this.operator, this.usageRules, ranges, initialSetpoint, networkElement, groupId, speed);
HvdcRangeActionImpl hvdcWithRange = new HvdcRangeActionImpl(this.id, this.name, this.operator, this.usageRules, ranges, initialSetpoint, networkElement, groupId, speed, activationCost, variationCosts);
this.getCrac().addHvdcRangeAction(hvdcWithRange);
return hvdcWithRange;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.powsybl.openrao.commons.logs.OpenRaoLoggerProvider.TECHNICAL_LOGS;
Expand All @@ -37,8 +38,8 @@ public class HvdcRangeActionImpl extends AbstractRangeAction<HvdcRangeAction> im
private final double initialSetpoint;

HvdcRangeActionImpl(String id, String name, String operator, Set<UsageRule> usageRules, List<StandardRange> ranges,
double initialSetpoint, NetworkElement networkElement, String groupId, Integer speed) {
super(id, name, operator, usageRules, groupId, speed);
double initialSetpoint, NetworkElement networkElement, String groupId, Integer speed, Double activationCost, Map<VariationDirection, Double> variationCosts) {
super(id, name, operator, usageRules, groupId, speed, activationCost, variationCosts);
this.networkElement = networkElement;
this.ranges = ranges;
this.initialSetpoint = initialSetpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public InjectionRangeAction add() {
}

Map<NetworkElement, Double> neAndDk = addNetworkElements();
InjectionRangeAction injectionRangeAction = new InjectionRangeActionImpl(this.id, this.name, this.operator, this.groupId, this.usageRules, this.ranges, this.initialSetpoint, neAndDk, speed);
InjectionRangeAction injectionRangeAction = new InjectionRangeActionImpl(this.id, this.name, this.operator, this.groupId, this.usageRules, this.ranges, this.initialSetpoint, neAndDk, speed, activationCost, variationCosts);
this.getCrac().addInjectionRangeAction(injectionRangeAction);
return injectionRangeAction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class InjectionRangeActionImpl extends AbstractRangeAction<InjectionRange
private final double initialSetpoint;

InjectionRangeActionImpl(String id, String name, String operator, String groupId, Set<UsageRule> usageRules,
List<StandardRange> ranges, double initialSetpoint, Map<NetworkElement, Double> injectionDistributionKeys, Integer speed) {
super(id, name, operator, usageRules, groupId, speed);
List<StandardRange> ranges, double initialSetpoint, Map<NetworkElement, Double> injectionDistributionKeys, Integer speed, Double activationCost, Map<VariationDirection, Double> variationCosts) {
super(id, name, operator, usageRules, groupId, speed, activationCost, variationCosts);
this.ranges = ranges;
this.initialSetpoint = initialSetpoint;
this.injectionDistributionKeys = injectionDistributionKeys;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public NetworkAction add() {
throw new OpenRaoException(String.format("NetworkAction %s has to have at least one ElementaryAction.", id));
}

NetworkAction networkAction = new NetworkActionImpl(id, name, operator, usageRules, elementaryActions, speed, networkElements);
NetworkAction networkAction = new NetworkActionImpl(id, name, operator, usageRules, elementaryActions, speed, activationCost, networkElements);
getCrac().addNetworkAction(networkAction);
return networkAction;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class NetworkActionImpl extends AbstractRemedialAction<NetworkAction> imp
private final Set<NetworkElement> networkElements;

NetworkActionImpl(String id, String name, String operator, Set<UsageRule> usageRules,
Set<Action> elementaryNetworkActions, Integer speed, Set<NetworkElement> networkElements) {
super(id, name, operator, usageRules, speed);
Set<Action> elementaryNetworkActions, Integer speed, Double activationCost, Set<NetworkElement> networkElements) {
super(id, name, operator, usageRules, speed, activationCost);
this.elementaryActions = new HashSet<>(elementaryNetworkActions);
this.networkElements = new HashSet<>(networkElements);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class PstRangeActionAdderImpl extends AbstractRemedialActionAdder<PstRang
private String groupId = null;
private Integer initialTap = null;
private Map<Integer, Double> tapToAngleConversionMap;
private Map<RangeAction.VariationDirection, Double> variationCosts;

@Override
protected String getTypeDescription() {
Expand All @@ -41,6 +42,7 @@ protected String getTypeDescription() {
PstRangeActionAdderImpl(CracImpl owner) {
super(owner);
this.ranges = new ArrayList<>();
this.variationCosts = new HashMap<>();
}

@Override
Expand Down Expand Up @@ -73,6 +75,12 @@ public PstRangeActionAdder withTapToAngleConversionMap(Map<Integer, Double> tapT
return this;
}

@Override
public PstRangeActionAdder withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection) {
this.variationCosts.put(variationDirection, variationCost);
return this;
}

@Override
public TapRangeAdder newTapRange() {
return new TapRangeAdderImpl(this);
Expand All @@ -98,7 +106,7 @@ public PstRangeAction add() {
}

NetworkElement networkElement = this.getCrac().addNetworkElement(networkElementId, networkElementName);
PstRangeActionImpl pstWithRange = new PstRangeActionImpl(this.id, this.name, this.operator, this.usageRules, validRanges, networkElement, groupId, initialTap, tapToAngleConversionMap, speed);
PstRangeActionImpl pstWithRange = new PstRangeActionImpl(this.id, this.name, this.operator, this.usageRules, validRanges, networkElement, groupId, initialTap, tapToAngleConversionMap, speed, activationCost, variationCosts);
this.getCrac().addPstRangeAction(pstWithRange);
return pstWithRange;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public final class PstRangeActionImpl extends AbstractRangeAction<PstRangeAction
private final int highTapPosition;

PstRangeActionImpl(String id, String name, String operator, Set<UsageRule> usageRules, List<TapRange> ranges,
NetworkElement networkElement, String groupId, int initialTap, Map<Integer, Double> tapToAngleConversionMap, Integer speed) {
super(id, name, operator, usageRules, groupId, speed);
NetworkElement networkElement, String groupId, int initialTap, Map<Integer, Double> tapToAngleConversionMap, Integer speed, Double activationCost, Map<VariationDirection, Double> variationCosts) {
super(id, name, operator, usageRules, groupId, speed, activationCost, variationCosts);
this.networkElement = networkElement;
this.ranges = ranges;
this.initialTapPosition = initialTap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import com.powsybl.openrao.data.cracapi.InstantKind;
import com.powsybl.openrao.data.cracapi.rangeaction.CounterTradeRangeAction;
import com.powsybl.openrao.data.cracapi.rangeaction.CounterTradeRangeActionAdder;
import com.powsybl.openrao.data.cracapi.rangeaction.RangeAction;
import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod;
import com.powsybl.iidm.network.Country;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Optional;

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

class CounterTradeRangeActionAdderImplTest {
Expand All @@ -35,6 +38,9 @@ void testAdd() {
.withId("id1")
.withOperator("BE")
.withGroupId("groupId1")
.withActivationCost(1000d)
.withVariationCost(10000d, RangeAction.VariationDirection.UP)
.withVariationCost(20000d, RangeAction.VariationDirection.DOWN)
.newRange().withMin(-5).withMax(10).add()
.newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add()
.withExportingCountry(Country.FR)
Expand All @@ -44,6 +50,9 @@ void testAdd() {
assertEquals("id1", counterTradeRangeAction.getId());
assertEquals("id1", counterTradeRangeAction.getName());
assertEquals("BE", counterTradeRangeAction.getOperator());
assertEquals(Optional.of(1000d), counterTradeRangeAction.getActivationCost());
assertEquals(Optional.of(10000d), counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.UP));
assertEquals(Optional.of(20000d), counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN));
assertTrue(counterTradeRangeAction.getGroupId().isPresent());
assertEquals("groupId1", counterTradeRangeAction.getGroupId().get());
assertEquals(1, counterTradeRangeAction.getRanges().size());
Expand All @@ -68,6 +77,9 @@ void testAddWithoutGroupId() {
assertEquals("id1", counterTradeRangeAction.getId());
assertEquals("BE", counterTradeRangeAction.getOperator());
assertTrue(counterTradeRangeAction.getGroupId().isEmpty());
assertTrue(counterTradeRangeAction.getActivationCost().isEmpty());
assertTrue(counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.UP).isEmpty());
assertTrue(counterTradeRangeAction.getVariationCost(RangeAction.VariationDirection.DOWN).isEmpty());
assertEquals(1, counterTradeRangeAction.getRanges().size());
assertEquals(1, counterTradeRangeAction.getUsageRules().size());
assertEquals(Country.FR, counterTradeRangeAction.getExportingCountry());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void equals() {
DanglingLineAction sameDanglingLineAction = new DanglingLineActionBuilder().withId("id").withDanglingLineId("DL1").withActivePowerValue(10).withRelativeValue(false).build();
assertEquals(danglingLineAction, sameDanglingLineAction);
NetworkAction dummy5 = new NetworkActionImpl("id", "name", "operator", null,
new HashSet<>(List.of(danglingLineAction, sameDanglingLineAction)), 0, Set.of());
new HashSet<>(List.of(danglingLineAction, sameDanglingLineAction)), 0, null, Set.of());
assertEquals(1, dummy5.getElementaryActions().size());
}
}
Loading
Loading