Completed
Pull Request — master (#43)
by Wojtek
03:06
created

Swarm   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
ccs 26
cts 26
cp 1
rs 10
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
A do_single_iteration() 0 8 3
A __init__() 0 8 2
A _update_best_particle() 0 5 3
A _update_velocieties() 0 3 2
A initialize() 0 4 2
1
"""Represents swarm."""
2 1
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
3
4 1
from grortir.main.pso.particle import Particle
5
6
7 1
class Swarm(object):
8
    """Class which represent swarm."""
9 1
    def __init__(self, process, stages, number_of_particles):
10 1
        self.stages = stages
11 1
        self.process = process
12 1
        self.number_of_particles = number_of_particles
13 1
        self.particles = [Particle(stages, self.process) for i in
14
                          range(number_of_particles)]
15 1
        self.best_particle_quality = np.inf
16 1
        self.best_particle = self.particles[0]
17
18 1
    def initialize(self):
19
        """Initialize all particles in swarm."""
20 1
        for particle in self.particles:
21 1
            particle.initialize()
22
23 1
    def do_single_iteration(self):
24
        """Iterate one time."""
25 1
        for particle in self.particles:
26 1
            particle.update_values()
27 1
        self._update_best_particle()
28 1
        self._update_velocieties()
29 1
        for particle in self.particles:
30 1
            particle.move()
31
32 1
    def _update_best_particle(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
33 1
        for particle in self.particles:
34 1
            if particle.best_quality < self.best_particle_quality:
35 1
                self.best_particle = particle
36 1
                self.best_particle_quality = particle.best_quality
37
38 1
    def _update_velocieties(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
39 1
        for particle in self.particles:
40
            particle.update_velocieties(self.best_particle)
41