Skip to content

Commit

Permalink
Merge branch 'rao_parameters_remove_curative_stop_criterion' of https…
Browse files Browse the repository at this point in the history
…://github.com/powsybl/open-rao into rao_parameters_separate_unit_from_objective_function_type

Signed-off-by: Philippe Edwards <philippe.edwards@rte-france.com>
  • Loading branch information
phiedw committed Jan 10, 2025
2 parents d588d48 + 053fa72 commit adff05d
Show file tree
Hide file tree
Showing 205 changed files with 8,565 additions and 1,514 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.commons;

import java.time.OffsetDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public interface TemporalData<T> {
Map<OffsetDateTime, T> getDataPerTimestamp();

default Optional<T> getData(OffsetDateTime timestamp) {
return Optional.ofNullable(getDataPerTimestamp().get(timestamp));
}

default List<OffsetDateTime> getTimestamps() {
return getDataPerTimestamp().keySet().stream().sorted().toList();
}

void add(OffsetDateTime timestamp, T data);
}
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.commons;

import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public class TemporalDataImpl<T> implements TemporalData<T> {
private final Map<OffsetDateTime, T> dataPerTimestamp;

public TemporalDataImpl() {
this(new HashMap<>());
}

public TemporalDataImpl(Map<OffsetDateTime, T> dataPerTimestamp) {
this.dataPerTimestamp = new HashMap<>(dataPerTimestamp);
}

public Map<OffsetDateTime, T> getDataPerTimestamp() {
return new HashMap<>(dataPerTimestamp);
}

public void add(OffsetDateTime timestamp, T data) {
dataPerTimestamp.put(timestamp, data);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.commons;

import org.junit.jupiter.api.Test;

import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.ejml.UtilEjml.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
class TemporalDataImplTest {
final OffsetDateTime timestamp1 = OffsetDateTime.of(2024, 6, 12, 17, 41, 0, 0, ZoneOffset.UTC);
final OffsetDateTime timestamp2 = OffsetDateTime.of(2024, 6, 12, 17, 42, 0, 0, ZoneOffset.UTC);
final OffsetDateTime timestamp3 = OffsetDateTime.of(2024, 6, 12, 17, 43, 0, 0, ZoneOffset.UTC);

@Test
void testCreateEmptyTemporalData() {
assertTrue(new TemporalDataImpl<>().getDataPerTimestamp().isEmpty());
}

@Test
void testCreateTemporalDataFromMap() {
Map<OffsetDateTime, String> stringPerTimestamp = Map.of(timestamp1, "Hello world!", timestamp2, "OpenRAO");
TemporalData<String> stringTemporalData = new TemporalDataImpl<>(stringPerTimestamp);

assertEquals(stringPerTimestamp, stringTemporalData.getDataPerTimestamp());
assertEquals(List.of(timestamp1, timestamp2), stringTemporalData.getTimestamps());
assertEquals(Optional.of("Hello world!"), stringTemporalData.getData(timestamp1));
assertEquals(Optional.of("OpenRAO"), stringTemporalData.getData(timestamp2));
assertTrue(stringTemporalData.getData(timestamp3).isEmpty());
}

@Test
void testAddData() {
TemporalData<String> stringTemporalData = new TemporalDataImpl<>();
stringTemporalData.add(timestamp3, "ABC");
assertEquals(Map.of(timestamp3, "ABC"), stringTemporalData.getDataPerTimestamp());
assertEquals(List.of(timestamp3), stringTemporalData.getTimestamps());
assertEquals(Optional.of("ABC"), stringTemporalData.getData(timestamp3));
}
}
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 @@ -21,6 +21,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.crac.api.rangeaction.RangeAction;
import com.powsybl.openrao.data.crac.api.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 @@ -35,15 +35,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 @@ -71,6 +73,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 @@ -26,6 +26,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 @@ -46,6 +47,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.crac.api.range.StandardRange;
import com.powsybl.openrao.data.crac.api.range.StandardRangeAdder;
import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction;
import com.powsybl.openrao.data.crac.api.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 @@ -68,7 +68,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
Loading

0 comments on commit adff05d

Please sign in to comment.