예제 #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,
    )
예제 #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
예제 #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)
예제 #4
0
    def __init__(
        self,
        problem: MOProblem,
        ideal: np.ndarray,
        nadir: np.ndarray,
        epsilon: float = 1e-6,
        objective_names: Optional[List[str]] = None,
        minimize: Optional[List[int]] = None,
    ):

        if not ideal.shape == nadir.shape:
            raise NautilusException(
                "The dimensions of the ideal and nadir point do not match.")

        if objective_names:
            if not len(objective_names) == ideal.shape[0]:
                raise NautilusException(
                    "The supplied objective names must have a length equal to "
                    "the numbr of objectives.")
            self._objective_names = objective_names
        else:
            self._objective_names = [
                f"f{i + 1}" for i in range(ideal.shape[0])
            ]

        if minimize:
            if not len(objective_names) == ideal.shape[0]:
                raise NautilusException(
                    "The minimize list must have "
                    "as many elements as there are objectives.")
            self._minimize = minimize
        else:
            self._minimize = [1 for _ in range(ideal.shape[0])]

        # initialize method with problem
        super().__init__(problem)
        self._problem = problem
        self._objectives: Callable = lambda x: self._problem.evaluate(
            x).objectives
        self._variable_bounds: Union[np.ndarray,
                                     None] = problem.get_variable_bounds()
        self._constraints: Optional[
            Callable] = lambda x: self._problem.evaluate(x).constraints

        # Used to calculate the utopian point from the ideal point
        self._epsilon = epsilon
        self._ideal = ideal
        self._nadir = nadir

        # calculate utopian vector
        self._utopian = [ideal_i - self._epsilon for ideal_i in self._ideal]

        # bounds of the reachable region
        self._lower_bounds: List[np.ndarray] = []
        self._upper_bounds: List[np.ndarray] = []

        # current iteration step number
        self._step_number = 1

        # iteration points
        self._zs: np.ndarray = []

        # solutions, objectives, and distances for each iteration
        self._xs: np.ndarray = []
        self._fs: np.ndarray = []
        self._ds: np.ndarray = []

        # The current reference point
        self._q: Union[None, np.ndarray] = None

        # preference information
        self._preference_method = None
        self._preference_info = None
        self._preferential_factors = None

        # number of total iterations and iterations left
        self._n_iterations = None
        self._n_iterations_left = None

        # flags for the iteration phase
        # not utilized atm
        self._use_previous_preference: bool = False
        self._step_back: bool = False
        self._short_step: bool = False
        self._first_iteration: bool = True

        # evolutionary method for minimizing
        self._method_de: ScalarMethod = ScalarMethod(
            lambda x, _, **y: differential_evolution(x, **y),
            method_args={
                "disp": False,
                "polish": False,
                "tol": 0.000001,
                "popsize": 10,
                "maxiter": 50000
            },
            use_scipy=True)
    def __init__(
        self,
        problem: MOProblem,
        ideal: np.ndarray,
        nadir: np.ndarray,
        epsilon: float = 1e-6,
        objective_names: Optional[List[str]] = None,
        minimize: Optional[List[int]] = None,
    ):

        if not ideal.shape == nadir.shape:
            raise RPMException(
                "The dimensions of the ideal and nadir point do not match.")

        if objective_names:
            if not len(objective_names) == ideal.shape[0]:
                raise RPMException(
                    "The supplied objective names must have a leangth equal to "
                    "the number of objectives.")
            self._objective_names = objective_names
        else:
            self._objective_names = [
                f"f{i + 1}" for i in range(ideal.shape[0])
            ]

        if minimize:
            if not len(objective_names) == ideal.shape[0]:
                raise RPMException("The minimize list must have "
                                   "as many elements as there are objectives.")
            self._minimize = minimize
        else:
            self._minimize = [1 for _ in range(ideal.shape[0])]

        # initialize method with problem
        super().__init__(problem)
        self._problem = problem
        self._objectives: Callable = lambda x: self._problem.evaluate(
            x).objectives
        self._variable_bounds: Union[np.ndarray,
                                     None] = problem.get_variable_bounds()
        self._constraints: Optional[
            Callable] = lambda x: self._problem.evaluate(x).constraints

        self._ideal = ideal
        self._nadir = nadir
        self._utopian = ideal - epsilon
        self._n_objectives = self._ideal.shape[0]

        # current iteration step number
        self._h = 1

        # solutions in decision and objective space, distances and referation points for each iteration
        self._xs = [None] * 10
        self._fs = [None] * 10
        self._ds = [None] * 10
        self._qs = [None] * 10

        # perturbed reference points
        self._pqs = [None] * 10

        # additional solutions
        self._axs = [None] * 10
        self._afs = [None] * 10

        # current reference point
        self._q: Union[None, np.ndarray] = None

        # weighting vector for achievement function
        self._w: np.ndarray = []

        # evolutionary method for minimizing
        self._method_de: ScalarMethod = ScalarMethod(
            lambda x, _, **y: differential_evolution(x, **y),
            method_args={
                "disp": False,
                "polish": False,
                "tol": 0.000001,
                "popsize": 10,
                "maxiter": 50000
            },
            use_scipy=True,
        )