Construct version 5.4.4
An agent based modeling framework
InteractionItem Struct Reference

Interaction Items is a container of three maps. Each map corresponds to a different datatype. More...

Inheritance diagram for InteractionItem:

Public Types

enum class  item_keys : char {
  knowledge , alter , belief , ktm ,
  btm , ktrust , twitter_event , facebook_event ,
  feed_position , emotion , banned , upvotes ,
  downvotes , subreddit , prev_banned , reddit_event
}
 
using attribute_iterator = std::unordered_set< item_keys >::iterator
 
using attribute_const_iterator = std::unordered_set< item_keys >::const_iterator
 
using index_iterator = std::unordered_map< item_keys, unsigned int >::iterator
 
using index_const_iterator = std::unordered_map< item_keys, unsigned int >::const_iterator
 
using value_iterator = std::unordered_map< item_keys, float >::iterator
 
using value_const_iterator = std::unordered_map< item_keys, float >::const_iterator
 

Public Member Functions

bool contains (item_keys key) const
 
InteractionItemset_knowledge_item (unsigned int knowledge_index) noexcept
 Sets an item to become a knowledge item. More...
 
InteractionItemset_knowledgeTM_item (unsigned int knowledge_index, unsigned int alter_agent) noexcept
 Sets an item to become a knowledge transactive memory item. More...
 
InteractionItemset_belief_item (unsigned int belief_index, float belief_value) noexcept
 Sets an item to become a belief item. More...
 
InteractionItemset_beliefTM_item (unsigned int belief_index, unsigned int alter_agent, float belief_value) noexcept
 Sets an item to become a belief transactive memory item. More...
 
InteractionItemset_knowledge_trust_item (unsigned int knowledge_index, float ktrust) noexcept
 Sets an item to become a knowledge trust item. More...
 
unsigned int get_knowledge () const
 Parses an item for knowledge More...
 
std::tuple< unsigned int, unsigned int > get_knowledgeTM () const
 Parses an item for knowledge transactive memory More...
 
std::tuple< unsigned int, float > get_belief () const
 Parses an item for beliefs. More...
 
std::tuple< unsigned int, unsigned int, float > get_beliefTM () const
 Parses an item for belief transactive memory. More...
 
std::tuple< unsigned int, float > get_knowledge_trust () const
 Parses an item for knowledge trust. More...
 
void clear (void) noexcept
 Clears all containers in item. More...
 

Static Public Member Functions

static const std::string & get_item_name (InteractionItem::item_keys key)
 Returns the name registered in InteractionItem::item_names for the submitted key.
 
static InteractionItem::item_keys get_item_key (const std::string &name)
 Returns the key registered in InteractionItem::item_names for the submitted name. More...
 
static InteractionItem create_knowledge_item (unsigned int knowledge_index) noexcept
 Creates a knowledge item using set_knowledge_item.

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
Returns
Returns a newly created item.
Example: More...
 
static InteractionItem create_knowledgeTM_item (unsigned int knowledge_index, unsigned int alter_agent) noexcept
 Creates a knowledge transactive memory item using set_knowledgeTM_item. More...
 
static InteractionItem create_belief_item (unsigned int belief_index, float belief_value) noexcept
 Creates a belief item using set_beliefTM_item. More...
 
static InteractionItem create_beliefTM_item (unsigned int belief_index, unsigned int alter_agent, float belief_value) noexcept
 Creates a belief transactive memory item using set_beliefTM_item. More...
 
static InteractionItem create_knowledge_trust_item (unsigned int knowledge_index, float ktrust) noexcept
 Creates a knowledge trust item using set_knowledge_trust_item. More...
 

Public Attributes

std::unordered_map< item_keys, unsigned int > indexes
 
std::unordered_map< item_keys, float > values
 
std::unordered_set< item_keysattributes
 

Static Public Attributes

static std::unordered_map< InteractionItem::item_keys, std::string > item_names
 

Detailed Description

Interaction Items is a container of three maps. Each map corresponds to a different datatype.

  • The attributes map holds a map with strings as keys to booleans. The booleans are a placeholder and are irrelevant for most purposes. Instead the presence of a key in the map corresponds to an item having that attribute.
  • The indexes map holds a map with strings as keys to unsigned ints.
  • The values map holds a map with strings as keys to floats.

Member Typedef Documentation

◆ attribute_const_iterator

