epymorph.simulator.world_list
A World
implementation -- ListWorld
-- which tracks the simulation state's
movement cohorts in a Python list-of-lists.
Cohort
Represents a group of individuals, divided into IPM compartments as appropriate for the simulation. These individuals share the same "home location" and a time at which they should return there.
These are somewhat abstract concepts, however; a completely nomadic group doesn't really have a home location, merely the next location in a chain of movements.
Parameters:
-
compartments
(NDArray[SimDType]
) –The group membership by compartment. A (C,)-shaped array.
-
return_location
(int
) –The location to which this cohort will return, or if they are home, the location where they currently are.
-
return_tick
(int
) –The simulation tick on which they will return. -1 implies never.
SORT_KEY
class-attribute
instance-attribute
SORT_KEY: ClassVar = attrgetter(
"return_tick", "return_location"
)
The natural sort order of a Cohort.
compartments
instance-attribute
The group membership by compartment. A (C,)-shaped array.
return_location
instance-attribute
return_location: int = return_location
The location to which this cohort will return, or if they are home, the location where they currently are.
return_tick
instance-attribute
return_tick: int = return_tick
The simulation tick on which they will return. -1 implies never.
can_merge_with
ListWorld
Bases: World
A world model which which tracks the simulation state's movement cohorts in a Python list-of-lists. That is, the world is a list of locations, and each location is a list of cohorts.
Parameters:
-
locations
(list[list[Cohort]]
) –The initial state of the world. It is assumed there is at least one location and at least one cohort at each.
HOME_TICK
class-attribute
instance-attribute
HOME_TICK: ClassVar = -1
The value of a population's return_tick
when the population is home.
locations
instance-attribute
All locations and all cohorts at each location.
from_initials
classmethod
Create a world with the given initial state given as a numpy array.
Everyone is assumed to be in their home location, there are no travelers.
Parameters:
-
initial_compartments
(NDArray[SimDType]
) –An (N,C)-shaped array of the compartment population at each node.
Returns:
-
Self
–The new world instance.
normalize
Sorts all cohorts within each location and combines mergeable cohorts (in place). The world should be normalized after any modification.
get_cohorts
get_cohort_array
get_local_array
get_local_cohorts
apply_cohort_delta
Apply a transition delta for all cohorts at the given location, updating the populations in each compartment.
Parameters:
apply_travel
Apply travel flows to the entire world, updating the cohorts at each location.
Parameters:
apply_return
Apply return-home flows to the entire world, updating the cohorts at each location. This finds cohorts which should return home (by looking at their return tick) and does so.
Parameters:
-
tick
(Tick
) –The current simulation tick.
-
return_stats
(bool
) –True to collect movement statistics and provide them as the function's return value.
Returns: