PresortingInverseUtilityFunction

class negmas.preferences.PresortingInverseUtilityFunction(ufun, levels=10, max_cache_size=100000)[source]

Bases: negmas.preferences.protocols.InverseUFun

A utility function inverter that uses pre-sorting.

The outcome-space is sampled if it is continuous and enumerated if it is discrete during the call to init() and an ordered list of outcomes with their utility values is then cached.

Attributes Summary

initialized

ufun

Methods Summary

__call__(rng, normalized)

Calling an inverse ufun directly is equivalent to calling one_in()

all(rng, normalized)

Finds all outcomes with in the given utility value range

best()

Finds the best outcome

best_in(rng, normalized)

Finds an outcome with highest utility within the given range

extreme_outcomes()

Finds the worst and best outcomes that can be returned.

init()

Used to intialize the inverse ufun.

max()

Finds the maximum utility value

min()

Finds the minimum utility value

minmax()

Finds the minimum and maximum utility values that can be returned.

one_in(rng, normalized)

Finds an outcmoe with the given utility value.

reset()

rtype

None

some(rng, normalized[, n])

Finds some outcomes with the given utility value (if discrete, all)

within_fractions(rng)

Finds outocmes within the given fractions of utility values (the fractions must be between zero and one)

within_indices(rng)

Finds outocmes within the given indices with the best at index 0 and the worst at largest index.

worst()

Finds the worst outcome

worst_in(rng, normalized)

Finds an outcome with lowest utility within the given range

Attributes Documentation

initialized: bool
ufun: UFun

Methods Documentation

__call__(rng, normalized)[source]

Calling an inverse ufun directly is equivalent to calling one_in()

Return type

Outcome | None

all(rng, normalized)[source]

Finds all outcomes with in the given utility value range

Parameters

rng (float | tuple[float, float]) – The range. If a value, outcome utilities must match it exactly

Remarks:
  • If issues or outcomes are not None, then init_inverse will be called first

  • If the outcome-space is discrete, this method will return all outcomes in the given range

Return type

list[Outcome]

best()[source]

Finds the best outcome

Return type

tuple

best_in(rng, normalized)[source]

Finds an outcome with highest utility within the given range

Parameters
  • rng (float | tuple[float, float]) – The range (or single value) of utility values to search for outcomes

  • normalized (bool) – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range

Return type

Outcome | None

extreme_outcomes()[source]

Finds the worst and best outcomes that can be returned.

Remarks:

These may be different from the results of ufun.extreme_outcomes() as they can be approximate.

Return type

tuple[tuple, tuple]

init()[source]

Used to intialize the inverse ufun. Any computationally expensive initialization should be done here not in the constructor.

max()[source]

Finds the maximum utility value

Return type

float

min()[source]

Finds the minimum utility value

Return type

float

minmax()[source]

Finds the minimum and maximum utility values that can be returned.

Remarks:

These may be different from the results of ufun.minmax() as they can be approximate.

Return type

tuple[float, float]

one_in(rng, normalized)[source]

Finds an outcmoe with the given utility value.

Parameters
  • rng (float | tuple[float, float]) – The range (or single value) of utility values to search for outcomes

  • normalized (bool) – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range

Return type

Outcome | None

reset()[source]
Return type

None

some(rng, normalized, n=None)[source]

Finds some outcomes with the given utility value (if discrete, all)

Parameters
  • rng (float | tuple[float, float]) – The range. If a value, outcome utilities must match it exactly

  • n (int | None) – The maximum number of outcomes to return

Remarks:
  • If issues or outcomes are not None, then init_inverse will be called first

  • If the outcome-space is discrete, this method will return all outcomes in the given range

Return type

list[Outcome]

within_fractions(rng)[source]

Finds outocmes within the given fractions of utility values (the fractions must be between zero and one)

Return type

list[tuple]

within_indices(rng)[source]

Finds outocmes within the given indices with the best at index 0 and the worst at largest index.

Remarks:
  • Works only for discrete outcome spaces

Return type

list[tuple]

worst()[source]

Finds the worst outcome

Return type

tuple

worst_in(rng, normalized)[source]

Finds an outcome with lowest utility within the given range

Parameters
  • rng (float | tuple[float, float]) – The range (or single value) of utility values to search for outcomes

  • normalized (bool) – if True, the input rng will be understood as ranging from 0-1 (1=max, 0=min) independent of the ufun actual range

Return type

Outcome | None