using InteractionItem::attribute_const_iterator = std::unordered_set<item_keys>::const_iterator

summary>

◆ attribute_iterator

using InteractionItem::attribute_iterator = std::unordered_set<item_keys>::iterator

summary>

◆ index_const_iterator

using InteractionItem::index_const_iterator = std::unordered_map<item_keys, unsigned int>::const_iterator

summary>

◆ index_iterator

using InteractionItem::index_iterator = std::unordered_map<item_keys, unsigned int>::iterator

summary>

◆ value_const_iterator

using InteractionItem::value_const_iterator = std::unordered_map<item_keys, float>::const_iterator

summary> Calls InteractionItem::attributes::contains and returns the result.

◆ value_iterator

using InteractionItem::value_iterator = std::unordered_map<item_keys, float>::iterator

summary>

Member Enumeration Documentation

◆ item_keys

enum class InteractionItem::item_keys : char
strong

Keys used for an InteractionItem.

Member Function Documentation

◆ clear()

void InteractionItem::clear ( void  )
noexcept

Clears all containers in item.

attributes, indexes, and values are cleared using unordered_map::clear.

Example

void print_item(const InteractionItem& item) {
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::belief)) {
auto [b_index, b_value] = item.get_belief();
std::cout << "belief index: " << belief_index << std::endl;
std::cout << "belief value: " << belief_value << std::endl;
}
if (item.contains(InteractionItem::item_keys::knowledge)) {
std::cout << "knowledge index: " << item.get_knowledge() << std::endl;
}
};
int main()
{
print_item(item);
item.set_belief_item(4, 0.3);
print_item(item);
item.clear();
item.set_belief_item(6, 0.2);
print_item(item);
}
Interaction Items is a container of three maps. Each map corresponds to a different datatype.
Definition: InteractionMessage.h:33
unsigned int get_knowledge() const
Parses an item for knowledge
Definition: InteractionMessage.cpp:106
void clear(void) noexcept
Clears all containers in item.
Definition: InteractionMessage.cpp:160
std::tuple< unsigned int, float > get_belief() const
Parses an item for beliefs.
Definition: InteractionMessage.cpp:126
InteractionItem & set_belief_item(unsigned int belief_index, float belief_value) noexcept
Sets an item to become a belief item.
Definition: InteractionMessage.cpp:57
InteractionItem & set_knowledge_item(unsigned int knowledge_index) noexcept
Sets an item to become a knowledge item.
Definition: InteractionMessage.cpp:40

Output:

This item contains:
knowledge index 5
This item contains:
knowledge index: 5
belief index: 3
belief value: 0.4
This item contains:
belief index: 5
belief value: 0.2

Complexity

Linear in container size of attributes, indexes, and values.

Iterator validity

All iterators, pointers, and references are invalidated.

Exception Safety

This member function never throws exceptions.

◆ create_belief_item()

InteractionItem InteractionItem::create_belief_item ( unsigned int  belief_index,
float  belief_value 
)
staticnoexcept

Creates a belief item using set_beliefTM_item.

Parameters
belief_indexValue the "belief" key in indexes is set to.
belief_valueValue the "belief" key in values is set to.
Returns
Returns the newly created item.

Example

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::belief)) {
auto [b_index, b_value] = item.get_belief();
std::cout << "belief index: " << b_index << std::endl;
std::cout << "belief value: " << b_value << std::endl;
}
}
static InteractionItem create_belief_item(unsigned int belief_index, float belief_value) noexcept
Creates a belief item using set_beliefTM_item.
Definition: InteractionMessage.cpp:91

Output:

This item contains:
belief index: 5
belief value: 0.3

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes, indexes and values.

Iterator validity

In most cases, all iterators in the attributes, indexes, and values container remain valid with the only exception when any container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

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

◆ create_beliefTM_item()

InteractionItem InteractionItem::create_beliefTM_item ( unsigned int  belief_index,
unsigned int  alter_agent,
float  belief_value 
)
staticnoexcept

Creates a belief transactive memory item using set_beliefTM_item.

Parameters
belief_indexValue the "belief" key in indexes is set to.
alter_agentValue the "alter" key in indexes is set to.
belief_valueValue the "belief" key in values is set to.
Returns
Returns the newly created item.

