def advertise(self, p): """ This function calculates the score of the advertised work activity to a person :param person.Person p: the person of interest :return score: :rtype: float """ DAY_2_MIN = temporal.DAY_2_MIN # this is the lowest score score = 0.0 # create a clock for the Need perception due the Activity when it's finished dt = (p.socio.job.t_end - p.clock.time_of_day) % DAY_2_MIN future_clock = temporal.Temporal(p.clock.t_univ + dt) # the current need level and the resulting need level if an Activity is done n_now = p.income.magnitude # if the Income need is under a threshold, send a score if (p.income.under_threshold(n_now)): n_later = p.income.perceive(future_clock, p.socio.job) score = score + (p.income.weight(n_now) - p.income.weight(n_later)) return score
def __init__(self, num_steps, dt, t_start, num_people, do_minute_by_minute=False): # create a clock. self.clock = temporal.Temporal() self.clock.dt = dt self.clock.t_univ = t_start self.clock.set_time() # store the initial time [minutes] in universal time self.t_start = t_start # the final time of the simulation in universal time self.t_end = self.t_start + num_steps * dt # create a home self.home = home.Home(self.clock) # list of persons self.people = [] # the schedule self.schedule = scheduler.Scheduler(clock=self.clock, num_people=num_people, \ do_minute_by_minute=do_minute_by_minute) return
def advertise(self, p): """ This function calculates the score of to commute from work. It does this by doing the \ following: #. calculate advertisement only if the person is located at work (off-site) #. calculate the score :math:`S` .. math:: S = \\begin{cases} 0 & n_{travel}(t) > \\lambda \\\\ W( n_{travel}(t) ) - W( n_{travel}(t + \\Delta{t} )) & n_{travel}(t) \\le \\lambda \\end{cases} where * :math:`t` is the current time * :math:`\\Delta{t}` is the duration of commuting from work [minutes] * :math:`n_{travel}(t)` is the satiation for Travel at time :math:`t` * :math:`\\lambda` is the threshold value of Travel * :math:`W(n)` is the weight function for Travel :param person.Person p: the person of interest :return: the advertised score :rtype: float """ # this is the lowest score score = 0.0 # seek a non zero advertisement if the person's location is off site (at work) if (p.location.local == location.OFF_SITE): # the end of the commute to work sequence is: # the current time + the time to commute to work + the time at work t_day = p.clock.day * temporal.DAY_2_MIN # the duration of the commute dt_commute = p.socio.job.commute_from_work_dt # store the time in universal time t_univ_later = t_day + p.socio.job.t_end + dt_commute # create a clock for the Need perception due the Activity when it's finished future_clock = temporal.Temporal(t_univ_later) # the current need level and the resulting need level if an Activity is done n_now = p.travel.magnitude # if the Travel need association is under a threshold, do something if (p.travel.under_threshold(n_now)): # calculate the magnitude of the need association assuming the commute activity has finished n_later = p.travel.perceive(future_clock, p.socio.job) # update the value of the advertisement score = score + (p.travel.weight(n_now) - p.travel.weight(n_later)) return score
def advertise(self, p): """ This function calculates the score of commuting to work by doing the following: #. calculate advertisement only if the person is located at work (off-site) #. calculate the score :math:`S` .. math:: S = \\begin{cases} 0 & n_{travel}(t) > \\lambda \\\\ W( n_{travel}(t) ) - W( n_{travel}(t + \\Delta{t} )) & n_{travel}(t) \\le \\lambda \\end{cases} where * :math:`t` is the current time * :math:`\\Delta{t}` is the duration of commuting to work [minutes] * :math:`n_{travel}(t)` is the satiation for Travel at time :math:`t` * :math:`\\lambda` is the threshold value of Travel * :math:`W(n)` is the weight function for Travel :param person.Person p: the person of interest :return score: the advertisement score :rtype: float """ DAY_2_MIN = temporal.DAY_2_MIN # this is the lowest score score = 0.0 if (p.location.local == location.HOME): # the end of the commute to work sequence is: # the time that the travel need should increase to 1 if ignored # the current time + the time to commute to work + the time at work t_univ_later = p.clock.t_univ + (p.socio.job.t_end - p.clock.time_of_day) % DAY_2_MIN # create a clock for the Need perception due the Activity when it's finished future_clock = temporal.Temporal(t_univ_later) # the current need level and the resulting need level if an Activity is done n_now = p.travel.magnitude # if the Travel need association is under a threshold, do something if (p.travel.under_threshold(n_now)): # calculate the magnitude of the need association assuming the commute activity has finished n_later = p.travel.perceive(future_clock, p.socio.job) # update the value of the advertisement score = score + (p.travel.weight(n_now) - p.travel.weight(n_later)) return score
def advertise(self, the_need, dt): """ Calculates the advertised score of doing an activity. Let :math:`\\Omega` be the set of all needs addressed by the activity. The score :math:`S` is calculated by doing the following .. math:: S = \\begin{cases} 0 & n(t) > \\lambda \\\\ \\sum_{j \in \Omega} W_j( n_j(t) ) - W_j( n_j(t + \\Delta{t} )) & n(t) \\le \\lambda \\end{cases} where * :math:`t` is the current time * :math:`\\Delta{t}` is the duration of the activity * :math:`n(t)` is the satiation at time :math:`t` * :math:`\\lambda` is the threshold value of the need * :math:`W(n)` is the weight function for the particular need :param need.Need the_need: the primary need associated with the respective activity :param int dt: the duration :math:`\\Delta{t}` of doing the activity [minutes] :returns score: the score of the advertisement :rtype: float """ # this is the lowest score score = 0.0 # create a clock for the Need perception due the activity when it's finished future_clock = temporal.Temporal(the_need.clock.t_univ + dt) # the current need association level n_now = the_need.magnitude # if the need association is below a threshold, make the advertise the activity's value if (the_need.under_threshold(n_now)): # the resulting need association level when the activity is done n_later = the_need.perceive(future_clock) # the score from the advertisement score = score + (the_need.weight(n_now) - the_need.weight(n_later)) # return the value of the score return score
def duration_to_next_commute_event(self, clock): """ This function is called in in order to calculate the amount of time until the next commute event by \ doing the following. #. If the agent is unemployed, return infinity #. If the time indicates that the agent should be currently working, set the duration to be the \ length of time remaining at work #. If the time indicates that the agent should be currently commuting to work, set the duration to be \ the duration until the commute to work should start #. If the time indicates that the agent should be currently commuting from work, set the duration to be \ the amount of time until the commute from work should end #. Else, calculate the amount of time until the next commute to work event .. note:: The only reason this code is place here is because the work activity and the commute activity use it. :param temporal.Temporal clock: the current time :return: the duration in time [minutes] until the next commute event :rtype: int """ DAY_2_MIN = temporal.DAY_2_MIN # if the person is unemployed, set the duration to infinity if not self.job.is_employed: dt = np.inf else: # should the agent be working work_time = occupation.is_work_time(clock, self.job, is_commute_to_work=False) # is it time for the person to be commuting to work commute_to_work_time = occupation.is_work_time( clock, self.job, is_commute_to_work=True) # is it time to commute from work t = max(0, clock.t_univ - self.job.commute_from_work_dt) temp_clock = temporal.Temporal() temp_clock.t_univ = t temp_clock.set_time() commute_from_work_time = occupation.is_work_time( temp_clock, self.job, is_commute_to_work=False) # if the agent is currently working, set the duration to be the length of time remaining at work if (work_time): t_end = self.job.t_end dt = (t_end - clock.time_of_day + DAY_2_MIN) % DAY_2_MIN # if the person should be commuting to work, set the duration to be the length of time remaining until # the commute starts elif (commute_to_work_time): t_start = self.job.commute_to_work_start dt = (t_start - clock.time_of_day + DAY_2_MIN) % DAY_2_MIN # if the person should be commuting from work, set the time to be the time when the commute should end elif (commute_from_work_time): t_start = self.job.t_end dt = (t_start + self.job.commute_from_work_dt - self.clock.time_of_day + DAY_2_MIN) % DAY_2_MIN # else, calculate the amount of time until the next commute event else: # time until the next work event dt = self.duration_to_work_event( clock) - self.job.commute_to_work_dt return dt