Exemplo n.º 1
0
    def _next(self):

        # all the elements in the interval
        a, left, right, b = self.pop

        # the golden ratio (precomputed constant)
        R = self.R

        # if the left solution is better than the right
        if left.F[0] < right.F[0]:

            # make the right to be the new right bound and the left becomes the right
            a, b = a, right
            right = left

            # create a new left individual and evaluate
            left = Individual(X=b.X - R * (b.X - a.X))
            self.evaluator.eval(self.problem, Population.create(left), algorithm=self)

        # if the right solution is better than the left
        else:

            # make the left to be the new left bound and the right becomes the left
            a, b = left, b
            left = right

            # create a new right individual and evaluate
            right = Individual(X=a.X + R * (b.X - a.X))
            self.evaluator.eval(self.problem, Population.create(right), algorithm=self)

        # update the population with all the four individuals
        self.pop = Population.create(a, left, right, b)
Exemplo n.º 2
0
    def _solve(self, pop):
        # generate direction vectors by random sampling
        ref_dirs = np.random.random((self.batch_size, self.n_obj))
        ref_dirs /= np.expand_dims(np.sum(ref_dirs, axis=1), 1)

        algo = MOEAD_algo(ref_dirs=ref_dirs, n_neighbors=len(ref_dirs), eliminate_duplicates=False)
        repair, crossover, mutation = algo.mating.repair, algo.mating.crossover, algo.mating.mutation

        if isinstance(algo.decomposition, str):
            decomp = algo.decomposition
            if decomp == 'auto':
                if self.n_obj <= 2:
                    decomp = 'tchebi'
                else:
                    decomp = 'pbi'
            decomposition = get_decomposition(decomp)
        else:
            decomposition = algo.decomposition

        ideal_point = np.min(pop.get('F'), axis=0)

        # find the optimal individual for each reference direction
        opt_pop = Population(0, individual=Individual())
        for i in range(self.batch_size):
            N = algo.neighbors[i, :]
            FV = decomposition.do(pop.get("F"), weights=ref_dirs[i], ideal_point=ideal_point)
            opt_pop = Population.merge(opt_pop, pop[np.argmin(FV)])

        all_off = Population(0, individual=Individual())
        for i in np.random.permutation(self.batch_size):
            N = algo.neighbors[i, :]

            if self.batch_size > 1:
                if np.random.random() < algo.prob_neighbor_mating:
                    parents = N[np.random.permutation(algo.n_neighbors)][:crossover.n_parents]
                else:
                    parents = np.random.permutation(algo.pop_size)[:crossover.n_parents]

                # do recombination and create an offspring
                off = crossover.do(self.real_problem, opt_pop, parents[None, :])
            else:
                off = opt_pop[N].copy()
                
            off = mutation.do(self.real_problem, off)
            off = off[np.random.randint(0, len(off))]

            # repair first in case it is necessary
            if repair:
                off = algo.repair.do(self.real_problem, off, algorithm=algo)

            all_off = Population.merge(all_off, off)
        
        return all_off
Exemplo n.º 3
0
    def _initialize(self):
        xl, xu = self.problem.bounds()
        R = self.R
        d = R * (xu - xl)

        a = Individual(X=xl)
        b = Individual(X=xu)

        left = Individual(X=xu - d)
        right = Individual(X=xl + d)

        pop = Population.create(a, left, right, b)

        self.evaluator.eval(self.problem, pop, algorithm=self)
        self.pop = pop
Exemplo n.º 4
0
    def _next(self):
        # the offspring population to finally evaluate and attach to the population
        off = Population()

        # find the potential optimal solution in the current population
        potential_optimal = self._potential_optimal()

        # for each of those solutions execute the division move
        for current in potential_optimal:

            # find the largest dimension the solution has not been evaluated yet
            nxl, nxu = norm_bounds(current, problem)
            k = np.argmax(nxu - nxl)

            # the delta value to be used to get left and right - this is one sixth of the range
            xl, xu = current.get("xl"), current.get("xu")

            delta = (xu[k] - xl[k]) / 6

            # print(current.X, delta, k, xl, xu)

            # create the left individual
            left_x = np.copy(current.X)
            left_x[k] = xl[k] + delta
            left = Individual(X=left_x)

            # create the right individual
            right_x = np.copy(current.X)
            right_x[k] = xu[k] - delta
            right = Individual(X=right_x)

            # update the boundaries for all the points accordingly
            for ind in [current, left, right]:
                update_bounds(ind, xl, xu, k, delta)

            # create the offspring population, evaluate and attach to current population
            _off = Population.create(left, right)
            _off.set("depth", current.get("depth") + 1)

            off = Population.merge(off, _off)

        # evaluate the offsprings
        self.evaluator.eval(self.problem, off, algorithm=self)

        # print(off.get("X"))

        # add the offsprings to the population
        self.pop = Population.merge(self.pop, off)
Exemplo n.º 5
0
 def copy(self, deep=False):
     # self.individual -> Individual()
     pop = Population(n_individuals=len(self), individual=Individual())
     for i in range(len(self)):
         val = copy.deepcopy(self[i]) if deep else self[i]
         pop[i] = val
     return pop
Exemplo n.º 6
0
    def __init__(self,
                 pop_size=None,
                 sampling=None,
                 selection=None,
                 crossover=None,
                 mutation=None,
                 survival=None,
                 n_offsprings=None,
                 eliminate_duplicates=DefaultDuplicateElimination(),
                 repair=None,
                 individual=Individual(),
                 **kwargs):

        super().__init__(**kwargs)

        # the population size used
        self.pop_size = pop_size

        # the survival for the genetic algorithm
        self.survival = survival

        # number of offsprings to generate through recombination
        self.n_offsprings = n_offsprings

        # if the number of offspring is not set - equal to population size
        if self.n_offsprings is None:
            self.n_offsprings = pop_size

        # the object to be used to represent an individual - either individual or derived class
        self.individual = individual

        # set the duplicate detection class - a boolean value chooses the default duplicate detection
        if isinstance(eliminate_duplicates, bool):
            if eliminate_duplicates:
                self.eliminate_duplicates = DefaultDuplicateElimination()
            else:
                self.eliminate_duplicates = NoDuplicateElimination()
        else:
            self.eliminate_duplicates = eliminate_duplicates

        # simply set the no repair object if it is None
        self.repair = repair if repair is not None else NoRepair()

        self.initialization = Initialization(
            sampling,
            individual=individual,
            repair=self.repair,
            eliminate_duplicates=self.eliminate_duplicates)

        self.mating = Mating(selection,
                             crossover,
                             mutation,
                             repair=self.repair,
                             eliminate_duplicates=self.eliminate_duplicates,
                             n_max_iterations=100)

        # other run specific data updated whenever solve is called - to share them in all algorithms
        self.n_gen = None
        self.pop = None
        self.off = None
Exemplo n.º 7
0
 def _update(self):
     D = self.D
     ind = Individual(X=np.copy(D["X"]),
                      F=np.copy(D["F"]),
                      G=np.copy(-D["G"]))
     pop = Population.merge(self.pop, Population.create(ind))
     set_cv(pop)
     self.pop = pop
Exemplo n.º 8
0
 def __new__(cls, n_individuals=0, individual=Individual()):
     obj = super(Population,
                 cls).__new__(cls,
                              n_individuals,
                              dtype=individual.__class__).view(cls)
     for i in range(n_individuals):
         obj[i] = individual.copy()
     obj.individual = individual
     return obj
