mango_library.coalition.core¶
Module, which provides some roles and models to support coalition creation with mango.
There are mainly two roles involved in this:
* CoalitionInitiatorRole: Initiates a coalition, therfore sends the invites, receives the
responses and informs all participants, which accepted, about the coalition and its topology
CoalitionParticipantRole: Participates in a coalition, the main responsibility isanswering the coalition invite and storing the coalition-assignment when a coalition creation was successful
The messages defined in this module:
* CoalitionAssignment: sent by the initiator when the accepted coalition really got created
* CoalitionInvite: sent by the initiator to start the coalition creation
* CoaltitionResponse: sent by any participant as answer to an CoalitionInvite
The role models defined in this module:
* CoalitionModel: contains all information for all coalitions an agent participates in
- class mango_library.coalition.core.CoalitionAssignment(coalition_id: uuid.UUID, neighbors: List[Tuple[int, Union[str, Tuple[str, int]], str]], topic: str, part_id: int, controller_agent_id: str, controller_agent_addr)¶
Message/Model for assigning a participant to an already accepted coalition. In this assignment all relevant information about the coalition are contained, f.e. participant id, neighbors, … .
- property coalition_id: uuid.UUID¶
Id of the colaition (unique)
- Returns
id of the coalition as UUID
- property controller_agent_addr: Union[str, Tuple[str, int]]¶
Adress of the controller agent
- Returns
adress as tuple
- property controller_agent_id¶
Id of the controller agent
- Returns
agent_id
- property neighbors: List[Tuple[int, Union[str, Tuple[str, int]], str]]¶
Neighbors of the participant.
- Returns
List of the participant, a participant is modelled as tuple (part_id, adress, aid)
- property part_id: int¶
The id of the participant
- Returns
id
- property topic¶
The topic of the coalition, f.e. COHDA
- Returns
the topic
- class mango_library.coalition.core.CoalitionInitiatorRole(participants: List, topic: str, details: str, topology_creator=<function clique_creator>)¶
Role responsible for initiating a coalition. Considered as proactive role.
The role will invite all given participants and add them to coalition if they accept the invite.
- handle_msg(content: mango_library.coalition.core.CoaltitionResponse, meta: Dict[str, Any]) → None¶
Handle the responses to the invites.
- Parameters
content – the invite response
meta – meta data
- async send_invitiations(agent_context: mango.role.api.RoleContext)¶
Send invitiations to all wanted participant for the coalition
- Parameters
agent_context – the context
- setup()¶
Lifecycle hook in, which will be called on adding the role to agent. The role context is known from hereon.
- class mango_library.coalition.core.CoalitionInvite(coalition_id: uuid.UUID, topic: str, details=None)¶
Message for inviting an agent to a coalition.
- property coalition_id: uuid.UUID¶
Return id of the coalition
- Returns
id of the coalition
- property details¶
Return details additional to the topic
- Returns
additional details
- property topic: str¶
Return the topic of the coalition
- Returns
the topic
- class mango_library.coalition.core.CoalitionModel¶
Role-model for coalitions
- add(coalition_id: uuid.UUID, assignment: mango_library.coalition.core.CoalitionAssignment)¶
Add a new assignment
- Parameters
coalition_id – uuid of the coalition you want to add assignment (CoalitionAssignment): new assignment
- property assignments: Dict[uuid.UUID, mango_library.coalition.core.CoalitionAssignment]¶
Dict of assignments coalition_id -> assignment
- Returns
the dict of assignments
- by_id(coalition_id: uuid.UUID) → mango_library.coalition.core.CoalitionAssignment¶
Get an assignment by coalition id
- Parameters
coalition_id – the coalition id
- Returns
the assignment
- exists(coalition_id: uuid.UUID)¶
Checks whether there exists an assignment for the given coalition id
- Parameters
coalition_id – the coalition id
- Returns
the assignment
- class mango_library.coalition.core.CoalitionParticipantRole(join_decider=<function CoalitionParticipantRole.<lambda>>)¶
Role responsible for participating in a coalition. Handles the messages
CoalitionInviteandCoalitionAssignment.When a valid assignment was received the model
CoalitionModelwill be created as central role model.- handle_assignment(content: mango_library.coalition.core.CoalitionAssignment, _: Dict[str, Any]) → None¶
Handle an incoming assignment to a coalition. Store the information in a CoalitionModel.
- Parameters
content – the assignment
_ – the meta data
- handle_invite(content: mango_library.coalition.core.CoalitionInvite, meta: Dict[str, Any]) → None¶
Handle invite messages, responding with a CoalitionResponse.
- Parameters
content – the invite
meta – meta data
- setup() → None¶
Lifecycle hook in, which will be called on adding the role to agent. The role context is known from hereon.
- class mango_library.coalition.core.CoaltitionResponse(accept: bool)¶
Message for responding to a coalition invite.
- property accept: bool¶
“”Flag whether the coalition is accpeted
- Returns
true if accepted, false otherwise
- mango_library.coalition.core.clique_creator(participants: List[Tuple[int, Union[str, Tuple[str, int]], str]]) → Dict[Tuple[int, Union[str, Tuple[str, int]], str], List[Tuple[int, Union[str, Tuple[str, int]], str]]]¶
Create a clique topology
- Parameters
participants – the list of all participants
- Returns
a map, mapping every participant to a list of their neighbors