negmas.inout

Defines import/export functionality

class negmas.inout.Scenario(outcome_space: ~negmas.outcomes.outcome_space.CartesianOutcomeSpace, ufuns: tuple[~negmas.preferences.crisp_ufun.UtilityFunction, ...], mechanism_type: type[~negmas.mechanisms.Mechanism] | None = <class 'negmas.sao.mechanism.SAOMechanism'>, mechanism_params: dict = NOTHING, info: dict[str, ~typing.Any] = NOTHING)[source]

Bases: object

A class representing a negotiation domain

calc_extra_stats(max_cardinality: int = 10000000000) dict[str, Any][source]

Calculates and returns several stats corresponding to the domain

Parameters:

max_cardinality (int) – The maximum number of outcomes considered when calculating the stats.

Returns:

A dictionary with the compiled stats

calc_stats() ScenarioStats[source]

Calc stats.

Returns:

The result.

Return type:

ScenarioStats

discretize(levels: int = 10)[source]

Discretize all issues

dumpas(folder: Path | str, type='yml', compact: bool = False) None[source]

Dumps the scenario in the given file format.

static from_genius_files(domain: PathLike, ufuns: Iterable[PathLike], info: PathLike | None = None, ignore_discount=False, ignore_reserved=False, safe_parsing=True) Scenario | None[source]

From genius files.

Parameters:
  • domain – Domain.

  • ufuns – Ufuns.

  • info – Info.

  • ignore_discount – Ignore discount.

  • ignore_reserved – Ignore reserved.

  • safe_parsing – Safe parsing.

Returns:

The result.

Return type:

Scenario | None

static from_genius_folder(path: PathLike | str, ignore_discount=False, ignore_reserved=False, safe_parsing=True) Scenario | None[source]

From genius folder.

Parameters:
  • path – Path.

  • ignore_discount – Ignore discount.

  • ignore_reserved – Ignore reserved.

  • safe_parsing – Safe parsing.

Returns:

The result.

Return type:

Scenario | None

static from_geniusweb_files(domain: PathLike, ufuns: Iterable[PathLike], info: PathLike | None = None, ignore_discount=False, ignore_reserved=False, use_reserved_outcome=False, safe_parsing=True) Scenario | None[source]

From geniusweb files.

Parameters:
  • domain – Domain.

  • ufuns – Ufuns.

  • info – Info.

  • ignore_discount – Ignore discount.

  • ignore_reserved – Ignore reserved.

  • use_reserved_outcome – Use reserved outcome.

  • safe_parsing – Safe parsing.

Returns:

The result.

Return type:

Scenario | None

static from_geniusweb_folder(path: PathLike | str, ignore_discount=False, ignore_reserved=False, use_reserved_outcome=False, safe_parsing=True) Scenario | None[source]

From geniusweb folder.

Parameters:
  • path – Path.

  • ignore_discount – Ignore discount.

  • ignore_reserved – Ignore reserved.

  • use_reserved_outcome – Use reserved outcome.

  • safe_parsing – Safe parsing.

Returns:

The result.

Return type:

Scenario | None

classmethod from_yaml_files(domain: PathLike, ufuns: Iterable[PathLike], info: PathLike | None = None, ignore_discount=False, ignore_reserved=False, safe_parsing=True, python_class_identifier='type') Scenario | None[source]

From yaml files.

Parameters:
  • domain – Domain.

  • ufuns – Ufuns.

  • info – Info.

  • ignore_discount – Ignore discount.

  • ignore_reserved – Ignore reserved.

  • safe_parsing – Safe parsing.

  • python_class_identifier – Python class identifier.

Returns:

The result.

Return type:

Scenario | None

classmethod from_yaml_folder(path: PathLike | str, ignore_discount=False, ignore_reserved=False, safe_parsing=True) Scenario | None[source]

From yaml folder.

Parameters:
  • path – Path.

  • ignore_discount – Ignore discount.

  • ignore_reserved – Ignore reserved.

  • safe_parsing – Safe parsing.

Returns:

The result.

Return type:

Scenario | None

info: dict[str, Any][source]
classmethod is_loadable(path: PathLike | str)[source]

Check if loadable.

Parameters:

path – Path.

is_normalized(to: tuple[float | None, float | None] = (None, 1.0), positive: bool = True, eps: float = 1e-06) bool[source]

Checks that all ufuns are normalized in the given range

property issue_names: list[str][source]

Issue names.

Returns:

The result.

Return type:

list[str]

property issues: tuple[Issue, ...][source]

Issues.

Returns:

The result.

Return type:

tuple[Issue, …]

classmethod load(folder: Path | str, safe_parsing=False, ignore_discount=False, **kwargs) Scenario | None[source]

Loads the scenario from a folder with supported formats: XML, YML

