Skip to content

Commit 6ad2ce3

Browse files
authored
Merge pull request #45 from Gromwud/main
Store offsprings in history
2 parents d6ebe79 + 0342023 commit 6ad2ce3

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

epde/operators/multiobjective/moeadd_specific.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,18 +360,22 @@ def apply(self, objective: ParetoLevels, arguments: dict):
360360
self.suboperators['chromosome_fitness'].apply(objective=temp_offspring,
361361
arguments=subop_args['chromosome_fitness'])
362362

363-
if all([not np.allclose(temp_offspring.obj_fun, solution.obj_fun) for solution in objective.population]):
363+
if (all([not np.allclose(temp_offspring.obj_fun, solution.obj_fun) for solution in objective.population])
364+
and tuple(temp_offspring.obj_fun) not in objective.history):
365+
# and all([not np.allclose(temp_offspring.obj_fun, obj_fun) for obj_fun in objective.history]):
366+
367+
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
368+
arguments=subop_args['pareto_level_updater'])
369+
objective.history.add(tuple(temp_offspring.obj_fun))
370+
break
371+
elif replaced >= attempt_limit:
372+
print("Allowed replication")
364373
self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
365374
arguments=subop_args['pareto_level_updater'])
366375
break
367-
# elif attempt >= attempt_limit and replaced:
368-
# print("Allowed replication")
369-
# self.suboperators['pareto_level_updater'].apply(objective=(temp_offspring, objective),
370-
# arguments=subop_args['pareto_level_updater'])
371-
# break
372376
elif attempt >= attempt_limit:
373377
temp_offspring.create()
374-
replaced = True
378+
replaced += 1
375379
attempt = 1
376380
self.suboperators['chromosome_mutation'].apply(objective=temp_offspring,
377381
arguments=subop_args['chromosome_mutation'])
@@ -430,6 +434,7 @@ def apply(self, objective : ParetoLevels, arguments : dict):
430434

431435
self.suboperators['chromosome_fitness'].apply(objective = objective.unplaced_candidates[idx],
432436
arguments = subop_args['chromosome_fitness'])
437+
objective.history.add(tuple(candidate.obj_fun))
433438
objective.initial_placing()
434439
return objective
435440

epde/optimizers/moeadd/moeadd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(self, population, sorting_method = fast_non_dominated_sorting,
6767
self.population = []
6868
self._update_method = update_method
6969
self.unplaced_candidates = population
70+
self.history = set()
7071

7172
def manual_reconst(self, attribute:str, value, except_attrs:dict):
7273
from epde.loader import attrs_from_dict

0 commit comments

Comments
 (0)