Example #1
0
 def request_preferences(self) -> Union[None, ReferencePointPreference]:
     dimensions_data = pd.DataFrame(
         index=["minimize", "ideal", "nadir"],
         columns=self.population.problem.get_objective_names(),
     )
     dimensions_data.loc[
         "minimize"] = self.population.problem._max_multiplier
     dimensions_data.loc["ideal"] = self.population.ideal_objective_vector
     dimensions_data.loc["nadir"] = self.population.nadir_objective_vector
     message = (
         f"Provide a reference point worse than to the ideal point and better than"
         f" the nadir point.\n"
         f"Ideal point: \n{dimensions_data.loc['ideal']}\n"
         f"Nadir point: \n{dimensions_data.loc['nadir']}\n"
         f"The reference point will be used to create scalarization functions in "
         f"the preferred region.\n")
     interaction_priority = "required"
     self._interaction_request_id = np.random.randint(0, 1e7)
     return ReferencePointPreference(
         dimensions_data=dimensions_data,
         message=message,
         interaction_priority=interaction_priority,
         preference_validator=validate_ref_point_with_ideal_and_nadir,
         request_id=self._interaction_request_id,
     )
Example #2
0
    def request_preferences(self) -> ReferencePointPreference:
        if (self.interact is False): return None

        dimensions_data = pd.DataFrame(
            index=["minimize", "ideal", "nadir"],
            columns=self.population.problem.get_objective_names(),
        )
        dimensions_data.loc[
            "minimize"] = self.population.problem._max_multiplier
        dimensions_data.loc["ideal"] = self.population.ideal_objective_vector
        dimensions_data.loc["nadir"] = self.population.nadir_objective_vector
        message = (
            "Please provide preferences as a reference point. Reference point cannot be better than ideal point:\n\n"
            f"{dimensions_data.loc['ideal']}\n"
            f"The reference point will be used to focus the search towards "
            f"the preferred region.\n")

        def validator(dimensions_data: pd.DataFrame,
                      reference_point: pd.DataFrame):
            validate_ref_point_dimensions(dimensions_data, reference_point)
            validate_ref_point_data_type(reference_point)
            validate_ref_point_with_ideal(dimensions_data, reference_point)
            return

        interaction_priority = "required"
        self._interaction_request_id = np.random.randint(0, 1e9)

        return ReferencePointPreference(
            dimensions_data=dimensions_data,
            message=message,
            interaction_priority=interaction_priority,
            preference_validator=validate_ref_point_with_ideal_and_nadir,
            request_id=self._interaction_request_id,
        )
Example #3
0
    def request_reference_point(self,
                                pop: Population) -> ReferencePointPreference:
        dimensions_data = pd.DataFrame(
            index=["minimize", "ideal", "nadir"],
            columns=pop.problem.get_objective_names(),
        )
        dimensions_data.loc["minimize"] = pop.problem._max_multiplier
        dimensions_data.loc["ideal"] = pop.ideal_objective_vector
        dimensions_data.loc["nadir"] = pop.nadir_objective_vector
        message = (
            f"Please provide a reference point worse than the ideal point:\n\n"
            f"{dimensions_data.loc['ideal']}\n"
            f"The reference point will be used to focus the reference vectors towards "
            f"the preferred region.\n"
            f"If a reference point is not provided, the reference vectors are spread uniformly"
            f" in the objective space.")

        def validator(dimensions_data: pd.DataFrame,
                      reference_point: pd.DataFrame):
            validate_ref_point_dimensions(dimensions_data, reference_point)
            validate_ref_point_data_type(reference_point)
            validate_ref_point_with_ideal(dimensions_data, reference_point)
            return

        self._interaction_request_id = np.random.randint(0, 1e9)

        return ReferencePointPreference(
            dimensions_data=dimensions_data,
            message=message,
            interaction_priority="recommended",
            preference_validator=validator,
            request_id=self._interaction_request_id,
        )
    def request_preferences(self) -> Union[None, ReferencePointPreference]:
        if self.a_priori is False and self.interact is False:
            return
        if (self.a_priori is True and self.interact is False
                and self._iteration_counter > 0):
            return
        dimensions_data = pd.DataFrame(
            index=["minimize", "ideal", "nadir"],
            columns=self.population.problem.get_objective_names(),
        )
        dimensions_data.loc[
            "minimize"] = self.population.problem._max_multiplier
        dimensions_data.loc["ideal"] = self.population.ideal_objective_vector
        dimensions_data.loc["nadir"] = self.population.nadir_objective_vector
        message = (
            f"Provide a reference point worse than or equal to the ideal point:\n"
            f"{dimensions_data.loc['ideal']}\n"
            f"The reference point will be used to focus the reference vectors towards "
            f"the preferred region.\n"
            f"If a reference point is not provided, the previous state of the reference"
            f" vectors is used.\n"
            f"If the reference point is the same as the ideal point, the ideal point, "
            f"the reference vectors are spread uniformly in the objective space."
        )

        def validator(dimensions_data: pd.DataFrame,
                      reference_point: pd.DataFrame):
            validate_ref_point_dimensions(dimensions_data, reference_point)
            validate_ref_point_data_type(reference_point)
            validate_ref_point_with_ideal(dimensions_data, reference_point)
            return

        interaction_priority = "recommended"
        self._interaction_request_id = np.random.randint(0, 1e10)
        return ReferencePointPreference(
            dimensions_data=dimensions_data,
            message=message,
            interaction_priority=interaction_priority,
            preference_validator=validator,
            request_id=self._interaction_request_id,
        )
