Skip to content

Commit

Permalink
Merge branch 'sp/#339-em-it' into all/#tbw
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-peter committed Nov 4, 2022
2 parents af6f7b5 + d0dafcf commit 3a1003f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ class EmAgent(
baseStateData.schedulerStateData.flexTrigger
) { case (flexTrigger, (uuid, issueCtrlMsg, _)) =>
// send out flex control messages
scheduleFlexTrigger(flexTrigger, issueCtrlMsg, uuid)
scheduleFlexTriggerOnce(flexTrigger, issueCtrlMsg, uuid)
}

val updatedScheduledStateData = sendEligibleTrigger(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ trait EmSchedulerHelper {
// schedule new flex requests, if applicable
completionMessage.requestAtTick
.foreach(newTick =>
scheduleFlexTrigger(
scheduleFlexTriggerOnce(
triggerData,
RequestFlexOptions(newTick),
completionMessage.modelUuid
Expand Down Expand Up @@ -222,47 +222,34 @@ trait EmSchedulerHelper {
flexTrigger: FlexTriggerData,
participantUuids: Set[UUID],
tick: Long
): FlexTriggerData = {
val alreadyScheduled =
flexTrigger.triggerQueue
.get(tick)
.getOrElse(Seq.empty)
.map(_.modelUuid)

// participants that have to be activated at any next tick
val filteredUuids =
participantUuids
.filterNot {
// filter out duplicates here: we might have been scheduled
// for this tick anyways
alreadyScheduled.contains
}

// add missing activation triggers
val updatedFlexTrigger =
filteredUuids.foldLeft(flexTrigger) { case (schedulerData, modelUuid) =>
scheduleFlexTrigger(
schedulerData,
RequestFlexOptions(tick),
modelUuid
)
}

updatedFlexTrigger
}
): FlexTriggerData =
participantUuids.foldLeft(flexTrigger) { case (schedulerData, modelUuid) =>
scheduleFlexTriggerOnce(
schedulerData,
RequestFlexOptions(tick),
modelUuid
)
}

protected def scheduleFlexTrigger(
protected def scheduleFlexTriggerOnce(
flexTrigger: FlexTriggerData,
trigger: Trigger with FlexibilityMessage,
modelUuid: UUID
): FlexTriggerData = {
flexTrigger.triggerQueue.add(
trigger.tick,
ScheduledFlexTrigger(
trigger,
modelUuid
val scheduledTrigger = ScheduledFlexTrigger(trigger, modelUuid)

val alreadyScheduled =
flexTrigger.triggerQueue
.get(trigger.tick)
.getOrElse(Seq.empty)
.contains(scheduledTrigger)

if (!alreadyScheduled)
flexTrigger.triggerQueue.add(
trigger.tick,
scheduledTrigger
)
)

flexTrigger
}

Expand Down Expand Up @@ -325,7 +312,7 @@ trait EmSchedulerHelper {
triggerMessage.actorToBeScheduled
)
stateData.copy(
flexTrigger = scheduleFlexTrigger(
flexTrigger = scheduleFlexTriggerOnce(
stateData.flexTrigger,
flexMessage,
uuid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import edu.ie3.simona.model.participant.evcs.EvcsModel.{
EvcsRelevantData,
EvcsState
}
import edu.ie3.simona.ontology.messages.FlexibilityMessage.RequestFlexOptions
import edu.ie3.simona.ontology.messages.PowerMessage.AssetPowerChangedMessage
import edu.ie3.simona.ontology.messages.SchedulerMessage.ScheduleTriggerMessage
import edu.ie3.simona.ontology.messages.services.EvMessage._
import edu.ie3.simona.util.SimonaConstants
import edu.ie3.simona.util.TickUtil.{RichZonedDateTime, TickLong}
Expand Down Expand Up @@ -460,6 +462,10 @@ protected trait EvcsAgentFundamentals

val newState = EvcsState(stayingEvs, stayingSchedules, tick)

baseStateData.flexStateData.foreach(
_.emAgent ! ScheduleTriggerMessage(RequestFlexOptions(tick), self)
)

baseStateData.copy(
stateDataStore = ValueStore.updateValueStore(
baseStateData.stateDataStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1535,6 +1535,10 @@ class EvcsAgentModelCalculationSpec
DepartingEvsRequest(4500L, Seq(ev900.getUuid))
)

emAgent.expectMsg(
ScheduleTriggerMessage(RequestFlexOptions(4500L), evcsAgent)
)

evService.expectMsgPF() { case DepartingEvsResponse(uuid, evs) =>
evs.size shouldBe 1
uuid shouldBe evcsInputModel.getUuid
Expand Down Expand Up @@ -2151,6 +2155,10 @@ class EvcsAgentModelCalculationSpec
DepartingEvsRequest(36000L, Seq(ev900.getUuid))
)

emAgent.expectMsg(
ScheduleTriggerMessage(RequestFlexOptions(36000L), evcsAgent)
)

evService.expectMsgPF() { case DepartingEvsResponse(uuid, evs) =>
evs.size shouldBe 1
uuid shouldBe evcsInputModel.getUuid
Expand Down

0 comments on commit 3a1003f

Please sign in to comment.