Skip to contents

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

Usage

Agent$get_id()


Method get_name()

Get the agent's name

Usage

Agent$get_name()


Method set_name()

Set the agent's name

Usage

Agent$set_name(name)

Arguments

name

New name to assign


Method get_behavior()

Get current behavior

Usage

Agent$get_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)

Arguments

value

New next behavior


Method get_fitness()

Get current fitness

Usage

Agent$get_fitness()


Method set_fitness()

Set current fitness

Usage

Agent$set_fitness(value)

Arguments

value

Numeric value to assign


Method get_next_fitness()

Get next fitness

Usage

Agent$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

Usage

Agent$advance_behavior()


Method advance_fitness()

Advance to the next fitness

Usage

Agent$advance_fitness()


Method get_neighbors()

Get neighbors object

Usage

Agent$get_neighbors()


Method set_neighbors()

Set neighbors object

Usage

Agent$set_neighbors(nbrs)

Arguments

nbrs

A Neighbors instance


Method add_neighbors()

Add one or more neighbors

Usage

Agent$add_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)

Usage

Agent$degree()

Returns

Integer degree


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

Usage

Agent$get_attribute(key)

Arguments

key

Attribute name


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

Usage

Agent$get_attributes()


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"