Completed
Pull Request — master (#43)
by Wojtek
09:32
created

GroupedOptimizer.__init__()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
1
"""Basic grouped optimizer."""
2
3
from grortir.main.pso.pso_algorithm import PsoAlgorithm
4
from main.model.core.optimization_status import OptimizationStatus
0 ignored issues
show
Bug introduced by
The name model does not seem to exist in module main.
Loading history...
Configuration introduced by
The import main.model.core.optimization_status 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...
5
6
7
class Result(object):
0 ignored issues
show
Coding Style introduced by
This class 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...
8
    def __init__(self, process):
9
        self.process = process
10
        self.summary_result = OptimizationStatus.not_started
11
        self.detailed_result = {}
12
13
    def generate(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...
14
        for stage in self.process.nodes():
15
            self.detailed_result[str(stage)] = stage.optimization_status
16
        for stage in self.process.nodes():
17
            if stage.optimization_status != OptimizationStatus.success:
18
                self.summary_result = OptimizationStatus.failed
19
20
21
class GroupedOptimizer:
22
    """Optimizer is object which optimize process."""
23
24
    def __init__(self, process, grouping_strategy):
25
        self.process = process
26
        self.grouping_strategy = grouping_strategy
27
        self.result = Result(self.process)
28
29
    def optimize_process(self):
30
        """Optimize process.
31
        Returns:
32
            True if success, False otherwise."""
33
        pso = PsoAlgorithm(self.process, self.grouping_strategy)
34
        pso.run()
35
        self.result.generate()
36