Ejemplo n.º 1
0
    def ga_predict_button_interaction(self):
        mouse_pos = pygame.mouse.get_pos()
        if (self.ga_predict_button.coords[0] < mouse_pos[0] < self.ga_predict_button.coords[0] + self.ga_predict_button.dimensions[0] and
                self.ga_predict_button.coords[1] < mouse_pos[1] < self.ga_predict_button.coords[1] + self.ga_predict_button.dimensions[1]):
            self.ga_predict_button.button_light(self.screen, (110, -3))
            mouse_click = pygame.mouse.get_pressed()
            if mouse_click[0] == 1:
                self.pause_background_video = True
                questions = ['Model name']
                input_box = InputBoxMenu(self.screen, len(questions),
                                         (self.ga_predict_button.coords[0] + 25, self.ga_predict_button.coords[1] + 75),
                                         questions, ['name'])
                input_box.help()
                inputs = input_box.ask_boxes()

                if os.path.exists('./used_models/ga/' + inputs[0] + '.h5') is False:
                    self.display_error_message("Model doesn't exists in /used_models/ga/. Loading default model.")
                    # replace with standard_model after training a good model ↓
                    inputs[0] = 'model_2000'

                agent = NeuroEvolutionary(self.screen, self.screen_width, self.screen_height, 0, False, False, False,
                                          None, None, False)
                agent.kinematic_ga.load_model(inputs[0])

                while pygame.key.get_pressed() != pygame.K_ESCAPE:
                    agent.ga_sim.run_ga(agent.kinematic_ga.model)
                quit()
        else:
            self.ga_predict_button.draw_button(self.screen, (110, -3))
Ejemplo n.º 2
0
    def drl_predict_button_interaction(self):
        mouse_pos = pygame.mouse.get_pos()
        if (self.drl_predict_button.coords[0] < mouse_pos[0] < self.drl_predict_button.coords[0] + self.drl_predict_button.dimensions[0] and
                self.drl_predict_button.coords[1] < mouse_pos[1] < self.drl_predict_button.coords[1] + self.drl_predict_button.dimensions[1]):
            self.drl_predict_button.button_light(self.screen, (110, -3))
            mouse_click = pygame.mouse.get_pressed()
            if mouse_click[0] == 1:
                self.pause_background_video = True
                questions = ['Rays_nr']
                input_box = InputBoxMenu(self.screen, len(questions),
                                         (self.drl_predict_button.coords[0] + 25, self.drl_predict_button.coords[1] + 75),
                                         questions, [int])
                input_box.help()
                inputs = input_box.ask_boxes()
                check = input_box.check_inputbox_input()
                error_message_pos = [20, 20]

                while check in input_box.errors:
                    self.display_error_message('Error ' + check, position=tuple(error_message_pos), sleep_time=0)
                    error_message_pos[1] += 40
                    inputs = input_box.ask_boxes()
                    check = input_box.check_inputbox_input()

                agent = DqnSimulator(self.screen, self.screen_width, self.screen_height, 0, False, False, False,
                                     None, None, False, rays_nr=int(inputs[0]))
                agent.predict_conv_dqn()
                quit()
        else:
            self.drl_predict_button.draw_button(self.screen, (110, -3))
Ejemplo n.º 3
0
    def replay_button_interaction(self):
        mouse_pos = pygame.mouse.get_pos()
        if (self.replay_button.coords[0] < mouse_pos[0] < self.replay_button.coords[0] + self.replay_button.dimensions[0] and
                self.replay_button.coords[1] < mouse_pos[1] < self.replay_button.coords[1] + self.replay_button.dimensions[1]):
            self.replay_button.button_light(self.screen, (125, -3))
            mouse_click = pygame.mouse.get_pressed()
            if mouse_click[0] == 1:
                questions = ['Sensor size', 'Replay_data path']
                input_box = InputBoxMenu(self.screen, len(questions),
                                         (self.replay_button.coords[0] + 25, self.replay_button.coords[1] + 75),
                                         questions, [int, 'path + csv'])
                input_box.help()
                inputs = input_box.ask_boxes()
                check = input_box.check_inputbox_input()
                error_message_pos = [20, 20]

                while check in input_box.errors:
                    self.display_error_message('Error ' + check, position=tuple(error_message_pos), sleep_time=0)
                    error_message_pos[1] += 40
                    inputs = input_box.ask_boxes()
                    check = input_box.check_inputbox_input()

                replay = Replay(self.screen, self.screen_width, self.screen_height,
                                activations=self.activation_cbox.isChecked(),
                                traffic=self.traffic_cbox.isChecked(),
                                sensors=self.sensors_cbox.isChecked(),
                                distance_sensor=self.distance_sensor_cbox.isChecked(),
                                sensor_size=int(inputs[0]),
                                enabled_menu=True)
                replay.replay(inputs[1], enable_trajectory=True)
                quit()
        else:
            self.replay_button.draw_button(self.screen, (125, -3))
