Represents a categorical variable for an individual.
This class should be used for discrete variables taking values in
a finite set, such as infection, health, or behavioral state. It should
be used in preference to IntegerVariable
if possible because certain operations will be faster.
new()
Create a new CategoricalVariable
CategoricalVariable$new(categories, initial_values)
get_index_of()
return a Bitset
for individuals with the given values
get_categories()
return a character vector of possible values. Note that the order of the returned vector may not be the same order that was given when the variable was intitialized, due to the underlying unordered storage type.
queue_update()
queue an update for this variable
value
the new value
index
the indices of individuals whose value will be updated
to the one specified in value
. This may be either a vector of integers or
a Bitset
.
restore_state()
restore the variable from a previously saved state.
timestep
the timestep at which simulation is resumed. This parameter's value is ignored, it only exists to conform to a uniform interface with events.
state
the previously saved state, as returned by the
save_state
method. NULL is passed when restoring from a saved
simulation in which this variable did not exist.