Construct version 5.4.4
An agent based modeling framework
Model Struct Reference

Parent class for Construct models. More...

Inheritance diagram for Model:
Collaboration diagram for Model:

Public Member Functions

 Model (Construct &_construct)
 Constructor for all models in Construct. More...
 
virtual ~Model (void)
 Virtual Deconstructor. More...
 
virtual void initialize (void)
 Function called once before any simulation cycles begin. More...
 
virtual void think (void)
 First function called in a simulation cycle. More...
 
virtual void update (void)
 Function called after the think functions in a simulation cycle. More...
 
virtual bool intercept (InteractionItem &item, unsigned int sender, unsigned int receiver, const CommunicationMedium *medium)
 Allows for models to effect change to items created by other models. More...
 
virtual void communicate (const InteractionMessage &msg)
 Function called after the update functions in a simulation cycle. More...
 
virtual void cleanup (void)
 Function called after the Model::communicate functions in a simulation cycle. More...
 
void add_base_model_to_model_manager (const std::string &base_model_name)
 Adds a derived model under the name of the base model and disables the model manager from calling its functions.
 

Public Attributes

Constructconstruct
 
GraphManagergraph_manager
 
NodesetManagerns_manager
 
Randomrandom
 
bool valid
 If member is false, the model's functions are not called.
 

Detailed Description

Parent class for Construct models.

This parent class allows all model pointers to be stored in the same array. All models are required to have a custom constructor, and 5 real functions to take the place of the virtual functions. A deconstructor is not required for models. By default models are considered valid unless explicitly stated otherwise. Non-valid models won't have their virtual functions called.

summary>

Constructor & Destructor Documentation

◆ Model()

Model::Model ( Construct _construct)

Constructor for all models in Construct.

All models require the Construct pointer and the name of the model to be defined. The Construct pointer is transferred via ModelManager::create_model which Construct passes to the ModelManager. All model names can be found in the namespace model_names. All models are valid by default unless otherwise stated. If a model is not valid, its functions are not called by the ModelManager.

◆ ~Model()

virtual Model::~Model ( void  )
inlinevirtual

Virtual Deconstructor.

Deconstructor is virtual so that when a Model is deallocated by the ModelManager, the derived model's deconstructor is also called. This virtual deconstructor preforms no operations.

Member Function Documentation

◆ cleanup()

virtual void Model::cleanup ( void  )
inlinevirtual

Function called after the Model::communicate functions in a simulation cycle.

End of cycle calculations are done during this function. Model::cleanup is called after GraphManager::push_deltas is called.

Reimplemented in SM_wf_emotions, KnowledgeTransactiveMemory, Subscription, Beliefs, Emotions, Forget, GrandInteraction, Trust, Location, Social_Media_no_followers, Social_Media_with_followers, Tasks, and Template.

◆ communicate()

virtual void Model::communicate ( const InteractionMessage msg)
inlinevirtual

Function called after the update functions in a simulation cycle.

Messages are typically parsed in this function.

Reimplemented in Emotions, SM_wf_emotions, Forget, GrandInteraction, KnowledgeTransactiveMemory, Trust, Social_Media_no_followers, Social_Media_with_followers, Subscription, and Template.

◆ initialize()

◆ intercept()

virtual bool Model::intercept ( InteractionItem item,
unsigned int  sender,
unsigned int  receiver,
const CommunicationMedium medium 
)
inlinevirtual

Allows for models to effect change to items created by other models.

A model change add, modify, or remove information from an item based other submitted information. Also allows for models to control what InteractionItems get created. Senders and receiver indexes can include values from 0 to and including the size of the agent nodeset. Always check if the index is equal to the agent nodeset size before accessing a node or network value. The medium can be a node in the medium nodeset, a medium for a specific model, or a null pointer. Always check that a node is not a null pointer before derefrencing it. Complexity and exceptions depend entirely on each models specific implementation. By default, models allow items to be created without modifying them.

Parameters
itemThe InteractionItem that is being created. This item can modified as each model sees fit.
senderThe index for the agent that is the source of the InteractionItem.
receiverThe index for the agent that is receiving the item. If the item does not have an intended recipient, its value will equal the agent nodeset size.
mediumThe communication medium intended for the item. If the medium is not yet chosen, it will be a null pointer. The medium may or may not be in the medium nodeset and there are no restraints on what index the medium could have.
Returns
Whether the item should be allowed to continue to exist (false) or if item should be discarded (true).

Example

item.set_knowledge(5);
knowledge_trust_net.at(4, 5) = 0.2;
auto [k, trust] = item.get_knowledge_trust();
std::cout << trust << std::endl;
const std::string TRUST
Definition: Model.h:306
ModelManager model_manager
The manager that holds all the models and executes all of their various functions.
Definition: Construct.h:111
Interaction Items is a container of three maps. Each map corresponds to a different datatype.
Definition: InteractionMessage.h:33
std::tuple< unsigned int, float > get_knowledge_trust() const
Parses an item for knowledge trust.
Definition: InteractionMessage.cpp:148
Construct & construct
Definition: Model.h:75
virtual bool intercept(InteractionItem &item, unsigned int sender, unsigned int receiver, const CommunicationMedium *medium)
Allows for models to effect change to items created by other models.
Definition: Model.h:177
Model * get_model(const std::string &name)
Definition: ModelManager.h:38

Output:

0.2

Reimplemented in Emotions, KnowledgeLearningDifficulty, Trust, and Social_Media_Moderation.

◆ think()

virtual void Model::think ( void  )
inlinevirtual

First function called in a simulation cycle.

Messages are typically created in this function.

Reimplemented in Subscription, Forget, Location, Social_Media_no_followers, StandardInteraction, and Template.

◆ update()

virtual void Model::update ( void  )
inlinevirtual

Function called after the think functions in a simulation cycle.

Messages are typically amended and/or removed in this function.

Reimplemented in Trust, Mail, and Template.

Member Data Documentation

◆ construct

Construct& Model::construct

summary>

◆ graph_manager

GraphManager& Model::graph_manager

summary>

◆ ns_manager

NodesetManager& Model::ns_manager

summary>