SerialGBMechanism

class negmas.gb.SerialGBMechanism(*args, **kwargs)[source]

Bases: GBMechanism

Attributes Summary

agent_ids

agent_names

agreement

completed

Ended without timing out (either with agreement or broken by a negotiator)

current_step

dynamic_entry

ended

Ended in any way

expected_relative_time

Returns a positive number indicating elapsed relative time or steps.

expected_remaining_steps

Returns the expected remaining number of steps until the end of the mechanism run.

expected_remaining_time

Returns remaining time in seconds (expectation).

extended_trace

Returns the negotiation history as a list of step/negotiator/offer tuples.

full_trace

genius_negotiator_ids

history

id

The unique ID of this entity

issues

Returns the issues of the outcome space (if defined).

max_n_negotiators

n_outcomes

n_steps

name

A convenient name of the entity (intended primarily for printing/logging/debugging).

negotiator_ids

negotiator_names

negotiator_times

The total time consumed by every negotiator.

negotiators

offers

Returns the negotiation history as a list of offers.

outcome_space

outcomes

participants

Returns a list of all participant names.

relative_time

Returns a number between 0 and 1 indicating elapsed relative time or steps.

remaining_steps

Returns the remaining number of steps until the end of the mechanism run.

remaining_time

Returns remaining time in seconds.

requirements

A dictionary specifying the requirements that must be in the capabilities of any negotiator to join the mechanism.

running

short_type_name

state

Returns the current state.

state4history

Returns the state as it should be stored in the history.

stats

time

Elapsed time since mechanism started in seconds.

time_limit

trace

Returns the negotiation history as a list of negotiator/offer tuples.

type_name

uuid

The unique ID of this entity

verbosity

Verbosity level.

Methods Summary

__call__(state[, action])

Implements a single step of the mechanism.

abort()

Aborts the negotiation.

add(negotiator, *[, preferences, role, ufun])

Add an negotiator to the negotiation.

add_requirements(requirements)

Adds requirements.

announce(event)

Raises an event and informs all event sinks that are registered for notifications on this event type

can_accept_more_negotiators()

Whether the mechanism can currently accept more negotiators.

can_enter(negotiator)

Whether the negotiator can enter the negotiation now.

can_leave(negotiator)

Can the negotiator leave now?

can_participate(negotiator)

Checks if the negotiator can participate in this type of negotiation in general.

checkpoint(path[, file_name, info, ...])

Saves a checkpoint of the current object at the given path.

checkpoint_final_step()

Should be called at the end of the simulation to save the final state

checkpoint_info(file_name)

Returns the information associated with a dump of the object saved in the given file

checkpoint_init([step_attrib, every, ...])

Initializes the object to automatically save a checkpoint

checkpoint_on_step_started()

Should be called on every step to save checkpoints as needed.

create(*args, **kwargs)

Creates an object and returns a proxy to it.

discrete_outcome_space([levels, max_cardinality])

Returns a stable discrete version of the given outcome-space.

discrete_outcomes([levels, max_cardinality])

A discrete set of outcomes that spans the outcome space.

from_checkpoint(file_name[, return_info])

Creates an object from a saved checkpoint

genius_id(id)

Gets the Genius ID corresponding to the given negotiator if known otherwise its normal ID

get_negotiator(source)

Returns the negotiator with the given ID if present in the negotiation.

get_negotiator_raise(source)

Returns the negotiator with the given ID if present in the negotiation otherwise it raises an exception.

is_satisfying(capabilities)

Checks if the given capabilities are satisfying mechanism requirements.

is_valid(outcome)

Checks whether the outcome is valid given the issues.

kalai_points([max_cardinality, frontier, ...])

rtype:

tuple[tuple[tuple[float, ...], tuple], ...]

log(nid, data, level)

Saves a log for a negotiator

log_critical(nid, data)

Logs at critical level

log_debug(nid, data)

Logs at debug level

log_error(nid, data)

Logs at error level

log_info(nid, data)

Logs at info level

log_warning(nid, data)

Logs at warning level

max_relative_welfare_points([...])

rtype:

tuple[tuple[tuple[float, ...], tuple], ...]

max_welfare_points([max_cardinality, ...])

rtype:

tuple[tuple[tuple[float, ...], tuple], ...]

