Construct version 5.3.9
An agent based modeling framework
InteractionMessageQueue Class Reference

An InteractionMessageQueue is a container of InteractionMessages using a list. More...

Public Types

using iterator = std::list< InteractionMessage >::iterator
 
using const_iterator = std::list< InteractionMessage >::const_iterator
 
using reverse_iterator = std::list< InteractionMessage >::reverse_iterator
 
using const_reverse_iterator = std::list< InteractionMessage >::const_reverse_iterator
 

Public Member Functions

iterator begin (void) noexcept
 Returns an iterator pointer to the first element in the list of InteractionMessages. More...
 
iterator end (void) noexcept
 Returns an iterator pointer to the after-the-last element in the list of InteractionMessages. More...
 
const_iterator begin (void) const noexcept
 Returns a const_iterator pointer to the first element in the list of InteractionMessages. More...
 
const_iterator end (void) const noexcept
 Returns a const_iterator pointer to the last element in the list of InteractionMessages. More...
 
reverse_iterator rbegin (void) noexcept
 Returns an iterator pointer to the last element in the list of InteractionMessages. More...
 
reverse_iterator rend (void) noexcept
 Returns an iterator pointer to the before-the-first element in the list of InteractionMessages. More...
 
const_reverse_iterator rbegin (void) const noexcept
 Returns a const_reverse_iterator pointer to the last element in the list of InteractionMessages. More...
 
const_reverse_iterator rend (void) const noexcept
 Returns a const_reverse_iterator pointer to the before-the-first element in the list of InteractionMessages. More...
 
void clear (void) noexcept
 Clears the list of InteractionMessages. More...
 
void addMessage (const InteractionMessage &msg)
 Adds the msg to the list of InteractionMessages. More...
 
iterator erase (iterator itr) noexcept
 Removes the InteractionMessage at the iterator position. More...
 

Detailed Description

An InteractionMessageQueue is a container of InteractionMessages using a list.

Messages are used send information from one agent to another agent. This class allows the list of all messages to be centralized in one structure.

Member Function Documentation

◆ addMessage()

void InteractionMessageQueue::addMessage ( const InteractionMessage msg)

Adds the msg to the list of InteractionMessages.

An InteractionMessage is only added to the list if the Message is valid. Messages enter the list at the front using list::push_front.

Parameters
msgInteractionMessage to be added to the list of InteractionMessages.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
Nodeset::iterator n = construct->getNodesetManager()->get_nodeset(nodeset_names::comm)->begin();
InteractionMessage msg1(5, 6, medium);
msg1.add_knowledge_item(4);
queue->addMessage(msg1);
InteractionMessage msg2(3, 4, medium);
msg2.add_belief_item(3, 0.2);
queue->addMessage(msg2);
for(auto msg = queue->begin(); msg != queue->end(); ++msg) {
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;
}
An Interaction Message is a container for InteractionItems. In addition a message has a sender,...
Definition: InteractionMessage.h:1077
An InteractionMessageQueue is a container of InteractionMessages using a list.
Definition: InteractionMessage.h:1871
void addMessage(const InteractionMessage &msg)
Adds the msg to the list of InteractionMessages.
Definition: InteractionMessage.cpp:281
iterator end(void) noexcept
Returns an iterator pointer to the after-the-last element in the list of InteractionMessages.
Definition: InteractionMessage.h:1958
iterator begin(void) noexcept
Returns an iterator pointer to the first element in the list of InteractionMessages.
Definition: InteractionMessage.h:1918
Class to contain the medium used by InteractionMessage% s.
Definition: CommunicationMedium.h:19

Output:

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

Complexity

Constant based on list::push_front.

Iterator validity

No changes

Exception Safety

This function never throws an exception.

Here is the caller graph for this function:

◆ begin() [1/2]

const_iterator InteractionMessageQueue::begin ( void  ) const
inlinenoexcept

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

Returns
A const_iterator pointing to the beginning of the queue's InteractionMessagess.

Example

const InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->begin(); msg != queue->end(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}

Output:

Message Sender - 1 : Message Receiver - 3
Message Sender - 4 : Message Receiver - 1
Message Sender - 3 : Message Receiver - 5

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

◆ begin() [2/2]

iterator InteractionMessageQueue::begin ( void  )
inlinenoexcept

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

Returns
An iterator pointing to the beginning of the queue's InteractionMessagess.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->begin(); msg != queue->end(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}

Output:

Message Sender - 1 : Message Receiver - 3
Message Sender - 4 : Message Receiver - 1
Message Sender - 3 : Message Receiver - 5

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

Here is the caller graph for this function:

◆ clear()

void InteractionMessageQueue::clear ( void  )
inlinenoexcept

Clears the list of InteractionMessages.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->begin(); msg != queue->end(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}
queue->clear();
std::cout << "Message queue size: " queue->size() << std::endl;
void clear(void) noexcept
Clears the list of InteractionMessages.
Definition: InteractionMessage.h:2227

Output:

Message Sender - 1 : Message Receiver - 3
Message Sender - 4 : Message Receiver - 1
Message Sender - 3 : Message Receiver - 5
Message queue size: 0

Complexity

Linear in number of InteractionMessages in list.

Iterator validity

All iterators, pointers, and references are invalidated.

Here is the caller graph for this function:

◆ end() [1/2]

const_iterator InteractionMessageQueue::end ( void  ) const
inlinenoexcept

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

