Construct version 5.3.9
An agent based modeling framework
InteractionMessage Class Reference

An Interaction Message is a container for InteractionItems. In addition a message has a sender, receiver, and medium. More...

Collaboration diagram for InteractionMessage:

Public Types

using iterator = std::vector< InteractionItem >::iterator
 
using const_iterator = std::vector< InteractionItem >::const_iterator
 

Public Member Functions

 InteractionMessage (unsigned int senderAgentIndex, unsigned int receiverAgentIndex, const CommunicationMedium *_medium, const std::vector< InteractionItem > &interactionItems=std::vector< InteractionItem >())
 Creates an empty message. More...
 
iterator begin (void) noexcept
 Returns an iterator pointer to the first element in the list of InteractionItems. More...
 
iterator end (void) noexcept
 Returns an iterator pointer to the last element in the list of InteractionItems. More...
 
const_iterator begin (void) const noexcept
 Returns a const_iterator pointer to the first element in the list of InteractionItems. More...
 
const_iterator end (void) const noexcept
 Returns a const_iterator pointer to the beyond the last element in the list of InteractionItems. More...
 
unsigned int size () noexcept
 Returns the number of elements of InteractionItems. More...
 
iterator erase (iterator itr) noexcept
 Removes the InteractionItem at the iterator position. More...
 
bool add_item (const InteractionItem &item) noexcept
 Adds the item to the list of InteractionItems. More...
 
bool add_knowledge_item (unsigned int knowledge_index) noexcept
 Uses add_item and InteractionItem::set_knowledge_item to add a knowledge item to the message. More...
 
bool add_knowledgeTM_item (unsigned int knowledge_index, unsigned int alter) noexcept
 Uses add_item and InteractionItem::set_knowledgeTM_item to add a transactive memory knowledge item to the message. More...
 
bool add_belief_item (unsigned int belief_index, float belief_value) noexcept
 Uses add_item and InteractionItem::set_belief_item to add a belief item to the message. More...
 
bool add_beliefTM_item (unsigned int belief_index, unsigned int alter, float belief_value) noexcept
 Uses add_item and InteractionItem::set_beliefTM_item to add a transactive memory belief item to the message. More...
 
bool add_knowledge_trust_item (unsigned int knowledge_index, float ktrust) noexcept
 Uses add_item and InteractionItem::set_knowledge_trust_item to add a knowledge trust item to the message. More...
 

Public Attributes

const CommunicationMediummedium
 The communication medium the message uses. More...
 
unsigned int sender
 Agent index of the sender of the message.
 
unsigned int receiver
 Agent index of the receiver of the message.
 
unsigned int time_to_send
 The number of time periods until this message should be added to the InteractionMessageQueue.
 
bool valid
 True if the medium is valid and the number InteractionItems is greater than zero.
 

Detailed Description

An Interaction Message is a container for InteractionItems. In addition a message has a sender, receiver, and medium.

Messages are used send information from one agent to another agent. The sender constructs the message and the receiver parses the message. The medium that a message uses has broader implication for parsing, but is used to restrict how large a message can be in terms of number of InteractionItems. InteractionItems are stored in a vector

Constructor & Destructor Documentation

◆ InteractionMessage()

InteractionMessage::InteractionMessage ( unsigned int  senderAgentIndex,
unsigned int  receiverAgentIndex,
const CommunicationMedium _medium,
const std::vector< InteractionItem > &  interactionItems = std::vector<InteractionItem>() 
)

Creates an empty message.

Empty messages have no sender, receiver, or communication medium. Empty messages are not valid messages. Empty messages can not be added to an InteractionMessageQueue and can not be parsed.

Returns
An invalid message.

Creates a message of information to be sent from agent to agent.

Information in a message is in the form of a list of InteractionItems. Messages are created to transfer that information from the sender agent to the recieving agent. Messages are transferred using a CommunicationMedium. This medium is mainly responsible for restricting the number of InteractionItems in a message. During construction if the size of interactionItems is greater than the medium maximum message complexity, only elements up to the complexity value of the vector are inserted into the list. Otherwise the entire vector is copied to a private member.

If either interactionItem has size zero or medium is not a valid medium, the message becomes an empty message and valid is set to false.

Parameters
senderAgentIndexAgent node index of the sender. The sender constructs the message.
receiverAgentIndexAgent node index of the receiver. The receiver parses messages that are sent to them.
_mediumThe CommunicationMedium used to send this message.
interactionItemsA vector of InteractionItems to be included in a message with length capped by the medium's maximum message complexity. Defaults to an empty vector.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledge_item(4);
msg.add_belief_item(3, 0.2);
std::cout << "Message Sender: " << msg.sender << std::endl;
std::cout << "Message Receiver: " << msg.receiver << std::endl;
std::cout << "Message Contents: ";
unsigned int k, bi, bv;
for(auto item = msg.begin(); item != msg.end(); ++msg) {
if ( item->get_knowledge_item(k) ) std::cout << "knowledge ";
if ( item->get_belief_item(bi, bv) ) std::cout << "belief ";
}
std::cout << std::endl;
}
An Interaction Message is a container for InteractionItems. In addition a message has a sender,...
Definition: InteractionMessage.h:1077
const CommunicationMedium * medium
The communication medium the message uses.
Definition: InteractionMessage.h:1096
Class to contain the medium used by InteractionMessage% s.
Definition: CommunicationMedium.h:19

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge belief

Complexity

Linear in interactionItem size or medium maximum message complexity, whichever is smaller.

Exception Safety

No throw guarantee: This constructor does not throw exceptions. If a problem occurs, the message will become an empty message in which valid is set to false.

Here is the call graph for this function:

Member Function Documentation

◆ add_belief_item()

bool InteractionMessage::add_belief_item ( unsigned int  belief_index,
float  belief_value 
)
noexcept

Uses add_item and InteractionItem::set_belief_item to add a belief item to the message.

Parameters
belief_indexThe index the belief item is set to.
belief_valueThe value of the belief.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_belief_item(4, 0.3);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int b;
float val;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_belief_item(b, val) ) {
std::cout << "belief, index " << b << " value " << val;
}
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: belief, index 4 value 0.3

Complexity

Combination of add_item and InteractionItem::set_belief_item complexity.

Iterator validity

If the list is equal to the medium max message complexity, the iterator at the beginning of the list is invalidated. If a reallocation happens due to the addition, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.

Exception Safety

If the -DEBUG flag is used during compilation a warning is printed when the front of the list is removed. Otherwise, this function does not throw exceptions.

Here is the call graph for this function:

◆ add_beliefTM_item()

bool InteractionMessage::add_beliefTM_item ( unsigned int  belief_index,
unsigned int  alter,
float  belief_value 
)
noexcept

Uses add_item and InteractionItem::set_beliefTM_item to add a transactive memory belief item to the message.

Parameters
belief_indexThe index the belief item is set to.
alterThe index the of the alter the knowledgeTM item is about.
belief_valueThe value of the belief.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_beliefTM_item(4, 4, 0.3);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int b, a;
float val;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_beliefTM_item(b, a, val) ) {
std::cout << "beliefTM, index " << b << " alter " << a << " value " << val;
}
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: beliefTM, index 4 alter 4 value 0.3

Complexity

Combination of add_item and InteractionItem::set_beliefTM_item complexity.

Iterator validity

If the list is equal to the medium max message complexity, the iterator at the beginning of the list is invalidated. If a reallocation happens due to the addition, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.

Exception Safety

If the -DEBUG flag is used during compilation a warning is printed when the front of the list is removed. Otherwise, this function does not throw exceptions.

Here is the call graph for this function:

◆ add_item()

bool InteractionMessage::add_item ( const InteractionItem item)
noexcept

Adds the item to the list of InteractionItems.

If size of the InteractionItem list is equal to the medium's max message complexity, the first item in the list is removed. This creates a first in, first out revolving door when many items are added.

Parameters
itemItem to be added to the list of InteractionItems.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
std::vector<InteractionItem> items;
items.push_back( InteractionItem().set_knowledge(4) );
InteractionMessage msg(5, 6, &medium, items);
msg.add_item( InteractionItem().set_belief(3, 0.2) );
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int k, bi, bv;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_item(k) ) std::cout << "knowledge ";
if ( item->get_belief_item(bi, bv) ) std::cout << "belief ";
}
std::cout << std::endl;
}
Interaction Items is a container of three maps. Each map corresponds to a different datatype.
Definition: InteractionMessage.h:39

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge belief

Complexity

Constant (amortized time, reallocation may happen). If a reallocation happens, the reallocation is itself up to linear in the entire size.

Iterator validity

If the list is equal to the medium max message complexity, the iterator at the beginning of the list is invalidated. If a reallocation happens due to the addition, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.

