OutcomeType

class negmas.outcomes.OutcomeType[source]

Bases: object

A helper class allowing for definition of types that behave as outcomes (either in the form of dict or tuple).

This class is intended to be used when a simple tuple or dict is not enough for describing an outcome (e.g. to use editor features like auto-completion of members). You simply define your class as a dataclass and add your fields to it then inherit from OutcomeType. As we do nothing in the __init__ function, that is compatible with python dataclasses.

Examples

>>> from negmas.outcomes import OutcomeType, Issue
>>> @dataclass
... class MyOutcome(OutcomeType):
...     price: float = 0.0
...     quantity: int = 0

You can use MyOutcome as an outcome directly or convert it to a tuple/dict for other functions

>>> outcome = MyOutcome(price=2.0, quantity=3)
>>> outcome.price
2.0
>>> outcome['price']
2.0
>>> outcome.astuple()
(2.0, 3)
>>> outcome.asdict()
{'price': 2.0, 'quantity': 3}

You can also use outputs from issues to initialize your class

>>> issues = [Issue(name='price', values=(0.0, 3.0)), Issue(name='quantity', values=10)]
>>> sample = Issue.sample(issues=issues, n_outcomes=1)[0]
>>> outcome = MyOutcome(**sample)
>>> outcome.price == outcome['price']
True

Methods Summary

asdict()

Converts the outcome to a dict containing all fields

astuple()

Converts the outcome to a tuple where the order of items is the same as they are defined as fields

get(name[, default])

Acts like dict.get

keys()

values()

Methods Documentation

asdict()[source]

Converts the outcome to a dict containing all fields

astuple()[source]

Converts the outcome to a tuple where the order of items is the same as they are defined as fields

get(name, default: Optional[Any] = None)[source]

Acts like dict.get

keys()List[str][source]
values()List[str][source]