1
|
|
|
"""Contain PsoAlgorithm.""" |
2
|
1 |
|
from grortir.main.model.core.optimization_status import OptimizationStatus |
3
|
1 |
|
from grortir.main.pso.process_validator import ProcessValidator |
4
|
1 |
|
from grortir.main.pso.whole_group_pso import WholeGroupPso |
5
|
|
|
|
6
|
|
|
|
7
|
1 |
|
class PsoAlgorithm: |
8
|
|
|
"""Optimize process with different strategies. |
9
|
|
|
|
10
|
1 |
|
Attributes: |
11
|
|
|
process (AbstractProcess): process |
12
|
1 |
|
""" |
13
|
1 |
|
|
14
|
1 |
|
def __init__(self, process, grouping_strategy, optimization_startegy, |
15
|
1 |
|
number_of_particle=40): |
16
|
1 |
|
self.process = process |
17
|
|
|
self.grouping_strategy = grouping_strategy |
18
|
1 |
|
self.optimization_strategy = optimization_startegy |
19
|
|
|
self.process_validator = ProcessValidator() |
20
|
1 |
|
self.whole_group_pso = WholeGroupPso(self.process, number_of_particle) |
21
|
1 |
|
|
22
|
1 |
|
def run(self): |
23
|
1 |
|
"""Run algorithm.""" |
24
|
1 |
|
self.process_validator.validate(self.process) |
25
|
|
|
self.process.optimizationStatus = OptimizationStatus.in_progress |
26
|
1 |
|
number_of_groups = self.grouping_strategy.get_actual_numbers_of_groups() |
27
|
|
|
for current_group_number in range(number_of_groups): |
28
|
1 |
|
current_stages = self.grouping_strategy.get_items_from_group( |
29
|
|
|
current_group_number) |
30
|
|
|
group_optimization_strategy = self.optimization_strategy. \ |
31
|
|
|
get_group_optimization_strategy(current_stages) |
32
|
|
|
self.whole_group_pso.optimize(current_stages, |
33
|
|
|
group_optimization_strategy) |
34
|
|
|
self._post_processing() |
35
|
|
|
|
36
|
|
|
def _post_processing(self): |
|
|
|
|
37
|
|
|
final_status = OptimizationStatus.success |
38
|
|
|
for stage in self.grouping_strategy.ordered_stages: |
39
|
|
|
if stage.optimization_status != OptimizationStatus.success: |
40
|
|
|
final_status = OptimizationStatus.failed |
41
|
|
|
self.process.optimization_status = final_status |
42
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.