Example

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::btm)) {
auto [b_index, alter, b_value] = item.get_beliefTM();
std::cout << "belief index: " << b_index << std::endl;
std::cout << "alter agent index: " << alter << std::endl;
std::cout << "belief value: " << b_value << std::endl;
}
}
std::tuple< unsigned int, unsigned int, float > get_beliefTM() const
Parses an item for belief transactive memory.
Definition: InteractionMessage.cpp:136
static InteractionItem create_beliefTM_item(unsigned int belief_index, unsigned int alter_agent, float belief_value) noexcept
Creates a belief transactive memory item using set_beliefTM_item.
Definition: InteractionMessage.cpp:96

Output:

This item contains:
belief index: 5
alter agent index: 4
belief value: 0.3

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes, indexes, and values.

Iterator validity

In most cases, all iterators in the attributes, indexes, and values container remain valid with the only exception when any container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

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

◆ create_knowledge_item()

InteractionItem InteractionItem::create_knowledge_item ( unsigned int  knowledge_index)
staticnoexcept

Creates a knowledge item using set_knowledge_item.

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
Returns
Returns a newly created item.
Example:

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::knowledge)) {
std::cout << "knowledge index: " << item.get_knowledge() << std::endl;
}
}
static InteractionItem create_knowledge_item(unsigned int knowledge_index) noexcept
Creates a knowledge item using set_knowledge_item. Value the "knowledge" key in indexes is set to....
Definition: InteractionMessage.cpp:81

Output:

This item contains:
knowledge index: 5

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes and indexes.

Iterator validity

No changes to iterators for values. In most cases, all iterators in the attributes and indexes container remain valid with the only exception when either container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the call graph for this function:

◆ create_knowledge_trust_item()

InteractionItem InteractionItem::create_knowledge_trust_item ( unsigned int  knowledge_index,
float  ktrust 
)
staticnoexcept

Creates a knowledge trust item using set_knowledge_trust_item.

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
ktrustValue the "knowledge trust" key in values is set to.
Returns
Returns the newly created item.

Example

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::ktrust)) {
auto [k, trust] = item.get_knowledge_trust();
std::cout << "knowledge index: " << k << std::endl;
std::cout << "knowledge trust value: " << trust << std::endl;
}
}
std::tuple< unsigned int, float > get_knowledge_trust() const
Parses an item for knowledge trust.
Definition: InteractionMessage.cpp:148
static InteractionItem create_knowledge_trust_item(unsigned int knowledge_index, float ktrust) noexcept
Creates a knowledge trust item using set_knowledge_trust_item.
Definition: InteractionMessage.cpp:101

Output:

This item contains:
knowledge index: 5
knowledge trust value: 0.3

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes, indexes and values.

Iterator validity

In most cases, all iterators in the attributes, indexes, and values container remain valid with the only exception when any container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the call graph for this function:

◆ create_knowledgeTM_item()

InteractionItem InteractionItem::create_knowledgeTM_item ( unsigned int  knowledge_index,
unsigned int  alter_agent 
)
staticnoexcept

Creates a knowledge transactive memory item using set_knowledgeTM_item.

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
alter_agentValue the "alter" key in indexes is set to.
Returns
Returns the newly created item.

Example

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::ktm)) {
auto [k, alter] = item.get_knowledgeTM_item();
std::cout << "knowledge index: " << k << std::endl;
std::cout << "alter agent index: " << alter << std::endl;
}
}
static InteractionItem create_knowledgeTM_item(unsigned int knowledge_index, unsigned int alter_agent) noexcept
Creates a knowledge transactive memory item using set_knowledgeTM_item.
Definition: InteractionMessage.cpp:86

Output:

This item contains:
knowledge index: 5
alter agent index: 4

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes and indexes.

Iterator validity

No changes to iterators for values. In most cases, all iterators in the attributes and indexes container remain valid with the only exception when either container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

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

◆ get_belief()

std::tuple< unsigned int, float > InteractionItem::get_belief ( ) const

Parses an item for beliefs.

Item should be checked to ensure it contains beliefs (InteractionItem::contains(InteractionItem::item_keys::belief)).

Returns
Returns a tuple with the first element being indexes[InteractionItem::item_keys::belief] and the second element being values[InteractionItem::item_keys::belief].

Example

