diff --git a/pymoo/algorithms/moo/ctaea.py b/pymoo/algorithms/moo/ctaea.py index 16f9a0e27..9c3ccb9af 100644 --- a/pymoo/algorithms/moo/ctaea.py +++ b/pymoo/algorithms/moo/ctaea.py @@ -14,7 +14,7 @@ from pymoo.util.display.multi import MultiObjectiveOutput from pymoo.util.dominator import Dominator from pymoo.util.function_loader import load_function -from pymoo.util.misc import has_feasible, random_permuations +from pymoo.util.misc import has_feasible, random_permutations from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting @@ -63,7 +63,7 @@ def _do(self, problem, Hm, n_select, n_parents, **kwargs): n_random = n_select * n_parents * self.pressure n_perms = math.ceil(n_random / n_pop) # get random permutations and reshape them - P = random_permuations(n_perms, n_pop)[:n_random] + P = random_permutations(n_perms, n_pop)[:n_random] P = np.reshape(P, (n_select * n_parents, self.pressure)) if Pc <= Pd: # Choose from DA diff --git a/pymoo/algorithms/moo/pinsga2.py b/pymoo/algorithms/moo/pinsga2.py index 59bdab82e..38382dcbb 100644 --- a/pymoo/algorithms/moo/pinsga2.py +++ b/pymoo/algorithms/moo/pinsga2.py @@ -1,25 +1,22 @@ -import numpy as np import sys - from abc import ABC, abstractmethod + +import numpy as np + from pymoo.algorithms.base.genetic import GeneticAlgorithm +from pymoo.algorithms.moo.nsga2 import binary_tournament from pymoo.docs import parse_doc_string from pymoo.operators.crossover.sbx import SBX from pymoo.operators.mutation.pm import PM -from pymoo.operators.survival.rank_and_crowding import RankAndCrowding from pymoo.operators.sampling.rnd import FloatRandomSampling -from pymoo.operators.selection.tournament import compare, TournamentSelection +from pymoo.operators.selection.tournament import TournamentSelection +from pymoo.operators.survival.rank_and_crowding import RankAndCrowding from pymoo.termination.default import DefaultMultiObjectiveTermination -from pymoo.util.display.multi import MultiObjectiveOutput -from pymoo.util.dominator import Dominator -from pymoo.util.vf_dominator import VFDominator -from pymoo.util.misc import has_feasible -from pymoo.util.reference_direction import select_points_with_maximum_distance from pymoo.util import value_functions as mvf +from pymoo.util.display.multi import MultiObjectiveOutput from pymoo.util.nds.non_dominated_sorting import NonDominatedSorting - -from pymoo.algorithms.moo.nsga2 import binary_tournament -from pymoo.algorithms.moo.nsga2 import RankAndCrowdingSurvival +from pymoo.util.reference_direction import select_points_with_maximum_distance +from pymoo.util.vf_dominator import VFDominator # ========================================================================================================= diff --git a/pymoo/operators/selection/rnd.py b/pymoo/operators/selection/rnd.py index 487460669..774e018bd 100644 --- a/pymoo/operators/selection/rnd.py +++ b/pymoo/operators/selection/rnd.py @@ -3,7 +3,7 @@ import numpy as np from pymoo.core.selection import Selection -from pymoo.util.misc import random_permuations +from pymoo.util.misc import random_permutations class RandomSelection(Selection): @@ -16,7 +16,7 @@ def _do(self, _, pop, n_select, n_parents, **kwargs): n_perms = math.ceil(n_random / len(pop)) # get random permutations and reshape them - P = random_permuations(n_perms, len(pop))[:n_random] + P = random_permutations(n_perms, len(pop))[:n_random] return np.reshape(P, (n_select, n_parents)) diff --git a/pymoo/operators/selection/tournament.py b/pymoo/operators/selection/tournament.py index 897e714f4..a1bc5adb3 100644 --- a/pymoo/operators/selection/tournament.py +++ b/pymoo/operators/selection/tournament.py @@ -3,7 +3,7 @@ import numpy as np from pymoo.core.selection import Selection -from pymoo.util.misc import random_permuations +from pymoo.util.misc import random_permutations class TournamentSelection(Selection): @@ -42,7 +42,7 @@ def _do(self, _, pop, n_select, n_parents=1, **kwargs): n_perms = math.ceil(n_random / len(pop)) # get random permutations and reshape them - P = random_permuations(n_perms, len(pop))[:n_random] + P = random_permutations(n_perms, len(pop))[:n_random] P = np.reshape(P, (n_select * n_parents, self.pressure)) # compare using tournament function diff --git a/pymoo/util/misc.py b/pymoo/util/misc.py index 480bd7378..f643133dc 100644 --- a/pymoo/util/misc.py +++ b/pymoo/util/misc.py @@ -58,7 +58,7 @@ def parameter_less_constraints(F, CV, F_max=None): return F -def random_permuations(n, l, concat=True): +def random_permutations(n, l, concat=True): P = [] for i in range(n): P.append(np.random.permutation(l))