Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
a1875e1
Enhancing and refactoring `ExtCoSimulation`.
staudtMarius Jan 9, 2025
2b64fa5
Enhancing API.
staudtMarius Jan 21, 2025
44f52d9
fmt
staudtMarius Jan 21, 2025
e171bf5
Update `simosaik`.
staudtMarius Jan 24, 2025
821479f
Some enhancements.
staudtMarius Feb 24, 2025
dfd6900
Adapting some parts.
staudtMarius Feb 24, 2025
8323f56
Adding some classes.
staudtMarius Feb 24, 2025
6eb6b66
Fixing `sonarqube` issues.
staudtMarius Feb 24, 2025
b5b7826
Merge branch 'dev' into ms/#237-enhancing-and-refactoring-ExtCoSimula…
staudtMarius Feb 24, 2025
a3d0db7
Merge remote-tracking branch 'refs/remotes/origin/ms/#237-enhancing-a…
staudtMarius Feb 25, 2025
ca89b0b
Fixing bugs.
staudtMarius Feb 25, 2025
601e553
Some Enhancements.
staudtMarius Feb 27, 2025
65d10b8
Some refactoring.
staudtMarius Feb 27, 2025
1bb0ad8
Updating to PSDM version `6.0.0`.
staudtMarius Mar 4, 2025
850564e
Refactoring external data connections.
staudtMarius Mar 6, 2025
b88d128
Adding `EmDataService` to `EmAgent`.
staudtMarius Mar 7, 2025
e7cc903
Adding test for `ExtEmDataService`. Fixing some issues.
staudtMarius Mar 10, 2025
0d76d41
Merge branch 'dev' into ms/ReCoDe
staudtMarius Mar 12, 2025
e6c6de3
Saving changes.
staudtMarius Mar 18, 2025
d20c1d1
Saving changes.
staudtMarius Mar 19, 2025
1fe90ec
Saving changes.
staudtMarius Mar 20, 2025
f16a6d9
Saving changes.
staudtMarius Mar 21, 2025
96c2144
Saving changes.
staudtMarius Mar 21, 2025
2600b84
Saving changes.
staudtMarius Mar 25, 2025
b61f4c4
Saving changes.
staudtMarius Mar 27, 2025
c9506a4
Saving changes.
staudtMarius Mar 28, 2025
4444f9a
Saving changes.
staudtMarius Mar 31, 2025
6fcd05a
Saving changes.
staudtMarius Mar 31, 2025
0b8a7f1
Merge branch 'dev' into ms/ReCoDe
staudtMarius Apr 1, 2025
5b07f84
Saving changes.
staudtMarius Apr 1, 2025
0fb5452
Saving changes.
staudtMarius Apr 2, 2025
89d9d29
Saving changes.
staudtMarius Apr 3, 2025
4477ff9
Saving changes.
staudtMarius Apr 10, 2025
495e97b
Saving changes.
staudtMarius Apr 10, 2025
d827707
Refactoring em messages.
staudtMarius Apr 11, 2025
046bd79
Saving changes.
staudtMarius Apr 15, 2025
0c05345
Saving changes.
staudtMarius Apr 16, 2025
6630daa
Merge branch 'dev' into ms/ReCoDe
staudtMarius Apr 17, 2025
78049cb
Refactoring handling of input and result data.
staudtMarius Apr 24, 2025
6336ee2
Some refactoring.
staudtMarius Apr 25, 2025
fec7556
Improving `EmServiceBaseCore`.
staudtMarius Apr 28, 2025
0200ebc
Refactoring flexibility optimizer.
staudtMarius Apr 28, 2025
f5b9351
Saving changes.
staudtMarius Apr 28, 2025
3d72b1d
Saving changes.
staudtMarius May 6, 2025
cc08a67
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 7, 2025
b77e3c4
Saving changes.
staudtMarius May 7, 2025
0f2eaa2
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 12, 2025
6770dc6
Added parsing of flex message delay.
staudtMarius May 12, 2025
e575804
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 20, 2025
33a6a10
Saving changes.
staudtMarius May 21, 2025
98fa444
Clean up.
staudtMarius May 22, 2025
67f894e
Merge branch 'dev' into ms/ReCoDe
staudtMarius May 26, 2025
9efe3b5
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 2, 2025
22121ea
Saving changes.
staudtMarius Jun 12, 2025
b74be20
Saving changes.
staudtMarius Jun 17, 2025
9d6daf5
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 17, 2025
9765162
Saving changes.
staudtMarius Jun 24, 2025
b647481
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 24, 2025
36153c0
Saving changes.
staudtMarius Jun 24, 2025
e1b2f71
Saving changes.
staudtMarius Jun 24, 2025
5ca185c
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jun 25, 2025
8ab0f8d
Adapting to changes in `dev`.
staudtMarius Jun 25, 2025
9650917
Saving changes.
staudtMarius Jun 25, 2025
c8fce5e
Merge branch 'ms/#304-enhance-api-to-support-external-em-communicatio…
staudtMarius Jun 26, 2025
0470eb9
Fixing some merging issues.
staudtMarius Jun 26, 2025
1421754
Adapting to changes in `simonaAPI`.
staudtMarius Jun 26, 2025
9ea82de
Merge remote-tracking branch 'origin/ms/#304-enhance-api-to-support-e…
staudtMarius Jun 26, 2025
05c80d3
Adding max delay parameter.
staudtMarius Jun 30, 2025
94f3735
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 7, 2025
2264f19
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 8, 2025
e755148
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 16, 2025
8c47493
Refactoring em communication delay.
staudtMarius Jul 21, 2025
385cef1
Saving changes.
staudtMarius Jul 22, 2025
e27cd1c
Updating to PSDM version 8.0
staudtMarius Jul 22, 2025
7c8583f
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 22, 2025
d5460fb
Saving changes.
staudtMarius Jul 22, 2025
54dae7b
Merge branch 'dev' into ms/ReCoDe
staudtMarius Jul 29, 2025
cea773c
Saving changes.
staudtMarius Aug 8, 2025
f738db7
Update to java21.
staudtMarius Aug 13, 2025
766e027
Saving changes.
staudtMarius Aug 20, 2025
abddecf
Saving changes.
staudtMarius Aug 25, 2025
7e3c93a
Saving changes.
staudtMarius Aug 26, 2025
013ba32
Saving changes.
staudtMarius Sep 1, 2025
17534c1
Saving changes.
staudtMarius Sep 1, 2025
8dc61aa
Saving changes.
staudtMarius Sep 1, 2025
62d5835
Merge remote-tracking branch 'origin/ms/#323-refactor-and-simpliyf-ex…
staudtMarius Sep 2, 2025
22df428
Merge remote-tracking branch 'origin/ms/#314-refactoring-external-ent…
staudtMarius Sep 2, 2025
f4029a3
Merge remote-tracking branch 'origin/ms/#325-refactor-result-handling…
staudtMarius Sep 2, 2025
b57f1f2
Saving changes.
staudtMarius Sep 2, 2025
e38bd47
Saving changes.
staudtMarius Sep 3, 2025
a69b1c5
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 4, 2025
62220c1
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 9, 2025
9a487e1
Saving changes.
staudtMarius Sep 10, 2025
c719777
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 11, 2025
20cb5f6
Saving changes.
staudtMarius Sep 11, 2025
909fa7a
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 15, 2025
b90e404
fmt
staudtMarius Sep 15, 2025
2a989cb
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 22, 2025
5bce927
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 24, 2025
912ce98
Merge branch 'dev' into ms/ReCoDe
staudtMarius Sep 30, 2025
f8c9552
Saving changes.
staudtMarius Oct 14, 2025
fb1b8b0
Saving changes.
staudtMarius Oct 15, 2025
6ddc50b
Saving changes.
staudtMarius Oct 15, 2025
2140e9c
Refactoring em communication.
staudtMarius Oct 17, 2025
25c43cb
Saving changes.
staudtMarius Oct 20, 2025
aef3075
Merge branch 'dev' into ms/ReCoDe
staudtMarius Oct 21, 2025
20f420a
Merge branch 'dev' into ms/ReCoDe
staudtMarius Oct 24, 2025
a804633
Saving changes.
staudtMarius Oct 24, 2025
1e9f889
Saving changes.
staudtMarius Oct 24, 2025
728d3ae
Saving changes.
staudtMarius Oct 27, 2025
9c2df60
Fixed issues related to em data
staudtMarius Oct 28, 2025
c2af515
Merge remote-tracking branch 'origin/ms/#366-fix-issues-related-to-em…
staudtMarius Oct 28, 2025
f7e0013
Saving changes.
staudtMarius Oct 28, 2025
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased/Snapshot]