modified_kalai_points([max_cardinality, ...])

rtype:

tuple[tuple[tuple[float, ...], tuple], ...]

nash_points([max_cardinality, frontier, ...])

rtype:

tuple[tuple[tuple[float, ...], tuple], ...]

negotiator_full_trace(negotiator_id)

Returns the (time/relative-time/step/outcome/response) given by a negotiator (in order)

negotiator_index(source)

Gets the negotiator index.

negotiator_offers(negotiator_id)

Returns the offers given by a negotiator (in order)

on_mechanism_error()

Called when there is a mechanism error.

on_negotiation_end()

Called at the end of each negotiation.

on_negotiation_start()

Called before starting the negotiation.

pareto_frontier([max_cardinality, ...])

rtype:

tuple[tuple[tuple[float, ...], ...], list[tuple]]

pareto_frontier_bf([max_cardinality, ...])

rtype:

tuple[list[tuple[float, ...]], list[tuple]]

plot([plotting_negotiators, save_fig, path, ...])

A method for plotting a negotiation session.

random_outcome()

Returns a single random offer

random_outcomes([n, with_replacement])

Returns random offers.

register_listener(event_type, listener)

Registers a listener for the given event_type.

remove(negotiator)

Remove the negotiator from the negotiation.

remove_requirements(requirements)

Adds requirements.

run([timeout])

rtype:

TypeVar(TState, bound= MechanismState)

run_threads([action])

rtype:

dict[str, tuple[ThreadState, Union[tuple, None, Literal['continue']]]]

run_with_progress([timeout])

rtype:

TypeVar(TState, bound= MechanismState)

runall(mechanisms[, keep_order, method])

Runs all mechanisms.

set_id(id)

Sets the unique ID of this entity

set_sync_call(v)

spawn([spawn_as, spawn_params])

spawn_object(*args, **kwargs)

step([action])

Runs a single step of the mechanism.

stepall(mechanisms[, keep_order])

Step all mechanisms.

Attributes Documentation

agent_ids
agent_names
agreement
completed

Ended without timing out (either with agreement or broken by a negotiator)

current_step
dynamic_entry
ended

Ended in any way

expected_relative_time

Returns a positive number indicating elapsed relative time or steps.

Remarks:
  • This is relative to the expected time/step at which the negotiation ends given all timing conditions (time_limit, n_step, pend, pend_per_second).

expected_remaining_steps

Returns the expected remaining number of steps until the end of the mechanism run.

None if unlimited

expected_remaining_time

Returns remaining time in seconds (expectation).

None if no time limit or pend_per_second is given.

extended_trace

Returns the negotiation history as a list of step/negotiator/offer tuples.

full_trace
genius_negotiator_ids
history
id

The unique ID of this entity

issues

Returns the issues of the outcome space (if defined).

Will raise an exception if the outcome space has no defined issues

max_n_negotiators
n_outcomes
n_steps
name

A convenient name of the entity (intended primarily for printing/logging/debugging).

negotiator_ids
negotiator_names
negotiator_times

The total time consumed by every negotiator.

Each mechanism class is responsible of updating this for any activities of the negotiator it controls.

negotiators
offers

Returns the negotiation history as a list of offers.

outcome_space
outcomes
participants

Returns a list of all participant names.

relative_time

Returns a number between 0 and 1 indicating elapsed relative time or steps.

Remarks:
  • If pend or pend_per_second are defined in the NegotiatorMechanismInterface, and time_limit/n_steps are not given, this becomes an expectation that is limited above by one.

remaining_steps

Returns the remaining number of steps until the end of the mechanism run.

None if unlimited

remaining_time

Returns remaining time in seconds.

None if no time limit is given.

requirements

A dictionary specifying the requirements that must be in the capabilities of any negotiator to join the mechanism.

running
short_type_name
state

Returns the current state.

Override extra_state if you want to keep extra state

state4history

Returns the state as it should be stored in the history.

stats
time

Elapsed time since mechanism started in seconds.

0.0 if the mechanism did not start running

time_limit
trace

Returns the negotiation history as a list of negotiator/offer tuples.

type_name
uuid

The unique ID of this entity

verbosity

Verbosity level.

  • Children of this class should only print if verbosity > 1

Methods Documentation

__call__(state, action=None)

Implements a single step of the mechanism. Override this!

