Skip to content

Commit d9d21da

Browse files
bqth29RoxaneChen02
andauthored
Separate global result from individual results per timestamp (#1302)
Separate global result from individual results per timestamp (#1302) --------- Signed-off-by: Thomas Bouquet <thomas.bouquet@rte-france.com> Co-authored-by: CHEN Roxane <roxane.chen@rte-france.com>
1 parent 441fc0a commit d9d21da

23 files changed

Lines changed: 1082 additions & 170 deletions
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
package com.powsybl.openrao.data.raoresult.api;
9+
10+
import com.powsybl.openrao.commons.PhysicalParameter;
11+
import com.powsybl.openrao.data.crac.api.Instant;
12+
import com.powsybl.openrao.data.crac.api.InstantKind;
13+
14+
import java.time.OffsetDateTime;
15+
import java.util.List;
16+
17+
/**
18+
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
19+
*/
20+
public interface InterTemporalRaoResult extends RaoResult {
21+
List<OffsetDateTime> getTimestamps();
22+
23+
default double getGlobalCost(InstantKind instantKind) {
24+
return getGlobalFunctionalCost(instantKind) + getGlobalVirtualCost(instantKind);
25+
}
26+
27+
double getGlobalFunctionalCost(InstantKind instantKind);
28+
29+
double getGlobalVirtualCost(InstantKind instantKind);
30+
31+
double getGlobalVirtualCost(InstantKind instantKind, String virtualCostName);
32+
33+
/**
34+
* It gives the global cost of the situation at a given {@link Instant} according to the objective
35+
* function defined in the RAO.
36+
*
37+
* @param optimizedInstant: The optimized instant to be studied (set to null to access initial results)
38+
* @param timestamp: The timestamp to be studied
39+
* @return The global cost of the situation state.
40+
*/
41+
default double getCost(Instant optimizedInstant, OffsetDateTime timestamp) {
42+
return getFunctionalCost(optimizedInstant, timestamp) + getVirtualCost(optimizedInstant, timestamp);
43+
}
44+
45+
/**
46+
* It gives the functional cost of the situation at a given {@link Instant} according to the objective
47+
* function defined in the RAO. It represents the main part of the objective function.
48+
*
49+
* @param optimizedInstant: The optimized instant to be studied (set to null to access initial results)
50+
* @param timestamp: The timestamp to be studied
51+
* @return The functional cost of the situation state.
52+
*/
53+
double getFunctionalCost(Instant optimizedInstant, OffsetDateTime timestamp);
54+
55+
/**
56+
* It gives the sum of virtual costs of the situation at a given {@link Instant} according to the
57+
* objective function defined in the RAO. It represents the secondary parts of the objective
58+
* function.
59+
*
60+
* @param optimizedInstant: The optimized instant to be studied (set to null to access initial results)
61+
* @param timestamp: The timestamp to be studied
62+
* @return The global virtual cost of the situation state.
63+
*/
64+
double getVirtualCost(Instant optimizedInstant, OffsetDateTime timestamp);
65+
66+
/**
67+
* It gives the specified virtual cost of the situation at a given {@link Instant}. It represents the
68+
* secondary parts of the objective. If the specified name is not part of the virtual costs defined in the
69+
* objective function, this method could return {@code Double.NaN} values.
70+
*
71+
* @param optimizedInstant: The optimized instant to be studied (set to null to access initial results)
72+
* @param virtualCostName: The name of the virtual cost.
73+
* @param timestamp: The timestamp to be studied
74+
* @return The specific virtual cost of the situation state.
75+
*/
76+
double getVirtualCost(Instant optimizedInstant, String virtualCostName, OffsetDateTime timestamp);
77+
78+
/**
79+
* Indicates whether the all the CNECs of a given type at a given instant of a given timestamp are secure.
80+
*
81+
* @param optimizedInstant: The instant to assess
82+
* @param timestamp: The timestamp to assess
83+
* @param u: The types of CNECs to check (FLOW -> FlowCNECs, ANGLE -> AngleCNECs, VOLTAGE -> VoltageCNECs). 1 to 3 arguments can be provided.
84+
* @return whether all the CNECs of the given type(s) are secure at the optimized instant.
85+
*/
86+
boolean isSecure(Instant optimizedInstant, OffsetDateTime timestamp, PhysicalParameter... u);
87+
88+
boolean isSecure(OffsetDateTime timestamp, PhysicalParameter... u);
89+
90+
default boolean isSecure(OffsetDateTime timestamp) {
91+
return isSecure(timestamp, PhysicalParameter.FLOW, PhysicalParameter.ANGLE, PhysicalParameter.VOLTAGE);
92+
}
93+
}

data/rao-result/rao-result-api/src/main/java/com/powsybl/openrao/data/raoresult/api/RaoResult.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,13 @@ private static byte[] getBytesFromInputStream(InputStream inputStream) throws IO
495495
}
496496

497497
/**
498-
* Write CRAC data into a file
498+
* Write RAO Result data into a file
499499
*
500-
* @param exporters candidate CRAC exporters
501-
* @param format desired output CRAC data type
500+
* @param exporters candidate RAO Result exporters
501+
* @param format desired output RAO Result data type
502502
* @param cracCreationContext CRAC creation context that contains the original CRAC
503503
* @param properties specific information needed for export
504-
* @param outputStream file where to write the CRAC data
504+
* @param outputStream file where to write the RAO Result data
505505
*/
506506
private void write(List<Exporter> exporters, String format, CracCreationContext cracCreationContext, Properties properties, OutputStream outputStream) {
507507
exporters.stream()
@@ -512,25 +512,25 @@ private void write(List<Exporter> exporters, String format, CracCreationContext
512512
}
513513

514514
/**
515-
* Write CRAC data into a file
515+
* Write RAO Result data into a file
516516
*
517-
* @param format desired output CRAC data type
517+
* @param format desired output RAO Result data type
518518
* @param cracCreationContext CRAC creation context that contains the original CRAC
519519
* @param properties specific information needed for export
520-
* @param outputStream file where to write the CRAC data
520+
* @param outputStream file where to write the RAO Result data
521521
*/
522522
default void write(String format, CracCreationContext cracCreationContext, Properties properties, OutputStream outputStream) {
523523
write(new ServiceLoaderCache<>(Exporter.class).getServices(), format, cracCreationContext, properties, outputStream);
524524
}
525525

526526
/**
527-
* Write CRAC data into a file
527+
* Write RAO Result data into a file
528528
*
529-
* @param exporters candidate CRAC exporters
530-
* @param format desired output CRAC data type
529+
* @param exporters candidate RAO Result exporters
530+
* @param format desired output RAO Result data type
531531
* @param crac CRAC data
532532
* @param properties specific information needed for export
533-
* @param outputStream file where to write the CRAC data
533+
* @param outputStream file where to write the RAO Result data
534534
*/
535535
private void write(List<Exporter> exporters, String format, Crac crac, Properties properties, OutputStream outputStream) {
536536
exporters.stream()
@@ -541,12 +541,12 @@ private void write(List<Exporter> exporters, String format, Crac crac, Propertie
541541
}
542542

543543
/**
544-
* Write CRAC data into a file
544+
* Write RAO Result data into a file
545545
*
546-
* @param format desired output CRAC data type
546+
* @param format desired output RAO Result data type
547547
* @param crac CRAC data
548548
* @param properties specific information needed for export
549-
* @param outputStream file where to write the CRAC data
549+
* @param outputStream file where to write the RAO Result data
550550
*/
551551
default void write(String format, Crac crac, Properties properties, OutputStream outputStream) {
552552
write(new ServiceLoaderCache<>(Exporter.class).getServices(), format, crac, properties, outputStream);

ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/InterTemporalRao.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import com.powsybl.commons.config.PlatformConfig;
1414
import com.powsybl.commons.util.ServiceLoaderCache;
1515
import com.powsybl.openrao.commons.OpenRaoException;
16-
import com.powsybl.openrao.commons.TemporalData;
17-
import com.powsybl.openrao.data.raoresult.api.RaoResult;
16+
import com.powsybl.openrao.data.raoresult.api.InterTemporalRaoResult;
1817
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
1918
import com.powsybl.tools.Version;
2019

@@ -47,7 +46,7 @@ public Runner(InterTemporalRaoProvider provider) {
4746
this.provider = Objects.requireNonNull(provider);
4847
}
4948

50-
public TemporalData<RaoResult> run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
49+
public InterTemporalRaoResult run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
5150
Objects.requireNonNull(raoInput, "RAO input should not be null");
5251
Objects.requireNonNull(parameters, "parameters should not be null");
5352

@@ -57,7 +56,7 @@ public TemporalData<RaoResult> run(InterTemporalRaoInput raoInput, RaoParameters
5756
return provider.run(raoInput, parameters).join();
5857
}
5958

60-
public TemporalData<RaoResult> run(InterTemporalRaoInput raoInput) {
59+
public InterTemporalRaoResult run(InterTemporalRaoInput raoInput) {
6160
return run(raoInput, RaoParameters.load());
6261
}
6362

@@ -138,11 +137,11 @@ public static InterTemporalRao.Runner find(String name, List<InterTemporalRaoPro
138137
return new InterTemporalRao.Runner(provider);
139138
}
140139

141-
public static TemporalData<RaoResult> run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
140+
public static InterTemporalRaoResult run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
142141
return find().run(raoInput, parameters);
143142
}
144143

145-
public static TemporalData<RaoResult> run(InterTemporalRaoInput raoInput) {
144+
public static InterTemporalRaoResult run(InterTemporalRaoInput raoInput) {
146145
return find().run(raoInput);
147146
}
148147
}

ra-optimisation/rao-api/src/main/java/com/powsybl/openrao/raoapi/InterTemporalRaoProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
package com.powsybl.openrao.raoapi;
99

1010
import com.powsybl.commons.Versionable;
11-
import com.powsybl.openrao.commons.TemporalData;
12-
import com.powsybl.openrao.data.raoresult.api.RaoResult;
11+
import com.powsybl.openrao.data.raoresult.api.InterTemporalRaoResult;
1312
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
1413

1514
import java.util.concurrent.CompletableFuture;
@@ -24,5 +23,5 @@ public interface InterTemporalRaoProvider extends Versionable {
2423
* @param parameters: RAO parameters.
2524
* @return A completable future of a RaoComputationResult for each timestamp.
2625
*/
27-
CompletableFuture<TemporalData<RaoResult>> run(InterTemporalRaoInput raoInput, RaoParameters parameters);
26+
CompletableFuture<InterTemporalRaoResult> run(InterTemporalRaoInput raoInput, RaoParameters parameters);
2827
}

ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/InterTemporalRaoTest.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
import com.powsybl.iidm.network.Network;
1414
import com.powsybl.iidm.network.VariantManager;
1515
import com.powsybl.openrao.commons.OpenRaoException;
16-
import com.powsybl.openrao.commons.TemporalData;
1716
import com.powsybl.openrao.commons.TemporalDataImpl;
1817
import com.powsybl.openrao.data.crac.api.Crac;
19-
import com.powsybl.openrao.data.raoresult.api.ComputationStatus;
20-
import com.powsybl.openrao.data.raoresult.api.RaoResult;
18+
import com.powsybl.openrao.data.raoresult.api.InterTemporalRaoResult;
2119
import com.powsybl.openrao.raoapi.parameters.RaoParameters;
2220
import com.powsybl.openrao.raoapi.raomock.AnotherInterTemporalRaoProviderMock;
2321
import com.powsybl.openrao.raoapi.raomock.InterTemporalRaoProviderMock;
@@ -36,7 +34,6 @@
3634
import static org.junit.jupiter.api.Assertions.assertEquals;
3735
import static org.junit.jupiter.api.Assertions.assertNotNull;
3836
import static org.junit.jupiter.api.Assertions.assertThrows;
39-
import static org.junit.jupiter.api.Assertions.assertTrue;
4037

4138
/**
4239
* @author Thomas Bouquet {@literal <thomas.bouquet at rte-france.com>}
@@ -73,12 +70,8 @@ void testDefaultOneProvider() {
7370
assertEquals("1.0", defaultRao.getVersion());
7471

7572
// run rao
76-
OffsetDateTime timestamp = OffsetDateTime.of(2024, 12, 13, 16, 17, 0, 0, ZoneOffset.UTC);
77-
TemporalData<RaoResult> result = defaultRao.run(raoInput, new RaoParameters());
73+
InterTemporalRaoResult result = defaultRao.run(raoInput, new RaoParameters());
7874
assertNotNull(result);
79-
assertEquals(List.of(timestamp), result.getTimestamps());
80-
assertTrue(result.getData(timestamp).isPresent());
81-
assertEquals(ComputationStatus.DEFAULT, result.getData(timestamp).get().getComputationStatus());
8275
}
8376

8477
@Test

ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/raomock/AnotherInterTemporalRaoProviderMock.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
package com.powsybl.openrao.raoapi.raomock;
99

1010
import com.google.auto.service.AutoService;
11-
import com.powsybl.openrao.commons.TemporalData;
12-
import com.powsybl.openrao.commons.TemporalDataImpl;
1311
import com.powsybl.openrao.data.raoresult.api.ComputationStatus;
12+
import com.powsybl.openrao.data.raoresult.api.InterTemporalRaoResult;
1413
import com.powsybl.openrao.data.raoresult.api.RaoResult;
1514
import com.powsybl.openrao.data.raoresult.impl.RaoResultImpl;
1615
import com.powsybl.openrao.raoapi.InterTemporalRaoInput;
@@ -28,14 +27,14 @@
2827
@AutoService(InterTemporalRaoProvider.class)
2928
public class AnotherInterTemporalRaoProviderMock implements InterTemporalRaoProvider {
3029
@Override
31-
public CompletableFuture<TemporalData<RaoResult>> run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
30+
public CompletableFuture<InterTemporalRaoResult> run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
3231
Map<OffsetDateTime, RaoResult> raoResultPerTimestamp = new HashMap<>();
3332
for (OffsetDateTime timestamp : raoInput.getTimestampsToRun()) {
3433
RaoResultImpl raoResult = new RaoResultImpl(raoInput.getRaoInputs().getData(timestamp).orElseThrow().getCrac());
3534
raoResult.setComputationStatus(ComputationStatus.FAILURE);
3635
raoResultPerTimestamp.put(timestamp, raoResult);
3736
}
38-
return CompletableFuture.completedFuture(new TemporalDataImpl<>(raoResultPerTimestamp));
37+
return CompletableFuture.completedFuture(new InterTemporalRaoResultMock());
3938
}
4039

4140
@Override

ra-optimisation/rao-api/src/test/java/com/powsybl/openrao/raoapi/raomock/InterTemporalRaoProviderMock.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
package com.powsybl.openrao.raoapi.raomock;
99

1010
import com.google.auto.service.AutoService;
11-
import com.powsybl.openrao.commons.TemporalData;
12-
import com.powsybl.openrao.commons.TemporalDataImpl;
1311
import com.powsybl.openrao.data.raoresult.api.ComputationStatus;
12+
import com.powsybl.openrao.data.raoresult.api.InterTemporalRaoResult;
1413
import com.powsybl.openrao.data.raoresult.api.RaoResult;
1514
import com.powsybl.openrao.data.raoresult.impl.RaoResultImpl;
1615
import com.powsybl.openrao.raoapi.InterTemporalRaoInput;
@@ -29,14 +28,14 @@
2928
public class InterTemporalRaoProviderMock implements InterTemporalRaoProvider {
3029

3130
@Override
32-
public CompletableFuture<TemporalData<RaoResult>> run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
31+
public CompletableFuture<InterTemporalRaoResult> run(InterTemporalRaoInput raoInput, RaoParameters parameters) {
3332
Map<OffsetDateTime, RaoResult> raoResultPerTimestamp = new HashMap<>();
3433
for (OffsetDateTime timestamp : raoInput.getTimestampsToRun()) {
3534
RaoResultImpl raoResult = new RaoResultImpl(raoInput.getRaoInputs().getData(timestamp).orElseThrow().getCrac());
3635
raoResult.setComputationStatus(ComputationStatus.DEFAULT);
3736
raoResultPerTimestamp.put(timestamp, raoResult);
3837
}
39-
return CompletableFuture.completedFuture(new TemporalDataImpl<>(raoResultPerTimestamp));
38+
return CompletableFuture.completedFuture(new InterTemporalRaoResultMock());
4039
}
4140

4241
@Override

0 commit comments

Comments
 (0)