Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-implementation of ParticipantAgent and models #960

Draft
wants to merge 86 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
e68be97
Initial commit
sebastian-peter Aug 28, 2024
5397f2b
Further dev
sebastian-peter Sep 19, 2024
fb8848c
Further dev
sebastian-peter Sep 19, 2024
2aaa970
Further dev
sebastian-peter Sep 26, 2024
6db21bd
Further dev
sebastian-peter Sep 27, 2024
cdea5e9
Further dev, connection to init
sebastian-peter Sep 30, 2024
d6431c2
Further dev
sebastian-peter Oct 2, 2024
2ac274d
Introducing PrimaryDataParticipantModel
sebastian-peter Oct 15, 2024
d2e8bab
Backup
sebastian-peter Oct 22, 2024
857dba5
Further dev
sebastian-peter Oct 22, 2024
24afead
Further dev
sebastian-peter Oct 25, 2024
5338fa3
Filling in some missing parts
sebastian-peter Oct 25, 2024
0787e73
Some shenanigans with self-types of primary data and more
sebastian-peter Oct 25, 2024
284786c
Some fixes concerning types
sebastian-peter Oct 26, 2024
ec5620f
Fixing type problems in PrimaryDataParticipantModel
sebastian-peter Oct 28, 2024
084a389
Scapegoat fixes
sebastian-peter Oct 28, 2024
0fe4c58
More type fixes
sebastian-peter Oct 28, 2024
f73887b
Reverting self type of primary data
sebastian-peter Oct 28, 2024
1edfd27
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Oct 28, 2024
df800bf
Adding power ctrl handling of EvcsModel
sebastian-peter Oct 28, 2024
8d159aa
Refactoring getRequiredServices
sebastian-peter Oct 28, 2024
647dff1
Adding WecModel
sebastian-peter Oct 28, 2024
06db12e
Adding FixedFeedInModel
sebastian-peter Oct 28, 2024
48d5da8
Added LoadModels
sebastian-peter Oct 28, 2024
9df5ace
Unifying init
sebastian-peter Oct 29, 2024
dfce915
Returning proper next tick
sebastian-peter Oct 31, 2024
ed7fd8f
Init models without secondary data
sebastian-peter Oct 31, 2024
d5a4e20
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 1, 2024
1424c55
Properly implementing operation interval consideration
sebastian-peter Nov 1, 2024
da6a9ff
ScalaDoc fix
sebastian-peter Nov 1, 2024
a3a1fc0
Small improvements
sebastian-peter Nov 1, 2024
33e5a95
Sending results
sebastian-peter Nov 1, 2024
a013ff6
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 13, 2024
d6eeb25
Some fixes
sebastian-peter Nov 13, 2024
50654c9
Adapting first tests for new models
sebastian-peter Nov 13, 2024
5298be2
Adding test for determineState
sebastian-peter Nov 14, 2024
de60e0c
Enhancing charging strats of evcs
sebastian-peter Nov 15, 2024
9ed582d
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 15, 2024
244dd4d
Adapting ScalaDoc
sebastian-peter Nov 15, 2024
d7a5f86
Fix compilation error
sebastian-peter Nov 15, 2024
4346981
Method inheritance
sebastian-peter Nov 15, 2024
25e7195
EVCS charging strat tests
sebastian-peter Nov 15, 2024
9070090
Some additions to EVCS
sebastian-peter Nov 15, 2024
a615d43
Lots of fixes in EVCS
sebastian-peter Nov 21, 2024
3c3fdcf
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 21, 2024
74ba115
Adapting to changes from dev
sebastian-peter Nov 21, 2024
ba69944
EVCS: Implement and test request handling
sebastian-peter Nov 22, 2024
0277ace
Introducing participant refs
sebastian-peter Nov 22, 2024
ff44773
Adding EVCS to init
sebastian-peter Nov 22, 2024
120f1f3
Providing PrimaryDataMeta
sebastian-peter Nov 22, 2024
b63c2e7
Adapting initialization
sebastian-peter Nov 22, 2024
df15211
Some improvements and new todos
sebastian-peter Nov 25, 2024
13cb38d
Some adaptations regarding state and first successful test
sebastian-peter Nov 25, 2024
05af6bc
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 25, 2024
b8c4e4e
Fixing starting tick scheduling
sebastian-peter Nov 25, 2024
79308f2
OperationInterval is now right-open
sebastian-peter Nov 25, 2024
673b933
Enhanced ParticipantAgent tests
sebastian-peter Nov 25, 2024
044209b
Removing unnecessary imports
sebastian-peter Nov 25, 2024
2043308
Some fixes and improvements to ParticipantAgent
sebastian-peter Nov 26, 2024
9c5dad7
Enhancing test
sebastian-peter Nov 26, 2024
45897ff
Removing dummy code
sebastian-peter Nov 26, 2024
f2ad723
Adding todo
sebastian-peter Nov 26, 2024
bdc36e0
Testing participant requests
sebastian-peter Nov 26, 2024
f65249c
Fixing participant for primary data
sebastian-peter Nov 26, 2024
885ce45
Preparations for further participant tests
sebastian-peter Nov 26, 2024
1bf4162
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 27, 2024
4ef7d50
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Nov 28, 2024
34e1834
Fixing next tick with secondary data, adding test
sebastian-peter Nov 28, 2024
d32a81b
Renaming ModelChangeIndicator
sebastian-peter Nov 28, 2024
cb49df5
Adding ScalaDoc
sebastian-peter Nov 28, 2024
7eaf563
Testing changesAtNext
sebastian-peter Nov 28, 2024
c37b25a
Improving primary data model
sebastian-peter Dec 1, 2024
b296350
Adding test for primary data participant agent
sebastian-peter Dec 1, 2024
d49fc8a
Testing primary data meta functions
sebastian-peter Dec 2, 2024
465bdcf
spotless
sebastian-peter Dec 2, 2024
b029006
Fixing some code smells and simplifying code
sebastian-peter Dec 2, 2024
bcfa9b4
Fixing code smell
sebastian-peter Dec 4, 2024
33a3a1f
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Dec 4, 2024
ec2fde6
Simplifying LoadModel setup
sebastian-peter Dec 5, 2024
426f513
Tests for profile and load models
sebastian-peter Dec 5, 2024
264d7de
Merge branch 'dev' into sp/#959-new-participant-agent
sebastian-peter Dec 6, 2024
d0777d4
Simplifying maximum calculation of load profiles
sebastian-peter Dec 11, 2024
95891c3
Using the correct param store
sebastian-peter Dec 11, 2024
0f1127d
Introducing test for FixedLoadModel
sebastian-peter Dec 11, 2024
55104d2
Transferring aggregation tests
sebastian-peter Dec 11, 2024
5e60447
Transferring aggregation tests for random model
sebastian-peter Dec 11, 2024
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
35 changes: 35 additions & 0 deletions docs/uml/main/participants/ParticipantStates.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@startuml
'https://plantuml.com/state-diagram