Exemplo n.º 9
0
    def __init__(self,
                 ref_dirs,
                 framework_id=None,
                 metamodel_list=None,
                 acq_list=None,
                 framework_acq_dict=None,
                 aggregation=None,
                 disp=False,
                 lf_algorithm_list=None,
                 init_pop_size=None,
                 pop_size_per_epoch=None,
                 pop_size_per_algorithm=None,
                 pop_size_lf=None,
                 n_split=10,
                 n_gen_lf=100,
                 **kwargs):
        kwargs['individual'] = Individual(rank=np.inf,
                                          niche=-1,
                                          dist_to_niche=np.inf)
        set_if_none(kwargs, 'pop_size', init_pop_size)
        set_if_none(kwargs, 'sampling', RandomSampling())
        set_if_none(kwargs, 'crossover',
                    SimulatedBinaryCrossover(prob_cross=1.0, eta_cross=15))
        set_if_none(kwargs, 'mutation',
                    PolynomialMutation(prob_mut=None, eta_mut=20))
        set_if_none(kwargs, 'selection',
                    TournamentSelection(func_comp=comp_by_cv_then_random))
        set_if_none(kwargs, 'survival', ReferenceDirectionSurvival(ref_dirs))
        set_if_none(kwargs, 'eliminate_duplicates', True)
        set_if_none(kwargs, 'disp', disp)
        super().__init__(**kwargs)

        self.func_display_attrs = disp_multi_objective
        self.init_pop_size = init_pop_size
        self.pop_size_lf = pop_size_lf
        self.pop_size_per_epoch = pop_size_per_epoch
        self.pop_size_per_algorithm = pop_size_per_algorithm
        self.framework_crossval = 10
        self.n_gen_lf = n_gen_lf
        self.ref_dirs = ref_dirs
        self.cur_ref_no = 0
        self.framework_id = framework_id
        self.metamodel_list = metamodel_list
        self.metamodel_list = self.metamodel_list
        self.acq_list = acq_list
        self.framework_acq_dict = framework_acq_dict
        self.aggregation = aggregation
        self.lf_algorithm_list = lf_algorithm_list
        self.n_split = n_split
        self.problem = None
        self.archive = None
        self.metamodel = None
        self.pop = None
        self.samoo_evaluator = SamooEvaluator()
        self.generative_algorithm = ['rga', 'rga_x', 'de']
        self.simultaneous_algorithm = ['mm_rga', 'nsga2', 'nsga3', 'moead']
Exemplo n.º 10
0
    def __init__(self,
                 pop_size,
                 sampling,
                 selection,
                 crossover,
                 mutation,
                 survival,
                 n_offsprings=None,
                 eliminate_duplicates=None,
                 func_repair=None,
                 individual=Individual(),
                 **kwargs):

        super().__init__(**kwargs)

        # population size of the genetic algorithm
        self.pop_size = pop_size

        # initial sampling method: object, 2d array, or population (already evaluated)
        self.sampling = sampling

        # the method to be used to select parents for recombination
        self.selection = selection

        # method to do the crossover
        self.crossover = crossover

        # method for doing the mutation
        self.mutation = mutation

        # function to repair an offspring after mutation if necessary
        self.func_repair = func_repair

        # survival selection
        self.survival = survival

        # number of offsprings to generate through recombination
        self.n_offsprings = n_offsprings

        # a function that returns the indices of duplicates
        self.eliminate_duplicates = eliminate_duplicates
        if isinstance(self.eliminate_duplicates, bool):
            self.eliminate_duplicates = default_is_duplicate

        # the object to be used to represent an individual - either individual or derived class
        self.individual = individual

        # if the number of offspring is not set - equal to population size
        if self.n_offsprings is None:
            self.n_offsprings = pop_size

        # other run specific data updated whenever solve is called - to share them in all methods
        self.n_gen = None
        self.pop = None
        self.off = None