Returns
A const_iterator pointing to the beyond the last element of the queue's InteractionMessagess. This iterator points to the element that would be created if an element is created at the end of the list. This iterator is invalid and should not be dereferenced.

Example

const InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->begin(); msg != queue->end(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}

Output:

Message Sender - 1 : Message Receiver - 3
Message Sender - 4 : Message Receiver - 1
Message Sender - 3 : Message Receiver - 5

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

◆ end() [2/2]

iterator InteractionMessageQueue::end ( void  )
inlinenoexcept

Returns an iterator pointer to the after-the-last element in the list of InteractionMessages.

Returns
An iterator pointing to the beyond the last element of the queue's InteractionMessagess. This iterator points to the element that would be created if an element is created at the end of the list. This iterator is invalid and should not be dereferenced.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->begin(); msg != queue->end(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}

Output:

Message Sender - 1 : Message Receiver - 3
Message Sender - 4 : Message Receiver - 1
Message Sender - 3 : Message Receiver - 5

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

Here is the caller graph for this function:

◆ erase()

InteractionMessageQueue::iterator InteractionMessageQueue::erase ( iterator  itr)
noexcept

Removes the InteractionMessage at the iterator position.

This reduces the size of the list by 1 and destroys the element. 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 InteractionMessage to be erased.
Returns
The iterator position of the element after the erased element.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
Nodeset::iterator n = construct->getNodesetManager()->get_nodeset(nodeset_names::comm)->begin();
InteractionMessage msg1(5, 6, InteractionItem().set_knowledge(4), medium);
msg1.add_knowledge_item(4);
queue->addMessage(msg1);
InteractionMessage msg2(3, 4, InteractionItem().set_belief(3, 0.2), medium);
msg2.add_belief_item(3, 0.2);
queue->addMessage(msg2);
for(auto msg = queue->begin(); msg != queue->end();) {
if (msg->sender == 3) {
msg = queue->erase(msg);
}
else {
std::cout << "Message Sender: " << msg->sender << std::endl;
std::cout << "Message Receiver: " << msg->sender << std::endl;
std::cout << "Message Contents: ";
InteractionMessage::iterator item = msg->begin();
unsigned int k, bi, bv;
for(item; 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;
}
}
iterator erase(iterator itr) noexcept
Removes the InteractionMessage at the iterator position.
Definition: InteractionMessage.cpp:286
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

Complexity

Constant based on list::erase.

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.

Here is the caller graph for this function:

◆ rbegin() [1/2]

const_reverse_iterator InteractionMessageQueue::rbegin ( void  ) const
inlinenoexcept

Returns a const_reverse_iterator pointer to the last element in the list of InteractionMessages.

Returns
A const_reverse_iterator pointing to the end of the queue's InteractionMessagess.

Example

const InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->rbegin(); msg != queue->rend(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}
reverse_iterator rend(void) noexcept
Returns an iterator pointer to the before-the-first element in the list of InteractionMessages.
Definition: InteractionMessage.h:2114
reverse_iterator rbegin(void) noexcept
Returns an iterator pointer to the last element in the list of InteractionMessages.
Definition: InteractionMessage.h:2074

Output:

Message Sender - 3 : Message Receiver - 5
Message Sender - 4 : Message Receiver - 1
Message Sender - 1 : Message Receiver - 3

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

◆ rbegin() [2/2]

reverse_iterator InteractionMessageQueue::rbegin ( void  )
inlinenoexcept

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

Returns
An iterator pointing to the end of the queue's InteractionMessagess.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->rbegin(); msg != queue->rend(); ++msg) {
std::cout << "Message Sender - " << msg->getSenderAgentIndex() << " : ";
std::cout << "Message Receiver - " << msg->getReceiverAgentIndex() << std::endl;
}

Output:

Message Sender - 1 : Message Receiver - 3
Message Sender - 4 : Message Receiver - 1
Message Sender - 3 : Message Receiver - 5

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

◆ rend() [1/2]

const_reverse_iterator InteractionMessageQueue::rend ( void  ) const
inlinenoexcept

Returns a const_reverse_iterator pointer to the before-the-first element in the list of InteractionMessages.

Returns
A const_reverse_iterator pointing to the beginning of the queue's InteractionMessagess. This iterator points to the element that would be created if an element is created at the beginning of the list. This iterator is invalid and should not be dereferenced.

Example

const InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = msg->rbegin(); msg != queue->rend(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}

Output:

Message Sender - 3 : Message Receiver - 5
Message Sender - 4 : Message Receiver - 1
Message Sender - 1 : Message Receiver - 3

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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

◆ rend() [2/2]

reverse_iterator InteractionMessageQueue::rend ( void  )
inlinenoexcept

Returns an iterator pointer to the before-the-first element in the list of InteractionMessages.

Returns
An iterator pointing to the beyond of the beginning of the queue's InteractionMessagess. This iterator points to the element that would be created if an element is created at the beginning of the list. This iterator is invalid and should not be dereferenced.

Example

InteractionMessageQueue* queue = construct->get_private_message_queue();
for(auto msg = queue->rbegin(); msg != queue->rend(); ++msg) {
std::cout << "Message Sender - " << msg->sender << " : ";
std::cout << "Message Receiver - " << msg->receiver << std::endl;
}

Output:

Message Sender - 3 : Message Receiver - 5
Message Sender - 4 : Message Receiver - 1
Message Sender - 1 : Message Receiver - 3

Complexity

Constant.

Iterator validity

No changes.

Exception Safety

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