Exception Safety

If the -DEBUG flag is used during compilation a warning is printed when the front of the list is removed. Otherwise, this function does not throw exceptions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_knowledge_item()

bool InteractionMessage::add_knowledge_item ( unsigned int  knowledge_index)
noexcept

Uses add_item and InteractionItem::set_knowledge_item to add a knowledge item to the message.

Parameters
knowledge_indexThe index the knowledge item is set to.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledge_item(4);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int k;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_item(k) ) {
std::cout << "knowledge, index " << k;
}
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge, index 4

Complexity

Combination of add_item and InteractionItem::set_knowledge_item complexity.

Iterator validity

If the list is equal to the medium max message complexity, the iterator at the beginning of the list is invalidated. If a reallocation happens due to the addition, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.

Exception Safety

If the -DEBUG flag is used during compilation a warning is printed when the front of the list is removed. Otherwise, this function does not throw exceptions.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_knowledge_trust_item()

bool InteractionMessage::add_knowledge_trust_item ( unsigned int  knowledge_index,
float  ktrust 
)
noexcept

Uses add_item and InteractionItem::set_knowledge_trust_item to add a knowledge trust item to the message.

Parameters
knowledge_indexThe index the knowledge item is set to.
ktrustValue the knowledge trust is set to.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledge_trust_item(4, 0.3);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int k;
float val;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_trust_item(k, val) ) {
std::cout << "knowledge trust, index " << k << " value " << val;
}
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge trust, index 4 value 0.3

Complexity

Combination of add_item and InteractionItem::set_knowledge_trust_item complexity.

Iterator validity

If the list is equal to the medium max message complexity, the iterator at the beginning of the list is invalidated. If a reallocation happens due to the addition, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.

Exception Safety

If the -DEBUG flag is used during compilation a warning is printed when the front of the list is removed. Otherwise, this function does not throw exceptions.

Here is the call graph for this function:

◆ add_knowledgeTM_item()

bool InteractionMessage::add_knowledgeTM_item ( unsigned int  knowledge_index,
unsigned int  alter 
)
noexcept

Uses add_item and InteractionItem::set_knowledgeTM_item to add a transactive memory knowledge item to the message.

Parameters
knowledge_indexThe index the knowledgeTM item is set to.
alterThe index the of the alter the knowledgeTM item is about.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledgeTM_item(4, 4);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int k, a;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledgeTM_item(k, a) ) {
std::cout << "knowledgeTM, index " << k << " alter " << a;
}
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledgeTM, index 4 alter 4

Complexity

Combination of add_item and InteractionItem::set_knowledgeTM_item complexity.

Iterator validity

If the list is equal to the medium max message complexity, the iterator at the beginning of the list is invalidated. If a reallocation happens due to the addition, all iterators, pointers and references related to the container are invalidated. Otherwise, only the end iterator is invalidated, and all iterators, pointers and references to elements are guaranteed to keep referring to the same elements they were referring to before the call.

Exception Safety

If the -DEBUG flag is used during compilation a warning is printed when the front of the list is removed. Otherwise, this function does not throw exceptions.

Here is the call graph for this function:

◆ begin() [1/2]

const_iterator InteractionMessage::begin ( void  ) const
inlinenoexcept

Returns a const_iterator pointer to the first element in the list of InteractionItems.

Returns
An iterator that points to the const element at the beginning of a message's InteractionItems.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
std::vector<InteractionItem> items;
items.push_back( InteractionItem().set_knowledge(4) );
items.push_back( InteractionItem().set_belief(3, 0.2) );
const InteractionMessage msg(5, 6, &medium, items);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
unsigned int k, bi, bv;
std::cout<<"This message contains:"<<std::endl;
for(item = msg.begin(); item != msg.end(); ++item) {
for(auto att = item->begin(); att != item->end(); ++att) {
std::cout << *att << std::endl;
}
}
}

Output:

Message Sender: 5
Message Receiver: 6
This message contains: 
knowledge 
belief

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

◆ begin() [2/2]

iterator InteractionMessage::begin ( void  )
inlinenoexcept

Returns an iterator pointer to the first element in the list of InteractionItems.

