def test_compute_J1_matrix(self): j1 = J1() for i in range(5): for j in range(5): assert_almost_equals( self.expected_values[i][j], j1(Coordinates([-3.0 + j * 1.5, -3.0 + i * 1.5])))
def setUp(self): self.objective_function = J1() self.coordinates1 = Coordinates([0.0, 0.0]) self.coordinates2 = Coordinates([1.0, 1.0]) self.coordinates3 = Coordinates([5.0, -5.0]) self.coordinates4 = Coordinates([2.0, 2.0]) self.coordinates5 = Coordinates([-1.0, -1.0])
def setUp(self): self.gso_parameters = GSOParameters() self.objective_function = J1() self.landscape_position1 = [ LandscapePosition(self.objective_function, Coordinates([0.0, 0.0])) ] self.landscape_position2 = [ LandscapePosition(self.objective_function, Coordinates([1.0, 1.0])) ] self.landscape_position3 = [ LandscapePosition(self.objective_function, Coordinates([2.0, 2.0])) ] self.landscape_position4 = [ LandscapePosition(self.objective_function, Coordinates([0.5, 0.5])) ] self.landscape_position5 = [ LandscapePosition(self.objective_function, Coordinates([5.0, 5.0])) ] self.landscape_position6 = [ LandscapePosition(self.objective_function, Coordinates([0.0, 1.0])) ] self.landscape_position7 = [ LandscapePosition(self.objective_function, Coordinates([0.1, 0.0])) ] self.landscape_position8 = [ LandscapePosition(self.objective_function, Coordinates([0.0, 0.1])) ] self.landscape_position9 = [ LandscapePosition(self.objective_function, Coordinates([0.2, 0.0])) ]
def setUp(self): self.golden_data_path = os.path.normpath(os.path.dirname(os.path.realpath(__file__))) + '/golden_data/' self.gso_parameters = GSOParameters() self.objective_function = J1() self.bounding_box = BoundingBox([Boundary(1, 2), Boundary(10, 15)]) self.number_of_glowworms = 50 self.random_number_generator = MTGenerator(324324)
def setUp(self): self.gso_parameters = GSOParameters() self.objective_function = J1() self.landscape_position1 = LandscapePosition(self.objective_function, Coordinates([0.0, 0.0])) self.landscape_position2 = LandscapePosition(self.objective_function, Coordinates([1.0, 1.0])) self.positions = [[self.landscape_position1, self.landscape_position2]]
def __init__(self): self.golden_data_path = Path( __file__).absolute().parent / 'golden_data' self.gso_parameters = GSOParameters() self.objective_function = J1() self.bounding_box = BoundingBox([Boundary(1, 2), Boundary(10, 15)]) self.number_of_glowworms = 50 self.random_number_generator = MTGenerator(324324)
def test_create_from_interface(self): objective_function = J1() gso_parameters = GSOParameters() number_of_glowworms = 50 initializer = Initializer(objective_function, number_of_glowworms, gso_parameters) swarm = initializer.generate_glowworms() assert swarm.get_size() > 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_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
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])
def test_GSO_with_J1(self): objective_function = J1() bounding_box = BoundingBox([Boundary(-3.0, 3.0), Boundary(-3.0, 3.0)]) number_of_glowworms = 50 random_number_generator = MTGenerator(324324) builder = GSOBuilder() gso = builder.create(number_of_glowworms, random_number_generator, self.gso_parameters, objective_function, bounding_box) gso.run(200) # Function peak coordinates peak_coordinates = [[1.28, 0.0], [0.0, 1.58], [-0.46, -0.63]] # Check with auxiliar function the position of the glowworms assert self.found_peaks(peak_coordinates, 2, gso.swarm.glowworms)
def test_create_swarm(self): objective_function = J1() gso_parameters = GSOParameters() number_of_glowworms = 15 seed = 324324 random_number_generator = MTGenerator(seed) bounding_box = BoundingBox([Boundary(1, 2), Boundary(10, 15)]) initializer = RandomInitializer([objective_function], number_of_glowworms, gso_parameters, bounding_box, random_number_generator) swarm = initializer.generate_glowworms() assert number_of_glowworms == swarm.get_size() for glowworm in swarm.glowworms: coordinates = glowworm.landscape_positions[0].coordinates assert coordinates[0] < 2 and coordinates[0] >= 1 assert coordinates[1] < 15 and coordinates[1] >= 10