Пример #1
0
 def test_pso_search(self):
     result = pso_search(self.population, self.config)
     self.assertTrue(result[0][0] < 1.0)
     self.assertTrue(result[0][1] < 1.0)
     self.assertTrue(result[1] < 1.0)
Пример #2
0
 def test_pso_search(self):
     result = pso_search(self.population, self.config)
     self.assertTrue(result[0][0] < 1.0)
     self.assertTrue(result[0][1] < 1.0)
     self.assertTrue(result[1] < 1.0)
Пример #3
0
from playground.swarm.pso import PSOParticleGenerator
from playground.swarm.pso import pso_search


def obj_func(vector):
    result = map(lambda el: el**2, vector)
    result = reduce(lambda x, y: x + y, result)
    return result


if __name__ == "__main__":
    config = {
        "c_1": 2.0,
        "c_2": 2.0,
        "max_population": 20,
        "max_generations": 50,
        "max_velocity": [0.5, 0.5],
        "bounds": [[0, 10], [0, 10]],
        "objective_function": obj_func,
        "animate": True,
        "animation_frame_delay": 0.1
    }

    # generate random particles
    generator = PSOParticleGenerator(config)
    population = generator.init()

    # search
    pso_search(population, config)
Пример #4
0

def obj_func(vector):
    result = map(lambda el: el ** 2, vector)
    result = reduce(lambda x, y: x + y, result)
    return result


if __name__ == "__main__":
    config = {
        "c_1": 2.0,
        "c_2": 2.0,

        "max_population": 20,
        "max_generations": 50,

        "max_velocity": [0.5, 0.5],
        "bounds": [[0, 10], [0, 10]],
        "objective_function": obj_func,

        "animate": True,
        "animation_frame_delay": 0.1
    }

    # generate random particles
    generator = PSOParticleGenerator(config)
    population = generator.init()

    # search
    pso_search(population, config)