Exemple #1
0
def create_fixture_unit():
    '''
    Creates fixture file for a regression test for the whole clss as an unit.
    '''
    # *******************************************************
    # Write fixture file for the BoidsMaster.fly_towards_center()
    fixt_boids = BoidsMaster()
    before_positions = deepcopy(fixt_boids.positions.tolist())
    before_velocities = deepcopy(fixt_boids.velocities.tolist())
    fixt_boids.update_boids()

    after_positions = fixt_boids.positions.tolist()
    after_velocities = fixt_boids.velocities.tolist()

    before = (before_positions, before_velocities)
    after = (after_positions, after_velocities)

    fixture = {"before": before, "after": after}
    fixture_file = open("tests/fixtures/fixture_general.yml", 'w')
    fixture_file.write(yaml.dump(fixture))
    fixture_file.close()
Exemple #2
0
def create_fixture3():
    '''
    Creates fixture file for testing the flight in formation.
    '''
    # *******************************************************
    # Write fixture file for the BoidsMaster.match_speed_w_neighbours()
    fixt_boids = BoidsMaster()
    before_positions = deepcopy(fixt_boids.positions.tolist())
    before_velocities = deepcopy(fixt_boids.velocities.tolist())
    fixt_boids.match_speed_w_neighbours()
    fixt_boids.update_positions()

    after_positions = fixt_boids.positions.tolist()
    after_velocities = fixt_boids.velocities.tolist()

    beforeM3 = (before_positions, before_velocities)
    afterM3 = (after_positions, after_velocities)

    fixture = {"before": beforeM3, "after": afterM3}
    fixture_file = open("tests/fixtures/fixture_match_speed.yml", 'w')
    fixture_file.write(yaml.dump(fixture))
    fixture_file.close()
Exemple #3
0
def create_fixture2():
    '''
    Creates fixture file for testing the flight away from newighbouring boids.
    '''
    # *******************************************************
    # Write fixture file for the BoidsMaster.fly_away_from_neighbours()
    fixt_boids = BoidsMaster()
    before_positions = deepcopy(fixt_boids.positions.tolist())
    before_velocities = deepcopy(fixt_boids.velocities.tolist())
    fixt_boids.fly_away_from_neighbours()
    fixt_boids.update_positions()

    after_positions = fixt_boids.positions.tolist()
    after_velocities = fixt_boids.velocities.tolist()

    beforeM2 = (before_positions, before_velocities)
    afterM2 = (after_positions, after_velocities)

    fixture = {"before": beforeM2, "after": afterM2}
    fixture_file = open("tests/fixtures/fixture_fly_away_neighbours.yml", 'w')
    fixture_file.write(yaml.dump(fixture))
    fixture_file.close()
Exemple #4
0
def create_fixture1():
    '''
    Creates fixture file for testing the flight towards the middle of the flock.
    '''
    # *******************************************************
    # Write fixture file for the BoidsMaster.fly_towards_center()
    fixt_boids = BoidsMaster()
    before_positions = deepcopy(fixt_boids.positions.tolist())
    before_velocities = deepcopy(fixt_boids.velocities.tolist())
    fixt_boids.fly_towards_center()
    fixt_boids.update_positions()

    after_positions = fixt_boids.positions.tolist()
    after_velocities = fixt_boids.velocities.tolist()

    beforeM1 = (before_positions, before_velocities)
    afterM1 = (after_positions, after_velocities)

    fixture = {"before": beforeM1, "after": afterM1}
    fixture_file = open("tests/fixtures/fixture_fly2center.yml", 'w')
    fixture_file.write(yaml.dump(fixture))
    fixture_file.close()
Exemple #5
0
def main_animate_boids(number_boids = 50,
                         collision_alert = 100,
                         formation_limit = 10000,
                         strength2middle = 0.01,
                         strength2formation = 0.125):
    '''
    This function initializes a BoidsMaster object that controlls the behaviour of the boids. The input parameters influence the simulation.

    :param number_boids: The number of boids to include in the simulation
    :type number_boids: int
    :param collision_alert: Sets which boids are considered neighbours in order to avoid collisions with them
    :type collision_alert: int
    :param formation_limit: Sets which boids are supposed to fly in a formation with matching speed
    :type formation_limit: int
    :param strength2middle: Sets the strength with which the boids fly towards the middle of the flock
    :type strength2middle: float
    :param strength2formation: Sets the strength of the flying in the same formation
    :type strength2formation: float

    :returns: An animation of the animated boid simulation and an .mp4 video with the recording.
    '''
    if not isinstance(number_boids, int):
        raise ValueError("The number of boids: " +
                         str(number_boids) + " is not an integer")
    if not isinstance(collision_alert, int):
        raise ValueError("The collision alert: " +
                         str(collision_alert) + " is not an integer")
    if not isinstance(formation_limit, int):
        raise ValueError("The formation limit: " +
                         str(formation_limit) + " is not an integer")
    if not isinstance(strength2middle, float):
        raise ValueError("The strength to middle: " +
                         str(strength2middle) + " is not an integer")
    if not isinstance(strength2formation, float):
        raise ValueError("The strength to formation: " +
                         str(strength2formation) + " is not an integer")

    if number_boids <= 0:
        raise ValueError("The number of boids: " +
                         str(number_boids) + " is non-positive")

    if collision_alert <= 0:
        raise ValueError("The collision alert: " +
                         str(collision_alert) + " is non-positive")

    if formation_limit <= 0:
        raise ValueError("The formation alert: " +
                         str(formation_limit) + " is non-positive")

    if strength2middle <= 0:
        raise ValueError("The strength to middle: " +
                         str(strength2middle) + " is non-positive")

    if strength2formation <= 0:
        raise ValueError("The strength to formation: " +
                         str(strength2formation) + " is non-positive")


    position_limits=np.array([[-450.0, 50.0], [300.0, 600.0]])
    velocity_limits=np.array([[0, 10.0], [-20.0, 20.0]])

    master_of_boids = BoidsMaster(position_limits,
                                  velocity_limits,
                                  number_boids,
                                  collision_alert,
                                  formation_limit,
                                  strength2middle,
                                  strength2formation)
    master_of_boids.start_animation()