Skip to content

Commit cd22541

Browse files
Merge pull request #367 from ie3-institute/ms/#366-fix-issues-related-to-em-data
Fixed issues related to em data
2 parents 71eef01 + 6cda87a commit cd22541

20 files changed

+203
-393
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased/Snapshot]
88

9+
### Changed
10+
- Changes to sent and received em data [#2366](https://github.com/ie3-institute/simonaAPI/issues/366)
11+
12+
### Fixed
13+
- Issues related to em data [#2366](https://github.com/ie3-institute/simonaAPI/issues/366)
14+
915
## [0.11.0] - 2025-10-23
1016

1117
### Added

src/main/java/edu/ie3/simona/api/data/connection/ExtEmDataConnection.java

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import edu.ie3.simona.api.data.model.em.*;
1010
import edu.ie3.simona.api.ontology.em.*;
1111
import java.util.*;
12+
import org.slf4j.Logger;
1213

1314
/** Enables data connection of em data between SIMONA and SimonaAPI */
1415
public final class ExtEmDataConnection
@@ -32,42 +33,39 @@ public List<UUID> getControlledEms() {
3233
}
3334

3435
/**
35-
* Tries to send em data to SIMONA. A message is sent, if at least one map is not empty.
36+
* Tries to send em data to SIMONA. A message is sent, if the map is not empty.
3637
*
3738
* @param tick current tick
38-
* @param flexRequests receiver to flex option request
39-
* @param flexOptions receiver to flex options
40-
* @param setPoints receiver to set point
41-
* @param maybeNextTick option for the next tick in the simulation
39+
* @param emData a map: receiver to em data
40+
* @param log logger for logging warnings
4241
* @return true, if data was sent
4342
*/
44-
public boolean sendEmData(
45-
long tick,
46-
Map<UUID, FlexOptionRequest> flexRequests,
47-
Map<UUID, List<FlexOptions>> flexOptions,
48-
Map<UUID, EmSetPoint> setPoints,
49-
Optional<Long> maybeNextTick) {
43+
public boolean sendEmData(long tick, Map<UUID, ? extends EmData> emData, Logger log) {
5044
// send message only if at least one value is present
51-
if (!flexRequests.isEmpty() || !flexOptions.isEmpty() || !setPoints.isEmpty()) {
52-
sendExtMsg(new ProvideEmData(tick, flexRequests, flexOptions, setPoints, maybeNextTick));
45+
if (!emData.isEmpty()) {
46+
sendExtMsg(ProvideEmData.create(tick, emData, log));
5347
return true;
5448
}
5549
return false;
5650
}
5751

5852
/**
59-
* Tries to send flex option requests to SIMONA. A message is sent, if at least one entity is
60-
* given.
53+
* Tries to send em data to SIMONA. A message is sent, if at least one map is not empty.
6154
*
6255
* @param tick current tick
63-
* @param entities for which flex options should be requested
64-
* @param disaggregated if disaggregated flex option should be returned
56+
* @param flexRequests receiver to flex option request
57+
* @param flexOptions receiver to flex options
58+
* @param setPoints receiver to set point that should be sent to SIMONA
6559
* @return true, if data was sent
6660
*/
67-
public boolean sendFlexRequest(long tick, Collection<UUID> entities, boolean disaggregated) {
61+
public boolean sendEmData(
62+
long tick,
63+
Map<UUID, FlexOptionRequest> flexRequests,
64+
Map<UUID, List<FlexOptions>> flexOptions,
65+
Map<UUID, EmSetPoint> setPoints) {
6866
// send message only if at least one value is present
69-
if (!entities.isEmpty()) {
70-
sendExtMsg(new RequestEmFlexResults(tick, new ArrayList<>(entities), disaggregated));
67+
if (!flexRequests.isEmpty() || !flexOptions.isEmpty() || !setPoints.isEmpty()) {
68+
sendExtMsg(new ProvideEmData(tick, flexRequests, flexOptions, setPoints));
7169
return true;
7270
}
7371
return false;
@@ -79,33 +77,13 @@ public boolean sendFlexRequest(long tick, Collection<UUID> entities, boolean dis
7977
*
8078
* @param tick current tick
8179
* @param emCommunicationMessages that should be sent
82-
* @param maybeNextTick an option for the next tick
8380
* @return true, if data was sent
8481
*/
8582
public boolean sendCommunicationMessage(
86-
long tick,
87-
List<EmCommunicationMessage<?>> emCommunicationMessages,
88-
Optional<Long> maybeNextTick) {
83+
long tick, List<EmCommunicationMessage<?>> emCommunicationMessages) {
8984
// send message only if at least one value is present
9085
if (!emCommunicationMessages.isEmpty()) {
91-
sendExtMsg(new EmCommunicationMessages(tick, emCommunicationMessages, maybeNextTick));
92-
return true;
93-
}
94-
return false;
95-
}
96-
97-
/**
98-
* Tries to send the em set points to SIMONA.
99-
*
100-
* @param tick current tick
101-
* @param setPoints receiver to set point, that should be sent to SIMONA
102-
* @param maybeNextTick option for the next tick in the simulation
103-
* @return true, if data was sent
104-
*/
105-
public boolean sendSetPoints(
106-
long tick, Map<UUID, EmSetPoint> setPoints, Optional<Long> maybeNextTick) {
107-
if (!setPoints.isEmpty()) {
108-
sendExtMsg(new ProvideEmSetPointData(tick, setPoints, maybeNextTick));
86+
sendExtMsg(new EmCommunicationMessages(tick, emCommunicationMessages));
10987
return true;
11088
}
11189
return false;
@@ -115,13 +93,18 @@ public boolean sendSetPoints(
11593
* Method to request em flexibility options from SIMONA.
11694
*
11795
* @param tick for which set points are requested
118-
* @param emEntities for which set points are requested
119-
* @return an {@link FlexOptionsResponse} message
96+
* @param entities for which set points are requested
97+
* @return a map: uuid to list of flex options
12098
* @throws InterruptedException - on interruptions
12199
*/
122-
public Map<UUID, ExtendedFlexOptionsResult> requestEmFlexResults(
123-
long tick, List<UUID> emEntities, boolean disaggregated) throws InterruptedException {
124-
sendExtMsg(new RequestEmFlexResults(tick, emEntities, disaggregated));
100+
public Map<UUID, List<FlexOptions>> requestEmFlexResults(
101+
long tick, List<UUID> entities, boolean disaggregated) throws InterruptedException {
102+
// create requests
103+
Map<UUID, FlexOptionRequest> requests = new HashMap<>();
104+
entities.forEach(
105+
emEntity -> requests.put(emEntity, new FlexOptionRequest(emEntity, disaggregated)));
106+
107+
sendExtMsg(new ProvideEmData(tick, requests, Collections.emptyMap(), Collections.emptyMap()));
125108
return receiveWithType(FlexOptionsResponse.class).receiverToFlexOptions();
126109
}
127110

src/main/java/edu/ie3/simona/api/data/connection/ExtOutputDataConnection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @param <T> type of response messages to ext
1616
*/
1717
public sealed interface ExtOutputDataConnection<T extends DataResponseMessageToExt>
18-
permits BiDirectional, ExtResultListener {
18+
extends ExtDataConnection permits BiDirectional, ExtResultListener {
1919

2020
/** Queues message from SIMONA that should be handled by the external simulation. */
2121
void queueExtResponseMsg(T msg) throws InterruptedException;

src/main/java/edu/ie3/simona/api/data/model/em/ExtendedFlexOptionsResult.java

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
import java.time.ZonedDateTime;
1111
import java.util.*;
1212
import javax.measure.quantity.Power;
13-
import org.slf4j.Logger;
1413
import tech.units.indriya.ComparableQuantity;
1514

1615
/**
1716
* Extended {@link FlexOptionsResult}, that contains the receiver of the flex options. This models
1817
* may also contain a disaggregation of the total flex options.
1918
*/
20-
public final class ExtendedFlexOptionsResult extends FlexOptionsResult implements EmData {
19+
public final class ExtendedFlexOptionsResult extends FlexOptionsResult {
2120

2221
/** The disaggregated flex option results. */
2322
private final Map<UUID, FlexOptionsResult> disaggregated;
@@ -49,6 +48,7 @@ public ExtendedFlexOptionsResult(
4948
* @param pRef active power that was suggested for regular usage by the system participant
5049
* @param pMin active minimal power that was determined by the system participant
5150
* @param pMax active maximum power that was determined by the system participant
51+
* @param disaggregated a map: uuid to disaggregated flex options
5252
*/
5353
public ExtendedFlexOptionsResult(
5454
ZonedDateTime time,
@@ -64,9 +64,6 @@ public ExtendedFlexOptionsResult(
6464
/**
6565
* Method for adding disaggregated flex option results to this object.
6666
*
67-
* <p>Note: This method does not check, if the disaggregated flex options match the total flex
68-
* options. To do this, please use the method {@link #checkFlexOptions(Logger)}.
69-
*
7067
* @param uuid of the inferior model
7168
* @param flexOptionsResult the flex options of the inferior model
7269
*/
@@ -89,69 +86,6 @@ public Map<UUID, FlexOptionsResult> getDisaggregated() {
8986
return Collections.unmodifiableMap(disaggregated);
9087
}
9188

92-
/**
93-
* Method for checking if the disaggregated flex options match the total flex options.
94-
*
95-
* @param log used for logging
96-
* @return {@code true} if the flex options match, else {@code false}
97-
*/
98-
public boolean checkFlexOptions(Logger log) {
99-
List<ComparableQuantity<Power>> refs = new ArrayList<>();
100-
List<ComparableQuantity<Power>> mins = new ArrayList<>();
101-
List<ComparableQuantity<Power>> maxs = new ArrayList<>();
102-
103-
disaggregated.forEach(
104-
(uuid, flexOptionsResult) -> {
105-
refs.add(flexOptionsResult.getpRef());
106-
mins.add(flexOptionsResult.getpMin());
107-
maxs.add(flexOptionsResult.getpMax());
108-
});
109-
110-
ComparableQuantity<Power> ref = getpRef();
111-
ComparableQuantity<Power> min = getpMin();
112-
ComparableQuantity<Power> max = getpMax();
113-
114-
Optional<ComparableQuantity<Power>> refSum = refs.stream().reduce(ComparableQuantity::add);
115-
Optional<ComparableQuantity<Power>> minSum = mins.stream().reduce(ComparableQuantity::add);
116-
Optional<ComparableQuantity<Power>> maxSum = maxs.stream().reduce(ComparableQuantity::add);
117-
118-
boolean isRefValid = false;
119-
boolean isMinValid = false;
120-
boolean isMaxValid = false;
121-
122-
if (refSum.isPresent()) {
123-
isRefValid = refSum.get().isEquivalentTo(ref);
124-
125-
if (!isRefValid) {
126-
log.warn("Disaggregated reference power does not match total reference power.");
127-
}
128-
} else {
129-
log.warn("Cannot check disaggregated reference power.");
130-
}
131-
132-
if (minSum.isPresent()) {
133-
isMinValid = minSum.get().isEquivalentTo(min);
134-
135-
if (!isMinValid) {
136-
log.warn("Disaggregated minimum power does not match total minimum power.");
137-
}
138-
} else {
139-
log.warn("Cannot check disaggregated minimum power.");
140-
}
141-
142-
if (maxSum.isPresent()) {
143-
isMaxValid = maxSum.get().isEquivalentTo(max);
144-
145-
if (!isMaxValid) {
146-
log.warn("Disaggregated maximum power does not match total maximum power.");
147-
}
148-
} else {
149-
log.warn("Cannot check disaggregated maximum power.");
150-
}
151-
152-
return isRefValid && isMinValid && isMaxValid;
153-
}
154-
15589
@Override
15690
public boolean equals(Object o) {
15791
if (this == o) return true;

src/main/java/edu/ie3/simona/api/data/model/em/FlexOptions.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,19 @@
66

77
package edu.ie3.simona.api.data.model.em;
88

9+
import java.util.UUID;
10+
911
/** Interface that defines flex options. */
10-
public interface FlexOptions extends EmData {}
12+
public interface FlexOptions extends EmData {
13+
14+
/** Returns the receiver of this flex options. */
15+
UUID receiver();
16+
17+
/**
18+
* Enriches the flex option with disaggregated flex options.
19+
*
20+
* @param model of the flex options
21+
* @param flexOptions to include
22+
*/
23+
void addDisaggregated(UUID model, FlexOptions flexOptions);
24+
}

src/main/java/edu/ie3/simona/api/data/model/em/GeneralFlexOptions.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package edu.ie3.simona.api.data.model.em;
88

99
import edu.ie3.util.interval.ClosedInterval;
10-
import java.util.Collections;
10+
import java.util.HashMap;
1111
import java.util.Map;
1212
import java.util.UUID;
1313
import javax.measure.quantity.Dimensionless;
@@ -25,20 +25,22 @@
2525
* @param etaCharge The charging losses in percent.
2626
* @param etaDischarge The discharging losses in percent.
2727
* @param tickToEnergyLimits A map: tick to energy limits.
28-
* @param disaggregatedFlexOptions A map: uuid to disaggregated flex options.
28+
* @param disaggregated A map: uuid to disaggregated flex options.
2929
*/
3030
public record GeneralFlexOptions(
31+
UUID receiver,
3132
UUID model,
3233
String flexType,
3334
ComparableQuantity<Power> pMin,
3435
ComparableQuantity<Power> pMax,
3536
ComparableQuantity<Dimensionless> etaCharge,
3637
ComparableQuantity<Dimensionless> etaDischarge,
3738
Map<Long, ClosedInterval<ComparableQuantity<Energy>>> tickToEnergyLimits,
38-
Map<UUID, FlexOptions> disaggregatedFlexOptions)
39+
Map<UUID, FlexOptions> disaggregated)
3940
implements FlexOptions {
4041

4142
public GeneralFlexOptions(
43+
UUID receiver,
4244
UUID model,
4345
String flexType,
4446
ComparableQuantity<Power> pMin,
@@ -47,13 +49,19 @@ public GeneralFlexOptions(
4749
ComparableQuantity<Dimensionless> etaDischarge,
4850
Map<Long, ClosedInterval<ComparableQuantity<Energy>>> tickToEnergyLimits) {
4951
this(
52+
receiver,
5053
model,
5154
flexType,
5255
pMin,
5356
pMax,
5457
etaCharge,
5558
etaDischarge,
5659
tickToEnergyLimits,
57-
Collections.emptyMap());
60+
new HashMap<>());
61+
}
62+
63+
@Override
64+
public void addDisaggregated(UUID model, FlexOptions flexOptions) {
65+
disaggregated.put(model, flexOptions);
5866
}
5967
}

src/main/java/edu/ie3/simona/api/data/model/em/PowerLimitFlexOptions.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
package edu.ie3.simona.api.data.model.em;
88

9-
import java.util.Collections;
9+
import java.util.HashMap;
1010
import java.util.Map;
1111
import java.util.UUID;
1212
import javax.measure.quantity.Power;
@@ -15,6 +15,7 @@
1515
/**
1616
* Power limit flex option that will be sent to SIMONA.
1717
*
18+
* @param receiver The uuid of the receiver. It can be the same as the model.
1819
* @param model That is providing this flex options.
1920
* @param pRef Active power (might be negative, thus feed-in) that was suggested for regular usage.
2021
* @param pMin Minimal active power to which the sender can be reduced (might be negative, thus
@@ -23,8 +24,10 @@
2324
* @param pMax Maximum active power to which the sender can be increased (might be negative, thus
2425
* feed-in), that was determined by the system. Therefore, equates to upper bound of possible
2526
* flexibility provision.
27+
* @param disaggregated A map: uuid to disaggregated flex options.
2628
*/
2729
public record PowerLimitFlexOptions(
30+
UUID receiver,
2831
UUID model,
2932
ComparableQuantity<Power> pRef,
3033
ComparableQuantity<Power> pMin,
@@ -33,10 +36,16 @@ public record PowerLimitFlexOptions(
3336
implements FlexOptions {
3437

3538
public PowerLimitFlexOptions(
39+
UUID receiver,
3640
UUID model,
3741
ComparableQuantity<Power> pRef,
3842
ComparableQuantity<Power> pMin,
3943
ComparableQuantity<Power> pMax) {
40-
this(model, pRef, pMin, pMax, Collections.emptyMap());
44+
this(receiver, model, pRef, pMin, pMax, new HashMap<>());
45+
}
46+
47+
@Override
48+
public void addDisaggregated(UUID model, FlexOptions flexOptions) {
49+
disaggregated.put(model, flexOptions);
4150
}
4251
}

0 commit comments

Comments
 (0)