Represents a integer valued variable for an individual. This class is similar to CategoricalVariable, but can be used for variables with unbounded ranges, or other situations where part of an individual's state is better represented by an integer, such as household or age bin.

Methods


Method new()

Create a new IntegerVariable.

Usage

IntegerVariable$new(initial_values)

Arguments

initial_values

a vector of the initial values for each individual


Method get_values()

Get the variable values.

Usage

IntegerVariable$get_values(index = NULL)

Arguments

index

optionally return a subset of the variable vector. If NULL, return all values; if passed a Bitset or integer vector, return values of those individuals.


Method get_index_of()

Return a Bitset for individuals with some subset of values. Either search for indices corresponding to values in set, or for indices corresponding to values in range \([a,b]\). Either set or a and b must be provided as arguments.

Usage

IntegerVariable$get_index_of(set = NULL, a = NULL, b = NULL)

Arguments

set

a vector of values (providing set means a,b are ignored)

a

lower bound

b

upper bound


Method get_size_of()

Return the number of individuals with some subset of values. Either search for indices corresponding to values in set, or for indices corresponding to values in range \([a,b]\). Either set or a and b must be provided as arguments.

Usage

IntegerVariable$get_size_of(set = NULL, a = NULL, b = NULL)

Arguments

set

a vector of values (providing set means a,b are ignored)

a

lower bound

b

upper bound


Method queue_update()

Queue an update for a variable. There are 4 types of variable update:

  1. Subset update: The argument index represents a subset of the variable to update. The argument values should be a vector whose length matches the size of index, which represents the new values for that subset.

  2. Subset fill: The argument index represents a subset of the variable to update. The argument values should be a single number, which fills the specified subset.

  3. Variable reset: The index vector is set to NULL and the argument values replaces all of the current values in the simulation. values should be a vector whose length should match the size of the population, which fills all the variable values in the population

  4. Variable fill: The index vector is set to NULL and the argument values should be a single number, which fills all of the variable values in the population.

Usage

IntegerVariable$queue_update(values, index = NULL)

Arguments

values

a vector or scalar of values to assign at the index

index

is the index at which to apply the change, use NULL for the fill options. If using indices, this may be either a vector of integers or a Bitset.


Method queue_extend()

extend the variable with new values

Usage

IntegerVariable$queue_extend(values)

Arguments

values

to add to the variable


Method queue_shrink()

shrink the variable

Usage

IntegerVariable$queue_shrink(index)

Arguments

index

a bitset or vector representing the individuals to remove


Method size()

get the size of the variable

Usage

IntegerVariable$size()


Method .update()

Usage

IntegerVariable$.update()


Method .resize()

Usage

IntegerVariable$.resize()


Method save_state()

save the state of the variable

Usage

IntegerVariable$save_state()


Method restore_state()

restore the variable from a previously saved state.

Usage

IntegerVariable$restore_state(timestep, state)

Arguments

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.


Method clone()

The objects of this class are cloneable with this method.

Usage

IntegerVariable$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.