Parameters:
  • state (GBState) – The mechanism state. When overriding, set the type of this to the specific MechanismState descendent for your mechanism.

  • action (dict[str, GBAction] | None) – An optional action (value) of the next negotiator (key). If given, the call should just execute the action without calling the next negotiator.

Return type:

MechanismStepResult

Returns:

MechanismStepResult showing the result of the negotiation step

abort()

Aborts the negotiation.

Return type:

TypeVar(TState, bound= MechanismState)

add(negotiator, *, preferences=None, role=None, ufun=None)

Add an negotiator to the negotiation.

Parameters:
  • negotiator (GBNegotiator) – The negotiator to be added.

  • preferences (Preferences | None) – The utility function to use. If None, then the negotiator must already have a stored utility function otherwise it will fail to enter the negotiation.

  • ufun (BaseUtilityFunction | None) – [depricated] same as preferences but must be a UFun object.

  • role (str | None) – The role the negotiator plays in the negotiation mechanism. It is expected that mechanisms inheriting from this class will check this parameter to ensure that the role is a valid role and is still possible for negotiators to join on that role. Roles may include things like moderator, representative etc based on the mechanism

Return type:

bool | None

Returns:

  • True if the negotiator was added.

  • False if the negotiator was already in the negotiation.

  • None if the negotiator cannot be added. This can happen in the following cases:

    1. The capabilities of the negotiator do not match the requirements of the negotiation

    2. The outcome-space of the negotiator’s preferences do not contain the outcome-space of the negotiation

    3. The negotiator refuses to join (by returning False from its join method) see Negotiator.join for possible reasons of that

add_requirements(requirements)

Adds requirements.

Return type:

None

announce(event)

Raises an event and informs all event sinks that are registered for notifications on this event type

can_accept_more_negotiators()

Whether the mechanism can currently accept more negotiators.

Return type:

bool

can_enter(negotiator)

Whether the negotiator can enter the negotiation now.

Return type:

bool

can_leave(negotiator)

Can the negotiator leave now?

Return type:

bool

can_participate(negotiator)

Checks if the negotiator can participate in this type of negotiation in general.

Returns:

True if the negotiator can participate

Return type:

bool

Remarks:

The only reason this may return False is if the mechanism requires some requirements that are not within the capabilities of the negotiator.

When evaluating compatibility, the negotiator is considered incapable of participation if any of the following conditions hold: * A mechanism requirement is not in the capabilities of the negotiator * A mechanism requirement is in the capabilities of the negotiator by the values required for it

is not in the values announced by the negotiator.

An negotiator that lists a None value for a capability is announcing that it can work with all its values. On the other hand, a mechanism that lists a requirement as None announces that it accepts any value for this requirement as long as it exist in the negotiator

checkpoint(path, file_name=None, info=None, exist_ok=False, single_checkpoint=True, step_attribs=('current_step', '_current_step', '_Entity__current_step', '_step'))

Saves a checkpoint of the current object at the given path.

Parameters:
  • path (PathLike) – Full path to a directory to store the checkpoint

  • file_name (str | None) – Name of the file to dump into. If not given, a unique name is created

  • info (dict[str, Any] | None) – Information to save with the checkpoint (must be json serializable)

  • exist_ok (bool) – If true, override existing dump

  • single_checkpoint (bool) – If true, keep a single checkpoint for the last step

  • step_attribs (tuple[str, ...]) – Attributes to represent the time-step of the object. Any of the given attributes will be used in the file name generated if single_checkpoint is False. If single_checkpoint is True, the filename will not contain time-step information

Return type:

Path

Returns:

full path to the file used to save the checkpoint

checkpoint_final_step()

Should be called at the end of the simulation to save the final state

Return type:

Path | None

Remarks:
  • Should be called after all processing of the final step is conducted.

classmethod checkpoint_info(file_name)

Returns the information associated with a dump of the object saved in the given file

Parameters:

file_name (Path | str) – Name of the object

Return type:

dict[str, Any]

Returns:

checkpoint_init(step_attrib='current_step', every=1, folder=None, filename=None, info=None, exist_ok=True, single=True)

Initializes the object to automatically save a checkpoint