Exemplo n.º 11
0
    def __init__(
            self,
            ref_dirs,
            pop_size=None,
            sampling=FloatRandomSampling(),
            selection=TournamentSelection(func_comp=comp_by_cv_then_random),
            crossover=SimulatedBinaryCrossover(eta=30, prob=1.0),
            mutation=PolynomialMutation(eta=20, prob=None),
            eliminate_duplicates=True,
            n_offsprings=None,
            **kwargs):
        """

        Parameters
        ----------

        ref_dirs : {ref_dirs}
        pop_size : int (default = None)
            By default the population size is set to None which means that it will be equal to the number of reference
            line. However, if desired this can be overwritten by providing a positive number.
        sampling : {sampling}
        selection : {selection}
        crossover : {crossover}
        mutation : {mutation}
        eliminate_duplicates : {eliminate_duplicates}
        n_offsprings : {n_offsprings}

        """

        self.ref_dirs = ref_dirs

        if pop_size is None:
            pop_size = len(ref_dirs)

        kwargs['individual'] = Individual(rank=np.inf,
                                          niche=-1,
                                          dist_to_niche=np.inf)

        if 'survival' in kwargs:
            survival = kwargs['survival']
            del kwargs['survival']
        else:
            survival = ReferenceDirectionSurvival(ref_dirs)

        super().__init__(pop_size=pop_size,
                         sampling=sampling,
                         selection=selection,
                         crossover=crossover,
                         mutation=mutation,
                         survival=survival,
                         eliminate_duplicates=eliminate_duplicates,
                         n_offsprings=n_offsprings,
                         **kwargs)

        self.func_display_attrs = disp_multi_objective
Exemplo n.º 12
0
    def _initialize(self):

        # the boundaries of the problem for initialization
        xl, xu = self.problem.bounds()

        # the golden ratio (precomputed constant)
        R = self.R

        # a and b always represents the boundaries
        a, b = Individual(X=xl), Individual(X=xu)

        # create the left and right in the interval itself
        left, right = Individual(X=xu - R * (xu - xl)), Individual(X=xl + R * (xu - xl))

        # create a population with all four individuals
        pop = Population.create(a, left, right, b)

        # evaluate all the points
        self.evaluator.eval(self.problem, pop, algorithm=self)
        self.pop = pop
Exemplo n.º 13
0
    def __init__(self,
                 sampling,
                 individual=Individual(),
                 repair=None,
                 eliminate_duplicates=None) -> None:

        super().__init__()
        self.sampling = sampling
        self.individual = individual
        self.repair = repair
        self.eliminate_duplicates = eliminate_duplicates
Exemplo n.º 14
0
    def _each_iteration_samoo(self, X, **kwargs):
        self.archive = self.samoo_evaluator.eval(problem=self.samoo_problem,
                                                 x=X,
                                                 archive=self.archive)
        temp_pop = Population(0, individual=Individual())
        temp_pop = temp_pop.new("X", self.archive['x'], "F", self.archive['f'],
                                "CV", self.archive['cv'], "G",
                                self.archive['g'], "feasible",
                                self.archive['feasible_index'])
        self.func_eval = self.archive['x'].shape[0]

        return temp_pop
Exemplo n.º 15
0
    def _next(self):
        a, left, right, b = self.pop
        R = self.R

        if left.F[0] < right.F[0]:

            a, b = a, right
            right = left

            left = Individual(X=b.X - R * (b.X - a.X))
            self.evaluator.eval(self.problem, Population.create(left), algorithm=self)

        else:

            a, b = left, b
            left = right

            right = Individual(X=a.X + R * (b.X - a.X))
            self.evaluator.eval(self.problem, Population.create(right), algorithm=self)

        self.pop = Population.create(a, left, right, b)
Exemplo n.º 16
0
    def __init__(self,
                 sampling,
                 individual=Individual(),
                 repair=None,
                 eliminate_duplicates=None) -> None:

        super().__init__()
        self.sampling = sampling
        self.individual = individual
        self.eliminate_duplicates = eliminate_duplicates if eliminate_duplicates is not None else NoDuplicateElimination(
        )
        self.repair = repair if repair is not None else NoRepair()