load_info(folder: PathLike | str)[source]

Load info.

Parameters:

folder – Folder.

load_info_file(file: Path)[source]

Load info file.

Parameters:

file – File.

make_session(negotiators: Callable[[], Negotiator] | type[Negotiator] | list[Negotiator] | tuple[Negotiator, ...] | None = None, n_steps: int | float | None = None, time_limit: float | None = None, roles: list[str] | None = None, raise_on_failure_to_enter: bool = True, share_ufuns: bool = False, share_reserved_values: bool = False, **kwargs)[source]

Generates a ready to run mechanism session for this domain.

mechanism_params: dict[source]
mechanism_type: type[Mechanism] | None[source]
property n_issues: int[source]

N issues.

Returns:

The result.

Return type:

int

property n_negotiators: int[source]

N negotiators.

Returns:

The result.

Return type:

int

normalize(to: tuple[float, float] = (0.0, 1.0)) Scenario[source]

Normalizes a utility function to the given range

Parameters:

rng – range to normalize to. Default is [0, 1]

outcome_space: CartesianOutcomeSpace[source]
plot(**kwargs)[source]

Plot.

Parameters:

**kwargs – Additional keyword arguments.

remove_discounting()[source]

Removes discounting from all ufuns

remove_reserved_values(r: float = -inf)[source]

Removes reserved values from all ufuns replaacing it with r

scale_max(to: float = 1.0) Scenario[source]

Normalizes a utility function to the given range

Parameters:
  • ufun – The utility function to normalize

  • outcomes – A collection of outcomes to normalize for

  • rng – range to normalize to. Default is [0, 1]

  • levels – Number of levels to use for discretizing continuous issues (if any)

  • max_cardinality – Maximum allowed number of outcomes resulting after all discretization is done

scale_min(to: float = 1.0) Scenario[source]

Normalizes a utility function to the given range

Parameters:
  • ufun – The utility function to normalize

  • outcomes – A collection of outcomes to normalize for

  • rng – range to normalize to. Default is [0, 1]

  • levels – Number of levels to use for discretizing continuous issues (if any)

  • max_cardinality – Maximum allowed number of outcomes resulting after all discretization is done

serialize() dict[str, Any][source]

Converts the current scenario into a serializable dict.

Remarks:
Rturns a dictionary with the following keys:
  • domain: The agenda/outcome-space

  • ufuns: A list of utility functions

to_genius_files(domain_path: Path, ufun_paths: list[Path])[source]

Save domain and ufun files to the path as XML.

to_genius_folder(path: Path)[source]

Save domain and ufun files to the path as XML.

to_json(folder: Path | str) None[source]

Saves the scenario as json :param folder: The destination path

to_numeric() Scenario[source]

Forces all issues in the domain to become numeric

Remarks:
  • maps the agenda and ufuns to work correctly together

to_single_issue(numeric=False, stringify=True, randomize=False) Scenario[source]

Forces the domain to have a single issue with all possible outcomes

Parameters:
  • numeric – If given, the output issue will be a ContiguousIssue otherwise it will be a DiscreteCategoricalIssue

  • stringify – If given, the output issue will have string values. Checked only if Numeric and Mathematical Modules is False

  • randomize – Randomize outcome order when creating the single issue

Remarks:
  • maps the agenda and ufuns to work correctly together

  • Only works if the outcome space is finite

to_yaml(folder: Path | str) None[source]

Saves the scenario as yaml :param folder: The destination path

ufuns: tuple[UtilityFunction, ...][source]
negmas.inout.find_genius_domain_and_utility_files(folder_name) tuple[PathLike | None, list[PathLike]][source]

Finds the domain and utility_function files in a folder

negmas.inout.find_geniusweb_domain_and_utility_files(folder_name) tuple[PathLike | None, list[PathLike]][source]

Finds the domain and utility_function files in a GeniusWeb formatted json folder

negmas.inout.get_domain_issues(domain_file_name: PathLike | str, n_discretization: int | None = None, safe_parsing=False) Sequence[Issue] | None[source]

Returns the issues of a given XML domain (Genius Format)

Parameters:
  • domain_file_name – Name of the file

  • n_discretization – Number of discrete levels per continuous variable.

  • max_cardinality – Maximum number of outcomes in the outcome space after discretization. Used only if n_discretization is given.

  • safe_parsing – Apply more checks while parsing

Returns:

List of issues

negmas.inout.load_genius_domain(domain_file_name: PathLike, utility_file_names: Iterable[PathLike] | None = None, ignore_discount=False, ignore_reserved=False, safe_parsing=True, **kwargs) Scenario[source]

Loads a genius domain, creates appropriate negotiators if necessary