int main()
{
item.attributes.insert(item_keys::belief);
item.indexes[item_keys::belief] = 3;
item.values[item_keys::belief] = 0.4;
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::belief)) {
auto [b_index, b_value] = item.get_belief();
std::cout << "belief index: " << b_index << std::endl;
std::cout << "belief value: " << b_value << std::endl;
}
}
std::unordered_map< item_keys, float > values
Definition: InteractionMessage.h:981
std::unordered_map< item_keys, unsigned int > indexes
Definition: InteractionMessage.h:977
std::unordered_set< item_keys > attributes
Definition: InteractionMessage.h:985

Output:

This item contains:
belief index: 3
belief value: 0.4

Complexity

This function uses unordered_map::find.
Average case: constant.
Worst case: linear in container size of attributes, indexes, and values.

Iterator validity

No changes.

Exception Safety

An assertion is raised when indexes does not contain an entry with the key InteractionItem::item_keys::belief or values does not contain an entry with the key InteractionItem::item_keys::belief.

◆ get_beliefTM()

std::tuple< unsigned int, unsigned int, float > InteractionItem::get_beliefTM ( ) const

Parses an item for belief transactive memory.

Item should be checked to ensure it contains beliefs (InteractionItem::contains(InteractionItem::item_keys::btm)).

Returns
Returns a tuple with the first element being indexes[InteractionItem::item_keys::belief], the second element being indexes[InteractionItem::item_keys::alter], and the third element being values[InteractionItem::item_keys::belief].

Example

int main()
{
item.attributes.insert(item_keys::btm);
item.indexes[item_keys::belief] = 3;
item.indexes[item_keys::alter] = 5;
item.values[item_keys::belief] = 0.4;
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::btm)) {
auto [b_index, alter, b_value] = item.get_beliefTM();
std::cout << "belief index: " << b_index << std::endl;
std::cout << "alter agent index: " << alter << std::endl;
std::cout << "belief value: " << b_value << std::endl;
}
}

Output:

This item contains:
belief index: 3
alter agent index: 5
belief value: 0.4

Complexity

This function uses unordered_map::find.
Average case: constant.
Worst case: linear in container size of attributes, indexes, and values.

Iterator validity

No changes.

Exception Safety

An assertion is raised when indexes does not contain an entry with the key InteractionItem::item_keys::belief or InteractionItem::item_keys::alter or values does not contain an entry with the key InteractionItem::item_keys::belief.

◆ get_item_key()

InteractionItem::item_keys InteractionItem::get_item_key ( const std::string &  name)
static

Returns the key registered in InteractionItem::item_names for the submitted name.

summary>

Here is the caller graph for this function:

◆ get_knowledge()

unsigned int InteractionItem::get_knowledge ( ) const

Parses an item for knowledge

Item should be checked to ensure it contains knowledge (InteractionItem::contains(InteractionItem::item_keys::knowledge)).

Returns
Returns the index at indexes[InteractionItem::item_keys::knowledge].

Example

int main()
{
item.attributes.insert(InteractionItem::item_keys::knowledge);
item.indexes[item_keys::knowledge] = 3;
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::knowledge)) {
std::cout << "knowledge index: " << item.get_knowledge() << std::endl;
}
}

Output:

This item contains:
knowledge index: 3

Complexity

This function uses unordered_map::find.
Average case: constant.
Worst case: linear in container size of attributes and indexes.

Iterator validity

No changes.

Exception Safety

An assertion is raised when indexes does not contain an entry with the key InteractionItem::item_keys::knowledge.

Here is the caller graph for this function:

◆ get_knowledge_trust()

std::tuple< unsigned int, float > InteractionItem::get_knowledge_trust ( ) const

Parses an item for knowledge trust.

Item should be checked to ensure it contains knowledge turst (InteractionItem::contains(InteractionItem::item_keys::ktrust)).

Returns
Returns a tuple with the first element being indexes[InteractionItem::item_keys::knowledge] and the second element being values[InteractionItem::item_keys::ktrust].

Example

int main()
{
item.attributes.insert(item_keys::ktrust);
item.indexes[item_keys::knowledge] = 3;
item.values[item_keys::ktrust] = 0.4;
unsigned int knowledge_index;
float ktrust;
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::ktrust)) {
auto [k, trust] = item.get_knowledge_trust();
std::cout << "knowledge index: " << k << std::endl;
std::cout << "knowledge trust value: " << trust << std::endl;
}
}

Output:

This item contains:
knowledge index: 3
knowledge trust: 0.4

