interaction.request

Module Contents

Classes

BaseRequest

The base class for all Request classes. Request classes are to be used

PrintRequest

Methods can use this request class to send out textual information to be

SimplePlotRequest

Methods can use this request class to send out some data to be shown to

ReferencePointPreference

Methods can use this request class to ask the DM to provide their preferences

PreferredSolutionPreference

Methods can use this class to ask the Decision maker to provide their preferences in form of preferred solution(s).

NonPreferredSolutionPreference

Methods can use this class to ask the Decision maker to provide their preferences in form of non-preferred

BoundPreference

Methods can use this class to ask the Decision maker to provide their preferences in form of preferred lower and

exception interaction.request.RequestError[source]

Bases: Exception

Raised when an error related to the Request class is encountered.

Initialize self. See help(type(self)) for accurate signature.

class interaction.request.BaseRequest(request_type: str, interaction_priority: str, content=None, request_id: int = None)[source]

Bases: desdeo_tools.utilities.frozen.FrozenClass

The base class for all Request classes. Request classes are to be used to handle interaction between the user and the methods, as well as within various methods. This class is frozen, so no variables other than that already defined in current __init__ can be defined in derived classes.

Initialize a BaseRequest class. This method contains a lot of boilerplate.

Parameters:
  • request_type (str) – The type of request. Currently, one of [“print”, “simple_plot”, “reference_point_preference”, “classification_preference”].

  • interaction_priority (str) – The priority of preference, as decided by the method. One of [“no_interaction”, “not_required”, “recommended”, “required”], with trivial meanings.

  • content ([type], optional) – The data relevant to the request packet. For example, if the request type is print, content may contain strings to be printed. Typically a dict. Defaults to None.

  • request_id (int, optional) – A unique identifier. Defaults to None.

Raises:
property request_type[source]
property interaction_priority[source]
property request_id[source]
property content[source]
property response[source]
class interaction.request.PrintRequest(message: str | List[str], request_id: int = None)[source]

Bases: BaseRequest

Methods can use this request class to send out textual information to be displayed to the decision maker. This could be a single message in the form of a string, or multiple messages in a list of strings. The method of displaying these messages is left to the UI.

Initialise the PrintRequest.

Parameters:
  • message (Union[str, List[str]]) – A single message (str) or a list of messages to be displayed to the decision maker

  • request_id (int, optional) – A unique identifier for this request. Defaults to None.

Raises:
  • RequestError – If message is not a str or a list

  • RequestError – If message is a list but one or more elements are not str.

class interaction.request.SimplePlotRequest(data: pandas.DataFrame, message: str | List[str], dimensions_data: pandas.DataFrame = None, chart_title: str = None, request_id=None)[source]

Bases: BaseRequest

Methods can use this request class to send out some data to be shown to the decision maker (typically in the form of a plot). This data is usually a set of solutions, stored in the content variable of this class. The manner of visualization is left to the UI.

content is a dict that contains the following keys:

“data” (pandas.DataFrame): The data to be plotted. “dimensional_data” (pandas.Dataframe): The data contained in this key can be

used to scale the data to be plotted.

“chart_title” (str): A recommended title for the visualization. “message” (Union[str, List[str]]): A message or list of messages to be

displayed to the decision maker.

Initialize the request packet

Parameters:
  • data (pd.DataFrame) – The data to be plotted.

  • message (Union[str, List[str]]) – A message or list of messages to be displayed to the decision maker.

  • dimensions_data (pd.DataFrame, optional) – Data used to used to scale the data to be plotted. Defaults to None.

  • chart_title (str, optional) – A recommended title for the visualization. Defaults to None.

  • request_id ([type], optional) – A unique identifier. Defaults to None.

Raises:
  • RequestError – data is not a pandas DataFrame.

  • RequestError – dimensions_data is not a pandas DataFrame or None.

  • RequestError – A mismatch in the column names of data and dimensions_data.

  • RequestError – If dimensions_data DataFrame contains indices other that “minimize”, “ideal”, or “nadir”.

  • RequestError – If chart_title is not str or None.

  • RequestError – If message is not a str or a list.

  • RequestError – If message is a list but one or more elements are not str.

class interaction.request.ReferencePointPreference(dimensions_data: pandas.DataFrame, message: str = None, interaction_priority: str = 'required', preference_validator: Callable = None, request_id: int = None)[source]

Bases: BaseRequest

Methods can use this request class to ask the DM to provide their preferences in the form of a reference point. This reference point is validated according to the needs of the method that initializes this class object, before the reference point can be accepted in the response variable.

Initialize the request class.

Parameters:
  • dimensions_data (pd.DataFrame) – Minimal data that should be shown to the decision maker. If a lot of data needs to be shown (i.e., with a visualization), use SimplePlotRequest or related classes for that purpose, and this class for the interaction with the decision maker.

  • message (str, optional) – Message to be displayed to a decision maker. Defaults to None.

  • interaction_priority (str, optional) – The importance of the interaction as decided by the method. If equal to “required”, the method will not continue without a DM preference. If equal to “recommended”, the interaction is recommended, but not required for the continuation of the method. The case “not_required” is similar to “recommended”. Defaults to “required”.

  • preference_validator (Callable, optional) – A callable function that tests whether a reference point provided by the DM is valid or not. Defaults to None.

  • request_id (int, optional) – A unique identifier. Defaults to None.

Raises:
  • RequestError – dimensions_data is not a pandas DataFrame.

  • RequestError – If dimensions_data DataFrame contains indices other that “minimize”, “ideal”, or “nadir”.

  • RequestError – If message is not a str or a list.

  • RequestError – If message is a list but one or more elements are not str.

class interaction.request.PreferredSolutionPreference(n_solutions: int, message: str = None, interaction_priority: str = 'required', preference_validator: Callable = None, request_id: int = None)[source]

Bases: BaseRequest

Methods can use this class to ask the Decision maker to provide their preferences in form of preferred solution(s).

Initialize preference-class with information about problem.

Parameters:
  • n_solutions (int) – Number of solutions in total.

  • message (str) – Message to be displayed to the Decision maker.

  • interaction_priority (str) – Level of priority.

  • preference_validator (Callable) – Function that validates the Decision maker’s preferences.

  • request_id (int) – Identification number of request.

class interaction.request.NonPreferredSolutionPreference(n_solutions: int, message: str = None, interaction_priority: str = 'required', preference_validator: Callable = None, request_id: int = None)[source]

Bases: BaseRequest

Methods can use this class to ask the Decision maker to provide their preferences in form of non-preferred solution(s).

Initialize preference-class with information about problem.

Parameters:
  • n_solutions (int) – Number of solutions in total.

  • message (str) – Message to be displayed to the Decision maker.

  • interaction_priority (str) – Level of priority.

  • preference_validator (Callable) – Function that validates the Decision maker’s preferences.

  • request_id (int) – Identification number of request.

class interaction.request.BoundPreference(dimensions_data: pandas.DataFrame, n_objectives: int, message: str = None, interaction_priority: str = 'required', preference_validator: Callable = None, request_id: int = None)[source]

Bases: BaseRequest

Methods can use this class to ask the Decision maker to provide their preferences in form of preferred lower and upper bounds for objective values.

Initialize preference-class with information about problem.

Parameters:
  • dimensions_data (pd.DataFrame) – DataFrame including information whether an objective is minimized or maximized, for each objective. In addition, includes ideal and nadir vectors.

  • n_objectives (int) – Number of objectives in problem.

  • message (str) – Message to be displayed to the Decision maker.

  • interaction_priority (str) – Level of priority.

  • preference_validator (Callable) – Function that validates the Decision maker’s preferences.

  • request_id (int) – Identification number of request.