def invite_friends_to_restaurant(self): shape = self.properties.risk_tolerance * get_parameters().get('typical_restaurant_event_size') event_size = np.random.gamma(shape, 1) logger().debug(f"Restaurant event size of {self} is {event_size}") accepted = [self] for human in self.tribe[TribeSelector.FRIEND]: if human != self and human.personal_decision(Dilemma.ACCEPT_FRIEND_INVITATION_TO_RESTAURANT): accepted.append(human) if len(accepted) >= event_size: break if len(accepted) == 1: return outdoor = flip_coin(linear_rescale(self.properties.risk_tolerance, 0, 0.5)) if flip_coin(linear_rescale(self.work_info.base_income, 0, 1 / 5)): restaurant_type = RestaurantType.FANCY else: restaurant_type = RestaurantType.FAST_FOOD event = self.work_district.get_available_restaurant(len(accepted), outdoor, restaurant_type) if event is not None and not outdoor: event = self.work_district.get_available_restaurant(len(accepted), True, restaurant_type) if event is None: return event.available -= len(accepted) for human in accepted: human.social_event = (self, event)
def build_tribe(self, human, humans, mininum, maximum, temperature = -0.9): n = int(round(linear_rescale(human.properties.extroversion, mininum, maximum))) if n >= len(humans): n = len(humans) - 1 if n <= 0: return [human] tribe_candidates = humans.copy() tribe_candidates.remove(human) tribe = self.find_friends(human, tribe_candidates,n,temperature) tribe.append(human) return tribe
def build_tribe(self, human, humans, mininum, maximum): n = linear_rescale(human.properties.extroversion, mininum, maximum) w = [self.similarity[human][h] for h in humans] tribe = [human] count = 0 while n > 0 and count < len(humans): count += 1 selected = roulette_selection(humans, w) if selected not in tribe: tribe.append(selected) n -= 1 return tribe
def build_tribe(self, human, humans, mininum, maximum): n = int(round(linear_rescale(human.properties.extroversion, mininum, maximum))) if n >= len(humans): n = len(humans) - 1 if n <= 0: return [human] tribe_candidates = humans.copy() tribe_candidates.remove(human) w = [self.similarity[human][h] for h in tribe_candidates] tribe = roulette_selection(tribe_candidates, w, num_selections=n) tribe.append(human) return tribe
def _compute_similarity(self, h1, h2): assert len(self.feature_vector[h1]) == len(self.feature_vector[h2]) d = np.linalg.norm(self.feature_vector[h1] - self.feature_vector[h2]) return linear_rescale(d, 1, 0, 0, math.sqrt(len(self.feature_vector[h1])))