コード例 #1
0
 def test_GSOBuilder_using_RandomInitializer(self):
     builder = GSOBuilder()
     gso = builder.create(self.number_of_glowworms, 
                          self.random_number_generator, 
                          self.gso_parameters, 
                          self.objective_function, 
                          self.bounding_box)
     population_lines =  str(gso.swarm).split(os.linesep)
     expected_lines = open(self.golden_data_path+'initial_population_random.txt').readlines()
     
     assert len(expected_lines) == len(population_lines)
     for line1, line2 in zip(expected_lines, population_lines):
         assert line1.rstrip() == line2.rstrip()
コード例 #2
0
ファイル: test_gso.py プロジェクト: brianjimenez/lightdock
 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)
コード例 #3
0
ファイル: test_gso.py プロジェクト: brianjimenez/lightdock
 def test_GSO_with_report(self):
     objective_function = J5()
     self.gso_parameters.initial_vision_range = 3.0
     self.gso_parameters.max_vision_range = 3.0
     bounding_box = BoundingBox([Boundary(-2.0*pi, 2.0*pi), Boundary(-2.0*pi, 2.0*pi)])
     number_of_glowworms = 5
     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(5)
     
     report = gso.report()
     assert 14 == len(report.split(os.linesep))
     assert str(gso) == report
コード例 #4
0
ファイル: test_gso.py プロジェクト: brianjimenez/lightdock
 def test_GSO_with_J5(self):
     objective_function = J5()
     self.gso_parameters.initial_vision_range = 3.0
     self.gso_parameters.max_vision_range = 3.0
     bounding_box = BoundingBox([Boundary(-2.0*pi, 2.0*pi), Boundary(-2.0*pi, 2.0*pi)])
     number_of_glowworms = 100
     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(70)
     
     # Save last step
     gso.swarm.save(70, self.test_path, 'gso_j5_70.out')
     
     assert filecmp.cmp(self.test_path + 'gso_j5_70.out', self.golden_data_path + 'gso_j5_70.out')
コード例 #5
0
ファイル: test_gso.py プロジェクト: brianjimenez/lightdock
 def test_GSO_with_J2(self):
     objective_function = J2()
     self.gso_parameters.initial_vision_range = 2.0
     self.gso_parameters.max_vision_range = 2.0
     bounding_box = BoundingBox([Boundary(-1.0, 1.0), Boundary(-1.0, 1.0)])
     number_of_glowworms = 70
     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 = [[-0.5, -0.5], [-0.5, 0.5], [0.5, -0.5], [0.5, 0.5]]
     
     # Check with auxiliar function the position of the glowworms
     assert self.found_peaks(peak_coordinates, 2, gso.swarm.glowworms, 3)
コード例 #6
0
ファイル: test_gso.py プロジェクト: lightdock/lightdock
    def test_GSO_with_J3(self):
        objective_function = J3()
        self.gso_parameters.initial_vision_range = 2.0
        self.gso_parameters.max_vision_range = 2.0
        bounding_box = BoundingBox(
            [Boundary(-10.0, 10.0),
             Boundary(-10.0, 10.0)])
        number_of_glowworms = 70
        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(50)

        # Save last step
        gso.swarm.save(50, self.test_path, 'gso_j3_50.out')

        assert filecmp.cmp(self.test_path / 'gso_j3_50.out',
                           self.golden_data_path / 'gso_j3_50.out')
コード例 #7
0
from lightdock.gso.parameters import GSOParameters
from lightdock.gso.searchspace.benchmark_ofunctions import J2
from lightdock.gso.algorithm import GSOBuilder
from lightdock.gso.boundaries import Boundary, BoundingBox
from lightdock.mathutil.lrandom import MTGenerator


gso_parameters = GSOParameters()
objective_function = J2()
bounding_box = BoundingBox([Boundary(-4.0, 4.0), Boundary(-4.0, 4.0)])
number_of_glowworms = 200
random_number_generator = MTGenerator(324324324)
builder = GSOBuilder()
gso = builder.create(number_of_glowworms, 
                     random_number_generator, 
                     gso_parameters, 
                     objective_function, 
                     bounding_box)        

gso.swarm.save(0, '.', file_name='gso_0.out')
for glowworm in gso.swarm.glowworms:
    print(glowworm.landscape_positions[0])

print('Step 1')

gso.run(100)

print('Step 100')
for glowworm in gso.swarm.glowworms:
    print(glowworm.landscape_positions[0])