Skip to content

Commit

Permalink
Merge pull request #373 from ie3-institute/vb/#159_current_tick
Browse files Browse the repository at this point in the history
Replacement of end tick by current tick within the simulation scheduler
  • Loading branch information
sebastian-peter authored Jan 24, 2023
2 parents e550fc1 + a76b5a1 commit 0733082
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adaption of abbreviations in PVModel and adjacent classes to naming convention [#326](https://github.com/ie3-institute/simona/issues/326)
- Fixed Latex equations [#264](https://github.com/ie3-institute/simona/issues/264)
- Documentation of the simulation configuration [#334](https://github.com/ie3-institute/simona/issues/334)
- Adapted to changes of Quantity units in PSU and PSDM [#419](https://github.com/ie3-institute/simona/pull/419)
- Adapted entry in Done message and deleted parallel window [#159](https://github.com/ie3-institute/simona/issues/159)

### Fixed
- Location of `vn_simona` test grid (was partially in Berlin and Dortmund) [#72](https://github.com/ie3-institute/simona/issues/72)
Expand Down
35 changes: 14 additions & 21 deletions src/main/scala/edu/ie3/simona/scheduler/SchedulerHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ trait SchedulerHelper extends SimonaActorLogging {
TimeUtil.withDefaults.toZonedDateTime(simonaTimeConfig.endDateTime)
)

private val parallelWindow = SimonaConstants.PARALLELISM_WINDOW

// if currentTick % checkWindowTick == 0 and all completionMessages have been
// received for currentTick, a CheckWindowPassed RuntimeEvent is issued
private val schedulerReadyCheckWindow =
Expand Down Expand Up @@ -130,12 +128,11 @@ trait SchedulerHelper extends SimonaActorLogging {
/* we do not want to pause the schedule, go on with normal schedule handling */
if (notFinishedAndTriggerAvailable(nowInTicks, stateData)) {

/* if we do not exceed nowInSeconds + parallelWindow OR do not wait on any responses we can send out new triggers */
/* if we do not exceed nowInSeconds OR do not wait on any responses we can send out new triggers */
if (
canWeSendTrigger(
stateData.trigger.awaitingResponseMap,
nowInTicks,
parallelWindow
nowInTicks
)
) {

Expand All @@ -149,12 +146,11 @@ trait SchedulerHelper extends SimonaActorLogging {
eligibleTriggerSendStateData.time.nowInTicks
)

/* if we do not exceed (nowInTicks+1) + parallelWindow OR do not wait on any responses, we can move on in time by one tick */
/* if we do not exceed (nowInTicks+1) OR do not wait on any responses, we can move on in time by one tick */
if (
nowInTicks <= endTick && canWeSendTrigger(
updatedStateData.trigger.awaitingResponseMap,
nowInTicks + 1,
parallelWindow
nowInTicks + 1
)
) {
doSimStep(
Expand Down Expand Up @@ -182,7 +178,7 @@ trait SchedulerHelper extends SimonaActorLogging {
val stateDataAfterCheckWindow = maybeCheckWindowPassed(
stateData,
schedulerReadyCheckWindow,
nowInTicks - parallelWindow) */
nowInTicks) */

maybeFinishSimulation(stateData)
}
Expand Down Expand Up @@ -283,26 +279,23 @@ trait SchedulerHelper extends SimonaActorLogging {
stateData.trigger.triggerQueue.headKeyOption.exists(_ <= endTick)

/** Checks if we can move on in time in the schedule by comparing the awaiting
* response map data with the current tick and the parallelWindow data
* response map data with the current tick
*
* @param awaitingResponseMap
* the map containing all information about triggers we still wait for
* completion messages
* @param nowInTicks
* the current tick
* @param parallelWindow
* the parallel window tick information
* @return
* true if trigger can be send, false otherwise
*/
private def canWeSendTrigger(
awaitingResponseMap: CountingMap[Long],
nowInTicks: Long,
parallelWindow: Long
nowInTicks: Long
): Boolean =
awaitingResponseMap.minKeyOption match {
case Some(minKey) =>
nowInTicks - minKey <= parallelWindow
nowInTicks <= minKey
case None =>
true // map empty, no completions awaited
}
Expand Down Expand Up @@ -453,9 +446,10 @@ trait SchedulerHelper extends SimonaActorLogging {
)

/* notify listeners */
/*The usage of min is necessary because the scheduler overshoots the target tick by 1 at the end of the simulation*/
notifyListener(
Done(
endTick,
Math.min(stateData.time.nowInTicks, endTick),
totalSimDuration,
stateData.runtime.noOfFailedPF,
errorInSim
Expand Down Expand Up @@ -614,18 +608,17 @@ trait SchedulerHelper extends SimonaActorLogging {

/* if there are no triggers left to send and we are only receiving completion messages, we still might
* pass a ready check window, this call is to ensure that for the last tick of the simulation a CheckWindowPassed()
* is issued lastTick % schedulerReadyCheckWindow == 0, parallel window does not account for last tick */
* is issued lastTick % schedulerReadyCheckWindow == 0 */
maybeCheckWindowPassed(
updatedStateData,
schedulerReadyCheckWindow,
stateData.time.nowInTicks - 1
)
/* if resolution == schedulerCheckWindow we need to subtract the parallel window for the current tick as we might
* move on in time already will still receiving completion messages for nowInTicks - parallelWindow */

maybeCheckWindowPassed(
updatedStateData,
schedulerReadyCheckWindow,
stateData.time.nowInTicks - parallelWindow
stateData.time.nowInTicks
)
} else {
/* we are @ the init tick (SimonaSim#initTick), if no init triggers are in the queue and in the await map
Expand Down Expand Up @@ -789,7 +782,7 @@ trait SchedulerHelper extends SimonaActorLogging {
context.watch(actorToBeScheduled)

// if the tick of this trigger is too much in the past, we cannot schedule it
if (stateData.time.nowInTicks - trigger.tick > parallelWindow) {
if (stateData.time.nowInTicks > trigger.tick) {
actorToBeScheduled ! IllegalTriggerMessage(
s"Cannot schedule an event $trigger at tick ${trigger.tick} when 'nowInSeconds' is at ${stateData.time.nowInTicks}!",
actorToBeScheduled
Expand Down
5 changes: 0 additions & 5 deletions src/main/scala/edu/ie3/simona/util/SimonaConstants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,4 @@ object SimonaConstants {
*/
val FIRST_TICK_IN_SIMULATION: Long = 0L

/** Amount of ticks, that an agent is allowed to be ahead of the slowest agent
* in population
*/
val PARALLELISM_WINDOW = 0L

}
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ class SimSchedulerSpec
)

val doneMsg = resultEventListener.expectMsgType[Done]
doneMsg.tick shouldBe 3600L
doneMsg.tick shouldBe 0L
doneMsg.noOfFailedPF shouldBe 2
doneMsg.errorInSim shouldBe true

Expand Down

0 comments on commit 0733082

Please sign in to comment.