Exemple #1
0
    def setUp(self):
        self.config = {
            "c_1": 2.0,
            "c_2": 2.0,
            "max_population": 10,
            "max_generations": 20,
            "max_velocity": [0.5, 0.5],
            "bounds": [[0, 10], [0, 10]],
            "objective_function": self.obj_func,
            "animate": True,
            "animation_frame_delay": 0.0
        }

        # generate random particles
        generator = PSOParticleGenerator(self.config)
        self.population = generator.init()
Exemple #2
0
    def setUp(self):
        self.max_velocity = [10.0, 10.0]
        self.bounds = [[0, 10], [0, 10]]

        config = {
            "max_population": 5,
            "max_velocity": self.max_velocity,
            "bounds": self.bounds,
            "objective_function": self.obj_func
        }

        self.particle = PSOParticle(score=0.0,
                                    position=[1.0, 1.0],
                                    velocity=[1.0, 1.0],
                                    max_velocity=self.max_velocity,
                                    bounds=self.bounds)

        self.generator = PSOParticleGenerator(config)
Exemple #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)