Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Implemented `ExtPrimaryData` and `ExtResultsData` [#145](https://github.com/ie3-institute/simonaAPI/issues/145)
- Have EV simulation communicate the next tick [#170](https://github.com/ie3-institute/simonaAPI/issues/170)

## [0.4.0] - 2023-11-22

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/edu/ie3/simona/api/data/ev/ExtEvData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package edu.ie3.simona.api.data.ev;

import edu.ie3.simona.api.data.ExtData;
import edu.ie3.simona.api.data.ev.model.ArrivingEvsData;
import edu.ie3.simona.api.data.ev.model.EvModel;
import edu.ie3.simona.api.data.ev.ontology.*;
import edu.ie3.simona.api.data.ontology.ScheduleDataServiceMessage;
Expand Down Expand Up @@ -81,9 +82,9 @@ public List<EvModel> requestDepartingEvs(Map<UUID, List<UUID>> departures)
* Provide all EVs that are arriving at some charging station to SIMONA. Method returns right away
* without expecting an answer from SIMONA.
*
* @param arrivals the arriving EV models per charging station UUID
* @param arrivals the arriving EVs data per charging station UUID
*/
public void provideArrivingEvs(Map<UUID, List<EvModel>> arrivals) {
public void provideArrivingEvs(Map<UUID, ArrivingEvsData> arrivals) {
sendExtMsg(new ProvideArrivingEvs(arrivals));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* © 2024. TU Dortmund University,
* Institute of Energy Systems, Energy Efficiency and Energy Economics,
* Research group Distribution grid planning and operation
*/

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

import java.util.List;
import java.util.Optional;

/**
* Data including arriving EVs and next arrival tick for a single charging station. Arriving EVs
* cannot be provided without being scheduled first.
*
* @param arrivals The arriving EVs for the current station. Can be empty if only the next tick
* needs to be communicated.
* @param maybeNextTick The optional next tick at which the next arrivals are expected. Empty if no
* next arrivals for the EVCS are known at this moment.
*/
public record ArrivingEvsData(List<EvModel> arrivals, Optional<Long> maybeNextTick) {}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

package edu.ie3.simona.api.data.ev.ontology;

import edu.ie3.simona.api.data.ev.model.EvModel;
import java.util.List;
import edu.ie3.simona.api.data.ev.model.ArrivingEvsData;
import java.util.Map;
import java.util.UUID;

/**
* Provide arriving EVs to SIMONA and its charging stations
* Provide arriving EVs data to SIMONA and its charging stations
*
* @param arrivals the arriving EVs per charging station UUID
* @param arrivingEvsData the arriving EVs data per charging station UUID
*/
public record ProvideArrivingEvs(Map<UUID, List<EvModel>> arrivals)
public record ProvideArrivingEvs(Map<UUID, ArrivingEvsData> arrivingEvsData)
implements EvDataMessageFromExt {}
11 changes: 5 additions & 6 deletions src/main/java/edu/ie3/simona/api/simulation/ExtSimulation.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ private boolean takeAndHandleMessage() throws InterruptedException {
Optional<Long> newTrigger;

if (activationMessage.tick() == -1L) {
newTrigger = initialize(); // this is blocking until initialization has finished
// this is blocking until initialization has finished
newTrigger = Optional.of(initialize());
} else {
newTrigger =
doActivity(
activationMessage
.tick()); // this is blocking until processing of this tick has finished
// this is blocking until processing of this tick has finished
newTrigger = doActivity(activationMessage.tick());
}
data.send(new CompletionMessage(newTrigger));

Expand All @@ -81,7 +80,7 @@ private boolean takeAndHandleMessage() throws InterruptedException {
* @return The first regular tick at which this external simulation wants to be triggered, if
* applicable.
*/
protected abstract Optional<Long> initialize();
protected abstract Long initialize();

/**
* This method is called for every tick of the external simulation that is triggered.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.ie3.simona.api.data.ev

import edu.ie3.simona.api.data.ev.model.ArrivingEvsData
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.testkit.TestProbe
import org.apache.pekko.testkit.javadsl.TestKit
Expand Down Expand Up @@ -94,14 +95,14 @@ class ExtEvDataTest extends Specification {
def extSimAdapter = new TestProbe(actorSystem)
def extEvData = new ExtEvData(dataService.ref(), extSimAdapter.ref())

def arrivingEvs = new HashMap<UUID, List<EvModel>>()
arrivingEvs.put(UUID.randomUUID(), new ArrayList<EvModel>())
def arrivingEvsData = new HashMap<UUID, ArrivingEvsData>()
arrivingEvsData.put(UUID.randomUUID(), new ArrivingEvsData(new ArrayList<EvModel>(), Optional.of(60L)))

when:
extEvData.provideArrivingEvs(arrivingEvs)
extEvData.provideArrivingEvs(arrivingEvsData)

then:
dataService.expectMsg(new ProvideArrivingEvs(arrivingEvs))
dataService.expectMsg(new ProvideArrivingEvs(arrivingEvsData))
extSimAdapter.expectMsg(new ScheduleDataServiceMessage(dataService.ref()))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ class ExtSimulationSpec extends Specification {
*/
private class TestSimulation extends ExtSimulation {

private Optional<Long> initReturnTicks
private Long initReturnTick
private Optional<Long> activationReturnTick

TestSimulation(Optional<Long> initReturnTick, Optional<Long> activationReturnTick) {
this.initReturnTicks = initReturnTick
TestSimulation(Long initReturnTick, Optional<Long> activationReturnTick) {
this.initReturnTick = initReturnTick
this.activationReturnTick = activationReturnTick
}

@Override
protected Optional<Long> initialize() {
return this.initReturnTicks
protected Long initialize() {
return this.initReturnTick
}

@Override
Expand All @@ -63,7 +63,7 @@ class ExtSimulationSpec extends Specification {
def "An ExtSimulation should handle initialization"() {
given:
def tick = -1L
def newTick = Optional.of(0L)
def newTick = 0L
def testProbe = new TestProbe(actorSystem)
def extSimData = new ExtSimAdapterData(testProbe.ref(), new String[0])
def extSim = new TestSimulation(newTick, Optional.of(-2L))
Expand All @@ -75,7 +75,7 @@ class ExtSimulationSpec extends Specification {

then:
finishedActual == false
testProbe.expectMsg(new CompletionMessage(newTick))
testProbe.expectMsg(new CompletionMessage(Optional.of(newTick)))
}

def "An ExtSimulation should handle activation and return given new triggers"() {
Expand All @@ -84,7 +84,7 @@ class ExtSimulationSpec extends Specification {
def extSimData = new ExtSimAdapterData(testProbe.ref(), new String[0])
def newTickOpt = newTick.isEmpty() ?
Optional.<Long>empty() : Optional.of(newTick.first())
def extSim = new TestSimulation(Optional.of(-2L), newTickOpt)
def extSim = new TestSimulation(-2L, newTickOpt)
extSim.setup(extSimData, new ArrayList<ExtData>())

when:
Expand All @@ -107,7 +107,7 @@ class ExtSimulationSpec extends Specification {
given:
def testProbe = new TestProbe(actorSystem)
def extSimData = new ExtSimAdapterData(testProbe.ref(), new String[0])
def extSim = new TestSimulation(Optional.empty(), Optional.empty())
def extSim = new TestSimulation(-1L, Optional.empty())
extSim.setup(extSimData, new ArrayList<ExtData>())

when:
Expand All @@ -130,7 +130,7 @@ class ExtSimulationSpec extends Specification {
given:
def testProbe = new TestProbe(actorSystem)
def extSimData = new ExtSimAdapterData(testProbe.ref(), new String[0])
def extSim = new TestSimulation(Optional.empty(), Optional.empty())
def extSim = new TestSimulation(-1L, Optional.empty())
extSim.setup(extSimData, new ArrayList<ExtData>())

when:
Expand Down