Example #1
0
def builder(base, point, params, random_generator, position_initializator):
    """Sistematically generate environments from parameters combination."""
    index = 1
    for param in parameters_matrix(params):
        # read parameters from the matrix
        error = param[0]
        inertial_weight = param[1]
        cognition = param[2]
        social = param[3]
        num_particles = param[4]
        velocity_max = param[5]
        iterations_per_particle = param[6]
        # point disturbed by a gaussian noise
        disturbed_point_gen = apply_noise_linear(point=point, error=error)
        # compute radius
        radius = matrix([distance(b, next(disturbed_point_gen)) for b in base])
        # build environment configuration
        env_config = {
            'inertial_weight': inertial_weight,
            'cognition': cognition,
            'social': social,
            'random': random_generator,
            'base': base,
            'radius': radius
        }
        env = Environment(config=env_config)
        # particle position generator
        position_generator = position_initializator(env)
        # particles inside env
        for i in range(num_particles):
            # particles
            PSOParticle(
                environment=env,
                id="P{}env{}".format(i, index),
                current=Information(position=next(position_generator)),
                velocity=velocity_max * random_generator.random(),
                vmax=velocity_max
            )

        # engine for env
        yield (param, ParticleEngine(
            config={
                'max_iterations': iterations_per_particle
            },
            environment=env
        ))
Example #2
0

random_generator = Random()

center = [1000, 1000, 1000]
side_length = 100

base_generator = generate_matrix_of_points_in_cube(
    center=center, side_length=side_length, num_of_points=4)
point_generator = generate_matrix_of_points_in_cube(
    center=center, side_length=side_length, num_of_points=1)

base = next(base_generator)
point = next(point_generator)
error = 10
disturbed_point_gen = apply_noise_linear(point=point, error=error)
radius = matrix([distance(b, next(disturbed_point_gen)) for b in base])

env_config = {
    'inertial_weight': 2,
    'cognition': 2,
    'social': 1,
    'random': random_generator,
    'base': base,
    'radius': radius
}
env1 = Environment(config=env_config)

position_generator = around_beacons(env1)

vmax = 5
Example #3
0
random_generator = Random()

center = [1000, 1000, 1000]
side_length = 100

base_generator = generate_matrix_of_points_in_cube(center=center,
                                                   side_length=side_length,
                                                   num_of_points=4)
point_generator = generate_matrix_of_points_in_cube(center=center,
                                                    side_length=side_length,
                                                    num_of_points=1)

base = next(base_generator)
point = next(point_generator)
error = 10
disturbed_point_gen = apply_noise_linear(point=point, error=error)
radius = matrix([distance(b, next(disturbed_point_gen)) for b in base])

env_config = {
    'inertial_weight': 2,
    'cognition': 2,
    'social': 1,
    'random': random_generator,
    'base': base,
    'radius': radius
}
env1 = Environment(config=env_config)

position_generator = around_beacons(env1)

vmax = 5