Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for a family_intervention() [in process] #11

Open
ambitious-octopus opened this issue Oct 29, 2020 · 0 comments
Open

Proposal for a family_intervention() [in process] #11

ambitious-octopus opened this issue Oct 29, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@ambitious-octopus
Copy link
Contributor

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()
   .
   .
   .

def family_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()
       for agent in model.schedule.agents:
           if agent.gender_is_male and agent.neighbors.get("offspring"):
               for age_condition in [offspring.age() < 18 and offspring.age() >= 12 for offspring in
                                     agent.neighbors.get("offspring")]:
                   if age_condition:
                       father_to_remove_pool.add(agent)

       if self.family_intervention == "remove-if-caught":
           father_to_remove_pool = [agent for agent in father_to_remove_pool if type(agent) == Prisoner]
       if self.family_intervention == "remove-if-OC-member":
           father_to_remove_pool = [agent for agent in father_to_remove_pool if agent.oc_member]
       if self.family_intervention == "remove-if-caught-and-OC-member":
           father_to_remove_pool = [agent for agent in father_to_remove_pool if
                                    type(agent) == Prisoner and agent.oc_member]
       if father_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))
           for father in father_to_remove:
               self.removed_fatherships[father] = list()
               self.kids_intervention_counter += 1
               for kid in father.neighbors.get("offspring"):
                   if kid.age() < 18 and kid.age() >= 12:
                       self.removed_fatherships[father].append(
                           [kid, ((18 * self.ticks_per_year + kid.birth_tick) - self.ticks)])

               # we only want households
               family = father.neighbors.get("household").copy()
               father.remove_from_household()
               self.welfare_createjobs(
                   [agent for agent in family if agent.age() >= 16 and not agent.my_job and not agent.my_school])
               self.soc_add_educational([agent for agent in family if agent.age() < 18 and not agent.my_job])
               self.soc_add_psychological(family)
               self.soc_add_more_friends(family)

   def return_kids(self):
       """
       If the conditions are respected, this procedure allows fathers to return to the household
       :return: None
       """
       if self.removed_fatherships:
               for father in self.removed_fatherships:
                   conditions = list()
                   for offspring_table in self.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(True if offspring_table[0].age() >= 18 and self.rng.random() < 6 / offspring_table[1] else False)
                   if all(conditions):
                       offsprings = [agent[0] for agent in self.removed_fatherships[father]]
                       for offspring in offsprings:
                           offspring.neighbors.get("household").add(father)
                           father.neighbors.get("household").add(offspring)
               returned_fathers = [father for father in self.removed_fatherships if father.neighbors.get("household")]
               if returned_fathers:
                   for father in  returned_fathers:
                       del self.removed_fatherships[father]
       def make_people_die(self):
       """
       Based on p_mortality table agents die.
       :return: None
       """
       dead_agents = list()
       for agent in self.schedule.agent_buffer(True):
           if self.rng.random() < agent.p_mortality() or agent.age() > 119:
               dead_agents.append(agent)
               if agent in self.removed_fatherships:
                   del self.removed_fatherships[agent]
               for key_father in self.removed_fatherships.keys():
                   for key_offspring, offspring in enumerate(self.removed_fatherships[key_father]):
                       if agent in offspring:
                           self.removed_fatherships[key_father].remove(
                               self.removed_fatherships[key_father][key_offspring])
                   if not self.removed_fatherships[key_father]:
                       del self.removed_fatherships[key_father]
@ambitious-octopus ambitious-octopus transferred this issue from LABSS/PROTON-OC Mar 25, 2021
@ambitious-octopus ambitious-octopus added the enhancement New feature or request label Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant