Completed
Push — master ( 40c094...b6a1c4 )
by Wojtek
02:30
created

CallsGroupOptimizationStrategy.initialize()   A

Complexity

Conditions 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
ccs 7
cts 7
cp 1
crap 3
1
"""Represents optimization strategy for group in PSO."""
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.group_optimization_strategy import \
5
    GroupOptimizationStrategy
6
7
8 1
class CallsGroupOptimizationStrategy(GroupOptimizationStrategy):
9
    """Represents optimization strategy for group in PSO."""
10
11 1
    def __init__(self, stages_in_group):
12 1
        self.stages_in_group = stages_in_group
13 1
        self.max_cost = 0
14 1
        self.expected_quality = np.inf
15
16 1
    def initialize(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'initialize' method
Loading history...
17
        """
18
            Initialize strategy.
19
        """
20 1
        max_cost = 0
21 1
        for stage in self.stages_in_group:
22 1
            max_cost += stage.max_calls
23 1
            if self.expected_quality > stage.maximum_acceptable_quality:
24 1
                self.expected_quality = stage.maximum_acceptable_quality
25 1
        self.max_cost = max_cost
26
27 1
    def should_continue(self, best_particle):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'should_continue' method
Loading history...
28
        """
29
30
        Args:
31
            best_particle Particle: best particle in swarm.
32
33
        Returns:
34
            bool: true if continuation is required.
35
36
        """
37 1
        return self._is_safe_cost() and not self._is_enough_quality(
38
            best_particle)
39
40 1
    def _is_safe_cost(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
        current_cost = 0
42 1
        for stage in self.stages_in_group:
43 1
            current_cost += stage.get_cost()
44 1
        return current_cost < self.max_cost
45
46 1
    def _is_enough_quality(self, best_particle):
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...
47
        return best_particle.best_quality <= self.expected_quality
48