Complexity

This function uses unordered_map::find.
Average case: constant.
Worst case: linear in container size of attributes, indexes, and values.

Iterator validity

No changes.

Exception Safety

An assertion is raised when an item's indexes does not contain the key InteractionItem::item_keys::knowledge, or values does not contain the key InteractionItem::item_keys::ktrust.

Here is the caller graph for this function:

◆ get_knowledgeTM()

std::tuple< unsigned int, unsigned int > InteractionItem::get_knowledgeTM ( ) const

Parses an item for knowledge transactive memory

Item should be checked to ensure it contains knowledge transactive memory (InteractionItem::contains(InteractionItem::item_keys::ktm)).

Returns
Returns a tuple with the first element being indexes[InteractionItem::item_keys::knowledge] and the second element being indexes[InteractionItem::item_keys::alter].

Example

int main()
{
item.attributes.insert(item_keys::ktm);
item.indexes[item_keys::knowledge] = 3;
item.indexes[item_keys::alter] = 4;
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::ktm)) {
auto [k, alter] = item.get_knowledgeTM_item();
std::cout << "knowledge index: " << k << std::endl;
std::cout << "alter agent index: " << alter << std::endl;
}
}

Output:

This item contains:
knowledge index: 3
alter agent index: 4

Complexity

This function uses unordered_map::find.
Average case: constant.
Worst case: linear in container size of attributes and indexes.

Iterator validity

No changes.

Exception Safety

An assertion is raised when indexes does not contain an entry with the key InteractionItem::item_keys::knowledge or InteractionItem::item_keys::alter.

◆ set_belief_item()

InteractionItem & InteractionItem::set_belief_item ( unsigned int  belief_index,
float  belief_value 
)
noexcept

Sets an item to become a belief item.

Adds InteractionItem::item_keys::belief to the item's attributes. Sets the item's indexes[InteractionItem::item_keys::belief] to the belief index and the item's values[InteractionItem::item_keys::belief] to the belief value.

Parameters
belief_indexValue the "belief" key in indexes is set to.
belief_valueValue the "belief" key in values is set to.
Returns
Returns the updated item.

Example

int main()
{
item.set_belief_item(5, 0.3);
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::belief)) {
auto [b_index, b_value] = item.get_belief();
std::cout << "belief index: " << b_index << std::endl;
std::cout << "belief value: " << b_value << std::endl;
}
}

Output:

This item contains:
belief index: 5
belief value: 0.3

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes, indexes and values.

Iterator validity

In most cases, all iterators in the attributes, indexes, and values container remain valid with the only exception when any container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the caller graph for this function:

◆ set_beliefTM_item()

InteractionItem & InteractionItem::set_beliefTM_item ( unsigned int  belief_index,
unsigned int  alter_agent,
float  belief_value 
)
noexcept

Sets an item to become a belief transactive memory item.

Adds the following keys to the item's attributes:

  • InteractionItem::item_keys::belief
  • InteractionItem::item_keys::alter
  • InteractionItem::item_keys::btm

Updates the following data structures:

  • indexes[InteractionItem::item_keys::belief] to the belief index
  • indexes[InteractionItem::item_keys::alter] to the alter index
  • values[InteractionItem::item_keys::belief] to the belief value
Parameters
belief_indexValue the "belief" key in indexes is set to.
alter_agentValue the "alter" key in indexes is set to.
belief_valueValue the "belief" key in values is set to.
Returns
Returns the updated item.

Example

int main()
{
item.set_beliefTM_item(5, 4, 0.3);
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::btm)) {
auto [b_index, alter, b_value] = item.get_beliefTM();
std::cout << "belief index: " << b_index << std::endl;
std::cout << "alter agent index: " << alter << std::endl;
std::cout << "belief value: " << b_value << std::endl;
}
}
InteractionItem & set_beliefTM_item(unsigned int belief_index, unsigned int alter_agent, float belief_value) noexcept
Sets an item to become a belief transactive memory item.
Definition: InteractionMessage.cpp:64

Output:

This item contains:
belief index: 5
alter agent index: 4
belief value: 0.3

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes, indexes, and values.

Iterator validity

In most cases, all iterators in the attributes, indexes, and values container remain valid with the only exception when any container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the caller graph for this function:

◆ set_knowledge_item()

