Exemplo n.º 1
0
def get_fitness(string):
    """ Run the simulation and return the fitness """
    state_machine = sm.StateMachine()
    behavior_tree = PyTree(string[:],
                           behaviors=behaviors,
                           world_interface=state_machine)

    # run the Behavior Tree
    behavior_tree.run_bt()

    return fitness_function.compute_fitness(state_machine, behavior_tree)
Exemplo n.º 2
0
    def get_fitness(self, individual, save_video=False):
        """
        Run the simulation and return the fitness
        In case of error, restarts world_interface and tries again.
        """
        pytree = PyTree(individual[:],
                        behaviors=behaviors,
                        world_interface=self.world_interface,
                        verbose=self.verbose)

        status_ok = True
        fitness = None

        while fitness is None:
            if self.counter >= self.maximum_runs or not status_ok:
                self.world_interface.restart()
                self.counter = 0
            else:
                self.world_interface.reset()
            self.counter += 1

            if save_video:
                self.world_interface.start_video()

            ticks, status_ok = pytree.run_bt(max_ticks=200)
            count = 0
            while count < 50 and status_ok:  #Wait up to five seconds for everything to come to a resting state
                old_sensor_data = self.world_interface.get_sensor_data()
                status_ok = self.world_interface.get_feedback()
                if status_ok:
                    if self.world_interface.at_standstill(old_sensor_data):
                        break
                    self.world_interface.send_references()
                    count += 1

            if save_video:
                time.sleep(1)  #Needed for ros synch
                self.world_interface.stop_video()

            if status_ok:
                fitness = fitness_function.compute_fitness(self.world_interface, pytree, ticks, \
                                                           self.targets, self.fitness_coeff, self.verbose)
            else:
                self.world_interface.restart()
                self.counter = 0
                print("Failed:", individual)
                fitness = -9999999

        return fitness
Exemplo n.º 3
0
    def get_fitness(self, individual):
        """ Run the simulation and return the fitness """
        state_machine = sm.StateMachine(self.start_positions,
                                        self.random_events, self.sm_pars,
                                        self.mode)
        pytree = PyTree(individual[:],
                        behaviors=behaviors,
                        world_interface=state_machine,
                        verbose=self.verbose)

        # run the Behavior Tree
        ticks, _ = pytree.run_bt()

        return fitness_function.compute_fitness(state_machine, pytree, ticks,
                                                self.targets,
                                                self.fitness_coeff)