Exemplo n.º 17
0
    def __init__(self,
                 pop_size=200,
                 n_parallel=10,
                 sampling=LatinHypercubeSampling(),
                 display=SingleObjectiveDisplay(),
                 repair=None,
                 individual=Individual(),
                 **kwargs):
        """

        Parameters
        ----------
        pop_size : {pop_size}
        sampling : {sampling}
        selection : {selection}
        crossover : {crossover}
        mutation : {mutation}
        eliminate_duplicates : {eliminate_duplicates}
        n_offsprings : {n_offsprings}

        """

        super().__init__(display=display, **kwargs)

        self.initialization = Initialization(sampling,
                                             individual=individual,
                                             repair=repair)

        self.pop_size = pop_size
        self.n_parallel = n_parallel
        self.each_pop_size = pop_size // n_parallel

        self.solvers = None
        self.niches = []

        def cmaes(problem, x):
            solver = CMAES(x0=x, tolfun=1e-11, tolx=1e-3, restarts=0)
            solver.initialize(problem)
            solver.next()
            return solver

        def nelder_mead(problem, x):
            solver = NelderMead(X=x)
            solver.initialize(problem)
            solver._initialize()
            solver.n_gen = 1
            solver.next()
            return solver

        self.func_create_solver = nelder_mead

        self.default_termination = SingleObjectiveDefaultTermination()
Exemplo n.º 18
0
    def __init__(self, save_to=None, continue_from=None, args=None, **kwargs):
        kwargs["individual"] = Individual(rank=np.inf, crowding=-1)
        super().__init__(**kwargs)

        logger.info("new version")
        self.tournament_type = "comp_by_dom_and_crowding"
        self.func_display_attrs = disp_multi_objective

        self.continue_from = continue_from
        self.args = args

        self.save_to = os.path.join(args.save, args.code)
        utils.create_exp_dir(self.save_to)
Exemplo n.º 19
0
    def _eval_grad(self):
        D = self.D

        # dF, dG = self.problem.evaluate(D["X"], return_values_of=["dF", "dG"])
        # if dF is None or dG is None:
        #     dF, dG = GradientApproximation(self.problem, evaluator=self.evaluator).do(Individual(X=D["X"]))

        dF, dG = GradientApproximation(self.problem, evaluator=self.evaluator).do(Individual(X=D["X"]))

        D["dF"] = concatenate([dF[0], [0]])
        if self.problem.n_constr > 0:
            D["dG"] = - np.column_stack([dG, zeros(self.problem.n_constr)])
        else:
            D["dG"] = zeros((1, self.problem.n_var + 1))
Exemplo n.º 20
0
    def __init__(self, ref_dirs, **kwargs):
        self.ref_dirs = ref_dirs
        kwargs['individual'] = Individual(rank=np.inf, niche=-1, dist_to_niche=np.inf)
        set_if_none(kwargs, 'pop_size', len(ref_dirs))
        set_if_none(kwargs, 'sampling', RandomSampling())
        set_if_none(kwargs, 'crossover', SimulatedBinaryCrossover(prob=1.0, eta=30))
        set_if_none(kwargs, 'mutation', PolynomialMutation(prob=None, eta=20))
        set_if_none(kwargs, 'selection', TournamentSelection(func_comp=comp_by_cv_then_random))
        set_if_none(kwargs, 'survival', ReferenceDirectionSurvival(ref_dirs))
        set_if_none(kwargs, 'eliminate_duplicates', True)

        super().__init__(**kwargs)

        self.func_display_attrs = disp_multi_objective
Exemplo n.º 21
0
    def __init__(
            self,
            ref_dirs,
            sampling=FloatRandomSampling(),
            selection=RestrictedMating(func_comp=comp_by_cv_dom_then_random),
            crossover=SimulatedBinaryCrossover(n_offsprings=1,
                                               eta=30,
                                               prob=1.0),
            mutation=PolynomialMutation(eta=20, prob=None),
            eliminate_duplicates=True,
            display=MultiObjectiveDisplay(),
            **kwargs):
        """

        Parameters
        ----------

        ref_dirs : {ref_dirs}
        sampling : {sampling}
        selection : {selection}
        crossover : {crossover}
        mutation : {mutation}
        eliminate_duplicates : {eliminate_duplicates}

        """

        self.ref_dirs = ref_dirs
        pop_size = len(ref_dirs)

        kwargs['individual'] = Individual(rank=np.inf, niche=-1, FV=-1)

        if 'survival' in kwargs:
            survival = kwargs['survival']
            del kwargs['survival']
        else:
            survival = CADASurvival(ref_dirs)

        # Initialize diversity archives
        self.da = None

        super().__init__(pop_size=pop_size,
                         sampling=sampling,
                         selection=selection,
                         crossover=crossover,
                         mutation=mutation,
                         survival=survival,
                         eliminate_duplicates=eliminate_duplicates,
                         n_offsprings=pop_size,
                         display=display,
                         **kwargs)