Parameters:
  • step_attrib (str) – The attribute that defines the current step. If None, there is no step concept

  • every (int) – Number of steps per checkpoint. If < 1 no checkpoints will be saved

  • folder (PathLike | Path | str | None) – The directory to store checkpoints under

  • filename (str | None) – Name of the file to save the checkpoint under. If None, a unique name will be chosen. If single_checkpoint was False, then multiple files will be used prefixed with the step number

  • info (dict[str, Any] | None) – Any extra information to save in the json file associated with each checkpoint

  • exist_ok (bool) – Override existing files if any

  • single (bool) – If True, only the most recent checkpoint will be kept

Remarks:

  • single_checkpoint implies exist_ok

checkpoint_on_step_started()

Should be called on every step to save checkpoints as needed.

Return type:

Path | None

Returns:

The path on which the checkpoint is stored if one is stored. None otherwise.

Remarks:

  • Should be called at the BEGINNING of every step before any processing takes place

classmethod create(*args, **kwargs)

Creates an object and returns a proxy to it.

discrete_outcome_space(levels=5, max_cardinality=10000000000)

Returns a stable discrete version of the given outcome-space.

Return type:

DiscreteOutcomeSpace

discrete_outcomes(levels=5, max_cardinality=inf)

A discrete set of outcomes that spans the outcome space.

Parameters:
  • max_cardinality (int | float) – The maximum number of outcomes to return. If None, all outcomes will be returned for discrete issues

  • continuous (and 10_000 if any of the issues was)

Returns:

list of n or less outcomes

Return type:

list[Outcome]

classmethod from_checkpoint(file_name, return_info=False)

Creates an object from a saved checkpoint

Parameters:
  • file_name (Path | str)

  • return_info (bool) – If True, tbe information saved when the file was dumped are returned

Return type:

NamedObject | tuple[NamedObject, dict[str, Any]]

Returns:

Either the object or the object and dump-info as a dict (if return_info was true)

Remarks:

  • If info is returned, it is guaranteed to have the following members:
    • time: Dump time

    • type: Type of the dumped object

    • id: ID

    • name: name

genius_id(id)

Gets the Genius ID corresponding to the given negotiator if known otherwise its normal ID

Return type:

str | None

get_negotiator(source)

Returns the negotiator with the given ID if present in the negotiation.

Return type:

Negotiator | None

get_negotiator_raise(source)

Returns the negotiator with the given ID if present in the negotiation otherwise it raises an exception.

Return type:

Negotiator

is_satisfying(capabilities)

Checks if the given capabilities are satisfying mechanism requirements.

Parameters:

capabilities (dict) – capabilities to check

Return type:

bool

Returns:

bool are the requirements satisfied by the capabilities.

Remarks:

  • Requirements are also a dict with the following meanings:

    • tuple: Min and max acceptable values

    • list/set: Any value in the iterable is acceptable

    • Single value: The capability must match this value

  • Capabilities can also have the same three possibilities.

is_valid(outcome)

Checks whether the outcome is valid given the issues.

kalai_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
Return type:

tuple[tuple[tuple[float, ...], tuple], ...]

log(nid, data, level)

Saves a log for a negotiator

Return type:

None

log_critical(nid, data)

Logs at critical level

Return type:

None

log_debug(nid, data)

Logs at debug level

Return type:

None

log_error(nid, data)

Logs at error level

Return type:

None

log_info(nid, data)

Logs at info level

Return type:

None

log_warning(nid, data)

Logs at warning level

Return type:

None

max_relative_welfare_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
Return type:

tuple[tuple[tuple[float, ...], tuple], ...]

max_welfare_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
Return type:

tuple[tuple[tuple[float, ...], tuple], ...]

modified_kalai_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
Return type:

tuple[tuple[tuple[float, ...], tuple], ...]

nash_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
Return type:

tuple[tuple[tuple[float, ...], tuple], ...]

negotiator_full_trace(negotiator_id)

Returns the (time/relative-time/step/outcome/response) given by a negotiator (in order)

Return type:

list[tuple[float, float, int, tuple, str]]

negotiator_index(source)

Gets the negotiator index.

Parameters:

source (str) – source

Return type:

int | None

negotiator_offers(negotiator_id)

Returns the offers given by a negotiator (in order)

Return type:

list[tuple]

on_mechanism_error()

Called when there is a mechanism error.

Return type:

None

