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

[WIP INTERNSHIP] Add constraints correctly on multi TimeSteps for PST #1037

Open
wants to merge 25 commits into
base: main_jeremy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2b1828c
Add builder of MultiTSFiller
wangjer Jun 7, 2024
72cac07
Add test scenarios and test file
wangjer Jun 7, 2024
69fd6e1
Update objective penalty cost to have closer pst values between time …
wangjer Jun 10, 2024
1b348ed
Add PST effect from previous TS on next TS
wangjer Jun 12, 2024
4284d2d
Update tests & check several TS before instead of only the previous one
wangjer Jun 17, 2024
1f54543
Run multiple RAO to take into account Network Actions
wangjer Jun 24, 2024
8df23ac
Add tests
wangjer Jun 27, 2024
cd98c26
fix bug
MartinBelthle Jun 26, 2024
8267fb6
put back the min max check
MartinBelthle Jun 26, 2024
20af648
Fix cases 2PST_3TS and 1PST_4TS
wangjer Jun 28, 2024
d60d9b9
Add MultiTsFillerTest
wangjer Jul 3, 2024
280b14d
Add new method withNetworkElement for InjectionRangeAction
wangjer Jul 9, 2024
63d8a77
Refactor MultiTSFiller to use RangeAction instead of PstRangeAction
wangjer Jul 12, 2024
09af0c3
Add balance constraint on Injections
wangjer Jul 12, 2024
b2d7cc7
Add tests for injection as redispatching
wangjer Jul 12, 2024
a8a9fb2
StandardRange can have other RangeTypes than ABSOLUTE
wangjer Jul 15, 2024
bb0cde2
Injections in MultiTSFiller and tests
wangjer Jul 17, 2024
64102ff
Tests scenarios for Injection MultiTS
wangjer Jul 25, 2024
f801e52
Clean code
wangjer Aug 5, 2024
460fa07
Add logs for multi time steps
wangjer Aug 6, 2024
7cb8127
Remove injection impact for injection range action
wangjer Aug 6, 2024
2f3fde9
Fixes after review 1
wangjer Aug 22, 2024
043ffb1
Fixes after review 2
wangjer Aug 23, 2024
2a9ccfd
Fix cucumber tests + log only 5 worst cnecs
wangjer Aug 29, 2024
27d5795
Avoid using UUID for constraints + clean code
wangjer Aug 30, 2024
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 @@ -24,7 +24,6 @@ public final class StandardRangeArrayDeserializer {
private StandardRangeArrayDeserializer() {
}

//a Standard range is implicitly of type "ABSOLUTE" : no RANGE_TYPE
public static void deserialize(JsonParser jsonParser, StandardRangeActionAdder<?> ownerAdder) throws IOException {
while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
StandardRangeAdder<?> adder = ownerAdder.newRange();
Expand All @@ -38,6 +37,10 @@ public static void deserialize(JsonParser jsonParser, StandardRangeActionAdder<?
jsonParser.nextToken();
adder.withMax(jsonParser.getDoubleValue());
break;
case RANGE_TYPE:
jsonParser.nextToken();
adder.withRangeType(deserializeRangeType(jsonParser.getText()));
break;
default:
throw new OpenRaoException("Unexpected field in StandardRange: " + jsonParser.getCurrentName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public void serialize(StandardRange value, JsonGenerator gen, SerializerProvider
if (value.getMax() < Integer.MAX_VALUE) {
gen.writeNumberField(MAX, value.getMax());
}
gen.writeStringField(RANGE_TYPE, serializeRangeType(value.getRangeType()));
gen.writeEndObject();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public interface StandardRangeAdder<T extends StandardRangeActionAdder<T>> {

StandardRangeAdder<T> withMax(double maxSetpoint);

StandardRangeAdder<T> withRangeType(RangeType rangeType);

T add();
}
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 @@ -46,6 +46,16 @@ public InjectionRangeActionAdder withNetworkElementAndKey(double key, String net
return this;
}

@Override
public InjectionRangeActionAdder withNetworkElement(String networkElementId) {
return withNetworkElementAndKey(1.0, networkElementId, networkElementId);
}

@Override
public InjectionRangeActionAdder withNetworkElement(String networkElementId, String networkElementName) {
return withNetworkElementAndKey(1.0, networkElementId, networkElementName);
}

@Override
public InjectionRangeAction add() {
checkId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.List;

/**
* Common code for StandradRangeAction implementations (adding another abstract class for standard range actions would be too much class depth)
* Common code for StandardRangeAction implementations (adding another abstract class for standard range actions would be too much class depth)
* @author Gabriel Plante {@literal <gabriel.plante_externe at rte-france.com}
*/
public final class StandardRangeActionUtils {
Expand All @@ -33,6 +33,9 @@ static double getMinAdmissibleSetpoint(double previousInstantSetPoint, List<Stan
case RELATIVE_TO_PREVIOUS_INSTANT:
minAdmissibleSetpoint = Math.max(minAdmissibleSetpoint, previousInstantSetPoint + range.getMin());
break;
// to avoid throwing exception
case RELATIVE_TO_PREVIOUS_TIME_STEP:
break;
default:
throw new NotImplementedException("Range Action type is not implemented yet.");
}
Expand All @@ -53,6 +56,9 @@ static double getMaxAdmissibleSetpoint(double previousInstantSetPoint, List<Stan
case RELATIVE_TO_PREVIOUS_INSTANT:
maxAdmissibleSetpoint = Math.min(maxAdmissibleSetpoint, previousInstantSetPoint + range.getMax());
break;
// to avoid throwing exception
case RELATIVE_TO_PREVIOUS_TIME_STEP:
break;
default:
throw new NotImplementedException("Range Action type is not implemented yet.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package com.powsybl.openrao.data.cracimpl;

import com.powsybl.openrao.commons.OpenRaoException;
import com.powsybl.openrao.data.cracapi.range.RangeType;
import com.powsybl.openrao.data.cracapi.range.StandardRange;
import com.powsybl.openrao.data.cracapi.range.StandardRangeAdder;
import com.powsybl.openrao.data.cracapi.rangeaction.*;
Expand All @@ -24,10 +25,13 @@ public class StandardRangeAdderImpl<T extends StandardRangeActionAdder<T>> imple
private Double min;
private Double max;

private RangeType rangeType;

StandardRangeAdderImpl(AbstractStandardRangeActionAdder<T> ownerAdder) {
this.ownerAdder = ownerAdder;
this.min = Double.MIN_VALUE;
this.max = Double.MAX_VALUE;
this.rangeType = RangeType.ABSOLUTE;
}

@Override
Expand All @@ -42,10 +46,17 @@ public StandardRangeAdder<T> withMax(double maxSetpoint) {
return this;
}

@Override
public StandardRangeAdder<T> withRangeType(RangeType rangeType) {
this.rangeType = rangeType;
return this;
}

@Override
public T add() {
AdderUtils.assertAttributeNotNull(min, CLASS_NAME, "min value", "withMin()");
AdderUtils.assertAttributeNotNull(max, CLASS_NAME, "max value", "withMax()");
AdderUtils.assertAttributeNotNull(rangeType, CLASS_NAME, "range type", "withRangeType()");

if (max == Double.MAX_VALUE) {
throw new OpenRaoException("StandardRange max value was not defined.");
Expand All @@ -57,7 +68,7 @@ public T add() {
throw new OpenRaoException("Max value of StandardRange must be equal or greater than min value.");
}

StandardRange standardRange = new StandardRangeImpl(min, max);
StandardRange standardRange = new StandardRangeImpl(min, max, rangeType);

ownerAdder.addRange(standardRange);
return (T) ownerAdder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class StandardRangeImpl extends AbstractRange implements StandardRange {
private final double min;
private final double max;

StandardRangeImpl(double min, double max) {
super(RangeType.ABSOLUTE, Unit.MEGAWATT);
// rangeType added to StandardRange to accept also RELATIVE_TO_PREVIOUS_TIME_STEP, and not only ABSOLUTE
StandardRangeImpl(double min, double max, RangeType rangeType) {
wangjer marked this conversation as resolved.
Show resolved Hide resolved
super(rangeType, Unit.MEGAWATT);
this.min = min;
this.max = max;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ void testAddWithoutGroupId() {
assertEquals(2, crac.getNetworkElements().size());
}

@Test
void testAddDefaultKey() {
InjectionRangeAction injectionRangeAction = crac.newInjectionRangeAction()
.withId("id1")
.withOperator("BE")
.withGroupId("groupId1")
.withNetworkElement(injectionId1)
.withNetworkElement(injectionId2, injectionName2)
.newRange().withMin(-5).withMax(10).add()
.newOnInstantUsageRule().withInstant(PREVENTIVE_INSTANT_ID).withUsageMethod(UsageMethod.AVAILABLE).add()
.add();

assertEquals("id1", injectionRangeAction.getId());
assertEquals("id1", injectionRangeAction.getName());
assertEquals("BE", injectionRangeAction.getOperator());
assertTrue(injectionRangeAction.getGroupId().isPresent());
assertEquals("groupId1", injectionRangeAction.getGroupId().get());
assertEquals(1, injectionRangeAction.getRanges().size());
assertEquals(1, injectionRangeAction.getUsageRules().size());

assertEquals(2, injectionRangeAction.getInjectionDistributionKeys().size());
assertEquals(1., injectionRangeAction.getInjectionDistributionKeys().get(crac.getNetworkElement(injectionId1)), 1e-6);
assertEquals(1., injectionRangeAction.getInjectionDistributionKeys().get(crac.getNetworkElement(injectionId2)), 1e-6);

assertEquals(2, crac.getNetworkElements().size());
assertNotNull(crac.getNetworkElement(injectionId1));
assertNotNull(crac.getNetworkElement(injectionId2));

assertEquals(1, crac.getRangeActions().size());
}

@Test
void testAddWithoutUsageRule() {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class StandardRangeImplTest {

@BeforeEach
public void setUp() {
fixedRange = new StandardRangeImpl(min, max);
fixedRange = new StandardRangeImpl(min, max, RangeType.ABSOLUTE);
}

@Test
Expand All @@ -45,19 +45,19 @@ void getRangeTypeTest() {

@Test
void testEquals() {
StandardRangeImpl range1 = new StandardRangeImpl(0, 10);
StandardRangeImpl range2 = new StandardRangeImpl(0, 10);
StandardRangeImpl range3 = new StandardRangeImpl(0, 11);
StandardRangeImpl range1 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
StandardRangeImpl range2 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
StandardRangeImpl range3 = new StandardRangeImpl(0, 11, RangeType.ABSOLUTE);

assertEquals(range1, range2);
assertNotEquals(range1, range3);
}

@Test
void testHashCode() {
StandardRangeImpl range1 = new StandardRangeImpl(0, 10);
StandardRangeImpl range2 = new StandardRangeImpl(0, 10);
StandardRangeImpl range3 = new StandardRangeImpl(0, 11);
StandardRangeImpl range1 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
StandardRangeImpl range2 = new StandardRangeImpl(0, 10, RangeType.ABSOLUTE);
StandardRangeImpl range3 = new StandardRangeImpl(0, 11, RangeType.ABSOLUTE);

assertEquals(range1.hashCode(), range2.hashCode());
assertNotEquals(range1.hashCode(), range3.hashCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.util.*;

/**
* @author Joris Mancini {@literal <joris.mancini at rte-france.com>}
* @author Jeremy Wang {@literal <jeremy.wang at rte-france.com>}
*/
public final class SensitivityComputerMultiTS {
private List<SystematicSensitivityInterface> systematicSensitivityInterfaces;
Expand All @@ -41,14 +41,14 @@ public static SensitivityComputerBuilder create() {
}

public void compute(List<Network> networks) {
results = new ArrayList<>(); //besoin d'initialiser?
results = new ArrayList<>();
for (int i = 0; i < networks.size(); i++) {
results.add(systematicSensitivityInterfaces.get(i).run(networks.get(i)));
}
}

public FlowResult getBranchResult(Network network, int i) {
return branchResultAdapters.get(i).getResult(results.get(i), network); //???
return branchResultAdapters.get(i).getResult(results.get(i), network);
}

public MultipleSensitivityResult getSensitivityResults() {
Expand All @@ -62,14 +62,15 @@ public MultipleSensitivityResult getSensitivityResults() {
public static final class SensitivityComputerBuilder {
private ToolProvider toolProvider;
private List<Set<FlowCnec>> flowCnecsList;
private List<Set<RangeAction<?>>> rangeActionsList;
private Set<RangeAction<?>> rangeActions;
private FlowResult fixedPtdfs;
private AbsolutePtdfSumsComputation absolutePtdfSumsComputation;
private FlowResult fixedCommercialFlows;
private LoopFlowComputation loopFlowComputation;
private List<Set<FlowCnec>> loopFlowCnecsList;
private AppliedRemedialActions appliedRemedialActions;
private Instant outageInstant; //list of outage instants?
private Instant outageInstant;
// curently using only one outageInstant, but we could use a List ot make it cleaner

public SensitivityComputerBuilder withToolProvider(ToolProvider toolProvider) {
this.toolProvider = toolProvider;
Expand All @@ -81,8 +82,8 @@ public SensitivityComputerBuilder withCnecs(List<Set<FlowCnec>> flowCnecsList) {
return this;
}

public SensitivityComputerBuilder withRangeActions(List<Set<RangeAction<?>>> rangeActionsList) {
this.rangeActionsList = rangeActionsList;
public SensitivityComputerBuilder withRangeActions(Set<RangeAction<?>> rangeActions) {
this.rangeActions = rangeActions;
return this;
}

Expand Down Expand Up @@ -124,7 +125,7 @@ public SensitivityComputerBuilder withOutageInstant(Instant outageInstant) {
public SensitivityComputerMultiTS build() {
Objects.requireNonNull(toolProvider);
Objects.requireNonNull(flowCnecsList);
Objects.requireNonNull(rangeActionsList);
Objects.requireNonNull(rangeActions);
Objects.requireNonNull(outageInstant);
SensitivityComputerMultiTS sensitivityComputer = new SensitivityComputerMultiTS();
boolean computePtdfs = absolutePtdfSumsComputation != null;
Expand All @@ -137,7 +138,7 @@ public SensitivityComputerMultiTS build() {
for (int i = 0; i < flowCnecsList.size(); i++) {
sensitivityComputer.systematicSensitivityInterfaces.add(toolProvider.getSystematicSensitivityInterface(
flowCnecsList.get(i),
rangeActionsList.get(i),
rangeActions,
computePtdfs,
computeLoopFlows,
appliedRemedialActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import static com.powsybl.openrao.commons.Unit.MEGAWATT;

/**
* @author Joris Mancini {@literal <joris.mancini at rte-france.com>}
wangjer marked this conversation as resolved.
Show resolved Hide resolved
* @author Jeremy Wang {@literal <jeremy.wang at rte-france.com>}
*/
public final class BestTapFinderMultiTS {

Expand Down
Loading
Loading