Beispiel #1
0
class GSOBuilder(object):
    """Builds a generic GSO simulation object.

    The GSO object can be created using random initial positions for the
    glowworms (create function) or using initial positions read from a given file
    (create_from_file function).
    """
    def __init__(self):
        self._initializer = None

    def create(self, number_of_glowworms, random_number_generator, gso_parameters,
               objective_function, bounding_box):
        """Creates a new GSO instance of the algorithm"""
        self._initializer = RandomInitializer([objective_function], number_of_glowworms, gso_parameters,
                                              bounding_box, random_number_generator)
        return GSO(self._initializer.generate_glowworms(), gso_parameters, random_number_generator)

    def create_from_file(self, number_of_glowworms, random_number_generator, gso_parameters,
                         objective_function, bounding_box, initial_population_file):
        """Creates a new GSO instance of the algorithm reading the initial position of the glowworms
        agents from initial_population_file.
        """
        self._initializer = FromFileInitializer([objective_function], number_of_glowworms,
                                                gso_parameters, bounding_box.dimension,
                                                initial_population_file)
        return GSO(self._initializer.generate_glowworms(), gso_parameters,
                   random_number_generator, initial_population_file)
Beispiel #2
0
class GSOBuilder(object):
    """Builds a generic GSO simulation object.

    The GSO object can be created using random initial positions for the
    glowworms (create function) or using initial positions read from a given file
    (create_from_file function).
    """
    def __init__(self):
        self._initializer = None

    def create(self, number_of_glowworms, random_number_generator, gso_parameters,
               objective_function, bounding_box):
        """Creates a new GSO instance of the algorithm"""
        self._initializer = RandomInitializer([objective_function], number_of_glowworms, gso_parameters,
                                              bounding_box, random_number_generator)
        return GSO(self._initializer.generate_glowworms(), gso_parameters, random_number_generator)

    def create_from_file(self, number_of_glowworms, random_number_generator, gso_parameters,
                         objective_function, bounding_box, initial_population_file):
        """Creates a new GSO instance of the algorithm reading the initial position of the glowworms
        agents from initial_population_file.
        """
        self._initializer = FromFileInitializer([objective_function], number_of_glowworms,
                                                gso_parameters, bounding_box.dimension,
                                                initial_population_file)
        return GSO(self._initializer.generate_glowworms(), gso_parameters,
                   random_number_generator, initial_population_file)
 def test_generate_landscape_positions_num_glowworms_different(self):
     objective_function = J1()
     gso_parameters = GSOParameters()
     number_of_glowworms = 50
     initializer = FromFileInitializer([objective_function], number_of_glowworms, gso_parameters,
              2, self.golden_data_path+'initial_positions_redux.txt')
     swarm = initializer.generate_glowworms()
     
     assert swarm.get_size() > 0
Beispiel #4
0
    def test_generate_landscape_positions_num_glowworms_different(self):
        objective_function = J1()
        gso_parameters = GSOParameters()
        number_of_glowworms = 50
        initializer = FromFileInitializer(
            [objective_function], number_of_glowworms, gso_parameters, 2,
            self.golden_data_path / 'initial_positions_redux.txt')
        swarm = initializer.generate_glowworms()

        assert swarm.get_size() > 0
 def test_create_swarm(self):
     objective_function = J1()
     gso_parameters = GSOParameters()
     number_of_glowworms = 50
     initializer = FromFileInitializer([objective_function], number_of_glowworms, gso_parameters,
              2, self.golden_data_path+'initial_positions.txt')
     swarm = initializer.generate_glowworms()
     
     assert number_of_glowworms == swarm.get_size()
     assert "(0.617171, -2.85014)   5.00000000  0 0.200   0.00000000" == str(swarm.glowworms[-1])
Beispiel #6
0
 def create_from_file(self, number_of_glowworms, random_number_generator, gso_parameters,
                      objective_function, bounding_box, initial_population_file):
     """Creates a new GSO instance of the algorithm reading the initial position of the glowworms
     agents from initial_population_file.
     """
     self._initializer = FromFileInitializer([objective_function], number_of_glowworms,
                                             gso_parameters, bounding_box.dimension,
                                             initial_population_file)
     return GSO(self._initializer.generate_glowworms(), gso_parameters,
                random_number_generator, initial_population_file)
Beispiel #7
0
    def test_generate_landscape_positions_without_coordinates(self):
        objective_function = J1()
        gso_parameters = GSOParameters()
        number_of_glowworms = 50
        initializer = FromFileInitializer(
            [objective_function], number_of_glowworms, gso_parameters, 2,
            self.golden_data_path + 'initial_positions_empty.txt')
        swarm = initializer.generate_glowworms()

        assert swarm.get_size() > 0
Beispiel #8
0
    def test_create_swarm(self):
        objective_function = J1()
        gso_parameters = GSOParameters()
        number_of_glowworms = 50
        initializer = FromFileInitializer(
            [objective_function], number_of_glowworms, gso_parameters, 2,
            self.golden_data_path + 'initial_positions.txt')
        swarm = initializer.generate_glowworms()

        assert number_of_glowworms == swarm.get_size()
        assert "(0.617171, -2.85014)   5.00000000  0 0.200   0.00000000" == str(
            swarm.glowworms[-1])
Beispiel #9
0
 def create(self, number_of_glowworms, random_number_generator,
            gso_parameters, objective_function, bounding_box):
     """Creates a new GSO instance of the algorithm"""
     self._initializer = RandomInitializer([objective_function],
                                           number_of_glowworms,
                                           gso_parameters, bounding_box,
                                           random_number_generator)
     return GSO(self._initializer.generate_glowworms(), gso_parameters,
                random_number_generator)
Beispiel #10
0
 def create_from_file(self, number_of_glowworms, random_number_generator, gso_parameters,
                      objective_function, bounding_box, initial_population_file):
     """Creates a new GSO instance of the algorithm reading the initial position of the glowworms
     agents from initial_population_file.
     """
     self._initializer = FromFileInitializer([objective_function], number_of_glowworms,
                                             gso_parameters, bounding_box.dimension,
                                             initial_population_file)
     return GSO(self._initializer.generate_glowworms(), gso_parameters,
                random_number_generator, initial_population_file)
Beispiel #11
0
 def create(self, number_of_glowworms, random_number_generator, gso_parameters,
            objective_function, bounding_box):
     """Creates a new GSO instance of the algorithm"""
     self._initializer = RandomInitializer([objective_function], number_of_glowworms, gso_parameters,
                                           bounding_box, random_number_generator)
     return GSO(self._initializer.generate_glowworms(), gso_parameters, random_number_generator)