Dynamic Teams and Roles
Contexts.DynamicTeam — Type
DynamicTeamAbstract supertype for all dynamic team types. Dynamic Teams group roles and their relationships in a relational context. Dynamic teams allow runtime changes in team composition and cardinality.
Concrete teams should be defined within the @newTeam and @newDynamicTeam macro.
Contexts.@newDynamicTeam — Macro
@newDynamicTeam(contextName, teamName, teamContent)Macro to define a new DynamicTeam type for a context, with specified roles, attributes, and cardinalities. Creates a mutable struct subtype of DynamicTeam and role structs, and registers them.
A dynamic team can change its role assignments over time, within the defined cardinalities. Roles can be assigned and disassigned dynamically without dissolving the team. Roles might be optional (i.e., minimum cardinality can be zero).
There are role-specific cardinalities as well as team-wide cardinalities.
Arguments:
contextName: The context for the dynamic teamteamName: The name of the dynamic teamteamContent: Block containing:
@IDAttribute: uniquely identifying attribute
@relationalAttributes: relational attributes of the team
@role: role definitions with cardinalities
@minPlayers: minimum number of players in the team (default 2)
@maxPlayers: maximum number of players in the team (default Inf)@role definitions must contain at least two roles including their cardinalities.
The syntax for defining roles is: @role RoleName << NaturalType [minCardinality..maxCardinality] begin # role-specific attributes end
Example: @context Sports @newDynamicTeam BasketballTeam <: SportsTeam begin @IDAttribute name::String @maxPlayers 15 @relationalAttributes begin city::String end @role HeadCoach << Person [1] begin end @role PointGuard << Person <: Player [1..Inf] begin number::Int end @role ShootingGuard << Person <: Player [1..Inf] begin number::Int end @role SmallForward << Person <: Player [1..Inf] begin number::Int end @role PowerForward << Person <: Player [1..Inf] begin number::Int end @role Center << Person <: Player [1..Inf] begin number::Int end end
@newDynamicTeam(contextName, teamName, teamContent)Macro to define a new DynamicTeam type with specified roles, attributes, and cardinalities. Creates a mutable struct subtype of DynamicTeam and role structs, and registers them.
A dynamic team can change its role assignments over time, within the defined cardinalities. Roles can be assigned and disassigned dynamically without dissolving the team. Roles might be optional (i.e., minimum cardinality can be zero).
There are role-specific cardinalities as well as team-wide cardinalities.
Arguments:
teamName: The name of the dynamic teamteamContent: Block containing:
@IDAttribute: uniquely identifying attribute
@relationalAttributes: relational attributes of the team
@role: role definitions with cardinalities
@minPlayers: minimum number of players in the team (default 2)
@maxPlayers: maximum number of players in the team (default Inf)@role definitions must contain at least two roles including their cardinalities.
The syntax for defining roles is: @role RoleName << NaturalType [minCardinality..maxCardinality] begin # role-specific attributes end
Example: @newDynamicTeam BasketballTeam <: SportsTeam begin @IDAttribute name::String @maxPlayers 15 @relationalAttributes begin city::String end @role HeadCoach << Person [1] begin end @role PointGuard << Person <: Player [1..Inf] begin number::Int end @role ShootingGuard << Person <: Player [1..Inf] begin number::Int end @role SmallForward << Person <: Player [1..Inf] begin number::Int end @role PowerForward << Person <: Player [1..Inf] begin number::Int end @role Center << Person <: Player [1..Inf] begin number::Int end end
Contexts.assignRoles — Function
assignRoles(context::Union{Context, Nothing}, team::Team, roles...)Assigns roles to objects in a team within a context.
Arguments:
context: Context or nothingteam: Teamroles...: Pairs of (object, Role)
Example: assignRoles(ctx, team, obj1 => RoleA, obj2 => RoleB)
assignRoles(context::Union{Context, Nothing}, team::DynamicTeam, roles...)Assigns roles to objects in a dynamic team within a context.
Arguments:
context: Context or nothingteam: DynamicTeamroles...: Pairs of (object, Role)
Example: assignRoles(ctx, team, obj1 => RoleA, obj2 => RoleB)
Contexts.disassignRoles — Function
disassignRoles(context::Union{Context, Nothing}, t::Team, roles::Pair...)Removes role assignments from objects in a team within a context.
Arguments:
context: Context or nothingt: Teamroles...: Pairs of (Role, object)
Example: disassignRoles(ctx, team, RoleA => obj1, RoleB => obj2)
disassignRoles(context::Union{Context, Nothing}, teamType::Type, roles::Pair...)Removes role assignments from objects in a team type within a context.
Arguments:
context: Context or nothingteamType: Team typeroles...: Pairs of (Role, object)
Example: disassignRoles(ctx, TeamType, RoleA => obj1)
disassignRoles(context::Union{Context, Nothing}, team::DynamicTeam)Removes all role assignments from a dynamic team within a context.
Arguments:
context: Context or nothingteam: DynamicTeam
Example: disassignRoles(ctx, team)
disassignRoles(team::DynamicTeam)Removes all role assignments from a dynamic team (no context).
Arguments:
team: DynamicTeam
Example: disassignRoles(team)
disassignRoles(context::Union{Context, Nothing}, teamType::Type, id)Removes all role assignments from a dynamic team by type and id within a context.
Arguments:
context: Context or nothingteamType: Team typeid: Team id
Example: disassignRoles(ctx, TeamType, 1)
disassignRoles(teamType::Type, id)Removes all role assignments from a dynamic team by type and id (no context).
Arguments:
teamType: Team typeid: Team id
Example: disassignRoles(TeamType, 1)
Contexts.@changeRoles — Macro
@changeRoles(context, team, id, attrs)Macro to change role assignments and disassignments in a dynamic team within a context.
Arguments:
context: Contextteam: DynamicTeam typeid: Team idattrs: Block of assignments (object >> Role, object << Role)
Example: @changeRoles(ctx, MyDynTeam, 1, begin obj1 >> RoleA obj2 << RoleB end)
@changeRoles(team, id, attrs)Macro to change role assignments and disassignments in a dynamic team (no context).
Arguments:
team: DynamicTeam typeid: Team idattrs: Block of assignments (object >> Role, object << Role)
Example: @changeRoles(MyDynTeam, 1, begin obj1 >> RoleA obj2 << RoleB end)
Contexts.changeRoles — Function
changeRoles(context::Union{Context, Nothing}, team::DynamicTeam, roleAssignment::Vector{Any}, roleDisassignment::Vector{Pair{T, DataType}})Changes role assignments and disassignments in a dynamic team within a context.
Arguments:
context: Context or nothingteam: DynamicTeamroleAssignment: Vector of assignments (object, Role)roleDisassignment: Vector of disassignments (object, Role type)
Example: changeRoles(ctx, team, [(obj1, RoleA)], [(obj2, RoleB)])
changeRoles(context::Union{Context, Nothing}, team::DynamicTeam, roleAssignment::Vector{Pair{T, R}}, roleDisassignment::Vector{Any}) where T where R <: RoleChanges role assignments in a dynamic team within a context.
Arguments:
context: Context or nothingteam: DynamicTeamroleAssignment: Vector of assignments (object, Role)roleDisassignment: Vector of objects to disassign
Example: changeRoles(ctx, team, [(obj1, RoleA)], [obj2])
changeRoles(context::Union{Context, Nothing}, team::DynamicTeam, roleAssignment::Vector{Pair{T1, R}}, roleDisassignment::Vector{Pair{T2, DataType}}) where T1 where T2 where R <: RoleChanges role assignments and disassignments in a dynamic team within a context.
Arguments:
context: Context or nothingteam: DynamicTeamroleAssignment: Vector of assignments (object, Role)roleDisassignment: Vector of disassignments (object, Role type)
Example: changeRoles(ctx, team, [(obj1, RoleA)], [(obj2, RoleB)])
Contexts.getDynamicTeam — Function
getDynamicTeam(context::Union{Context, Nothing}, role::Role)Returns the dynamic team in a context that has a specific role.
Arguments:
context: Context or nothingrole: Role type
Example: getDynamicTeam(MyContext, Manager)
getDynamicTeam(role::Role)Convenience function to getDynamicTeam with no context.
Arguments:
role: Role type
Example: getDynamicTeam(Manager)
getDynamicTeam(context::Union{Context, Nothing}, teamType::DataType, id::T) where TReturns a dynamic team by id in a context.
Arguments:
context: Context or nothingteamType: Team typeid: Id value
Example: getDynamicTeam(MyContext, MyDynTeam, :teamid, 123)
getDynamicTeam(teamType::DataType, id::T) where TConvenience function to getDynamicTeam with no context.
Arguments:
teamType: Team typeid: Id value
Example: getDynamicTeam(MyDynTeam, 123)
Contexts.getDynamicTeams — Function
getDynamicTeams(context::Union{Context, Nothing}, teamType::Type)Returns all dynamic teams of a given type in a context.
Arguments:
context: Context or nothingteamType: Team type
Example: getDynamicTeams(MyContext, MyDynTeam)
getDynamicTeams(teamType::Type)Convenience function to getDynamicTeams with no context.
Arguments:
teamType: Team type
Example: getDynamicTeams(MyDynTeam)
Contexts.getDynamicTeamID — Function
getDynamicTeamID(context::Union{Context, Nothing}, team::DynamicTeam)Returns the properties of a dynamic team in a context.
Arguments:
context: Context or nothingteam: DynamicTeam type
Example: getDynamicTeamID(MyContext, MyDynTeam)
getDynamicTeamID(team::DynamicTeam)Convenience function to getDynamicTeamID with no context.
Arguments:
team: DynamicTeam type
Example: getDynamicTeamID(MyDynTeam)
Contexts.getObjectsOfRole — Function
getObjectsOfRole(context::Union{Context, Nothing}, team::DynamicTeam, role::Type)Returns all objects in a context that have a specific role in a specific dynamic team.
Arguments:
context: Context or nothingteam: DynamicTeam typerole: Role type
Example: getObjectsOfRole(MyContext, MyDynTeam, Manager)
getObjectsOfRole(team::DynamicTeam, role::Type)Convenience function to getObjectsOfRole with no context.
Arguments:
team: DynamicTeam typerole: Role type
Example: getObjectsOfRole(MyDynTeam, Manager)
Contexts.getRolesOfTeam — Function
getRolesOfTeam(context::Union{Context, Nothing}, team::Team)Returns all roles in a team in a context.
Arguments:
context: Context or nothingteam: Team type
Example: getRolesOfTeam(MyContext, MyTeam)
getRolesOfTeam(team::Team)Convenience function to getRolesOfTeam with no context.
Arguments:
team: Team type
Example: getRolesOfTeam(MyTeam)
getRolesOfTeam(context::Union{Context, Nothing}, team::DynamicTeam)Returns all roles in a dynamic team in a context.
Arguments:
context: Context or nothingteam: DynamicTeam type
Example: getRolesOfTeam(MyContext, MyDynTeam)
getRolesOfTeam(team::DynamicTeam)Convenience function to getRolesOfTeam with no context.
Arguments:
team: DynamicTeam type
Example: getRolesOfTeam(MyDynTeam)
Contexts.hasRole — Method
hasRole(context::Union{Context, Nothing}, obj, role::Type, team::DynamicTeam)Checks if an object has a specific role in a specific dynamic team in a context.
Arguments:
context: Context or nothingobj: Objectrole: Role typeteam: DynamicTeam type
Returns true or false.
Example: hasRole(MyContext, obj, Manager, MyDynTeam)
Dynamic teams allow runtime changes in team composition and cardinality. Use @newDynamicTeam to define dynamic teams, and assignRoles, disassignRoles, and changeRoles to manage role assignments. Query dynamic teams and their roles with the provided functions.
See also: assignRoles, changeRoles