Exemplo n.º 22
0
    def initialize(self, problem, **kwargs):
        super().initialize(problem, **kwargs)

        xl, xu = problem.bounds()
        X = denormalize(0.5 * np.ones(problem.n_var), xl, xu)
        x0 = Individual(X=X)
        x0.set("xl", xl)
        x0.set("xu", xu)
        x0.set("depth", 0)
        self.x0 = x0
Exemplo n.º 23
0
    def __init__(self, pop_size=100, **kwargs):
        # always store the individual to store rank and crowding
        kwargs['individual'] = Individual(rank=np.inf, crowding=-1)

        # default settings for nsga2 - not overwritten if provided as kwargs
        set_if_none(kwargs, 'pop_size', pop_size)
        set_if_none(kwargs, 'sampling', RandomSampling())
        set_if_none(kwargs, 'selection', TournamentSelection(func_comp=binary_tournament))
        set_if_none(kwargs, 'crossover', SimulatedBinaryCrossover(prob_cross=0.9, eta_cross=15))
        set_if_none(kwargs, 'mutation', PolynomialMutation(prob_mut=None, eta_mut=20))
        set_if_none(kwargs, 'survival', RankAndCrowdingSurvival())
        set_if_none(kwargs, 'eliminate_duplicates', True)

        super().__init__(**kwargs)

        self.tournament_type = 'comp_by_dom_and_crowding'
        self.func_display_attrs = disp_multi_objective
Exemplo n.º 24
0
    def solve(self, X_init, Y_init):
        '''
        Solve the real multi-objective problem from initial data.

        Parameters
        ----------
        X_init: np.array
            Initial design variables.
        Y_init: np.array
            Initial performance values.

        Returns
        -------
        X_next: np.array
            Proposed design samples to evaluate next.
        Y_prediction: tuple
            (None, None) because there is no prediction in MOO algorithms.
        '''
        # forward transformation
        X_init = self.transformation.do(X_init)

        # convert maximization to minimization
        X, Y = X_init, Y_init.copy()
        obj_type = self.real_problem.obj_type
        if isinstance(obj_type, str):
            obj_type = [obj_type] * Y.shape[1]
        assert isinstance(obj_type, Iterable)
        maxm_idx = np.array(obj_type) == 'max'
        Y[:, maxm_idx] = -Y[:, maxm_idx]

        # construct population
        pop = Population(0, individual=Individual())
        pop = pop.new('X', X)
        pop.set('F', Y)
        pop.set('CV', np.zeros([X.shape[0],
                                1]))  # assume input samples are all feasible

        off = self._solve(pop)

        X_next = off.get('X')[:self.batch_size]

        # backward transformation
        X_next = self.transformation.undo(X_next)

        return X_next, (None, None)
Exemplo n.º 25
0
    def _pattern_move(self, _current, _next):

        # get the direction and assign the corresponding delta value
        direction = (_next.X - _current.X)

        # get the delta sign adjusted
        sign = np.sign(direction)
        sign[sign == 0] = -1
        self.explr_delta = sign * np.abs(self.explr_delta)

        # calculate the new X and repair out of bounds if necessary
        X = _current.X + self.pattern_step * direction
        set_to_bounds_if_outside_by_problem(self.problem, X)

        # create the new center individual without evaluating it
        trial = Individual(X=X)

        return trial
