Esempio n. 1
0
class DefaultTermination(ToleranceBasedTermination):
    def __init__(self,
                 x_tol,
                 cv_tol,
                 f_tol,
                 nth_gen=5,
                 n_last=20,
                 n_max_gen=1000,
                 n_max_evals=100000,
                 **kwargs) -> None:
        """

        Parameters
        ----------
        cv_tol
        x_tol
        f_tol

        n_max_gen : int
            A limit on maximum number of generations to avoid it never terminates
            (set to `None` or infinity to disable)

        n_max_evals : int
            A limit on maximum number of function evaluations to avoid it never terminates
            (set to `None` or infinity to disable)

        nth_gen
        n_last
        kwargs
        """

        super().__init__(n_last=n_last, nth_gen=nth_gen, **kwargs)

        self.n_max_gen = MaximumGenerationTermination(n_max_gen)
        self.n_max_evals = MaximumFunctionCallTermination(n_max_evals)

        self.x_tol = DesignSpaceToleranceTermination(tol=x_tol,
                                                     n_last=n_last,
                                                     nth_gen=nth_gen)

        self.cv = ConstraintViolationToleranceTermination(tol=cv_tol,
                                                          n_last=n_last,
                                                          nth_gen=nth_gen)
        self.f_tol = f_tol

    def _store(self, algorithm):
        return {
            "n_max_gen": self.n_max_gen.do_continue(algorithm),
            "n_max_evals": self.n_max_evals.do_continue(algorithm),
            "x_tol": self.x_tol.do_continue(algorithm),
            "cv": self.cv.do_continue(algorithm),
            "f_tol": self.f_tol.do_continue(algorithm)
        }

    def _decide(self):
        metric = self.history[-1]
        return metric["n_max_gen"] and metric["n_max_evals"] and metric[
            "x_tol"] and (metric["cv"] or metric["f_tol"])
Esempio n. 2
0
    def __init__(self,
                 x_tol,
                 cv_tol,
                 f_tol,
                 nth_gen=5,
                 n_last=20,
                 n_max_gen=1000,
                 n_max_evals=100000,
                 **kwargs) -> None:
        """

        Parameters
        ----------
        cv_tol
        x_tol
        f_tol

        n_max_gen : int
            A limit on maximum number of generations to avoid it never terminates
            (set to `None` or infinity to disable)

        n_max_evals : int
            A limit on maximum number of function evaluations to avoid it never terminates
            (set to `None` or infinity to disable)

        nth_gen
        n_last
        kwargs
        """

        super().__init__(n_last=n_last, nth_gen=nth_gen, **kwargs)

        self.n_max_gen = MaximumGenerationTermination(n_max_gen)
        self.n_max_evals = MaximumFunctionCallTermination(n_max_evals)

        self.x_tol = DesignSpaceToleranceTermination(tol=x_tol,
                                                     n_last=n_last,
                                                     nth_gen=nth_gen)

        self.cv = ConstraintViolationToleranceTermination(tol=cv_tol,
                                                          n_last=n_last,
                                                          nth_gen=nth_gen)
        self.f_tol = f_tol
Esempio n. 3
0
 def __init__(self,
              x_tol=1e-32,
              cv_tol=1e-6,
              f_tol=1e-6,
              nth_gen=5,
              n_last=20,
              **kwargs) -> None:
     super().__init__(DesignSpaceToleranceTermination(tol=x_tol, n_last=n_last),
                      ConstraintViolationToleranceTermination(tol=cv_tol, n_last=n_last),
                      NicheSingleObjectiveSpaceToleranceTermination(tol=f_tol, n_last=n_last, nth_gen=nth_gen),
                      **kwargs)
Esempio n. 4
0
 def __init__(self,
              x_tol=1e-8,
              cv_tol=1e-6,
              f_tol=0.0025,
              nth_gen=5,
              n_last=30,
              **kwargs) -> None:
     super().__init__(
         DesignSpaceToleranceTermination(tol=x_tol, n_last=n_last),
         ConstraintViolationToleranceTermination(tol=cv_tol, n_last=n_last),
         MultiObjectiveSpaceToleranceTermination(tol=f_tol,
                                                 n_last=n_last,
                                                 nth_gen=nth_gen), **kwargs)
def calculate_pareto_front(
    state_space_equation,
    tau,
    y_measured,
    x0,
    xl: Union[np.ndarray, None],
    xu: Union[np.ndarray, None],
    n_var: int,
    n_obj: int,
    normalize_quaternions: bool,
    n_constr=0,
    pop_size=100,
    n_max_gen=1000,
    verbose=True,
    display=MyDisplay(),
) -> Result:

    # calculate pareto frontier
    problem = UUVParameterProblem(
        state_space_equation,
        tau,
        y_measured,
        x0,
        n_var=n_var,
        n_obj=n_obj,
        n_constr=n_constr,
        xl=xl,
        xu=xu,
        normalize_quaternions=normalize_quaternions,
    )
    algorithm = NSGA2(
        pop_size=pop_size,
        # n_offsprings=int(pop_size / 2),
        crossover=SimulatedBinaryCrossover(eta=15, prob=0.9),
        mutation=PolynomialMutation(prob=None, eta=15),
    )
    termination_default = MultiObjectiveDefaultTermination(n_max_gen=n_max_gen)
    termination_design_space = DesignSpaceToleranceTermination(n_max_gen=n_max_gen)
    termination_generations = get_termination("n_gen", 100)

    res = minimize(
        problem,
        algorithm,
        termination_default,
        verbose=verbose,
        display=display,
    )

    return res
Esempio n. 6
0
from pymoo.algorithms.nsga2 import NSGA2
from pymoo.factory import get_problem
from pymoo.optimize import minimize
from pymoo.util.termination.x_tol import DesignSpaceToleranceTermination

problem = get_problem("zdt3")
algorithm = NSGA2(pop_size=100)
termination = DesignSpaceToleranceTermination(tol=0.0025, n_last=20)

res = minimize(problem,
               algorithm,
               termination,
               pf=problem.pareto_front(),
               seed=1,
               verbose=False)

print(res.algorithm.n_gen)