Parameters:
  • domain_file_name – XML file containing Genius-formatted domain spec

  • utility_file_names – XML files containing Genius-fromatted ufun spec

  • ignore_reserved – Sets the reserved_value of all ufuns to -inf

  • ignore_discount – Ignores discounting

  • safe_parsing – Applies more stringent checks during parsing

Returns:

A Domain ready to run

negmas.inout.load_genius_domain_from_folder(folder_name: str | PathLike, ignore_reserved=False, ignore_discount=False, safe_parsing=False, **kwargs) Scenario[source]

Loads a genius domain from a folder. See load_genius_domain for more details.

Parameters:
  • folder_name – A folder containing one XML domain file and one or more ufun files in Genius format

  • ignore_reserved – Sets the reserved_value of all ufuns to -inf

  • ignore_discount – Ignores discounting

  • safe_parsing – Applies more stringent checks during parsing

  • kwargs – Extra arguments to pass verbatim to SAOMechanism constructor

Returns:

A domain ready for make_session

Examples

>>> import pkg_resources
>>> from negmas import load_genius_domain_from_folder

Try loading and running a domain with predetermined agents: >>> domain = load_genius_domain_from_folder( … pkg_resources.resource_filename(“negmas”, resource_name=”tests/data/Laptop”) … )

Try loading a domain and check the resulting ufuns >>> domain = load_genius_domain_from_folder( … pkg_resources.resource_filename(“negmas”, resource_name=”tests/data/Laptop”) … )

>>> domain.n_issues, domain.n_negotiators
(3, 2)
>>> [type(_) for _ in domain.ufuns]
[<class 'negmas.preferences.crisp.linear.LinearAdditiveUtilityFunction'>, <class 'negmas.preferences.crisp.linear.LinearAdditiveUtilityFunction'>]

Try loading a domain forcing a single issue space >>> domain = load_genius_domain_from_folder( … pkg_resources.resource_filename(“negmas”, resource_name=”tests/data/Laptop”) … ).to_single_issue() >>> domain.n_issues, domain.n_negotiators (1, 2) >>> [type(_) for _ in domain.ufuns] [<class ‘negmas.preferences.crisp.linear.LinearAdditiveUtilityFunction’>, <class ‘negmas.preferences.crisp.linear.LinearAdditiveUtilityFunction’>]

Try loading a domain with nonlinear ufuns: >>> folder_name = pkg_resources.resource_filename( … “negmas”, resource_name=”tests/data/10issues” … ) >>> domain = load_genius_domain_from_folder(folder_name) >>> print(domain.n_issues) 10 >>> print(domain.n_negotiators) 2 >>> print([type(u) for u in domain.ufuns]) [<class ‘negmas.preferences.crisp.nonlinear.HyperRectangleUtilityFunction’>, <class ‘negmas.preferences.crisp.nonlinear.HyperRectangleUtilityFunction’>] >>> u = domain.ufuns[0] >>> print(u.outcome_ranges[0]) {1: (7.0, 9.0), 3: (2.0, 7.0), 5: (0.0, 8.0), 8: (0.0, 7.0)}

>>> print(u.mappings[0])
97.0
>>> print(u([0.0] * domain.n_issues))
0
>>> print(u([0.5] * domain.n_issues))
186.0
negmas.inout.load_geniusweb_domain(domain_file_name: PathLike, utility_file_names: Iterable[PathLike] | None = None, ignore_discount=False, ignore_reserved=False, use_reserved_outcome=False, safe_parsing=True, **kwargs) Scenario[source]

Loads a geniusweb domain, creates appropriate negotiators if necessary

Parameters:
  • domain_file_name – XML file containing Genius-formatted domain spec

  • utility_file_names – XML files containing Genius-fromatted ufun spec

  • ignore_reserved – Sets the reserved_value of all ufuns to -inf

  • ignore_discount – Ignores discounting

  • safe_parsing – Applies more stringent checks during parsing

  • kwargs – Extra arguments to pass verbatim to SAOMechanism constructor

Returns:

A Domain ready to run

negmas.inout.load_geniusweb_domain_from_folder(folder_name: str | PathLike, ignore_reserved=False, ignore_discount=False, use_reserved_outcome=False, safe_parsing=False, **kwargs) Scenario[source]

Loads a genius-web domain from a folder. See load_geniusweb_domain for more details.

Parameters:
  • folder_name – A folder containing one XML domain file and one or more ufun files in Genius format

  • ignore_reserved – Sets the reserved_value of all ufuns to -inf

  • ignore_discount – Ignores discounting

  • safe_parsing – Applies more stringent checks during parsing

  • kwargs – Extra arguments to pass verbatim to SAOMechanism constructor

Returns:

A domain ready for make_session

negmas.inout.scenario_size(self: Scenario)[source]

Scenario size.