Completed
Push — master ( 375895...8c5af0 )
by Wojtek
8s
created

could_be_optimized()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
cc 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
"""Module contains class CallsStage."""
2 1
from grortir.main.model.core.abstract_stage import AbstractStage
3
4
5 1
class CallsStage(AbstractStage):
6
    """Implementation of basic stage.
7
8
    Cost is calculated by number of calls of cost function.
9
    Attributes:
10
        cost (float): Actual cost of stage.
11
        max_calls (int): Maximum possible calls of cost quality function
12
        name (str): Name of stage
13
    """
14
15 1
    def __init__(self, name, max_calls, input_vector=()):
16
        """Constructor."""
17 1
        super().__init__(input_vector)
18 1
        self.max_calls = max_calls
19 1
        self.name = name
20 1
        self.control_params = [0] * len(self.input_vector)
21 1
        self.cost = 0
22
23 1
    def get_quality(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'get_quality' method
Loading history...
24
        """
25
        Return quality of actual output.
26
27
        Returns:
28
            quality (float): quality
29
30
        """
31 1
        self.cost += 1
32 1
        return self.calculate_quality()
33
34 1
    def calculate_quality(self):
35
        """
36
        Function for calculating quality.
37
38
        Returns:
39
            quality (float): quality
40
41
        Raises:
42
            AssertionError: If length of `control_params`
43
                is not equal length of `current_vector`
44
        """
45 1
        assert len(self.control_params) == len(self.current_vector)
46 1
        quality = 0
47 1
        for i in enumerate(self.control_params):
48 1
            quality += (self.control_params[i[0]] - self.current_vector[
49
                i[0]]) ** 2
50 1
        return quality
51
52 1
    def get_cost(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'get_cost' method
Loading history...
53
        """
54
        Return actual cost of stage.
55
56
        Returns:
57
            cost (float): cost
58
        """
59 1
        return self.cost
60
61 1
    def could_be_optimized(self):
0 ignored issues
show
Bug introduced by
Arguments number differs from overridden 'could_be_optimized' method
Loading history...
62
        """Return answer if it is still possible to optimize that stage."""
63
        return self.get_cost() < self.max_calls
64