Agent class for socmod
Agent class for socmod
Details
Represents an individual agent in a social network. Each agent stores behavioral,
fitness, and neighbor information. This class is designed to be encapsulated,
with all data access via getter/setter methods.
Methods
Method new()
Initialize an Agent
Sets up a new Agent instance with an ID, optional name, initial behavior,
and fitness values. Behavior and fitness are copied into both the current
and next state fields. A Neighbors container is also initialized.
Usage
Agent$new(id, name = NULL, behavior = "0", fitness = 0)
Arguments
id
Integer or string ID for the agent (used internally, not necessarily name)
name
Optional character name for the agent. Defaults to "aid".
behavior
Initial behavior (character). Default is "0".
fitness
Initial fitness (numeric). Default is 0.
Method get_id()
Get the agent's vertex ID
Method get_name()
Get the agent's name
Method set_name()
Set the agent's name
Method get_behavior()
Get current behavior
Method set_behavior()
Set current behavior
Usage
Agent$set_behavior(value)
Arguments
value
New current behavior
Method get_next_behavior()
Get next behavior
Usage
Agent$get_next_behavior()
Method set_next_behavior()
Set next behavior
Usage
Agent$set_next_behavior(value)
Method get_fitness()
Get current fitness
Method set_fitness()
Set current fitness
Arguments
value
Numeric value to assign
Method get_next_fitness()
Get next fitness
Method set_next_fitness()
Set next fitness
Usage
Agent$set_next_fitness(value)
Arguments
value
Numeric value to assign
Method advance_behavior()
Advance to the next behavior
Method advance_fitness()
Advance to the next fitness
Method get_neighbors()
Get neighbors object
Method set_neighbors()
Set neighbors object
Usage
Agent$set_neighbors(nbrs)
Arguments
nbrs
A Neighbors instance
Method add_neighbors()
Add one or more neighbors
Arguments
...
Agent instances to add as neighbors
Method remove_neighbors()
Remove one or more neighbors
Usage
Agent$remove_neighbors(...)
Arguments
...
Agent instances to remove
Method degree()
Get agent's degree (via neighbors)
Method set_attribute()
Set an arbitrary named attribute
Usage
Agent$set_attribute(key, value)
Arguments
key
Attribute name
value
Value to assign
Method get_attribute()
Get the value of a named attribute
Method set_attributes()
Set multiple attributes
Usage
Agent$set_attributes(attr_list)
Arguments
attr_list
A named list of attributes
Method get_attributes()
Get all custom attributes as a named list
Method clone()
The objects of this class are cloneable with this method.
Usage
Agent$clone(deep = FALSE)
Arguments
deep
Whether to make a deep clone.
Examples
# Create a basic agent with default settings
a1 <- Agent$new(1)
# Create a named agent with specific behavior and fitness
a2 <- Agent$new(id = 1, name = "Mia", behavior = "1", fitness = 0.75)
# Access ID and name
a2$get_id()
#> [1] 1
a2$get_name()
#> [1] "Mia"
# Check and update behavior
a2$get_behavior()
#> [1] "1"
a2$set_behavior("0")
a2$advance_behavior()
# Set and retrieve custom attributes
a2$set_attribute("group", "treatment")
a2$get_attribute("group")
#> [1] "treatment"