Total Complexity | 6 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | """Basic optimizer.""" |
||
8 | 1 | class Optimizer(BaseOptimizer): |
|
9 | """Optimizer is object which optimize process.""" |
||
10 | |||
11 | 1 | def optimize_process(self): |
|
12 | """Optimize process. |
||
13 | Raises: |
||
14 | AttributeError: When project has incorrect structure. |
||
15 | |||
16 | Returns: |
||
17 | bool: True if success, False otherwise.""" |
||
18 | 1 | for stage in self.ordered_stages: |
|
19 | 1 | if not self.process.predecessors(stage): |
|
20 | 1 | self.run_pso(stage) |
|
21 | 1 | elif len(self.process.predecessors(stage)) == 1: |
|
22 | 1 | predecessor = self.process.predecessors(stage)[0] |
|
23 | 1 | stage.input_vector = predecessor.get_output_of_stage() |
|
24 | 1 | self.run_pso(stage) |
|
25 | else: |
||
26 | 1 | raise AttributeError('Incorrect process structure.') |
|
27 | |||
28 | 1 | if stage.optimization_status != OptimizationStatus.success: |
|
29 | 1 | return False |
|
30 | 1 | return True |
|
31 | |||
32 | 1 | def run_pso(self, stage): |
|
33 | """Run pso with predefined parameters.""" |
||
34 | pso(stage, swarmsize=self.swarm_size) |
||
35 |