Ejemplo n.º 4
0
    def ga_train_button_interaction(self):
        mouse_pos = pygame.mouse.get_pos()
        if (self.ga_train_button.coords[0] < mouse_pos[0] < self.ga_train_button.coords[0] + self.ga_train_button.dimensions[0] and
                self.ga_train_button.coords[1] < mouse_pos[1] < self.ga_train_button.coords[1] + self.ga_train_button.dimensions[1]):
            self.ga_train_button.button_light(self.screen, (110, -3))
            mouse_click = pygame.mouse.get_pressed()
            if mouse_click[0] == 1:
                self.pause_background_video = True
                questions = ['No_population', 'No_generations', 'Rays_nr']
                input_box = InputBoxMenu(self.screen, len(questions),
                                         (self.ga_train_button.coords[0] + 25, self.ga_train_button.coords[1] + 75),
                                         questions, [int, int, int])
                input_box.help()
                inputs = input_box.ask_boxes()
                check = input_box.check_inputbox_input()
                error_message_pos = [20, 20]

                while check in input_box.errors:
                    self.display_error_message('Error ' + check, position=tuple(error_message_pos), sleep_time=0)
                    error_message_pos[1] += 40
                    inputs = input_box.ask_boxes()
                    check = input_box.check_inputbox_input()

                agent = NeuroEvolutionary(self.screen, self.screen_width, self.screen_height, 0, False, False, False,
                                          None, None, False,
                                          population_size=int(inputs[0]),
                                          num_generations=int(inputs[1]),
                                          shape=int(inputs[2]))
                agent.neuro_trainer.train(agent.kinematic_ga.neuro_eval)
                quit()
        else:
            self.ga_train_button.draw_button(self.screen, (110, -3))
Ejemplo n.º 5
0
    def manual_driving_button_interaction(self):
        mouse_pos = pygame.mouse.get_pos()
        if (self.manual_driving_button.coords[0] < mouse_pos[0] < self.manual_driving_button.coords[0] + self.manual_driving_button.dimensions[0] and
                self.manual_driving_button.coords[1] < mouse_pos[1] < self.manual_driving_button.coords[1] + self.manual_driving_button.dimensions[1]):
            self.manual_driving_button.button_light(self.screen, (75, -3))
            mouse_click = pygame.mouse.get_pressed()
            if mouse_click[0] == 1:
                self.pause_background_video = True
                questions = ['Sensor size']
                input_box = InputBoxMenu(self.screen, len(questions),
                                         (self.manual_driving_button.coords[0] + 25, self.manual_driving_button.coords[1] + 75),
                                         questions, [int])
                input_box.help()
                inputs = input_box.ask_boxes()
                check = input_box.check_inputbox_input()
                error_message_pos = [20, 20]
                while check in input_box.errors:
                    self.display_error_message('Error ' + check, position=tuple(error_message_pos), sleep_time=0)
                    error_message_pos[1] += 40
                    inputs = input_box.ask_boxes()
                    check = input_box.check_inputbox_input()

                sim = CitySimulator(self.screen, self.screen_width, self.screen_height,
                                    activations=self.activation_cbox.isChecked(), record_data=False,
                                    sensor_size=int(inputs[0]),
                                    traffic=self.traffic_cbox.isChecked(),
                                    sensors=self.sensors_cbox.isChecked(),
                                    distance_sensor=self.distance_sensor_cbox.isChecked(),
                                    enabled_menu=True)
                sim.run()
                quit()
        else:
            self.manual_driving_button.draw_button(self.screen, (75, -3))