def replay_frame(self, constant, index_simulation, time_replay, constant_target, constant_target_magnitude, in_group_a_strength, in_group_a_range, in_group_r_strength, in_group_r_range): frame = (time_replay / constants.frame_store_sample_frequency) * ( constants.frame_store_sample_frequency / constants.timestep) intframe = int(frame) #filename = str(constant) + "_" + str(index_simulation) + "_" + str(intframe) filename = "%s" % (str(in_group_r_strength) + "_" + str(in_group_a_strength) + "_" + str(constant) + "_" + str(index_simulation) + "_" + str(intframe)) index_simulation = index_simulation * 2 #filename = str(index_simulation) + "_" + str(intframe) frame_log_file = open( "%s.json" % os.path.join(constants.framecontext_dir, filename)) json_str = frame_log_file.read() currentframecontext = json.loads(json_str, cls=FrameContextLog_Decoder) pedestrian_list = currentframecontext.get_pedestrian_list() ''' set parameter ''' self.in_group_a_strength = in_group_a_strength self.in_group_a_range = in_group_a_range self.in_group_r_strength = in_group_r_strength self.in_group_r_range = in_group_r_range 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'] = self.parameters[ 'in_group_a_strength'] * (1 / constant) self.parameters['out_group_a_range'] = self.parameters[ 'in_group_a_range'] self.parameters['out_group_r_strength'] = self.parameters[ 'in_group_r_strength'] * constant self.parameters['out_group_r_range'] = self.parameters[ 'in_group_r_range'] self.parameters['target_a_strength'] = 22000000000 self.parameters['target_a_range'] = 435 self.parameters['constant_target'] = constant_target self.parameters[ 'constant_target_magnitude'] = constant_target_magnitude '''update position and target shift for pedestrian list ''' for pedestrian in pedestrian_list: position = (pedestrian['position'][0] - self.shift, pedestrian['position'][1]) # del pedestrian['position'] pedestrian['position'] = position target = (pedestrian['target'][0] - self.shift, pedestrian['target'][1]) # del pedestrian['target'] pedestrian['target'] = target simulation_id = "Replay frame" """ initialize social force model """ force_model.set_parameters(self.parameters) force_model.set_start_simulation_time(time_replay) self.time = time_replay self.frames = frame if pedestrian_list is not None and len(pedestrian_list) > 0: for group_member in pedestrian_list: '''should modify target position based on y''' (x, y) = group_member['position'] if y <= self.y_horizontal_line: del group_member['target'] group_member['target'] = self.target_upper else: del group_member['target'] group_member['target'] = self.target_below force_model.add_group_pedestrian(group_member) self._init_drawing(simulation_id) finished = False ###IMPORTANT PART FOR SHARED OBJECT constants.tracked_pedestrian_id = -1 """ initialize the real-time plot """ self.pedestrian_track = Pedestrian_Track(self.time) self.tracking_sample_frequency = int(constants.plot_sample_frequency / (2 * self.timestep)) count = 0 try: while self._tick() and not finished: force_model.update_pedestrians() self._draw() self._revise_target() if (not self.frames % self.spawn_frequency): self._spawn_pedestrians(index_simulation) #if not self.frames % self.tracking_sample_frequency: # self._plot_track_ped() self.show_canvas.create_image(count) #self.frames) count += 1 self.time += self.timestep self.frames += 1 if self._done(): finished = True except KeyboardInterrupt: pass self._uninit_drawing()
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])