### Changed
- Changes to sent and received em data [#2366](https://github.com/ie3-institute/simonaAPI/issues/366)

### Fixed
- Issues related to em data [#2366](https://github.com/ie3-institute/simonaAPI/issues/366)

## [0.11.0] - 2025-10-23

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ public int size() {
return receiverTriggerDeque.size();
}

/**
* Method for clearing this queue.
*/
public void clear() {
receiverTriggerDeque.clear();
}

/**
* Method for adding an {@link ExtDataContainer} to the queue.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import edu.ie3.simona.api.exceptions.UnexpectedResponseMessageException;
import edu.ie3.simona.api.ontology.DataMessageFromExt;
import edu.ie3.simona.api.ontology.DataResponseMessageToExt;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;

/**
Expand Down Expand Up @@ -38,6 +41,12 @@ public final R receiveAny() throws InterruptedException {
return receiveTriggerQueue.take();
}

public final List<R> receiveAll() {
List<R> result = new ArrayList<>();
receiveTriggerQueue.drainTo(result);
return result;
}

@Override
@SuppressWarnings("unchecked")
public final <T extends R> T receiveWithType(Class<T> expectedMessageClass)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import edu.ie3.simona.api.data.model.em.*;
import edu.ie3.simona.api.ontology.em.*;
import java.util.*;
import org.slf4j.Logger;

/** Enables data connection of em data between SIMONA and SimonaAPI */
public final class ExtEmDataConnection
Expand All @@ -32,80 +33,80 @@ public List<UUID> getControlledEms() {
}

/**
* Tries to send em data to SIMONA. A message is sent, if at least one map is not empty.
* Tries to send flex option requests to SIMONA. A message is sent, if at least one entity is
* given.
*
* @param tick current tick
* @param flexRequests receiver to flex option request
* @param flexOptions receiver to flex options
* @param setPoints receiver to set point
* @param maybeNextTick option for the next tick in the simulation
* @param entities for which flex options should be requested
* @param disaggregated if disaggregated flex option should be returned
* @return true, if data was sent
*/
public boolean sendEmData(
long tick,
Map<UUID, FlexOptionRequest> flexRequests,
Map<UUID, List<FlexOptions>> flexOptions,
Map<UUID, EmSetPoint> setPoints,
Optional<Long> maybeNextTick) {
public boolean sendFlexRequest(long tick, Collection<UUID> entities, boolean disaggregated) {
// create requests
Map<UUID, FlexOptionRequest> requests = new HashMap<>();
entities.forEach(
emEntity -> requests.put(emEntity, new FlexOptionRequest(emEntity, disaggregated)));

// send message only if at least one value is present
if (!flexRequests.isEmpty() || !flexOptions.isEmpty() || !setPoints.isEmpty()) {
sendExtMsg(new ProvideEmData(tick, flexRequests, flexOptions, setPoints, maybeNextTick));
if (!entities.isEmpty()) {
sendExtMsg(new ProvideEmData(tick, requests, Collections.emptyMap(), Collections.emptyMap()));
return true;
}
return false;
}

/**
* Tries to send flex option requests to SIMONA. A message is sent, if at least one entity is
* given.
* Tries to send em data to SIMONA. A message is sent, if the map is not empty.
*
* @param tick current tick
* @param entities for which flex options should be requested
* @param disaggregated if disaggregated flex option should be returned
* @param emData a map: receiver to em data
* @param log logger for logging warnings
* @return true, if data was sent
*/
public boolean sendFlexRequest(long tick, Collection<UUID> entities, boolean disaggregated) {
public boolean sendEmData(long tick, Map<UUID, ? extends EmData> emData, Logger log) {
// send message only if at least one value is present
if (!entities.isEmpty()) {
sendExtMsg(new RequestEmFlexResults(tick, new ArrayList<>(entities), disaggregated));
if (!emData.isEmpty()) {
sendExtMsg(ProvideEmData.create(tick, emData, log));
return true;
}
return false;
}

/**
* Tries to send communication messages to SIMONA. A message is sent, if at least one message is
* given.
* Tries to send em data to SIMONA. A message is sent, if at least one map is not empty.
*
* @param tick current tick
* @param emCommunicationMessages that should be sent
* @param maybeNextTick an option for the next tick
* @param flexRequests receiver to flex option request
* @param flexOptions receiver to flex options
* @param setPoints receiver to set point that should be sent to SIMONA
* @return true, if data was sent
*/
public boolean sendCommunicationMessage(
public boolean sendEmData(
long tick,
List<EmCommunicationMessage<?>> emCommunicationMessages,
Optional<Long> maybeNextTick) {
Map<UUID, FlexOptionRequest> flexRequests,
Map<UUID, List<FlexOptions>> flexOptions,
Map<UUID, EmSetPoint> setPoints) {
// send message only if at least one value is present
if (!emCommunicationMessages.isEmpty()) {
sendExtMsg(new EmCommunicationMessages(tick, emCommunicationMessages, maybeNextTick));
if (!flexRequests.isEmpty() || !flexOptions.isEmpty() || !setPoints.isEmpty()) {
sendExtMsg(new ProvideEmData(tick, flexRequests, flexOptions, setPoints));
return true;
}
return false;
}

/**
* Tries to send the em set points to SIMONA.
* Tries to send communication messages to SIMONA. A message is sent, if at least one message is
* given.
*
* @param tick current tick
* @param setPoints receiver to set point, that should be sent to SIMONA
* @param maybeNextTick option for the next tick in the simulation
* @param emCommunicationMessages that should be sent
* @return true, if data was sent
*/
public boolean sendSetPoints(
long tick, Map<UUID, EmSetPoint> setPoints, Optional<Long> maybeNextTick) {
if (!setPoints.isEmpty()) {
sendExtMsg(new ProvideEmSetPointData(tick, setPoints, maybeNextTick));
public boolean sendCommunicationMessage(
long tick, List<EmCommunicationMessage<?>> emCommunicationMessages) {
// send message only if at least one value is present
if (!emCommunicationMessages.isEmpty()) {
sendExtMsg(new EmCommunicationMessages(tick, emCommunicationMessages));
return true;
}
return false;
Expand All @@ -116,12 +117,12 @@ public boolean sendSetPoints(
*
* @param tick for which set points are requested
* @param emEntities for which set points are requested
* @return an {@link FlexOptionsResponse} message
* @return a map: uuid to list of flex options
* @throws InterruptedException - on interruptions
*/
public Map<UUID, ExtendedFlexOptionsResult> requestEmFlexResults(
public Map<UUID, List<FlexOptions>> requestEmFlexResults(
long tick, List<UUID> emEntities, boolean disaggregated) throws InterruptedException {
sendExtMsg(new RequestEmFlexResults(tick, emEntities, disaggregated));
sendFlexRequest(tick, emEntities, disaggregated);
return receiveWithType(FlexOptionsResponse.class).receiverToFlexOptions();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @param <T> type of response messages to ext
*/
public sealed interface ExtOutputDataConnection<T extends DataResponseMessageToExt>
permits BiDirectional, ExtResultListener {
extends ExtDataConnection permits BiDirectional, ExtResultListener {

/** Queues message from SIMONA that should be handled by the external simulation. */
void queueExtResponseMsg(T msg) throws InterruptedException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,17 @@ public String flexOptionsString() {
public String setPointsString() {
return setPoints.toString();
}

@Override
public String toString() {
return "ExtInputContainer{" +
"tick=" + tick +
", maybeNextTick=" + maybeNextTick +
", primaryData=" + primaryData +
", flexRequests=" + flexRequests +
", flexOptions=" + flexOptions +
", setPoints=" + setPoints +
", emMessages=" + emMessages +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,14 @@ public List<ResultEntity> getResult(UUID assetId) {
public List<EmData> getEmData(UUID assetId) {
return emDataMap.getOrDefault(assetId, Collections.emptyList());
}

@Override
public String toString() {
return "ExtOutputContainer{" +
"tick=" + tick +
", maybeNextTick=" + maybeNextTick +
", resultMap=" + resultMap +
", emDataMap=" + emDataMap +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import java.time.ZonedDateTime;
import java.util.*;
import javax.measure.quantity.Power;
import org.slf4j.Logger;
import tech.units.indriya.ComparableQuantity;

/**
* Extended {@link FlexOptionsResult}, that contains the receiver of the flex options. This models
* may also contain a disaggregation of the total flex options.
*/
public final class ExtendedFlexOptionsResult extends FlexOptionsResult implements EmData {
public final class ExtendedFlexOptionsResult extends FlexOptionsResult {

/** The disaggregated flex option results. */
private final Map<UUID, FlexOptionsResult> disaggregated;
Expand Down Expand Up @@ -49,6 +48,7 @@ public ExtendedFlexOptionsResult(
* @param pRef active power that was suggested for regular usage by the system participant
* @param pMin active minimal power that was determined by the system participant
* @param pMax active maximum power that was determined by the system participant
* @param disaggregated a map: uuid to disaggregated flex options
*/
public ExtendedFlexOptionsResult(
ZonedDateTime time,
Expand All @@ -64,9 +64,6 @@ public ExtendedFlexOptionsResult(
/**
* Method for adding disaggregated flex option results to this object.
*
* <p>Note: This method does not check, if the disaggregated flex options match the total flex
* options. To do this, please use the method {@link #checkFlexOptions(Logger)}.
*
* @param uuid of the inferior model
* @param flexOptionsResult the flex options of the inferior model
*/
Expand All @@ -89,69 +86,6 @@ public Map<UUID, FlexOptionsResult> getDisaggregated() {
return Collections.unmodifiableMap(disaggregated);
}

/**
* Method for checking if the disaggregated flex options match the total flex options.
*
* @param log used for logging
* @return {@code true} if the flex options match, else {@code false}
*/
public boolean checkFlexOptions(Logger log) {
List<ComparableQuantity<Power>> refs = new ArrayList<>();
List<ComparableQuantity<Power>> mins = new ArrayList<>();
List<ComparableQuantity<Power>> maxs = new ArrayList<>();

disaggregated.forEach(
(uuid, flexOptionsResult) -> {
refs.add(flexOptionsResult.getpRef());
mins.add(flexOptionsResult.getpMin());
maxs.add(flexOptionsResult.getpMax());
});

ComparableQuantity<Power> ref = getpRef();
ComparableQuantity<Power> min = getpMin();
ComparableQuantity<Power> max = getpMax();

Optional<ComparableQuantity<Power>> refSum = refs.stream().reduce(ComparableQuantity::add);
Optional<ComparableQuantity<Power>> minSum = mins.stream().reduce(ComparableQuantity::add);
Optional<ComparableQuantity<Power>> maxSum = maxs.stream().reduce(ComparableQuantity::add);

boolean isRefValid = false;
boolean isMinValid = false;
boolean isMaxValid = false;

if (refSum.isPresent()) {
isRefValid = refSum.get().isEquivalentTo(ref);

if (!isRefValid) {
log.warn("Disaggregated reference power does not match total reference power.");
}
} else {
log.warn("Cannot check disaggregated reference power.");
}

if (minSum.isPresent()) {
isMinValid = minSum.get().isEquivalentTo(min);

if (!isMinValid) {
log.warn("Disaggregated minimum power does not match total minimum power.");
}
} else {
log.warn("Cannot check disaggregated minimum power.");
}

if (maxSum.isPresent()) {
isMaxValid = maxSum.get().isEquivalentTo(max);

if (!isMaxValid) {
log.warn("Disaggregated maximum power does not match total maximum power.");
}
} else {
log.warn("Cannot check disaggregated maximum power.");
}

return isRefValid && isMinValid && isMaxValid;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/edu/ie3/simona/api/data/model/em/FlexOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,19 @@

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

import java.util.UUID;

/** Interface that defines flex options. */
public interface FlexOptions extends EmData {}
public interface FlexOptions extends EmData {

/** Returns the receiver of this flex options. */
UUID receiver();

/**
* Enriches the flex option with disaggregated flex options.
*
* @param model of the flex options
* @param flexOptions to include
*/
void addDisaggregated(UUID model, FlexOptions flexOptions);
}
Loading
Loading