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 <[email protected]>
  • Loading branch information
phiedw committed Jan 24, 2025
2 parents adff05d + a61875c commit 1e3818e
Show file tree
Hide file tree
Showing 200 changed files with 7,481 additions and 1,391 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
name: CI

on: [push]
on: [ push ]

jobs:
build:
name: Build OS ${{ matrix.os }}
name: Build and test on ${{ matrix.os }} with ${{ matrix.jvm }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ ubuntu-latest, windows-latest, macos-latest ]
jvm: [ java, graalvm ]

steps:
- name: Checkout sources
uses: actions/checkout@v1

- name: Set up JDK 17
- name: Set up Java 17
if: matrix.jvm == 'java'
uses: actions/setup-java@v1
with:
java-version: 17

- name: Setup GraalVM
if: matrix.jvm == 'graalvm'
uses: graalvm/setup-graalvm@v1
with:
java-version: '17.0.12'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build with Maven
if: matrix.os == 'ubuntu-latest'
run: mvn --batch-mode -Pjacoco install -DskipCucumberTests=true
Expand All @@ -37,3 +47,6 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

- name: Run cucumber tests
run: mvn test -pl tests
22 changes: 0 additions & 22 deletions .github/workflows/run_cucumber_tests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-open-rao</artifactId>
<version>6.2.0-SNAPSHOT</version>
<version>6.3.0-SNAPSHOT</version>
</parent>
<artifactId>open-rao-commons</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
Expand All @@ -27,4 +28,6 @@ default List<OffsetDateTime> getTimestamps() {
}

void add(OffsetDateTime timestamp, T data);

