Update the behavior of MOEA/D without using inner componentsΒΆ
In some situations, the framework components may not allow you to implement all your ideas. In this case, you can directly alter the behavior of the algorithms as we will see in this example.
In this example, we want to shuffle all weight vectors at the end of each generation.
To do this, we need to extend the algorithm class and more precisely
the `run`
method to add one line : random.shuffle(self.weights)
.
You can rewrite all methods available in algorithms : https://moead-framework.github.io/framework/html/moead_framework/moead_framework.algorithm.abstract_moead.AbstractMoead.html#moead-framework-algorithm-abstract-moead-abstractmoead
"""
MoeadExample is a custom algorithm used as an example to show how to rewrite the run method to alter the behavior
of the MOEA/D algorithm.
"""
import random
from moead_framework.algorithm.combinatorial import Moead
class MoeadExample(Moead):
def run(self, checkpoint=None):
while self.termination_criteria.test():
# For each sub-problem i
for i in self.get_sub_problems_to_visit():
if checkpoint is not None:
checkpoint(self)
self.optimize_sub_problem(sub_problem_index=i)
# shuffle all weights
random.shuffle(self.weights)
return self.ep