Skip to content

Commit 7565615

Browse files
Merge pull request #356 from ie3-institute/ms/#348-abstract-flex-options
Refactoring flex options and em set points.
2 parents d3b9659 + 66d3beb commit 7565615

22 files changed

+433
-218
lines changed

CHANGELOG.md

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

77
## [Unreleased/Snapshot]
88

9+
### Added
10+
- General flex options [#348](https://github.com/ie3-institute/simonaAPI/issues/348)
11+
- Enhanced em set points [#357](https://github.com/ie3-institute/simonaAPI/issues/348)
12+
- Added dedicated flex communication classes [#358](https://github.com/ie3-institute/simonaAPI/issues/348)
13+
914
### Changed
1015
- Updated the maven central publishing scripts [#339](https://github.com/ie3-institute/simonaAPI/issues/339)
1116
- Refactoring `ExtSimAdapterData` [#347](https://github.com/ie3-institute/simonaAPI/issues/347)

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

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66

77
package edu.ie3.simona.api.data.connection;
88

9-
import edu.ie3.simona.api.data.model.em.EmSetPoint;
10-
import edu.ie3.simona.api.data.model.em.ExtendedFlexOptionsResult;
11-
import edu.ie3.simona.api.data.model.em.FlexOptionRequest;
12-
import edu.ie3.simona.api.data.model.em.FlexOptions;
9+
import edu.ie3.simona.api.data.model.em.*;
1310
import edu.ie3.simona.api.ontology.em.*;
1411
import java.util.*;
1512

@@ -58,6 +55,45 @@ public boolean sendEmData(
5855
return false;
5956
}
6057

58+
/**
59+
* Tries to send flex option requests to SIMONA. A message is sent, if at least one entity is
60+
* given.
61+
*
62+
* @param tick current tick
63+
* @param entities for which flex options should be requested
64+
* @param disaggregated if disaggregated flex option should be returned
65+
* @return true, if data was sent
66+
*/
67+
public boolean sendFlexRequest(long tick, Collection<UUID> entities, boolean disaggregated) {
68+
// send message only if at least one value is present
69+
if (!entities.isEmpty()) {
70+
sendExtMsg(new RequestEmFlexResults(tick, new ArrayList<>(entities), disaggregated));
71+
return true;
72+
}
73+
return false;
74+
}
75+
76+
/**
77+
* Tries to send communication messages to SIMONA. A message is sent, if at least one message is
78+
* given.
79+
*
80+
* @param tick current tick
81+
* @param emCommunicationMessages that should be sent
82+
* @param maybeNextTick an option for the next tick
83+
* @return true, if data was sent
84+
*/
85+
public boolean sendCommunicationMessage(
86+
long tick,
87+
List<EmCommunicationMessage<?>> emCommunicationMessages,
88+
Optional<Long> maybeNextTick) {
89+
// send message only if at least one value is present
90+
if (!emCommunicationMessages.isEmpty()) {
91+
sendExtMsg(new EmCommunicationMessages(tick, emCommunicationMessages, maybeNextTick));
92+
return true;
93+
}
94+
return false;
95+
}
96+
6197
/**
6298
* Tries to send the em set points to SIMONA.
6399
*

src/main/java/edu/ie3/simona/api/data/container/ExtDataContainer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
package edu.ie3.simona.api.data.container;
88

9+
import java.util.ArrayList;
910
import java.util.HashMap;
11+
import java.util.List;
1012
import java.util.Map;
1113

1214
/** Interface for data that are exchanged between an external simulation and SimonaAPI */
@@ -28,4 +30,17 @@ default <K, V> Map<K, V> copyAndClear(Map<K, V> map) {
2830
map.clear();
2931
return result;
3032
}
33+
34+
/**
35+
* Method to copy a given list and clear the original.
36+
*
37+
* @param list to be copied and cleared
38+
* @return the copy
39+
* @param <V> type of value
40+
*/
41+
default <V> List<V> copyAndClear(List<V> list) {
42+
List<V> result = new ArrayList<>(list);
43+
list.clear();
44+
return result;
45+
}
3146
}

src/main/java/edu/ie3/simona/api/data/container/ExtInputContainer.java

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import edu.ie3.datamodel.models.value.PValue;
1010
import edu.ie3.datamodel.models.value.Value;
11+
import edu.ie3.simona.api.data.model.em.EmCommunicationMessage;
1112
import edu.ie3.simona.api.data.model.em.EmSetPoint;
1213
import edu.ie3.simona.api.data.model.em.FlexOptionRequest;
1314
import edu.ie3.simona.api.data.model.em.FlexOptions;
@@ -36,6 +37,9 @@ public final class ExtInputContainer implements ExtDataContainer {
3637
/** Map uuid to em set points. */
3738
private final Map<UUID, EmSetPoint> setPoints = new HashMap<>();
3839

40+
/** List of em communication messages. */
41+
private final List<EmCommunicationMessage<?>> emMessages = new ArrayList<>();
42+
3943
/**
4044
* Container class for input data for SIMONA which can be read by SimonaAPI
4145
*
@@ -82,15 +86,18 @@ public void addPrimaryValue(UUID asset, Value value) {
8286
primaryData.put(asset, value);
8387
}
8488

89+
public void addFlexComMessage(EmCommunicationMessage<?> message) {
90+
emMessages.add(message);
91+
}
92+
8593
/**
8694
* Method for adding flex option requests. No disaggregated flex option will be requested using
8795
* this method.
8896
*
8997
* @param receiver the uuid of the agent, that will receive the request
90-
* @param sender option for the uuid of the sender
9198
*/
92-
public void addRequest(UUID receiver, UUID sender) {
93-
flexRequests.put(receiver, new FlexOptionRequest(receiver, sender, false));
99+
public void addRequest(UUID receiver) {
100+
flexRequests.put(receiver, new FlexOptionRequest(receiver, false));
94101
}
95102

96103
public void addRequest(UUID receiver, FlexOptionRequest request) {
@@ -104,12 +111,7 @@ public void addRequest(UUID receiver, FlexOptionRequest request) {
104111
* @param flexOption that will be added
105112
*/
106113
public void addFlexOptions(UUID receiver, List<FlexOptions> flexOption) {
107-
if (!flexOptions.containsKey(receiver)) {
108-
List<FlexOptions> flexOptionValues = new ArrayList<>(flexOption);
109-
flexOptions.put(receiver, flexOptionValues);
110-
} else {
111-
flexOptions.get(receiver).addAll(flexOption);
112-
}
114+
flexOptions.computeIfAbsent(receiver, k -> new ArrayList<>()).addAll(flexOption);
113115
}
114116

115117
/**
@@ -118,8 +120,8 @@ public void addFlexOptions(UUID receiver, List<FlexOptions> flexOption) {
118120
* @param asset that will receive the set point
119121
* @param power of the set point
120122
*/
121-
public void addSetPoint(UUID asset, UUID sender, PValue power) {
122-
setPoints.put(asset, new EmSetPoint(asset, sender, power));
123+
public void addSetPoint(UUID asset, PValue power) {
124+
setPoints.put(asset, new EmSetPoint(asset, power));
123125
}
124126

125127
/**
@@ -160,6 +162,13 @@ public Map<UUID, EmSetPoint> extractSetPoints() {
160162
return copyAndClear(setPoints);
161163
}
162164

165+
/**
166+
* Extracts the em message input data from this container. All other input data remains the same.
167+
*/
168+
public List<EmCommunicationMessage<?>> extractEmMessages() {
169+
return copyAndClear(emMessages);
170+
}
171+
163172
/**
164173
* Returns a string representation of the primary input data without changing the data. To extract
165174
* (remove) the primary input data, use {@link #extractPrimaryData()} instead.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* © 2025. TU Dortmund University,
3+
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
4+
* Research group Distribution grid planning and operation
5+
*/
6+
7+
package edu.ie3.simona.api.data.model.em;
8+
9+
import java.util.UUID;
10+
11+
/**
12+
* Model of communication messages that can be sent between em agents.
13+
*
14+
* @param receiver of the data
15+
* @param sender of the data
16+
* @param msgId the message id of this message
17+
* @param content the actual em data that is sent
18+
* @param <D> type of the em data
19+
*/
20+
public record EmCommunicationMessage<D extends EmData>(
21+
UUID receiver, UUID sender, UUID msgId, D content) implements EmData {
22+
23+
/**
24+
* Constructor for {@link EmCommunicationMessage} that will generate a random message id.
25+
*
26+
* @param receiver of the data
27+
* @param sender of the data
28+
* @param content the actual em data that is sent
29+
*/
30+
public EmCommunicationMessage(UUID receiver, UUID sender, D content) {
31+
this(receiver, sender, UUID.randomUUID(), content);
32+
}
33+
}

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,5 @@
66

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

9-
import java.util.UUID;
10-
119
/** Interface that is extended by all em data models. */
12-
public interface EmData {
13-
14-
/** Returns the uuid of the receiver. */
15-
UUID getReceiver();
16-
17-
/** Returns the uuid of the sender. */
18-
UUID getSender();
19-
}
10+
public interface EmData {}

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

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

99
import edu.ie3.datamodel.models.value.PValue;
10+
import java.util.Collections;
11+
import java.util.Map;
1012
import java.util.Optional;
1113
import java.util.UUID;
1214
import javax.measure.quantity.Power;
@@ -16,51 +18,49 @@
1618
* Energy management set point that will be sent to SIMONA.
1719
*
1820
* @param receiver The receiver of the set point.
19-
* @param sender The sender of the set point.
2021
* @param power An option for the em set point.
2122
*/
22-
public record EmSetPoint(UUID receiver, UUID sender, Optional<PValue> power) implements EmData {
23+
public record EmSetPoint(UUID receiver, Optional<PValue> power, Map<UUID, PValue> disaggregated)
24+
implements EmData {
2325
/**
2426
* Constructor for {@link EmSetPoint}.
2527
*
2628
* <p>Note: Using this constructor will signal SIMONA, that the current set point should be kept.
2729
*
2830
* @param receiver The receiver of the set point.
29-
* @param sender The sender of the set point.
3031
*/
31-
public EmSetPoint(UUID receiver, UUID sender) {
32-
this(receiver, sender, Optional.empty());
32+
public EmSetPoint(UUID receiver) {
33+
this(receiver, Optional.empty(), Collections.emptyMap());
3334
}
3435

3536
/**
3637
* Constructor for {@link EmSetPoint}.
3738
*
3839
* @param receiver The receiver of the set point.
39-
* @param sender The sender of the set point.
4040
* @param p Power value of the set point.
4141
*/
42-
public EmSetPoint(UUID receiver, UUID sender, ComparableQuantity<Power> p) {
43-
this(receiver, sender, Optional.of(new PValue(p)));
42+
public EmSetPoint(UUID receiver, ComparableQuantity<Power> p) {
43+
this(receiver, Optional.of(new PValue(p)), Collections.emptyMap());
4444
}
4545

4646
/**
4747
* Constructor for {@link EmSetPoint}.
4848
*
4949
* @param receiver The receiver of the set point.
50-
* @param sender The sender of the set point.
51-
* @param power value of the set point.
50+
* @param power Value of the set point.
5251
*/
53-
public EmSetPoint(UUID receiver, UUID sender, PValue power) {
54-
this(receiver, sender, Optional.ofNullable(power));
52+
public EmSetPoint(UUID receiver, PValue power) {
53+
this(receiver, Optional.ofNullable(power), Collections.emptyMap());
5554
}
5655

57-
@Override
58-
public UUID getReceiver() {
59-
return receiver;
60-
}
61-
62-
@Override
63-
public UUID getSender() {
64-
return sender;
56+
/**
57+
* Constructor for {@link EmSetPoint}.
58+
*
59+
* @param receiver The receiver of the set point.
60+
* @param power Value of the set point.
61+
* @param disaggregated Map: uuid to disaggregated set points.
62+
*/
63+
public EmSetPoint(UUID receiver, PValue power, Map<UUID, PValue> disaggregated) {
64+
this(receiver, Optional.of(power), disaggregated);
6565
}
6666
}

0 commit comments

Comments
 (0)