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, stats: ~negmas.preferences.ops.ScenarioStats | None = None, name: str | None = None, source: ~pathlib.Path | tuple[~pathlib.Path, ...] | None = None)[source]¶
Bases:
objectA 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_standard_info(calc_rational: bool = True) dict[str, Any][source]¶
Calculate and store standard scenario information metrics.
Computes basic statistics about the negotiation scenario and stores them in the scenario’s info dictionary. The metrics include:
n_negotiators: Number of negotiators
n_outcomes: Total number of outcomes
n_issues: Number of negotiation issues
rational_fraction: Fraction of outcomes with positive utility for all parties
opposition_level: Conflict measure between negotiators (0=no conflict, higher=more conflict)
- Returns:
Dictionary containing the calculated information metrics.
Examples
>>> from negmas import make_issue, make_os >>> from negmas.preferences import LinearUtilityFunction >>> issues = [make_issue([0, 1, 2], "x")] >>> os = make_os(issues) >>> u1 = LinearUtilityFunction(weights=[1.0], outcome_space=os) >>> u2 = LinearUtilityFunction(weights=[0.5], outcome_space=os) >>> scenario = Scenario(outcome_space=os, ufuns=[u1, u2]) >>> info = scenario.calc_standard_info() >>> info["n_negotiators"] 2 >>> info["n_outcomes"] 3 >>> info["n_issues"] 1
- calc_stats() ScenarioStats[source]¶
Calculates scenario statistics and stores them in the stats attribute.
- discretize(levels: int = 10, recalculate_stats: bool = True)[source]¶
Discretizes all continuous issues in the outcome space.
- Parameters:
levels – Number of discrete levels to create for each continuous issue.
recalculate_stats – If True and stats exist, recalculate them after discretizing. If False and stats exist, invalidate stats by setting them to None.
- dumpas(folder: Path | str, type='yml', compact: bool = False, save_stats=True, save_info=True, save_plot=False, include_pareto_frontier: bool = True, include_pareto_utils: bool | None = None, include_pareto_outcomes: bool | None = None, plot_extension: str | None = None, plot_kwargs: dict | None = None) None[source]¶
Dumps the scenario in the given file format.
- Parameters:
folder – Destination folder path.
type – File format (“yml”, “json”, or “xml”).
compact – If True, use compact JSON formatting.
save_stats – If True, save scenario statistics to stats.json.
save_info – If True, save scenario info to info file.
save_plot – If True, save utility space plots. Default is False.
include_pareto_frontier – If True, include pareto_utils and pareto_outcomes in stats.json. If False, exclude them to save disk space. Default is True.
include_pareto_utils – If specified, controls inclusion of pareto_utils independently. If None, falls back to include_pareto_frontier value.
include_pareto_outcomes – If specified, controls inclusion of pareto_outcomes independently. If None, falls back to include_pareto_frontier value.
plot_extension – File extension for plots (e.g., ‘png’, ‘jpg’, ‘svg’, ‘pdf’, ‘webp’). If None, uses DEFAULT_IMAGE_FORMAT from negmas.plots.util (currently ‘webp’).
plot_kwargs – Additional keyword arguments to pass to the plot() method. Default is None.
- static from_genius_files(domain: PathLike, ufuns: Iterable[PathLike], info: PathLike | None = None, ignore_discount=False, ignore_reserved=False, safe_parsing=True, name: str | None = None) Scenario | None[source]¶
Loads a scenario from specific Genius-format XML file paths.
- Parameters:
domain – Path to the domain XML file.
ufuns – Paths to the utility function XML files.
info – Optional path to the scenario info file.
ignore_discount – If True, ignore time-based discounting.
ignore_reserved – If True, set reserved values to -inf.
safe_parsing – If True, apply more stringent validation during parsing.
name – Optional name for the scenario. If None, uses domain file stem.
- Returns:
The loaded Scenario, or None if loading fails.
- static from_genius_folder(path: PathLike | str, ignore_discount=False, ignore_reserved=False, safe_parsing=True) Scenario | None[source]¶
Loads a scenario from a folder containing Genius-format XML files.
- Parameters:
path – Directory containing the domain and utility function XML files.
ignore_discount – If True, ignore time-based discounting in utility functions.
ignore_reserved – If True, set reserved values to -inf.
safe_parsing – If True, apply more stringent validation during parsing.
- Returns:
The loaded Scenario, or None if loading fails.
- 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, name: str | None = None) Scenario | None[source]¶
Loads a scenario from specific GeniusWeb-format JSON file paths.
- Parameters:
domain – Path to the domain JSON file.
ufuns – Paths to the utility function JSON files.
info – Optional path to the scenario info file.
ignore_discount – If True, ignore time-based discounting.
ignore_reserved – If True, set reserved values to -inf.
use_reserved_outcome – If True, use reserved outcome instead of reserved value.
safe_parsing – If True, apply more stringent validation during parsing.
name – Optional name for the scenario. If None, uses domain file stem.
- Returns:
The loaded Scenario, or None if loading fails.
- static from_geniusweb_folder(path: PathLike | str, ignore_discount=False, ignore_reserved=False, use_reserved_outcome=False, safe_parsing=True) Scenario | None[source]¶
Loads a scenario from a folder containing GeniusWeb-format JSON files.
- Parameters:
path – Directory containing the domain and utility function JSON files.
ignore_discount – If True, ignore time-based discounting.
ignore_reserved – If True, set reserved values to -inf.
use_reserved_outcome – If True, use reserved outcome instead of reserved value.
safe_parsing – If True, apply more stringent validation during parsing.
- Returns:
The loaded Scenario, or None if loading fails.
- 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', name: str | None = None) Scenario | None[source]¶
Loads a scenario from specific YAML file paths.
- Parameters:
domain – Path to the domain YAML file.
ufuns – Paths to the utility function YAML files.
info – Optional path to the scenario info file.
ignore_discount – If True, ignore time-based discounting.
ignore_reserved – If True, set reserved values to -inf.
safe_parsing – Unused; YAML parsing is always safe.
python_class_identifier – Key used to identify the Python class type in YAML.
name – Optional name for the scenario. If None, uses name from YAML or domain file stem.
- Returns:
The loaded Scenario, or None if loading fails.
- classmethod from_yaml_folder(path: PathLike | str, ignore_discount=False, ignore_reserved=False, safe_parsing=True) Scenario | None[source]¶
Loads a scenario from a folder containing YAML files.
- Parameters:
path – Directory containing the domain and utility function YAML files.
ignore_discount – If True, ignore time-based discounting.
ignore_reserved – If True, set reserved values to -inf.
safe_parsing – Unused; YAML parsing is always safe.
- Returns:
The loaded Scenario, or None if loading fails.
- property is_linear: bool[source]¶
Checks if all utility functions in the scenario are linear.
- Returns:
True if all utility functions are linear (including LinearAdditiveUtilityFunction, AffineUtilityFunction, LinearUtilityFunction, LinearUtilityAggregationFunction, or ConstUtilityFunction). Handles DiscountedUtilityFunction by checking the base utility function.
Examples
>>> from negmas import make_issue, Scenario >>> from negmas.preferences import LinearUtilityFunction >>> issues = [make_issue([0, 1, 2], "x")] >>> u1 = LinearUtilityFunction(weights=[1.0], issues=issues) >>> u2 = LinearUtilityFunction(weights=[0.5], issues=issues) >>> scenario = Scenario(outcome_space=make_os(issues), ufuns=(u1, u2)) >>> scenario.is_linear True
- classmethod is_loadable(path: PathLike | str)[source]¶
Checks whether a directory contains a valid loadable scenario.
- is_normalized(to: tuple[float | None, float | None] = (None, 1.0), positive: bool = True, independent: bool | None = None, common_range: bool | None = None, eps: float = 1e-06, finite_reserved_value: bool = False) bool[source]¶
Checks that all ufuns are normalized in the given range.
- Parameters:
to – Target range (min, max) to check. None means no constraint on that bound.
positive – If True, checks that all minimums are non-negative.
common_range – If True (default), checks common-scale normalization (all ufuns within range, at least one reaches each bound). If False, checks that each ufun individually spans the full range.
independent – Deprecated. Use common_range instead. If True, checks that each ufun individually spans the full range. If False, checks common-scale normalization. This parameter will be removed in a future version.
eps – Tolerance for floating point comparisons.
finite_reserved_value – If True, also checks that all reserved values are finite (not None, inf, -inf, or NaN).
- Returns:
True if the scenario is normalized according to the specified criteria.
- classmethod load(folder: Path | str, safe_parsing=False, ignore_discount=False, load_stats=True, load_info=True, **kwargs) Scenario | None[source]¶
Loads the scenario from a folder with supported formats: XML, YML
- load_info(folder: PathLike | str)[source]¶
Loads scenario info from a folder, searching for supported formats.
- load_stats(folder: PathLike | str, calc_pareto_if_missing: bool = False)[source]¶
Loads scenario statistics from a folder, searching for supported formats.
- Parameters:
folder – Folder containing the stats file.
calc_pareto_if_missing – If True and the loaded stats have no pareto frontier data, calculate it using this scenario’s utility functions.
- Returns:
Self for method chaining.
Notes
Looks for stats in the following order (for backward compatibility): 1. _stats.yaml (new format) 2. stats.json (legacy format from cartesian_tournament < 0.14.0)
Handles stats files that may have been saved without pareto frontier data (when include_pareto_frontier=False was used during saving).
When calc_pareto_if_missing=True, the pareto frontier will be computed on-the-fly, which may be slow for large outcome spaces.
- load_stats_file(file: Path, calc_pareto_if_missing: bool = False)[source]¶
Load stats file.
- Parameters:
file – File path to load stats from.
calc_pareto_if_missing – If True and the loaded stats have no pareto frontier data, calculate it using this scenario’s utility functions.
- Returns:
Self for method chaining.
Notes
Handles stats files that may have been saved without pareto frontier data (when include_pareto_frontier=False was used during saving).
When calc_pareto_if_missing=True, the pareto frontier will be computed on-the-fly, which may be slow for large outcome spaces.
- 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.
- property n_negotiators: int[source]¶
The number of negotiators (utility functions) in this scenario.
- normalize(to: tuple[float, float] = (0.0, 1.0), outcome_space: OutcomeSpace | None = None, guarantee_max: bool = True, guarantee_min: bool | None = None, independent: bool | None = None, common_range: bool | None = None, recalculate_stats: bool = True, normalize_reserved_values: bool = False, reserved_value_penalty: float | None = None) Scenario[source]¶
Normalizes all utility functions to the given range.
- Parameters:
to – Target range (min, max) to normalize all utility functions to.
outcome_space – The outcome space to use for normalization. If None, uses the scenario’s outcome space.
guarantee_max – If True, guarantees that the maximum value is exactly to[1].
guarantee_min – If True, guarantees that the minimum value is exactly to[0]. When None (default), automatically set to True for common_range=True, False for common_range=False.
common_range – If True (default), normalizes all utility functions to a common scale. If False, normalizes each utility function independently to span the full range.
independent – Deprecated. Use common_range instead. If True, normalizes each utility function independently. If False, uses common scale normalization. This parameter will be removed in a future version.
recalculate_stats – If True and stats exist, recalculate them after normalizing. If False and stats exist, invalidate stats by setting them to None.
normalize_reserved_values – If True, corrects non-finite reserved values (None, inf, -inf, NaN) in all utility functions before normalization.
reserved_value_penalty – Penalty to subtract from ufun.min() when correcting reserved values. If None, uses DEFAULT_RESERVED_VALUE_PENALTY from negmas.common.
- Remarks:
If either value of
toisNone, then all ufuns will just be scaled to match the constraint of the other value.When common_range=True (default), all utility functions are normalized to a common scale, ensuring that utility values are comparable across agents.
When common_range=False, each utility function is normalized independently to span the full range.
If normalize_reserved_values is True, any non-finite reserved values will be corrected before normalization.
- outcome_space: CartesianOutcomeSpace[source]¶
- plot(ufun_indices: tuple[int, int] | None = None, backend: str = 'matplotlib', **kwargs)[source]¶
Visualizes the scenario’s utility space using a 2D plot.
- Parameters:
ufun_indices – Tuple of (i, j) specifying which pair of utility functions to plot. If None, plots the first two ufuns (indices 0 and 1). For scenarios with exactly 2 ufuns, this parameter is ignored.
backend – Plotting backend to use. Either “matplotlib” or “plotly”. Default is “matplotlib”.
**kwargs – Additional arguments passed to plot_2dutils.
- Returns:
A matplotlib Figure object if backend=”matplotlib”, or a plotly Figure object if backend=”plotly”.
- Raises:
ValueError – If the scenario has fewer than 2 utility functions, or if backend is invalid.
IndexError – If ufun_indices contains invalid indices.
- remove_discounting(recalculate_stats: bool = True)[source]¶
Removes time-based discounting from all utility functions.
- Parameters:
recalculate_stats – If True and stats exist, recalculate them after removing discounting. If False and stats exist, invalidate stats by setting them to None.
- remove_reserved_values(r: float = -inf, recalculate_stats: bool = True)[source]¶
Replaces reserved values in all utility functions with the given value.
- Parameters:
r – The value to set as the new reserved value for all utility functions.
recalculate_stats – If True and stats exist, recalculate them after removing reserved values. If False and stats exist, invalidate stats by setting them to None.
- rotate_ufuns(n: int = 1, rotate_info: bool = True) Scenario[source]¶
Creates a new scenario with utility functions rotated by n positions.
This method is useful for creating variants of scenarios where negotiators swap positions, commonly used in tournament testing to evaluate negotiators in different roles (e.g., buyer vs seller).
- Parameters:
n – Number of positions to rotate. Default is 1 (rotate right by one position). Can be negative to rotate left. The rotation is modulo len(ufuns).
rotate_info – If True, rotate private info entries in the same way as ufuns. Only affects info entries that are lists/tuples matching the number of ufuns.
- Returns:
A new Scenario with rotated utility functions and updated stats/info.
Notes
The outcome space remains unchanged (outcomes are not rotated).
Stats are rotated to match the new ufun order: * All _utils values (utility tuples) are rotated * All _outcomes values (outcome objects) remain the same * utility_ranges list is rotated to match new ufun positions
Info dict is deep copied. If rotate_info=True, any list/tuple values with length matching len(ufuns) are also rotated.
The source path is cleared since this is a derived scenario.
Mechanism type and params are preserved.
Examples:
scenario = Scenario(outcome_space=os, ufuns=(u0, u1, u2)) # Rotate right by 1: (u0, u1, u2) -> (u2, u0, u1) rotated = scenario.rotate_ufuns(1) assert rotated.ufuns == (u2, u0, u1) # Rotate left by 1: (u0, u1, u2) -> (u1, u2, u0) rotated = scenario.rotate_ufuns(-1) assert rotated.ufuns == (u1, u2, u0)
- save_plots(folder: Path | str, ext: str = 'webp', backend: str = 'matplotlib', **plot_kwargs) list[Path][source]¶
Saves utility space plots for all pairs of utility functions.
- Parameters:
folder – Destination folder where plots will be saved.
ext – Image file extension (e.g., ‘png’, ‘jpg’, ‘svg’, ‘pdf’, ‘webp’). Defaults to DEFAULT_IMAGE_FORMAT from negmas.plots.util (currently ‘webp’).
backend – Plotting backend to use. Either “matplotlib” or “plotly”. Default is “matplotlib”.
**plot_kwargs – Additional arguments passed to plot() method.
- Returns:
List of Path objects for all saved plot files.
- Raises:
ValueError – If the scenario has fewer than 2 utility functions, or if backend is invalid.
- Remarks:
For scenarios with exactly 2 ufuns: saves a single plot as “_plot.{ext}”
For scenarios with >2 ufuns: creates a “_plots/” subfolder and saves plots with names: “{u0_name}-{u1_name}.{ext}”, “{u1_name}-{u2_name}.{ext}”, …, “{u{n-1}_name}-{u0_name}.{ext}” This creates a circular sequence of plots for all consecutive pairs plus the wraparound.
For matplotlib backend, uses Figure.savefig() to save plots.
For plotly backend, uses Figure.write_image() to save plots.
- save_stats(folder: Path | str, compact: bool = False, include_pareto_frontier: bool = True) None[source]¶
- scale_max(to: float = 1.0, outcome_space: OutcomeSpace | None = None, recalculate_stats: bool = True) Scenario[source]¶
Scales all utility functions so their maximum value equals the given target.
This method scales each utility function independently by finding its maximum over the specified outcome space and multiplying by an appropriate scale factor.
- Parameters:
to – Target maximum value for all utility functions.
outcome_space – The outcome space to use when computing min/max values. If None, uses each ufun’s own outcome space (which should match the scenario’s outcome space).
recalculate_stats – If True and stats exist, recalculate them after scaling. If False and stats exist, invalidate stats by setting them to None.
- Returns:
Self for method chaining.
Note
Each utility function is scaled independently. This is different from normalize() which can perform common-scale normalization across all ufuns.
- scale_min(to: float = 0.0, outcome_space: OutcomeSpace | None = None, recalculate_stats: bool = True) Scenario[source]¶
Scales all utility functions so their minimum value equals the given target.
This method scales each utility function independently by finding its minimum over the specified outcome space and multiplying by an appropriate scale factor.
- Parameters:
to – Target minimum value for all utility functions.
outcome_space – The outcome space to use when computing min/max values. If None, uses each ufun’s own outcome space (which should match the scenario’s outcome space).
recalculate_stats – If True and stats exist, recalculate them after scaling. If False and stats exist, invalidate stats by setting them to None.
- Returns:
Self for method chaining.
Note
Each utility function is scaled independently. This is different from normalize() which can perform common-scale normalization across all ufuns.
- 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
- stats: ScenarioStats | None[source]¶
- to_genius_files(domain_path: Path, ufun_paths: list[Path])[source]¶
Save domain and ufun files to the
pathas 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, recalculate_stats: bool = True) Scenario[source]¶
Converts the scenario to use a single issue containing all possible outcomes.
- Parameters:
numeric – If True, the output issue will be a
ContiguousIssue, otherwise aDiscreteCategoricalIssue.stringify – If True and
Numeric and Mathematical Modulesis False, the output issue will have string values.randomize – If True, randomize outcome order when creating the single issue.
recalculate_stats – If True and stats exist, recalculate them after conversion. If False and stats exist, invalidate stats by setting them to None.
- 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]¶
- update(compact: bool = False, save_stats=True, save_info=True, save_plot=False, include_pareto_frontier: bool = True, include_pareto_utils: bool | None = None, include_pareto_outcomes: bool | None = None, plot_extension: str | None = None, plot_kwargs: dict | None = None) bool[source]¶
Updates the scenario at its source location.
- Parameters:
compact – If True, use compact JSON formatting.
save_stats – If True, save scenario statistics to stats.json.
save_info – If True, save scenario info to info file.
save_plot – If True, save utility space plots. Default is False.
include_pareto_frontier – If True, include both pareto_utils and pareto_outcomes in stats.json. If False, exclude both. This is overridden by the more specific include_pareto_utils and include_pareto_outcomes parameters.
include_pareto_utils – If specified, controls inclusion of pareto_utils independently. If None, uses the value of include_pareto_frontier.
include_pareto_outcomes – If specified, controls inclusion of pareto_outcomes independently. If None, uses the value of include_pareto_frontier.
plot_extension – File extension for plots (e.g., ‘png’, ‘jpg’, ‘svg’, ‘pdf’, ‘webp’). If None, uses DEFAULT_IMAGE_FORMAT from negmas.plots.util (currently ‘webp’).
plot_kwargs – Additional keyword arguments to pass to the plot() method. Default is None.
- Returns:
True if successfully saved, False if no source is available.
- Remarks:
Only works if the scenario has a source (was loaded from somewhere).
If source is a folder, saves to that folder.
If source is a single file, saves to the parent directory of that file.
If source is a tuple of files, saves to the parent directory of the first file.
Auto-detects format based on source file extension (yml, json, xml).
- 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_discretizationis 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, name: str | None = None, **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
name – Optional name for the scenario. If None, uses domain file stem.
- Returns:
A
Domainready 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_domainfor 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, name: str | None = None, **kwargs) Scenario[source]¶
Loads a geniusweb domain, creates appropriate negotiators if necessary
- Parameters:
domain_file_name – JSON file containing GeniusWeb-formatted domain spec
utility_file_names – JSON files containing GeniusWeb-fromatted ufun spec
ignore_reserved – Sets the reserved_value of all ufuns to -inf
ignore_discount – Ignores discounting
use_reserved_outcome – If True, use reserved outcome instead of reserved value
safe_parsing – Applies more stringent checks during parsing
name – Optional name for the scenario. If None, uses name from JSON or domain file stem.
kwargs – Extra arguments to pass verbatim to SAOMechanism constructor
- Returns:
A
Domainready 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_domainfor 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