<U> TemporalData<U> map(Function<T, U> function);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.time.OffsetDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
Expand All @@ -32,4 +34,8 @@ public Map<OffsetDateTime, T> getDataPerTimestamp() {
public void add(OffsetDateTime timestamp, T data) {
dataPerTimestamp.put(timestamp, data);
}

public <U> TemporalData<U> map(Function<T, U> function) {
return new TemporalDataImpl<>(dataPerTimestamp.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> function.apply(entry.getValue()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,13 @@ void testAddData() {
assertEquals(List.of(timestamp3), stringTemporalData.getTimestamps());
assertEquals(Optional.of("ABC"), stringTemporalData.getData(timestamp3));
}

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

TemporalData<Integer> intTemporalData = stringTemporalData.map(String::length);
assertEquals(Map.of(timestamp1, 12, timestamp2, 7), intTemporalData.getDataPerTimestamp());
}
}
2 changes: 1 addition & 1 deletion data/crac/crac-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>open-rao-crac</artifactId>
<groupId>com.powsybl</groupId>
<version>6.2.0-SNAPSHOT</version>
<version>6.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public interface InjectionRangeActionAdder extends StandardRangeActionAdder<Inje

InjectionRangeActionAdder withNetworkElementAndKey(double key, String networkElementId, String networkElementName);

InjectionRangeActionAdder withNetworkElement(String networkElementId);

InjectionRangeActionAdder withNetworkElement(String networkElementId, String networkElementName);

InjectionRangeActionAdder withInitialSetpoint(double initialSetpoint);

StandardRangeAdder<InjectionRangeActionAdder> newRange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface PstRangeActionAdder extends RemedialActionAdder<PstRangeActionA

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

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

TapRangeAdder newTapRange();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,4 @@ 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,6 +20,6 @@ public interface StandardRangeActionAdder<T extends StandardRangeActionAdder<T>>

T withInitialSetpoint(double initialSetpoint);

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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.crac.api.rangeaction;

/**
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
*/
public enum VariationDirection {
UP, DOWN
}
2 changes: 1 addition & 1 deletion data/crac/crac-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>open-rao-crac</artifactId>
<groupId>com.powsybl</groupId>
<version>6.2.0-SNAPSHOT</version>
<version>6.3.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package com.powsybl.openrao.data.crac.impl;

import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction;
import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;
import com.powsybl.openrao.data.crac.api.usagerule.UsageRule;

import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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 com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -26,7 +26,7 @@ public abstract class AbstractStandardRangeActionAdder<T extends StandardRangeAc
protected String groupId;
protected double initialSetpoint;
protected List<StandardRange> ranges;
protected Map<RangeAction.VariationDirection, Double> variationCosts;
protected Map<VariationDirection, Double> variationCosts;

AbstractStandardRangeActionAdder(CracImpl crac) {
super(crac);
Expand All @@ -47,7 +47,7 @@ public T withInitialSetpoint(double initialSetpoint) {
}

@Override
public T withVariationCost(Double variationCost, RangeAction.VariationDirection variationDirection) {
public T withVariationCost(Double variationCost, VariationDirection variationDirection) {
this.variationCosts.put(variationDirection, variationCost);
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.powsybl.openrao.data.crac.api.NetworkElement;
import com.powsybl.openrao.data.crac.api.range.StandardRange;
import com.powsybl.openrao.data.crac.api.rangeaction.CounterTradeRangeAction;
import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;
import com.powsybl.openrao.data.crac.api.usagerule.UsageRule;
import com.powsybl.iidm.network.Country;
import com.powsybl.iidm.network.Network;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.openrao.data.crac.api.NetworkElement;
import com.powsybl.openrao.data.crac.api.range.StandardRange;
import com.powsybl.openrao.data.crac.api.rangeaction.HvdcRangeAction;
import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;
import com.powsybl.openrao.data.crac.api.usagerule.UsageRule;
import com.powsybl.iidm.network.HvdcLine;
import com.powsybl.iidm.network.Network;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ public InjectionRangeActionAdder withNetworkElementAndKey(double key, String net
return this;
}

@Override
public InjectionRangeActionAdder withNetworkElement(String networkElementId) {
if (distributionKeys.isEmpty()) {
return withNetworkElementAndKey(1.0, networkElementId, networkElementId);
} else {
throw new OpenRaoException("There are already NetworkElements tied to this injection. Use instead withNetworkElementAndKey() to add multiple NetworkElements");
}
}

@Override
public InjectionRangeActionAdder withNetworkElement(String networkElementId, String networkElementName) {
if (distributionKeys.isEmpty()) {
return withNetworkElementAndKey(1.0, networkElementId, networkElementName);
} else {
throw new OpenRaoException("There are already NetworkElements tied to this injection. Use instead withNetworkElementAndKey() to add multiple NetworkElements");
}
}

@Override
public InjectionRangeAction add() {
checkId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.powsybl.openrao.data.crac.api.NetworkElement;
import com.powsybl.openrao.data.crac.api.range.StandardRange;
import com.powsybl.openrao.data.crac.api.rangeaction.InjectionRangeAction;
import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;
import com.powsybl.openrao.data.crac.api.usagerule.UsageRule;
import com.powsybl.iidm.network.Generator;
import com.powsybl.iidm.network.Load;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import com.powsybl.action.*;
import com.powsybl.commons.report.ReportNode;
import com.powsybl.iidm.modification.NetworkModificationImpact;
import com.powsybl.iidm.network.*;
import com.powsybl.openrao.data.crac.api.networkaction.NetworkAction;
import com.powsybl.openrao.data.crac.api.networkaction.SwitchPair;
import com.powsybl.openrao.data.crac.api.NetworkElement;
import com.powsybl.openrao.data.crac.api.usagerule.UsageRule;
import org.apache.commons.lang3.NotImplementedException;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -46,41 +46,10 @@ public Set<Action> getElementaryActions() {
@Override
public boolean hasImpactOnNetwork(Network network) {
return elementaryActions.stream().anyMatch(elementaryAction -> {
if (elementaryAction instanceof GeneratorAction generatorAction) {
Generator generator = network.getGenerator(generatorAction.getGeneratorId());
return Math.abs(generator.getTargetP() - generatorAction.getActivePowerValue().getAsDouble()) >= EPSILON;
} else if (elementaryAction instanceof LoadAction loadAction) {
Load load = network.getLoad(loadAction.getLoadId());
return Math.abs(load.getP0() - loadAction.getActivePowerValue().getAsDouble()) >= EPSILON;
} else if (elementaryAction instanceof DanglingLineAction danglingLineAction) {
DanglingLine danglingLine = network.getDanglingLine(danglingLineAction.getDanglingLineId());
return Math.abs(danglingLine.getP0() - danglingLineAction.getActivePowerValue().getAsDouble()) >= EPSILON;
} else if (elementaryAction instanceof ShuntCompensatorPositionAction shuntCompensatorPositionAction) {
ShuntCompensator shuntCompensator = network.getShuntCompensator(shuntCompensatorPositionAction.getShuntCompensatorId());
return Math.abs(shuntCompensator.getSectionCount() - shuntCompensatorPositionAction.getSectionCount()) > 0;
} else if (elementaryAction instanceof PhaseTapChangerTapPositionAction phaseTapChangerTapPositionAction) {
PhaseTapChanger phaseTapChanger = network.getTwoWindingsTransformer(phaseTapChangerTapPositionAction.getTransformerId()).getPhaseTapChanger();
return phaseTapChangerTapPositionAction.getTapPosition() != phaseTapChanger.getTapPosition();
} else if (elementaryAction instanceof SwitchPair switchPair) {
if (elementaryAction instanceof SwitchPair switchPair) {
return !network.getSwitch(switchPair.getSwitchToOpen().getId()).isOpen() || network.getSwitch(switchPair.getSwitchToClose().getId()).isOpen();
} else if (elementaryAction instanceof TerminalsConnectionAction terminalsConnectionAction) {
Identifiable<?> element = network.getIdentifiable(terminalsConnectionAction.getElementId());
if (element instanceof Branch<?> branch) {
if (terminalsConnectionAction.isOpen()) {
// Line is considered closed if both terminal are connected
return branch.getTerminal1().isConnected() && branch.getTerminal2().isConnected();
} else {
// Line is already considered opened if one of the terminals is disconnected
return !branch.getTerminal1().isConnected() || !branch.getTerminal2().isConnected();
}
} else {
throw new NotImplementedException("TerminalsConnectionAction are only on branches for now");
}
} else if (elementaryAction instanceof SwitchAction switchAction) {
Switch aSwitch = network.getSwitch(switchAction.getSwitchId());
return aSwitch.isOpen() != switchAction.isOpen();
} else {
throw new NotImplementedException();
return elementaryAction.toModification().hasImpactOnNetwork(network) == NetworkModificationImpact.HAS_IMPACT_ON_NETWORK;
}
});
}
Expand All @@ -97,25 +66,12 @@ public boolean apply(Network network) {

@Override
public boolean canBeApplied(Network network) {
// TODO: To implement on powsybl-core Action
return elementaryActions.stream().allMatch(elementaryAction -> {
if (elementaryAction instanceof ShuntCompensatorPositionAction shuntCompensatorPositionAction) {
ShuntCompensator shuntCompensator = network.getShuntCompensator(shuntCompensatorPositionAction.getShuntCompensatorId());
return shuntCompensatorPositionAction.getSectionCount() <= shuntCompensator.getMaximumSectionCount();
} else if (elementaryAction instanceof GeneratorAction || elementaryAction instanceof LoadAction || elementaryAction instanceof DanglingLineAction) {
return true;
} else if (elementaryAction instanceof PhaseTapChangerTapPositionAction phaseTapChangerTapPositionAction) {
// hypothesis: transformer is a two windings transformer
PhaseTapChanger phaseTapChanger = network.getTwoWindingsTransformer(phaseTapChangerTapPositionAction.getTransformerId()).getPhaseTapChanger();
int tapPosition = phaseTapChangerTapPositionAction.getTapPosition();
return tapPosition >= phaseTapChanger.getLowTapPosition() && tapPosition <= phaseTapChanger.getHighTapPosition();
} else if (elementaryAction instanceof SwitchPair switchPair) {
if (elementaryAction instanceof SwitchPair switchPair) {
// It is only applicable if, initially, one switch was closed and the other was open.
return network.getSwitch(switchPair.getSwitchToOpen().getId()).isOpen() != network.getSwitch(switchPair.getSwitchToClose().getId()).isOpen();
} else if (elementaryAction instanceof TerminalsConnectionAction || elementaryAction instanceof SwitchAction) {
return true;
} else {
throw new NotImplementedException();
return elementaryAction.toModification().hasImpactOnNetwork(network) != NetworkModificationImpact.CANNOT_BE_APPLIED;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.powsybl.openrao.data.crac.api.range.RangeType;
import com.powsybl.openrao.data.crac.api.range.TapRange;
import com.powsybl.openrao.data.crac.api.range.TapRangeAdder;
import com.powsybl.openrao.data.crac.api.rangeaction.RangeAction;
import com.powsybl.openrao.data.crac.api.rangeaction.VariationDirection;
import com.powsybl.openrao.data.crac.api.usagerule.UsageRule;

import java.util.*;
Expand All @@ -34,7 +34,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;
private Map<VariationDirection, Double> variationCosts;

@Override
protected String getTypeDescription() {
Expand Down Expand Up @@ -78,7 +78,7 @@ public PstRangeActionAdder withTapToAngleConversionMap(Map<Integer, Double> tapT
}

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

0 comments on commit 1e3818e

Please sign in to comment.