community module¶
-
class
community.
Community
(n_groups=1, non_offender_adult_population=100, offender_pool_size=0.0, free_offender_pool_size=0.0)[source]¶ Bases:
cortix.src.module.Module
Community Cortix module used to model criminal group population in a community system. Community here is the system at large with all possible adult individuals included in a society.
Notes
These are the port names available in this module to connect to respective modules: probation, adjudication, jail, prison, arrested, and parole. See instance attribute port_names_expected.
-
__init__
(n_groups=1, non_offender_adult_population=100, offender_pool_size=0.0, free_offender_pool_size=0.0)[source]¶ - Parameters
n_groups (int) – Number of groups in the population.
non_offender_adult_population (float) – Pool of individuals reaching the adult age (SI) unit. Default: 100.
offender_pool_size (float) – Upperbound on the range of the existing population groups. A random value from 0 to the upperbound value will be assigned to each group. This is typically a small number, say a fraction of a percent.
-
run
(*args)[source]¶ Module run function
Run method with an option to pass data back to the parent process when running in Python multiprocessing mode. If the user does not want to share data with the parent process, this function can be overriden with run(self) or run(self, *args) as long as self.state = None. If self.state points to anything but None, the user must use `run(self, *args).
Notes
When in multiprocessing, *args has two elements: comm_idx and comm_state. To pass back the state of the module, the user should insert the provided index comm_idx and the state into the queue as follows:
- if self.use_multiprocessing:
- try:
pickle.dumps(self.state)
- except pickle.PicklingError:
args[1].put((arg[0],None))
- else:
args[1].put((arg[0],self.state))
at the bottom of the user defined run() function.
Warning
This function must be overridden by all Cortix modules
- Parameters
arg[0] (int) – Index of the state in the communication queue.
arg[1] (multiprocessing.Queue) – When using the Python multiprocessing library state_comm must have the module’s self.state in it. That is, state_comm.put((idx_comm,self.state)) must be the last command in the method before return. In addition, self.state must be pickle-able.
-