Example #5
0
    def request_preferences(
        self
    ) -> Union[None, Tuple[PreferredSolutionPreference,
                           NonPreferredSolutionPreference,
                           ReferencePointPreference, BoundPreference, ], ]:

        if self.a_priori is False and self.interact is False:
            return
        if (self.a_priori is True and self.interact is False
                and self._iteration_counter > 0):
            return
        dimensions_data = pd.DataFrame(
            index=["minimize", "ideal", "nadir"],
            columns=self.population.problem.get_objective_names(),
        )
        dimensions_data.loc[
            "minimize"] = self.population.problem._max_multiplier
        dimensions_data.loc["ideal"] = self.population.ideal_objective_vector
        dimensions_data.loc["nadir"] = self.population.nadir_objective_vector
        message = (
            "Please provide preferences. There is four ways to do this. You can either:\n\n"
            "\t1: Select preferred solution(s)\n"
            "\t2: Select non-preferred solution(s)\n"
            "\t3: Specify a reference point worse than or equal to the ideal point\n"
            "\t4: Specify desired ranges for objectives.\n\n"
            "In case you choose \n\n"
            "1, please specify index/indices of preferred solutions in a numpy array (indexing starts from 0).\n"
            "For example: \n"
            "\tnumpy.array([1]), for choosing the solutions with index 1.\n"
            "\tnumpy.array([2, 4, 5, 16]), for choosing the solutions with indices 2, 4, 5, and 16.\n\n"
            "2, please specify index/indices of non-preferred solutions in a numpy array (indexing starts from 0).\n"
            "For example: \n"
            "\tnumpy.array([3]), for choosing the solutions with index 3.\n"
            "\tnumpy.array([1, 2]), for choosing the solutions with indices 1 and 2.\n\n"
            "3, please provide a reference point worse than or equal to the ideal point:\n\n"
            f"{dimensions_data.loc['ideal']}\n"
            f"The reference point will be used to focus the reference vectors towards "
            f"the preferred region.\n"
            f"If a reference point is not provided, the previous state of the reference"
            f" vectors is used.\n"
            f"If the reference point is the same as the ideal point, "
            f"the reference vectors are spread uniformly in the objective space.\n\n"
            "4, please specify desired lower and upper bound for each objective, starting from \n"
            "the first objective and ending with the last one. Please specify the bounds as a numpy array containing \n"
            "lists, so that the first item of list is the lower bound and the second the upper bound, for each \n"
            "objective. \n"
            "\tFor example: numpy.array([[1, 2], [2, 5], [0, 3.5]]), for problem with three "
            "objectives.\n"
            f"Ideal vector: \n{dimensions_data.loc['ideal']}\n"
            f"Nadir vector: \n{dimensions_data.loc['nadir']}.")

        def validator(dimensions_data: pd.DataFrame,
                      reference_point: pd.DataFrame):
            validate_ref_point_dimensions(dimensions_data, reference_point)
            validate_ref_point_data_type(reference_point)
            validate_ref_point_with_ideal(dimensions_data, reference_point)
            return

        interaction_priority = "recommended"
        self._interaction_request_id = np.random.randint(0, 1e9)

        # return multiple preference-requests, user decides with request will (s)he respond to by using an index.
        return (
            PreferredSolutionPreference(
                n_solutions=self.population.objectives.shape[0],
                message=message,
                interaction_priority=interaction_priority,
                request_id=self._interaction_request_id,
            ),
            NonPreferredSolutionPreference(
                n_solutions=self.population.objectives.shape[0],
                message=None,
                interaction_priority=interaction_priority,
                request_id=self._interaction_request_id,
            ),
            ReferencePointPreference(
                dimensions_data=dimensions_data,
                message=None,
                interaction_priority=interaction_priority,
                preference_validator=validator,
                request_id=self._interaction_request_id,
            ),
            BoundPreference(
                dimensions_data=dimensions_data,
                n_objectives=self.population.problem.n_of_objectives,
                message=None,
                interaction_priority=interaction_priority,
                request_id=self._interaction_request_id,
            ),
        )