' clock "Cock 0" as C0 with period 50
skinparam componentStyle rectangle

package "t0" {
component "State (t0)" as s0
component "OperatingPoint (t0 - ?)" as op0
component "OperationRelevantData (t0)" as or0

}

package t1 {
component "State (t1)" as s1
}

package t2 {
component "State (t2)" as s2
}


s0 -> op0
or0 -> op0

s0 -> s1
op0 -> s1

s1 -> s2

' Layouting:
s0 -[hidden]-> or0
'States --> OperatingPoints

@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import edu.ie3.simona.agent.participant.ParticipantAgent.{
getAndCheckNodalVoltage,
}
import edu.ie3.simona.agent.participant.data.Data
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithApparentPower
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithComplexPower
import edu.ie3.simona.agent.participant.data.Data.{PrimaryData, SecondaryData}
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService
import edu.ie3.simona.agent.participant.statedata.BaseStateData.{
Expand Down Expand Up @@ -89,7 +89,7 @@ import scala.reflect.ClassTag
* @since 2019-07-04
*/
abstract class ParticipantAgent[
PD <: PrimaryDataWithApparentPower[PD],
PD <: PrimaryDataWithComplexPower[PD],
CD <: CalcRelevantData,
MS <: ModelState,
D <: ParticipantStateData[PD],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import edu.ie3.simona.agent.participant.data.Data.PrimaryData.{
ComplexPower,
ComplexPowerAndHeat,
EnrichableData,
PrimaryDataWithApparentPower,
PrimaryDataWithComplexPower,
}
import edu.ie3.simona.agent.participant.data.Data.{PrimaryData, SecondaryData}
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService
Expand Down Expand Up @@ -103,7 +103,7 @@ import scala.util.{Failure, Success, Try}
/** Useful functions to use in [[ParticipantAgent]] s
*/
protected trait ParticipantAgentFundamentals[
PD <: PrimaryDataWithApparentPower[PD],
PD <: PrimaryDataWithComplexPower[PD],
CD <: CalcRelevantData,
MS <: ModelState,
D <: ParticipantStateData[PD],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package edu.ie3.simona.agent.participant

import org.apache.pekko.actor.ActorRef
import edu.ie3.datamodel.models.input.system.{EvcsInput, SystemParticipantInput}
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithApparentPower
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithComplexPower
import edu.ie3.simona.agent.participant.data.Data.SecondaryData
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService.{
Expand All @@ -28,7 +28,7 @@ import edu.ie3.simona.ontology.messages.services.EvMessage.RegisterForEvDataMess
import edu.ie3.simona.ontology.messages.services.WeatherMessage.RegisterForWeatherMessage

trait ServiceRegistration[
PD <: PrimaryDataWithApparentPower[PD],
PD <: PrimaryDataWithComplexPower[PD],
CD <: CalcRelevantData,
MS <: ModelState,
D <: ParticipantStateData[PD],
Expand Down
60 changes: 52 additions & 8 deletions src/main/scala/edu/ie3/simona/agent/participant/data/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import edu.ie3.util.scala.quantities.{Kilovars, ReactivePower}
import squants.energy.{Kilowatts, Power}
import tech.units.indriya.ComparableQuantity

import java.time.ZonedDateTime
import scala.jdk.OptionConverters.RichOptional
import scala.util.{Failure, Success, Try}

Expand All @@ -39,16 +38,22 @@ object Data {
def toComplexPower: ComplexPower
}

sealed trait PrimaryDataMeta[T <: PrimaryData] {
def zero: T

def scale(data: T, factor: Double): T
}

object PrimaryData {

sealed trait EnrichableData[E <: PrimaryDataWithApparentPower[E]] {
sealed trait EnrichableData[E <: PrimaryDataWithComplexPower[E]] {
def add(q: ReactivePower): E
}

/** Denoting all primary data, that carry apparent power
/** Denoting all primary data, that carry complex power
*/
sealed trait PrimaryDataWithApparentPower[
+T <: PrimaryDataWithApparentPower[T]
sealed trait PrimaryDataWithComplexPower[
+T <: PrimaryDataWithComplexPower[T]
] extends PrimaryData {
val q: ReactivePower

Expand Down Expand Up @@ -81,6 +86,13 @@ object Data {
ComplexPower(p, q)
}

object ActivePowerMeta extends PrimaryDataMeta[ActivePower] {
override def zero: ActivePower = ActivePower(zeroKW)

override def scale(data: ActivePower, factor: Double): ActivePower =
ActivePower(data.p * factor)
}

/** Active and Reactive power as participant simulation result
*
* @param p
Expand All @@ -91,13 +103,20 @@ object Data {
final case class ComplexPower(
override val p: Power,
override val q: ReactivePower,
) extends PrimaryDataWithApparentPower[ComplexPower] {
) extends PrimaryDataWithComplexPower[ComplexPower] {
override def toComplexPower: ComplexPower = this

override def withReactivePower(q: ReactivePower): ComplexPower =
copy(q = q)
}

object ComplexPowerMeta extends PrimaryDataMeta[ComplexPower] {
override def zero: ComplexPower = ComplexPower(zeroKW, zeroKVAr)

override def scale(data: ComplexPower, factor: Double): ComplexPower =
ComplexPower(data.p * factor, data.q * factor)
}

/** Active power and heat demand as participant simulation result
*
* @param p
Expand All @@ -121,6 +140,16 @@ object Data {
ComplexPowerAndHeat(p, q, qDot)
}

object ActivePowerAndHeatMeta extends PrimaryDataMeta[ActivePowerAndHeat] {
override def zero: ActivePowerAndHeat = ActivePowerAndHeat(zeroKW, zeroKW)

override def scale(
data: ActivePowerAndHeat,
factor: Double,
): ActivePowerAndHeat =
ActivePowerAndHeat(data.p * factor, data.qDot * factor)
}

/** Apparent power and heat demand as participant simulation result
*
* @param p
Expand All @@ -134,7 +163,7 @@ object Data {
override val p: Power,
override val q: ReactivePower,
override val qDot: Power,
) extends PrimaryDataWithApparentPower[ComplexPowerAndHeat]
) extends PrimaryDataWithComplexPower[ComplexPowerAndHeat]
with Heat {
override def toComplexPower: ComplexPower =
ComplexPower(p, q)
Expand All @@ -143,6 +172,22 @@ object Data {
copy(q = q)
}

object ComplexPowerAndHeatMeta
extends PrimaryDataMeta[ComplexPowerAndHeat] {
override def zero: ComplexPowerAndHeat =
ComplexPowerAndHeat(zeroKW, zeroKVAr, zeroKW)

override def scale(
data: ComplexPowerAndHeat,
factor: Double,
): ComplexPowerAndHeat =
ComplexPowerAndHeat(
data.p * factor,
data.q * factor,
data.qDot * factor,
)
}

implicit class RichValue(private val value: Value) {
def toPrimaryData: Try[PrimaryData] =
value match {
Expand Down Expand Up @@ -241,7 +286,6 @@ object Data {
*/
trait SecondaryData extends Data
object SecondaryData {
final case class DateTime(dateTime: ZonedDateTime) extends SecondaryData
final case class WholesalePrice(price: ComparableQuantity[EnergyPrice])
extends SecondaryData
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class EvcsAgent(

when(Idle) {
case Event(
EvFreeLotsRequest(tick),
EvFreeLotsRequest(tick, _),
modelBaseStateData: ParticipantModelBaseStateData[
ComplexPower,
EvcsRelevantData,
Expand All @@ -97,7 +97,7 @@ class EvcsAgent(
stay()

case Event(
DepartingEvsRequest(tick, departingEvs),
DepartingEvsRequest(tick, departingEvs, _),
modelBaseStateData: ParticipantModelBaseStateData[
ComplexPower,
EvcsRelevantData,
Expand All @@ -115,7 +115,7 @@ class EvcsAgent(
// in case the activation has arrived first

case Event(
EvFreeLotsRequest(tick),
EvFreeLotsRequest(tick, _),
stateData: DataCollectionStateData[ComplexPower],
) =>
stateData.baseStateData match {
Expand All @@ -134,7 +134,7 @@ class EvcsAgent(
}

case Event(
DepartingEvsRequest(tick, departingEvs),
DepartingEvsRequest(tick, departingEvs, _),
stateData: DataCollectionStateData[ComplexPower],
) =>
stateData.baseStateData match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
package edu.ie3.simona.agent.participant.statedata

import edu.ie3.simona.agent.ValueStore
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithApparentPower
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithComplexPower
import edu.ie3.simona.agent.participant.data.Data.SecondaryData
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService
import edu.ie3.simona.event.notifier.NotifierConfig
Expand All @@ -33,10 +33,10 @@ import scala.collection.SortedSet
* agents
*
* @tparam PD
* Type of [[PrimaryDataWithApparentPower]], that the represented Participant
* Type of [[PrimaryDataWithComplexPower]], that the represented Participant
* produces
*/
trait BaseStateData[+PD <: PrimaryDataWithApparentPower[PD]]
trait BaseStateData[+PD <: PrimaryDataWithComplexPower[PD]]
extends ParticipantStateData[PD] {

/** The date, that fits the tick 0
Expand Down Expand Up @@ -90,15 +90,15 @@ object BaseStateData {
/** The agent is supposed to carry out model calculations
*
* @tparam PD
* Type of [[PrimaryDataWithApparentPower]], that the represented
* Type of [[PrimaryDataWithComplexPower]], that the represented
* Participant produces
* @tparam CD
* Type of [[CalcRelevantData]], that is required by the included model
* @tparam M
* Restricting the model to a certain class
*/
trait ModelBaseStateData[
+PD <: PrimaryDataWithApparentPower[PD],
+PD <: PrimaryDataWithComplexPower[PD],
CD <: CalcRelevantData,
MS <: ModelState,
+M <: SystemParticipant[_ <: CalcRelevantData, PD, MS],
Expand Down Expand Up @@ -156,7 +156,7 @@ object BaseStateData {
_ <: CalcRelevantData,
P,
_,
], +P <: PrimaryDataWithApparentPower[P]](
], +P <: PrimaryDataWithComplexPower[P]](
model: M,
override val startDate: ZonedDateTime,
override val endDate: ZonedDateTime,
Expand Down Expand Up @@ -207,7 +207,7 @@ object BaseStateData {
* Type of model, the base state data is attached to
*/
final case class ParticipantModelBaseStateData[
+PD <: PrimaryDataWithApparentPower[PD],
+PD <: PrimaryDataWithComplexPower[PD],
CD <: CalcRelevantData,
MS <: ModelState,
M <: SystemParticipant[_ <: CalcRelevantData, PD, MS],
Expand Down Expand Up @@ -272,7 +272,7 @@ object BaseStateData {
* @return
* A copy of the base data with updated value stores
*/
def updateBaseStateData[PD <: PrimaryDataWithApparentPower[PD]](
def updateBaseStateData[PD <: PrimaryDataWithComplexPower[PD]](
baseStateData: BaseStateData[PD],
updatedResultValueStore: ValueStore[PD],
updatedRequestValueStore: ValueStore[PD],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package edu.ie3.simona.agent.participant.statedata

import org.apache.pekko.actor.ActorRef
import edu.ie3.simona.agent.participant.data.Data
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithApparentPower
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithComplexPower

import scala.reflect.{ClassTag, classTag}

Expand All @@ -24,10 +24,10 @@ import scala.reflect.{ClassTag, classTag}
* True, if an [[edu.ie3.simona.ontology.messages.Activation]] has already
* arrived
* @tparam PD
* Type of the [[PrimaryDataWithApparentPower]], that the model will produce
* Type of the [[PrimaryDataWithComplexPower]], that the model will produce
* or receive as primary data
*/
final case class DataCollectionStateData[+PD <: PrimaryDataWithApparentPower[
final case class DataCollectionStateData[+PD <: PrimaryDataWithComplexPower[
PD
]](
baseStateData: BaseStateData[PD],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package edu.ie3.simona.agent.participant.statedata

import edu.ie3.datamodel.models.input.container.ThermalGrid
import edu.ie3.datamodel.models.input.system.SystemParticipantInput
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithApparentPower
import edu.ie3.simona.agent.participant.data.Data.PrimaryData.PrimaryDataWithComplexPower
import edu.ie3.simona.agent.participant.data.Data.{PrimaryData, SecondaryData}
import edu.ie3.simona.agent.participant.data.secondary.SecondaryDataService
import edu.ie3.simona.config.SimonaConfig
Expand Down Expand Up @@ -261,11 +261,11 @@ object ParticipantStateData {
* Mapping from service provider to foreseen next tick, it will send new
* data
* @tparam PD
* Type of [[PrimaryDataWithApparentPower]], that is covered by given
* Type of [[PrimaryDataWithComplexPower]], that is covered by given
* [[BaseStateData]]
*/
final case class CollectRegistrationConfirmMessages[
+PD <: PrimaryDataWithApparentPower[PD]
+PD <: PrimaryDataWithComplexPower[PD]
](
baseStateData: BaseStateData[PD],
pendingResponses: Iterable[ClassicActorRef],
Expand Down
Loading
Loading