You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the blueprint for a different kind of family intervention. Surely it must be discussed, I will leave some ideas here from now on. 🏗️
.
.
def__init__():
self.removed_fatherships=dict()
.
.
.
deffamily_intervene_mesa_version(self):
""" This procedure is active when the self.family_intervention attribute is different from None. There are 3 possible family interventions: remove_if_caught, remove_if_OC_member and remove_if_caught_and_OC_member. These parameters determine the portion of the population on which the intervention will have effect. Differences with Netlogo implementation: The selection of members is done in a different way, instead of selecting the children and from them to the fathers, the fathers are selected directly. Since the interventions act on the whole family except the fathers this avoids double calls. Also in this procedure the fathers are completely removed from the nets, This does not happen in the netlogo version. Causing possible bugs and maintaining an inconsistent network structure. The intervention consists of the application of 5 procedures on eligible family members: 1. Fathers who comply with the conditions are removed from their families (Removed fathers are stored within the removed_fatherships attribute so it is possible at any time to reintroduce them into the family.) 2. welfare_createjobs, new jobs are created and assigned to eligible members. 3. soc_add_educational, the max_education_level attribute of the eligible members is increased by one 4. soc_add_psychological, a new support member (who has not committed crimes) is added to the friends network 5. soc_add_more_friends, a new support member (with a low level of tendency to crime) is added to the friends network :return: None """father_to_remove_pool=set()
foragentinmodel.schedule.agents:
ifagent.gender_is_maleandagent.neighbors.get("offspring"):
forage_conditionin [offspring.age() <18andoffspring.age() >=12foroffspringinagent.neighbors.get("offspring")]:
ifage_condition:
father_to_remove_pool.add(agent)
ifself.family_intervention=="remove-if-caught":
father_to_remove_pool= [agentforagentinfather_to_remove_pooliftype(agent) ==Prisoner]
ifself.family_intervention=="remove-if-OC-member":
father_to_remove_pool= [agentforagentinfather_to_remove_poolifagent.oc_member]
ifself.family_intervention=="remove-if-caught-and-OC-member":
father_to_remove_pool= [agentforagentinfather_to_remove_pooliftype(agent) ==Prisonerandagent.oc_member]
iffather_to_remove_pool:
how_many=int(np.ceil(self.targets_addressed_percent/100*len(father_to_remove_pool)))
father_to_remove=list(self.rng.choice(father_to_remove_pool, how_many, replace=False))
forfatherinfather_to_remove:
self.removed_fatherships[father] =list()
self.kids_intervention_counter+=1forkidinfather.neighbors.get("offspring"):
ifkid.age() <18andkid.age() >=12:
self.removed_fatherships[father].append(
[kid, ((18*self.ticks_per_year+kid.birth_tick) -self.ticks)])
# we only want householdsfamily=father.neighbors.get("household").copy()
father.remove_from_household()
self.welfare_createjobs(
[agentforagentinfamilyifagent.age() >=16andnotagent.my_jobandnotagent.my_school])
self.soc_add_educational([agentforagentinfamilyifagent.age() <18andnotagent.my_job])
self.soc_add_psychological(family)
self.soc_add_more_friends(family)
defreturn_kids(self):
""" If the conditions are respected, this procedure allows fathers to return to the household :return: None """ifself.removed_fatherships:
forfatherinself.removed_fatherships:
conditions=list()
foroffspring_tableinself.removed_fatherships[father]:
# todo: what is the condition for the return of the father?# For now let's only return it in case all the children are over 18 years old.conditions.append(Trueifoffspring_table[0].age() >=18andself.rng.random() <6/offspring_table[1] elseFalse)
ifall(conditions):
offsprings= [agent[0] foragentinself.removed_fatherships[father]]
foroffspringinoffsprings:
offspring.neighbors.get("household").add(father)
father.neighbors.get("household").add(offspring)
returned_fathers= [fatherforfatherinself.removed_fathershipsiffather.neighbors.get("household")]
ifreturned_fathers:
forfatherinreturned_fathers:
delself.removed_fatherships[father]
defmake_people_die(self):
""" Based on p_mortality table agents die. :return: None """dead_agents=list()
foragentinself.schedule.agent_buffer(True):
ifself.rng.random() <agent.p_mortality() oragent.age() >119:
dead_agents.append(agent)
ifagentinself.removed_fatherships:
delself.removed_fatherships[agent]
forkey_fatherinself.removed_fatherships.keys():
forkey_offspring, offspringinenumerate(self.removed_fatherships[key_father]):
ifagentinoffspring:
self.removed_fatherships[key_father].remove(
self.removed_fatherships[key_father][key_offspring])
ifnotself.removed_fatherships[key_father]:
delself.removed_fatherships[key_father]
The text was updated successfully, but these errors were encountered:
This is the blueprint for a different kind of family intervention. Surely it must be discussed, I will leave some ideas here from now on. 🏗️
The text was updated successfully, but these errors were encountered: