def add_new_users(self): num_agents = random.choice([i for i in range(MAX_NUMBER_OF_NEW_USERS)]) # Create users for i in range(num_agents): user = UserAgent( self.increment_curr_user_id(), define_user_interests(), define_user_actions_probabilities(self.exp_normalized), self.define_user_influence(), self) self.schedule.add(user) self.users.append(user) user.add_random_friends(10) user.expand_influence()
def __init__(self, num_agents): super().__init__() self.running = True self.num_agents = num_agents self.schedule = RandomActivation(self) self.schedule_groups = RandomActivation(self) self.schedule_roles = RandomActivation(self) self.exp = np.random.exponential(1, num_agents * 2) self.exp_normalized = [ float(value) / max(self.exp) for value in self.exp ] self.influence_values = deepcopy(self.exp_normalized) self.users = [] self.role_agents = [] self.groups = [] self.curr_user_id = 0 self.negotiations = {} self.roles_count = defaultdict(list) self.curr_iteration = 0 self.role_changes_from = {} for role in roles: self.roles_count[role] = [] # Create users for i in range(num_agents): user = UserAgent( self.increment_curr_user_id(), define_user_interests(), define_user_actions_probabilities(self.exp_normalized), self.define_user_influence(), self) self.schedule.add(user) self.users.append(user) for user in self.users: user.add_random_friends( round( math.ceil( random.choice(self.exp_normalized) * num_agents / 3)) + 1) user.expand_influence() self.data_collector = DataCollector( agent_reporters={"Post_written": get_number_of_post_written}) self.data_group_collector = DataCollector( model_reporters={ "biggestGroup": biggest_group, "groupSizeDistribution": group_size_dist, "number_of_groups": get_number_of_groups })