def run_aggregate(self, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range, out_group_a_strength, out_group_a_range, out_group_r_strength, out_group_r_range, target_a_strength, target_a_range, context, spawn_new_pedestrians=False, simulation=True, drawing=True): """ initialize social force model """ force_model.set_parameters(self.parameters) self.spawn_new_pedestrians = spawn_new_pedestrians self.drawing = drawing total_group_num = len(self.parameters['group_num']) ''' set parameter ''' self.parameters['in_group_a_strength'] = in_group_a_strength self.parameters['in_group_a_range'] = in_group_a_range self.parameters['in_group_r_strength'] = in_group_r_strength self.parameters['in_group_r_range'] = in_group_r_range self.parameters['out_group_a_strength'] = out_group_a_strength self.parameters['out_group_a_range'] = out_group_a_range self.parameters['out_group_r_strength'] = out_group_r_strength self.parameters['out_group_r_range'] = out_group_r_range self.parameters['target_a_strength'] = target_a_strength self.parameters['target_a_range'] = target_a_range self.flowrate_simulations = [] self.flowrate = 0 #we only measure pedestrians inside this area self.turning_angles = [] self.effective_evacuation = [] self.simulation_index = "%s" % str(datetime.now().microsecond) population_generator = PopulationGenerator( self.parameters, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range, out_group_a_strength, out_group_a_range, out_group_r_strength, out_group_r_range, target_a_strength, target_a_range) """ perform simulation over context_placement_num""" radii_generators = context._get_radii_generators() placement_generators = context._get_placement_generators() t = len(placement_generators) current_simulation_run = 0 while current_simulation_run < 1: #len(placement_generators)/total_group_num : simulation_id = "%s" % (self.simulation_index + "_" + str(current_simulation_run + 1)) print(">> running simulation %s" % (simulation_id)) self._init_observation_plots() index = current_simulation_run * total_group_num radii_generator = radii_generators[index:index + total_group_num] placement_generator = placement_generators[index:index + total_group_num] generated_group_member_index = population_generator._generate_population( radii_generator, placement_generator) group_pedestrians1 = population_generator._get_generated_group_pedestrians_population( ) bio_index = int(len(radii_generators) / 2) + index radii_generator = radii_generators[bio_index:bio_index + total_group_num] placement_generator = placement_generators[bio_index:bio_index + total_group_num] population_generator._generate_population( radii_generator, placement_generator, generated_group_member_index) group_pedestrians2 = population_generator._get_generated_group_pedestrians_population( ) group_pedestrians = group_pedestrians1 + group_pedestrians2 self._run(index, simulation_id, group_pedestrians) self.plots._dump_influential_matrix(current_simulation_run) self.flowrate_simulations.append(self.flowrate) #turning_angels angels = self.plots.get_turning_angles() #print(angels) for item in angels: self.turning_angles.append(item) #get effective evacuation effectiveness = self.plots.get_effective_evacuation() #print(effectiveness) for item in effectiveness: self.effective_evacuation.append(item) self.plots.reset_sample() force_model.reset_model() self.flowrate = 0 current_simulation_run += 1
def run_aggregate(self, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range, out_group_a_strength, out_group_a_range, out_group_r_strength, out_group_r_range, target_a_strength, target_a_range, context, spawn_new_pedestrians=False, simulation=True, drawing=True): """ initialize social force model """ force_model.set_parameters(self.parameters) self.spawn_new_pedestrians = spawn_new_pedestrians self.drawing = drawing total_group_num = len(self.parameters['group_num']) ''' set parameter ''' self.parameters['in_group_a_strength'] = in_group_a_strength self.parameters['in_group_a_range'] = in_group_a_range self.parameters['in_group_r_strength'] = in_group_r_strength self.parameters['in_group_r_range'] = in_group_r_range self.parameters['out_group_a_strength'] = out_group_a_strength self.parameters['out_group_a_range'] = out_group_a_range self.parameters['out_group_r_strength'] = out_group_r_strength self.parameters['out_group_r_range'] = out_group_r_range self.parameters['target_a_strength'] = target_a_strength self.parameters['target_a_range'] = target_a_range self.flowrate_simulations = [] self.flowrate = 0 #we only measure pedestrians inside this area self.turning_angles = [] self.effective_evacuation = [] self.simulation_index = "%s" % str(datetime.now().microsecond) population_generator = PopulationGenerator( self.parameters, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range, out_group_a_strength, out_group_a_range, out_group_r_strength, out_group_r_range, target_a_strength, target_a_range) """ perform simulation over context_placement_num""" radii_generators = context._get_radii_generators() placement_generators = context._get_placement_generators() current_simulation_run = 0 while current_simulation_run < 1: #len(placement_generators)/total_group_num : simulation_id = "%s" % (self.simulation_index + "_" + str(current_simulation_run + 1)) print(">> running simulation %s" % (simulation_id)) self._init_observation_plots() index = current_simulation_run * total_group_num group_pedestrians = [] if self.spawn_new_pedestrians == False: disp_level = self.parameters[ 'out_group_r_strength'] / self.parameters[ 'in_group_r_strength'] frame_filename = "%s" % (str(disp_level) + "_" + str(index) + "_0") adaptivecontext_file = open( "%s.json" % os.path.join(self.framecontext_dir, frame_filename)) json_str = adaptivecontext_file.read() currentframecontext = json.loads(json_str, cls=FrameContextLog_Decoder) pedestrian_list = currentframecontext.get_pedestrian_list() adaptivecontext_file.close() additional_ped_info = dict() for pedestrian in pedestrian_list: ped_id = pedestrian['pedestrian_id'] friend_zone = pedestrian['friend_zone'] additional_ped_info[ped_id] = friend_zone radii_generator1 = radii_generators[index:index + total_group_num] placement_generator1 = placement_generators[index:index + total_group_num] population_generator._generate_population( radii_generator1, placement_generator1) group_pedestrians1 = population_generator._initialize_generated_group_pedestrians_friend_zone( additional_ped_info) bio_index = int(len(radii_generators) / 2) + index radii_generator2 = radii_generators[bio_index:bio_index + total_group_num] placement_generator2 = placement_generators[ bio_index:bio_index + total_group_num] population_generator._generate_population( radii_generator2, placement_generator2, len(group_pedestrians1)) group_pedestrians2 = population_generator._initialize_generated_group_pedestrians_friend_zone( additional_ped_info) group_pedestrians = group_pedestrians1 + group_pedestrians2 else: radii_generator1 = radii_generators[index:index + total_group_num] placement_generator1 = placement_generators[index:index + total_group_num] population_generator._generate_population( radii_generator1, placement_generator1) ids_each_group = population_generator._get_ids_group() group_pedestrians1 = population_generator._initialize_generated_group_pedestrians_population( ids_each_group) bio_index = int(len(radii_generators) / 2) + index radii_generator2 = radii_generators[bio_index:bio_index + total_group_num] placement_generator2 = placement_generators[ bio_index:bio_index + total_group_num] population_generator._generate_population( radii_generator2, placement_generator2, len(group_pedestrians1)) ids_each_group2 = population_generator._get_ids_group() group_pedestrians2 = population_generator._initialize_generated_group_pedestrians_population( ids_each_group2) group_pedestrians = group_pedestrians1 + group_pedestrians2 self._run(index, simulation_id, group_pedestrians) self.plots._dump_influential_matrix(current_simulation_run) self.flowrate_simulations.append(self.flowrate) #turning_angels angels = self.plots.get_turning_angles() #print(angels) for item in angels: self.turning_angles.append(item) #get effective evacuation effectiveness = self.plots.get_effective_evacuation() #print(effectiveness) for item in effectiveness: self.effective_evacuation.append(item) self.plots.reset_sample() force_model.reset_model() self.flowrate = 0 current_simulation_run += 1
def run_aggregate(self, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range, out_group_a_strength, out_group_a_range, out_group_r_strength, out_group_r_range, target_a_strength, target_a_range, context, spawn_new_pedestrians=False, simulation=True, drawing=True): """ initialize social force model """ force_model.set_parameters(self.parameters) self.spawn_new_pedestrians = spawn_new_pedestrians self.drawing = drawing total_group_num = len(self.parameters['group_num']) ''' set parameter ''' self.parameters['in_group_a_strength'] = in_group_a_strength self.parameters['in_group_a_range'] = in_group_a_range self.parameters['in_group_r_strength'] = in_group_r_strength self.parameters['in_group_r_range'] = in_group_r_range self.parameters['out_group_a_strength'] = out_group_a_strength self.parameters['out_group_a_range'] = out_group_a_range self.parameters['out_group_r_strength'] = out_group_r_strength self.parameters['out_group_r_range'] = out_group_r_range self.parameters['target_a_strength'] = target_a_strength self.parameters['target_a_range'] = target_a_range #measure by x-position, start from 0 (coordinator -30) avg_velocity_x_position = [[] for i in range(601)] self.flowrate_simulations = [] self.flowrate = 0 self.simulation_index = "%s" % str(datetime.now().microsecond) population_generator = PopulationGenerator( self.parameters, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range, out_group_a_strength, out_group_a_range, out_group_r_strength, out_group_r_range, target_a_strength, target_a_range) """ perform simulation over context_placement_num""" radii_generators = context._get_radii_generators() placement_generators = context._get_placement_generators() current_simulation_run = 0 while current_simulation_run < 1: #len(placement_generators)/total_group_num : simulation_id = "%s" % (self.simulation_index + "_" + str(current_simulation_run + 1)) print(">> running simulation %s" % (simulation_id)) self._init_observation_plots() index = current_simulation_run * total_group_num radii_generator = radii_generators[index:index + total_group_num] placement_generator = placement_generators[index:index + total_group_num] population_generator._generate_population(radii_generator, placement_generator) group_pedestrians = population_generator._get_generated_group_pedestrians_population( ) self._run(index, simulation_id, group_pedestrians) self.flowrate_simulations.append(self.flowrate) #get velocity over x-position average_velocity_x_position = self.plots.get_velocity_by_x_position( ) print(average_velocity_x_position) for scale_meter in range(len(average_velocity_x_position)): avg_velocity_x_position[scale_meter].append( average_velocity_x_position[scale_meter]) seperation_c_value = out_group_r_strength / in_group_r_strength self.plots.dump_velocity_log(str(seperation_c_value), str(current_simulation_run + 1)) self.plots._dump_influential_matrix(current_simulation_run) self.plots.reset_sample() force_model.reset_model() self.flowrate = 0 current_simulation_run += 1 '''compute velocity over x-direction of 50 simulation times ''' self.avg_multi_velocity_x_position_scale = [0] * 601 for scale_meter in range(len(avg_velocity_x_position)): if len(avg_velocity_x_position[scale_meter]) > 0: self.avg_multi_velocity_x_position_scale[ scale_meter] = np.mean( avg_velocity_x_position[scale_meter])