| Total Complexity | 6 |
| Total Lines | 28 |
| 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 | predecessor.input_vector, predecessor.control_params) |
||
| 25 | 1 | self.run_pso(stage) |
|
| 26 | else: |
||
| 27 | 1 | raise AttributeError('Incorrect process structure.') |
|
| 28 | |||
| 29 | 1 | if stage.optimization_status != OptimizationStatus.success: |
|
| 30 | 1 | return False |
|
| 31 | 1 | return True |
|
| 32 | |||
| 33 | 1 | def run_pso(self, stage): |
|
| 34 | """Run pso with predefined parameters.""" |
||
| 35 | pso(stage, swarmsize=self.swarm_size) |
||
| 36 |