Exemplo n.º 26
0
    def do(self, individual, **kwargs):
        prob = self.problem
        n_var, n_obj, n_constr = prob.n_var, prob.n_obj, prob.n_constr
        individual = Individual(X=individual.X)
        self.evaluator.eval(self.problem, Population.create(individual))

        dF = np.zeros((n_obj, n_var))
        dG = np.zeros((n_constr, n_var))

        for i in range(n_var):
            x = np.copy(individual.X)
            x[i] += self.epsilon

            eps_F, _, eps_G = self.evaluator.eval(prob, x)
            dF[:, i] = (eps_F - individual.F) / self.epsilon

            if n_constr > 0 and eps_G is not None:
                dG[:, i] = (eps_G - individual.G) / self.epsilon

        return dF, dG
Exemplo n.º 27
0
    def __init__(self,
                 pop_size=None,
                 sampling=None,
                 eliminate_duplicates=DefaultDuplicateElimination(),
                 individual=Individual(),
                 **kwargs
                 ):

        super().__init__(**kwargs)

        # the population size used
        self.pop_size = pop_size

        # number of offsprings
        self.n_offsprings = pop_size

        # the object to be used to represent an individual - either individual or derived class
        self.individual = individual

        # set the duplicate detection class - a boolean value chooses the default duplicate detection
        if isinstance(eliminate_duplicates, bool):
            if eliminate_duplicates:
                self.eliminate_duplicates = DefaultDuplicateElimination()
            else:
                self.eliminate_duplicates = NoDuplicateElimination()
        else:
            self.eliminate_duplicates = eliminate_duplicates

        # simply set the no repair object if it is None
        self.repair = NoRepair()

        self.initialization = Initialization(sampling,
                                             individual=individual,
                                             repair=self.repair,
                                             eliminate_duplicates=self.eliminate_duplicates)

        self.n_gen = None
        self.pop = None
        self.off = None
Exemplo n.º 28
0
    def __init__(self,
                 pop_size=100,
                 sampling=FloatRandomSampling(),
                 selection=TournamentSelection(func_comp=binary_tournament),
                 crossover=SimulatedBinaryCrossover(eta=15, prob=0.9),
                 mutation=PolynomialMutation(prob=None, eta=20),
                 eliminate_duplicates=True,
                 n_offsprings=None,
                 display=MultiObjectiveDisplay(),
                 **kwargs):
        """

        Parameters
        ----------
        pop_size : {pop_size}
        sampling : {sampling}
        selection : {selection}
        crossover : {crossover}
        mutation : {mutation}
        eliminate_duplicates : {eliminate_duplicates}
        n_offsprings : {n_offsprings}

        """

        kwargs['individual'] = Individual(rank=np.inf, crowding=-1)
        super().__init__(pop_size=pop_size,
                         sampling=sampling,
                         selection=selection,
                         crossover=crossover,
                         mutation=mutation,
                         survival=RankAndCrowdingSurvival(),
                         eliminate_duplicates=eliminate_duplicates,
                         n_offsprings=n_offsprings,
                         display=display,
                         **kwargs)

        self.tournament_type = 'comp_by_dom_and_crowding'
Exemplo n.º 29
0
    def __init__(self,
                 pop_size=20,
                 w=0.9,
                 c1=2.0,
                 c2=2.0,
                 sampling=LatinHypercubeSampling(),
                 adaptive=True,
                 pertube_best=True,
                 display=PSODisplay(),
                 repair=None,
                 individual=Individual(),
                 **kwargs):
        """

        Parameters
        ----------
        pop_size : {pop_size}
        sampling : {sampling}

        """

        super().__init__(display=display, **kwargs)

        self.initialization = Initialization(sampling,
                                             individual=individual,
                                             repair=repair)

        self.pop_size = pop_size
        self.adaptive = adaptive
        self.pertube_best = pertube_best
        self.default_termination = SingleObjectiveDefaultTermination()
        self.V_max = None

        self.w = w
        self.c1 = c1
        self.c2 = c2
Exemplo n.º 30
0
 def fun(x, n):
     ind = Individual(X=np.copy(x))
     Evaluator().eval(problem, ind)
     global pop
     pop = Population.merge(pop, ind)
     return ind.F[0]