InteractionItem & InteractionItem::set_knowledge_item ( unsigned int  knowledge_index)
noexcept

Sets an item to become a knowledge item.

Adds item_keys::knowledge to the item's attributes. Adds the corresponding index to the item's indexes using the same key.

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
Returns
Returns the updated item.

Example:

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::knowledge)) {
std::cout << "knowledge index: " << item.get_knowledge() << std::endl;
}
}

Output:

This item contains:
knowledge index: 5

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes and indexes.

Iterator validity

No changes to iterators for values. In most cases, all iterators in the attributes and indexes container remain valid with the only exception when either container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the caller graph for this function:

◆ set_knowledge_trust_item()

InteractionItem & InteractionItem::set_knowledge_trust_item ( unsigned int  knowledge_index,
float  ktrust 
)
noexcept

Sets an item to become a knowledge trust item.

Adds InteractionItem::item_keys::knowledge and InteractionItem::item_keys::ktrust to the item. Sets indexes[InteractionItem::item_keys::knowledge] to the knowledge index and values[InteractionItem::item_keys::ktrust] to the knowledge trust.

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
ktrustValue the "knowledge trust" key in values is set to.
Returns
Returns the updated item.

Example

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::ktrust)) {
auto [k, trust] = item.get_knowledge_trust();
std::cout << "knowledge index: " << k << std::endl;
std::cout << "knowledge trust value: " << trust << std::endl;
}
}
InteractionItem & set_knowledge_trust_item(unsigned int knowledge_index, float ktrust) noexcept
Sets an item to become a knowledge trust item.
Definition: InteractionMessage.cpp:73

Output:

This item contains:
knowledge index: 5
knowledge trust value: 0.3

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes, indexes and values.

Iterator validity

In most cases, all iterators in the attributes, indexes, and values container remain valid with the only exception when any container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the caller graph for this function:

◆ set_knowledgeTM_item()

InteractionItem & InteractionItem::set_knowledgeTM_item ( unsigned int  knowledge_index,
unsigned int  alter_agent 
)
noexcept

Sets an item to become a knowledge transactive memory item.

Adds InteractionItem::item_keys::ktm, InteractionItem::item_keys::knowledge, and InteractionItem::item_keys::alter to the item's attributes. The knowledge index is saved at indexes[InteractionItem::item_keys::knowledge] and the alter index is saved at indexes[InteractionItem::item_keys::alter].

Parameters
knowledge_indexValue the "knowledge" key in indexes is set to.
alter_agentValue the "alter" key in indexes is set to.
Returns
Returns the updated item.

Example

int main()
{
std::cout << "This item contains:" << std::endl;
if(item.contains(InteractionItem::item_keys::ktm)) {
auto [k, alter] = item.get_knowledgeTM_item();
std::cout << "knowledge index: " << k << std::endl;
std::cout << "alter agent index: " << alter << std::endl;
}
}
InteractionItem & set_knowledgeTM_item(unsigned int knowledge_index, unsigned int alter_agent) noexcept
Sets an item to become a knowledge transactive memory item.
Definition: InteractionMessage.cpp:46

Output:

This item contains:
knowledge index: 5
alter agent index: 4

Complexity

This function uses unordered_map::insert.
Average case: constant.
Worst case: linear in container size of attributes and indexes.

Iterator validity

No changes to iterators for values. In most cases, all iterators in the attributes and indexes container remain valid with the only exception when either container is rehashed. See unordered_map::insert for further details.

Exception Safety

This member function never throws exceptions.

Here is the caller graph for this function:

Member Data Documentation

◆ item_names

std::unordered_map< InteractionItem::item_keys, std::string > InteractionItem::item_names
static
Initial value:
{
{InteractionItem::item_keys::knowledge, "knowledge"},
{InteractionItem::item_keys::alter, "alter"},
{InteractionItem::item_keys::belief, "belief"},
{InteractionItem::item_keys::ktm, "knowledgeTM"},
{InteractionItem::item_keys::btm, "beliefTM"},
{InteractionItem::item_keys::ktrust, "knowledge trust"},
{InteractionItem::item_keys::twitter_event, "twitter event"},
{InteractionItem::item_keys::facebook_event,"facebook event"},
{InteractionItem::item_keys::feed_position, "feed position"},
{InteractionItem::item_keys::emotion, "emotion"},
{InteractionItem::item_keys::banned, "banned"}
}