Ejemplo n.º 1
0
def payoff_table_method(
    problem: MOProblem,
    initial_guess: Optional[np.ndarray] = None,
    solver_method: Optional[Union[ScalarMethod, str]] = "scipy_de",
) -> Tuple[np.ndarray, np.ndarray]:
    """Uses the payoff table method to solve for the ideal and nadir points of a MOProblem.
    Call through to payoff_table_method_general.
    
    Args:
        problem (MOProblem): The problem defined as a MOProblem class instance.
        initial_guess (Optional[np.ndarray]): The initial guess of decision variables
            to be used in the solver. If None, uses the lower bounds defined for
            the variables in MOProblem. Defaults to None.
        solver_method (Optional[Union[ScalarMethod, str]]): The method used to minimize the
            invidual problems in the payoff table method. Defaults to 'scipy_de'.
    
    Returns:
        Tuple[np.ndarray, np.ndarray]: The ideal and nadir points
    """
    if problem.n_of_constraints > 0:
        constraints = lambda x: problem.evaluate(x).constraints.squeeze()
    else:
        constraints = None

    return payoff_table_method_general(
        lambda xs: problem.evaluate(xs).objectives,
        problem.n_of_objectives,
        problem.get_variable_bounds(),
        constraints,
        initial_guess,
        solver_method,
    )
Ejemplo n.º 2
0
def solve_pareto_front_representation(
    problem: MOProblem,
    step: Optional[Union[np.ndarray, float]] = 0.1,
    eps: Optional[float] = 1e-6,
    solver_method: Optional[Union[ScalarMethod, str]] = "scipy_de",
) -> Tuple[np.ndarray, np.ndarray]:
    """Pass through to solve_pareto_front_representation_general when the
    problem for which the front is being calculated for is defined as an
    MOProblem object.
    
    Computes a representation of a Pareto efficient front
    from a multiobjective minimizatino problem. Does so by generating an
    evenly spaced set of reference points (in the objective space), in the
    space spanned by the supplied ideal and nadir points. The generated
    reference points are then used to formulate achievement scalaraization
    problems, which when solved, yield a representation of a Pareto efficient
    solution.
    
    Args:
        problem (MOProblem): The multiobjective minimization problem for which the front is to be solved for.
        step (Optional[Union[np.ndarray, float]], optional): Either a float
            or an array of floats. If a single float is given, generates
            reference points with the objectives having values a step apart
            between the ideal and nadir points. If an array of floats is given,
            use the steps defined in the array for each objective's values.
            Default to 0.1.
        eps (Optional[float], optional): An offset to be added to the nadir
            value to keep the nadir inside the range when generating reference
            points. Defaults to 1e-6.
        solver_method (Optional[Union[ScalarMethod, str]], optional): The
            method used to minimize the achievement scalarization problems
            arising when calculating Pareto efficient solutions. Defaults to
            "scipy_de".
    
    Returns:
        Tuple[np.ndarray, np.ndarray]: A tuple containing representations of
        the Pareto optimal variable values, and the corresponsing objective
        values.
    """
    if problem.n_of_constraints > 0:
        constraints = lambda x: problem.evaluate(x).constraints.squeeze()
    else:
        constraints = None

    var_values, obj_values = solve_pareto_front_representation_general(
        lambda x: problem.evaluate(x).objectives,
        problem.n_of_objectives,
        problem.get_variable_bounds(),
        step,
        eps,
        problem.ideal * problem._max_multiplier,
        problem.nadir * problem._max_multiplier,
        constraints,
        solver_method,
    )

    return var_values, obj_values * problem._max_multiplier
Ejemplo n.º 3
0
    def __init__(self,
                 problem: MOProblem,
                 scalar_method: Optional[ScalarMethod] = None):
        # check if ideal and nadir are defined
        if problem.ideal is None or problem.nadir is None:
            # TODO: use same method as defined in scalar_method
            ideal, nadir = payoff_table_method(problem)
            self._ideal = ideal
            self._nadir = nadir
        else:
            self._ideal = problem.ideal
            self._nadir = problem.nadir

        self._scalar_method = scalar_method

        # generate Pareto optimal starting point
        asf = SimpleASF(np.ones(self._ideal.shape))
        scalarizer = Scalarizer(
            lambda x: problem.evaluate(x).objectives,
            asf,
            scalarizer_args={"reference_point": np.atleast_2d(self._ideal)},
        )

        if problem.n_of_constraints > 0:
            _con_eval = lambda x: problem.evaluate(x).constraints.squeeze()
        else:
            _con_eval = None

        solver = ScalarMinimizer(
            scalarizer,
            problem.get_variable_bounds(),
            constraint_evaluator=_con_eval,
            method=self._scalar_method,
        )
        # TODO: fix tools to check for scipy methods in general and delete me!
        solver._use_scipy = True

        res = solver.minimize(problem.get_variable_upper_bounds() / 2)

        if res["success"]:
            self._current_solution = res["x"]
            self._current_objectives = problem.evaluate(
                self._current_solution).objectives.squeeze()

        self._archive_solutions = []
        self._archive_objectives = []
        self._state = "classify"

        super().__init__(problem)