Returns
An iterator pointing to the beginning of a message's InteractionItems.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledge_item(4);
msg.add_belief_item(3, 0.2);
std::cout << "Message Sender: " << msg.sender << std::endl;
std::cout << "Message Receiver: " << msg.receiver << std::endl;
std::cout << "Message Contents: ";
unsigned int k, bi, bv;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_item(k) ) std::cout << "knowledge ";
if ( item->get_belief_item(bi, bv) ) std::cout << "belief ";
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge belief

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

◆ end() [1/2]

const_iterator InteractionMessage::end ( void  ) const
inlinenoexcept

Returns a const_iterator pointer to the beyond the last element in the list of InteractionItems.

Returns
An iterator pointing to the end of a message's InteractionItems.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
std::vector<InteractionItem> items;
items.push_back( InteractionItem().set_knowledge(4) );
items.push_back( InteractionItem().set_belief(3, 0.2) );
const InteractionMessage msg(5, 6, &medium, items);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
unsigned int k, bi, bv;
std::cout<<"This message contains:"<<std::endl;
for(auto item = msg.begin(); item != msg.end(); ++item) {
for(auto att = item->begin(); att != item->end(); ++att) {
std::cout << *att << std::endl;
}
}
}

Output:

Message Sender: 5
Message Receiver: 6
This message contains: 
knowledge 
belief

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

◆ end() [2/2]

iterator InteractionMessage::end ( void  )
inlinenoexcept

Returns an iterator pointer to the last element in the list of InteractionItems.

Returns
An iterator pointing to the end of a message's InteractionItems.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledge_item(4);
msg.add_belief_item(3, 0.2);
std::cout << "Message Sender: " << msg.sender << std::endl;
std::cout << "Message Receiver: " << msg.receiver << std::endl;
std::cout << "Message Contents: ";
unsigned int k, bi, bv;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_item(k) ) std::cout << "knowledge ";
if ( item->get_belief_item(bi, bv) ) std::cout << "belief ";
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge belief

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

◆ erase()

InteractionMessage::iterator InteractionMessage::erase ( iterator  itr)
noexcept

Removes the InteractionItem at the iterator position.

This reduces the size of the list by 1. Because the data structure is a list, inserting and removal at any position is efficient even in the middle of the sequence.

Parameters
itrIterator position of the InteractionItem to be erased.
Returns
The iterator position of the element after the erased element.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
std::vector<InteractionItem> items;
items.push_back( InteractionItem().set_knowledge(4) );
items.push_back( InteractionItem().set_belief(3, 0.2) );
InteractionMessage msg(5, 6, &medium, items);
std::cout << "Message Sender: " << msg.getSenderAgentIndex() << std::endl;
std::cout << "Message Receiver: " << msg.getReceiverAgentIndex() << std::endl;
std::cout << "Message Contents: ";
unsigned int k, bi, bv;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_item(k) ) std::cout << "knowledge ";
if ( item->get_belief_item(bi, bv) ) std::cout << "belief ";
}
std::cout << std::endl;
msg.erase(msg.begin());
std::cout << "New Message Contents: ";
unsigned int k, bi, bv;
for(auto item = msg.begin(); item != msg.end(); ++item) {
if ( item->get_knowledge_item(k) ) std::cout << "knowledge ";
if ( item->get_belief_item(bi, bv) ) std::cout << "belief ";
}
std::cout << std::endl;
}

Output:

Message Sender: 5
Message Receiver: 6
Message Contents: knowledge belief
New Message Contents: belief

Complexity

Linear on the number of elements erased (destructions) plus the number of elements after the last element deleted (moving).

Iterator validity

Iterators, pointers and references referring to the element removed by the function are invalidated. All other iterators, pointers, and references kepp their validity.

Exception Safety

If itr is valid, the function never throws exceptions. Otherwise, it causes undefined behavior.

◆ size()

unsigned int InteractionMessage::size ( )
inlinenoexcept

Returns the number of elements of InteractionItems.

Returns
The number of elements in the list of InteractionItems.

Example

int main()
{
CommunicationMedium medium("twitter", 0, 1, 1, 0);
msg.add_knowledge_item(4);
msg.add_belief_item(3, 0.2);
std::cout << "This message contains " << msg.size() << " items." << std::endl;
}

Output:

This message contains 2 items. 

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

No-throw guarantee: this member function never throws exceptions.

Member Data Documentation

◆ medium

const CommunicationMedium* InteractionMessage::medium

The communication medium the message uses.

A message is only valid if its medium is valid. The number of InteractionItems holds is limited by a medium's maximum message complexity.