Remarks:
  • When overriding this function you MUST call the base class version

on_negotiation_end()

Called at the end of each negotiation.

Return type:

None

Remarks:
  • When overriding this function you MUST call the base class version

on_negotiation_start()

Called before starting the negotiation.

If it returns False then negotiation will end immediately

Return type:

bool

pareto_frontier(max_cardinality=inf, sort_by_welfare=True)
Return type:

tuple[tuple[tuple[float, ...], ...], list[tuple]]

pareto_frontier_bf(max_cardinality=inf, sort_by_welfare=True)
Return type:

tuple[list[tuple[float, ...]], list[tuple]]

plot(plotting_negotiators=(0, 1), save_fig=False, path=None, fig_name=None, ignore_none_offers=True, with_lines=True, show_agreement=False, show_pareto_distance=True, show_nash_distance=True, show_kalai_distance=True, show_max_welfare_distance=True, show_max_relative_welfare_distance=False, show_end_reason=True, show_annotations=False, show_reserved=True, show_total_time=True, show_relative_time=True, show_n_steps=True, colors=None, markers=None, colormap='jet', ylimits=None, common_legend=True, xdim='step', colorizer=<function default_colorizer>, only2d=False, fast=False, simple_offers_view=False, **kwargs)

A method for plotting a negotiation session.

random_outcome()

Returns a single random offer

Return type:

tuple

random_outcomes(n=1, with_replacement=False)

Returns random offers.

Parameters:
  • n (int) – Number of outcomes to generate

  • with_replacement (bool) – If true, outcomes may be repeated

Return type:

list[tuple]

Returns:

A list of outcomes of at most n outcomes.

Remarks:

  • If the number of outcomes n cannot be satisfied, a smaller number will be returned

  • Sampling is done without replacement (i.e. returned outcomes are unique).

register_listener(event_type, listener)

Registers a listener for the given event_type.

Parameters:
  • event_type (str | None) – The type to register. If None, the listener will be registered for all types

  • listener (EventSink) – The listening agent (must have an on_event method that receives an event: Event and a sender: EventSource)

remove(negotiator)

Remove the negotiator from the negotiation.

Return type:

bool | None

Returns:

  • True if the negotiator was removed.

  • False if the negotiator was not in the negotiation already.

  • None if the negotiator cannot be removed.

remove_requirements(requirements)

Adds requirements.

Return type:

None

run(timeout=None)
Return type:

TypeVar(TState, bound= MechanismState)

run_threads(action=None)
Return type:

dict[str, tuple[ThreadState, Union[tuple, None, Literal['continue']]]]

run_with_progress(timeout=None)
Return type:

TypeVar(TState, bound= MechanismState)

classmethod runall(mechanisms, keep_order=True, method='serial')

Runs all mechanisms.

Parameters:
  • mechanisms (list[Mechanism] | tuple[Mechanism, ...]) – list of mechanisms

  • keep_order – if True, the mechanisms will be run in order every step otherwise the order will be randomized at every step. This is only allowed if the method is serial

  • method – the method to use for running all the sessions. Acceptable options are: serial, threads, processes

Return type:

list[Optional[TypeVar(TState, bound= MechanismState)]]

Returns:

  • list of states of all mechanisms after completion

  • None for any such states indicates disagreements

set_id(id)

Sets the unique ID of this entity

set_sync_call(v)
classmethod spawn(spawn_as='object', spawn_params=None, *args, **kwargs)
classmethod spawn_object(*args, **kwargs)
step(action=None)

Runs a single step of the mechanism.

Returns:

The state of the negotiation after the round is conducted action: An optional action (value) for the next negotiator (key). If given, the call

should just execute the action without calling the next negotiator.

Return type:

MechanismState

Remarks:

  • Every call yields the results of one round (see round())

  • If the mechanism was yet to start, it will start it and runs one round

  • There is another function (run()) that runs the whole mechanism in blocking mode

classmethod stepall(mechanisms, keep_order=True)

Step all mechanisms.

Parameters:
  • mechanisms (list[Mechanism] | tuple[Mechanism, ...]) – list of mechanisms

  • keep_order – if True, the mechanisms will be run in order every step otherwise the order will be randomized at every step

Return type:

list[TypeVar(TState, bound= MechanismState)]

Returns:

  • list of states of all mechanisms after completion