Swarm   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 64
ccs 47
cts 47
cp 1
rs 10
wmc 20

8 Methods

Rating   Name   Duplication   Size   Complexity  
A _update_velocieties() 0 3 2
A initialize() 0 4 2
A do_single_iteration() 0 8 3
A __init__() 0 8 2
A _update_best_particle() 0 5 3
A _post_process_run_stages() 0 11 3
A _post_process_not_run_stages() 0 8 3
A post_processing() 0 7 2
1
"""Represents swarm."""
2
3 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...
4
5 1
from grortir.main.pso.particle import Particle
6
7
8 1
class Swarm(object):
9
    """Class which represent swarm."""
10
11 1
    def __init__(self, process, stages, number_of_particles):
12 1
        self.stages = stages
13 1
        self.process = process
14 1
        self.number_of_particles = number_of_particles
15 1
        self.particles = [Particle(stages, self.process, i) for i in
16
                          range(number_of_particles)]
17 1
        self.best_particle_quality = np.inf
18 1
        self.best_particle = self.particles[0]
19
20 1
    def initialize(self):
21
        """Initialize all particles in swarm."""
22 1
        for particle in self.particles:
23 1
            particle.initialize()
24
25 1
    def do_single_iteration(self):
26
        """Iterate one time."""
27 1
        for particle in self.particles:
28 1
            particle.update_values()
29 1
        self._update_best_particle()
30 1
        self._update_velocieties()
31 1
        for particle in self.particles:
32 1
            particle.move()
33
34 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...
35 1
        for particle in self.particles:
36 1
            if particle.best_quality < self.best_particle_quality:
37 1
                self.best_particle = particle
38 1
                self.best_particle_quality = particle.best_quality
39
40 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...
41 1
        for particle in self.particles:
42 1
            particle.update_velocities(self.best_particle)
43
44 1
    def post_processing(self):
45
        """Method which should be done after all iterations."""
46
        # calculate output:
47 1
        if self.best_particle_quality == np.inf:
48 1
            self._post_process_not_run_stages()
49
        else:
50 1
            self._post_process_run_stages(self.best_particle.best_positions)
51
52 1
    def _post_process_run_stages(self, best_control_params):
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...
53 1
        for stage in self.stages:
54 1
            current_output = stage.get_output_of_stage(
55
                stage.input_vector, best_control_params[stage])
56 1
            successors = self.process.successors(stage)
57 1
            for successor in successors:
58 1
                successor.input_vector = current_output
59 1
            stage.final_output = current_output
60 1
            stage.final_cost = stage.get_cost()
61 1
            stage.final_quality = stage.get_quality(
62
                stage.input_vector, best_control_params[stage])
63
64 1
    def _post_process_not_run_stages(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...
65 1
        for stage in self.stages:
66 1
            successors = self.process.successors(stage)
67 1
            for successor in successors:
68 1
                successor.input_vector = None
69 1
            stage.final_output = None
70 1
            stage.final_cost = None
71
            stage.final_quality = None
72