OneShotSingleAgreementAgent

class scml.oneshot.OneShotSingleAgreementAgent(*args, strict=False, **kwargs)[source]

Bases: SAOSingleAgreementController, OneShotSyncAgent

A synchronized agent that tries to get no more than one agreement.

This controller manages a set of negotiations from which only a single one – at most – is likely to result in an agreement. To guarantee a single agreement, pass strict=True

The general algorithm for this controller is something like this:

  • Receive offers from all partners.

  • Find the best offer among them by calling the abstract best_offer method.

  • Check if this best offer is acceptable using the abstract is_acceptable method.

    • If the best offer is acceptable, accept it and end all other negotiations.

    • If the best offer is still not acceptable, then all offers are rejected and with the partner who sent it receiving the result of best_outcome while the rest of the partners receive the result of make_outcome.

  • The default behavior of best_outcome is to return the outcome with maximum utility.

  • The default behavior of make_outcome is to return the best offer received in this round if it is valid for the respective negotiation and the result of best_outcome otherwise.

Parameters:

strict (bool) – If True the controller is guaranteed to get a single agreement but it will have to send no-response repeatedly so there is a higher chance of never getting an agreement when two of those controllers negotiate with each other

Attributes Summary

active_negotiators

Returns the negotiators whose negotiations are running.

awi

Returns a OneShotAWI object for accessing the simulation.

crisp_ufun

Returns the preferences if it is a CrispUtilityFunction else None

has_cardinal_preferences

Does the entity has an associated ufun?

has_preferences

Does the entity has an associated ufun?

has_ufun

Does the entity has an associated ufun?

id

The unique ID of this entity

internal_state

Returns the internal state of the agent for debugging purposes.

name

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

negotiators

Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context.

preferences

The utility function attached to that object

prob_ufun

Returns the preferences if it is a ProbUtilityFunction else None

reserved_outcome

Reserved outcome is the outcome that will be realized by default for this agent.

reserved_value

Reserved value is what the entity gets if no agreement is reached in the negotiation.

running_negotiations

The negotiations currently requested by the agent.

short_type_name

Returns a short name of the type of this entity

states

Gets the current states of all negotiations as a mapping from negotiator ID to mechanism.

type_name

Returns the name of the type of this entity

type_postfix

ufun

Returns the preferences if it is a BaseUtilityFunction else None

unsigned_contracts

All contracts that are not yet signed.

uuid

The unique ID of this entity

Methods Summary

add_negotiator(negotiator[, cntxt])

Adds a negotiator to the controller.

after_join(negotiator_id, nmi, state, *[, ...])

Called by children negotiators after joining a negotiation to inform the controller

before_join(negotiator_id, nmi, state, *[, ...])

Called by children negotiators to get permission to join negotiations

before_step()

Called at the beginning of every step.

best_offer(offers)

Return the ID of the negotiator with the best offer

best_outcome(negotiator[, state])

The best outcome for the negotiation negotiator engages in given the state .

call(negotiator, method, *args, **kwargs)

Calls the given method on the given negotiator safely without causing recursion.

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

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

checkpoint_info(file_name)

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

connect_to_2021_adapter(owner)

Connects the agent to its adapter (used internally)

connect_to_oneshot_adapter(owner)

Connects the agent to its adapter (used internally)

counter_all(offers, states)

Counters all responses

create(*args, **kwargs)

Creates an object and returns a proxy to it.

create_negotiator([negotiator_type, name, cntxt])

Creates a negotiator passing it the context

first_offer(negotiator_id)

Finds the first offer for this given negotiator.

first_proposals()

Gets a set of proposals to use for initializing the negotiation.

from_checkpoint(file_name[, return_info])

Creates an object from a saved checkpoint

get_ami(partner_id)

Returns the SAONMI (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner.

get_negotiator(partner_id)

Returns the negotiator corresponding to the given partner ID.

get_nmi(partner_id)

Returns the SAONMI (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner.

init()

Called once after the AWI is set.

init_()

Called to initialize the agent after the world is initialized.

is_acceptable(offer, source, state)

Should decide if the given offer is acceptable

is_better(a, b, negotiator, state)

Compares two outcomes of the same negotiation

join(negotiator_id, nmi, state, *[, ...])

Called by the mechanism when the agent is about to enter a negotiation.

kill_negotiator(negotiator_id[, force])

Kills the negotiator sending it an before_death message.

make_negotiator([negotiator_type, name])

Creates a negotiator but does not add it to the controller.

make_offer(negotiator, state, best_offer, ...)

Generate an offer for the given partner

make_ufun([add_exogenous])

Creates a utility function for the agent.

on_contract_breached(contract, breaches, ...)

rtype:

None

on_contract_executed(contract)

rtype:

None

on_leave(negotiator_id, state)

A call back called after leaving a negotiation.

on_mechanism_error(negotiator_id, state)

A call back called whenever an error happens in the mechanism.

on_negotiation_end(negotiator_id, state)

A call back called at each negotiation end

on_negotiation_failure(partners, annotation, ...)

Called whenever a negotiation ends without agreement.

on_negotiation_start(negotiator_id, state)

A call back called at each negotiation start

on_negotiation_success(contract, mechanism)

Called whenever a negotiation ends with agreement.

on_notification(negotiator_id, notification, ...)

on_preferences_changed(changes)

Called to inform the entity that its ufun has changed.

on_round_end(negotiator_id, state)

A call back called at each negotiation round end

on_round_start(negotiator_id, state)

A call back called at each negotiation round start

partner_agent_ids(negotiator_id)

Finds the agent ID negotiating with one of our negotiators.

partner_agent_names(negotiator_id)

Finds the negotiator names negotiating with one of our negotiators.

partner_negotiator_ids(negotiator_id)

Finds the negotiator ID negotiating with one of our negotiators.

partner_negotiator_names(negotiator_id)

Finds the negotiator names negotiating with one of our negotiators.

propose(negotiator_id, state)

Proposes an offer to one of the partners.

reset()

Resets the controller and kills any negotiators it may have

respond(negotiator_id, state[, source])

Responds to an offer from one of the partners.

response_to_best_offer(negotiator, state, offer)

Return a response to the partner from which the best current offer was received

set_preferences(value[, force])

Sets tha utility function/Preferences.

sign_all_contracts(contracts)

Signs all contracts (used internally)

spawn([spawn_as, spawn_params])

spawn_object(*args, **kwargs)

step()

Called at the end of every step.

step_()

Called at every time-step.

Attributes Documentation

active_negotiators

Returns the negotiators whose negotiations are running.

Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context

Return type:

dict[str, NegotiatorInfo]

awi

Returns a OneShotAWI object for accessing the simulation.

Return type:

OneShotAWI

crisp_ufun

Returns the preferences if it is a CrispUtilityFunction else None

Return type:

Optional[UtilityFunction]

has_cardinal_preferences

Does the entity has an associated ufun?

Return type:

bool

has_preferences

Does the entity has an associated ufun?

Return type:

bool

has_ufun

Does the entity has an associated ufun?

Return type:

bool

id

The unique ID of this entity

internal_state

Returns the internal state of the agent for debugging purposes.

Remarks:
  • In your agent, you can add any key-value pair to this dict and then use agent_log_* methods to log this information at any point.

Return type:

dict[str, Any]

name

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

negotiators

Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context.

Return type:

dict[str, NegotiatorInfo]

preferences

The utility function attached to that object

Return type:

Optional[Preferences]

prob_ufun

Returns the preferences if it is a ProbUtilityFunction else None

Return type:

Optional[ProbUtilityFunction]

reserved_outcome

Reserved outcome is the outcome that will be realized by default for this agent.

Remarks:

  • Reserved outcomes are defined for OrdinalPreferences.

See also

reserved_value

Return type:

Optional[tuple]

reserved_value

Reserved value is what the entity gets if no agreement is reached in the negotiation.

The reserved value can either be explicity defined for the ufun or it can be the output of the ufun for None outcome.

Return type:

float

running_negotiations

The negotiations currently requested by the agent.

Return type:

list[RunningNegotiationInfo]

Returns:

A list of negotiation information objects (RunningNegotiationInfo)

short_type_name
Return type:

str

states

Gets the current states of all negotiations as a mapping from negotiator ID to mechanism.

Return type:

dict[str, MechanismState]

type_name
Return type:

str

type_postfix
ufun

Returns the preferences if it is a BaseUtilityFunction else None

Return type:

Optional[BaseUtilityFunction]

unsigned_contracts

All contracts that are not yet signed.

Return type:

list[Contract]

uuid

The unique ID of this entity

Methods Documentation

add_negotiator(negotiator, cntxt=None)

Adds a negotiator to the controller.

Parameters:
  • negotaitor – The negotaitor to add

  • name – negotiator name

  • cntxt (Any) – The context to be associated with this negotiator.

  • **kwargs – any key-value pairs to be passed to the negotiator constructor

Return type:

None

after_join(negotiator_id, nmi, state, *, preferences=None, role='negotiator')

Called by children negotiators after joining a negotiation to inform the controller

Parameters:
  • negotiator_id – The negotiator ID

  • nmi (NegotiatorMechanismInterface) – The negotiation.

  • state (MechanismState) – The current state of the negotiation

  • ufun (UtilityFunction) – The ufun function to use before any discounting.

  • role (str) – role of the agent.

before_join(negotiator_id, nmi, state, *, preferences=None, role='negotiator')

Called by children negotiators to get permission to join negotiations

Parameters:
  • negotiator_id (str) – The negotiator ID

  • nmi (NegotiatorMechanismInterface) – The negotiation.

  • state (MechanismState) – The current state of the negotiation

  • ufun (UtilityFunction) – The ufun function to use before any discounting.

  • role (str) – role of the agent.

Return type:

bool

Returns:

True if the negotiator is allowed to join the negotiation otherwise False

before_step()

Called at the beginning of every step.

Remarks:
  • Use this for any proactive code that needs to be done every simulation step.

abstract best_offer(offers)[source]

Return the ID of the negotiator with the best offer

Parameters:

offers (dict[str, tuple]) – A mapping from negotiator ID to the offer it received

Return type:

Optional[str]

Returns:

The ID of the negotiator with best offer. Ties should be broken. Return None only if there is no way to calculate the best offer.

best_outcome(negotiator, state=None)

The best outcome for the negotiation negotiator engages in given the state .

Parameters:
  • negotiator (str) – The negotiator for which the best outcome is to be found

  • state (Optional[SAOState]) – If given, the state of the negotiation. If None, should return the absolute best outcome

Return type:

Optional[tuple]

Returns:

The outcome with maximum utility.

Remarks:

  • The default implementation, just returns the best outcome for this negotiation without considering the state or returns None if it is not possible to find this best outcome.

  • If the negotiator defines a ufun, it is used otherwise the ufun defined for the controller if used (if any)

call(negotiator, method, *args, **kwargs)

Calls the given method on the given negotiator safely without causing recursion. The controller MUST use this function to access any callable on the negotiator.

Parameters:
  • negotiator (ControlledNegotiator) –

  • method (str) –

  • *args

  • **kwargs

Returns:

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 (Optional[str]) – Name of the file to dump into. If not given, a unique name is created

  • info (Optional[dict[str, Any]]) – 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

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

Returns:

Return type:

dict[str, Any]

connect_to_2021_adapter(owner)

Connects the agent to its adapter (used internally)

connect_to_oneshot_adapter(owner)

Connects the agent to its adapter (used internally)

counter_all(offers, states)

Counters all responses

Parameters:
  • offers (dict[str, tuple]) – A dictionary mapping partner ID to offer

  • states (dict[str, SAOState]) – A dictionary mapping partner ID to mechanism state

Return type:

dict[str, SAOResponse]

Returns:

A dictionary mapping partner ID to a response

Remarks:

The agent will counter all offers by either ending all negotiations except one which is accepted or by rejecting all offers and countering them using the make_offer method.

classmethod create(*args, **kwargs)

Creates an object and returns a proxy to it.

create_negotiator(negotiator_type=None, name=None, cntxt=None, **kwargs)

Creates a negotiator passing it the context

Parameters:
  • negotiator_type (Union[str, TypeVar(ControlledNegotiatorType, bound= SAONegotiator), None]) – Type of the negotiator to be created

  • name (Optional[str]) – negotiator name

  • cntxt (Any) – The context to be associated with this negotiator.

  • **kwargs – any key-value pairs to be passed to the negotiator constructor

Return type:

TypeVar(ControlledNegotiatorType, bound= SAONegotiator)

Returns:

The negotiator to be controlled. None for failure

first_offer(negotiator_id)

Finds the first offer for this given negotiator. By default it will be the best offer

Parameters:

negotiator_id (str) – The ID of the negotiator

Return type:

Optional[tuple]

Returns:

The first offer to use.

Remarks:

Default behavior is to use the ufun defined for the controller if any then try the ufun defined for the negotiator. If neither exists, the first offer will be None.

first_proposals()

Gets a set of proposals to use for initializing the negotiation.

Return type:

dict[str, Optional[tuple]]

Returns:

A dictionary mapping each negotiator (in self.negotiators dict) to an outcome to be used as the first proposal if the agent is to start a negotiation.

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

get_ami(partner_id)

Returns the SAONMI (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner.

Return type:

SAONMI

get_negotiator(partner_id)

Returns the negotiator corresponding to the given partner ID.

Remarks:
  • Note that the negotiator ID and the partner ID are always the same.

Return type:

SAONegotiator

get_nmi(partner_id)

Returns the SAONMI (Agent Mechanism Interface) connecting the agent to the negotiation mechanism for the given partner.

Return type:

SAONMI

init()

Called once after the AWI is set.

Remarks:
  • Use this for any proactive initialization code.

init_()

Called to initialize the agent after the world is initialized. the AWI is accessible at this point.

abstract is_acceptable(offer, source, state)[source]

Should decide if the given offer is acceptable

Parameters:
  • offer (tuple) – The offer being tested

  • source (str) – The ID of the negotiator that received this offer

  • state (SAOState) – The state of the negotiation handled by that negotiator

Remarks:
  • If True is returned, this offer will be accepted and all other negotiations will be ended.

Return type:

bool

abstract is_better(a, b, negotiator, state)[source]

Compares two outcomes of the same negotiation

Parameters:
  • a (tuple) – “Outcome”

  • b (tuple) – “Outcome”

  • negotiator (str) – The negotiator for which the comparison is to be made

  • state (SAOState) – Current state of the negotiation

Returns:

True if utility(a) > utility(b)

join(negotiator_id, nmi, state, *, preferences=None, ufun=None, role='negotiator')

Called by the mechanism when the agent is about to enter a negotiation. It can prevent the agent from entering

Parameters:
  • negotiator_id (str) – The negotiator ID

  • nmi (AgentMechanismInterface) – The negotiation.

  • state (MechanismState) – The current state of the negotiation

  • preferences (Preferences) – The preferences.

  • ufun (BaseUtilityFunction) – The ufun function to use before any discounting (overrides preferences)

  • role (str) – role of the agent.

Return type:

bool

Returns:

bool indicating whether or not the agent accepts to enter.If False is returned it will not enter the negotiation.

kill_negotiator(negotiator_id, force=False)

Kills the negotiator sending it an before_death message.

Parameters:
  • negotiator_id (str) – The ID of the negotiator to kill.

  • force (bool) – Whether to kill the negotiator in case it refused to die.

Remarks:

  • Killing a negotiator amounts to nothing more than removing it form the list of negotiators maintained by the controller.

Return type:

None

make_negotiator(negotiator_type=None, name=None, **kwargs)

Creates a negotiator but does not add it to the controller. Call add_negotiator to add it.

Parameters:
  • negotiator_type (Union[str, TypeVar(ControlledNegotiatorType, bound= Negotiator), None]) – Type of the negotiator to be created. If None, A ControlledNegotiator negotiator will be controlled (which is fully controlled by the controller).

  • name (Optional[str]) – negotiator name

  • **kwargs – any key-value pairs to be passed to the negotiator constructor

Return type:

TypeVar(ControlledNegotiatorType, bound= Negotiator)

Returns:

The negotiator to be controlled. None for failure

make_offer(negotiator, state, best_offer, best_from)

Generate an offer for the given partner

Parameters:
  • negotiator (str) – The ID of the negotiator for who an offer is to be made.

  • state (SAOState) – The mechanism state of this partner

  • best_offer (Optional[tuple]) – The best offer received in this round. None means that no known best offers.

  • best_from (Optional[str]) – The ID of the negotiator that received the best offer

Return type:

Optional[tuple]

Returns:

The outcome to be offered to negotiator (None means no-offer)

Remarks:

Default behavior is to offer everyone best_offer if available otherwise, it returns no offers (None). The best_from negotiator will be sending the result of best_outcome.

make_ufun(add_exogenous=False)

Creates a utility function for the agent.

Parameters:

add_exogenous – If True then the exogenous contracts of the agent will be automatically added whenever the ufun is evaluated for any set of contracts, offers or otherwise.

Remarks:
  • You can always as assume that self.ufun returns the ufun for your. You will not need to directly use this method in most cases.

on_contract_breached(contract, breaches, resolution)
Return type:

None

on_contract_executed(contract)
Return type:

None

on_leave(negotiator_id, state)

A call back called after leaving a negotiation.

Parameters:
  • negotiator_id (str) – The negotiator ID

  • state (MechanismState) – MechanismState giving current state of the negotiation.

Return type:

None

on_mechanism_error(negotiator_id, state)

A call back called whenever an error happens in the mechanism. The error and its explanation are accessible in state

Parameters:
  • negotiator_id (str) – The negotiator ID

  • state (MechanismState) – MechanismState giving current state of the negotiation.

Return type:

None

on_negotiation_end(negotiator_id, state)

A call back called at each negotiation end

Parameters:
  • negotiator_id (str) – The negotiator ID

  • state (MechanismState) – MechanismState or one of its descendants giving the state at which the negotiation ended.

Return type:

None

on_negotiation_failure(partners, annotation, mechanism, state)

Called whenever a negotiation ends without agreement.

Parameters:
  • partners (list[str]) – List of the partner IDs consisting from self and the opponent.

  • annotation (dict[str, Any]) – The annotation of the negotiation including the seller ID, buyer ID, and the product.

  • mechanism (NegotiatorMechanismInterface) – The NegotiatorMechanismInterface instance containing all information about the negotiation.

  • state (MechanismState) – The final state of the negotiation of the type SAOState including the agreement if any.

Return type:

None

on_negotiation_start(negotiator_id, state)

A call back called at each negotiation start

Parameters:
  • negotiator_id (str) – The negotiator ID

  • state (MechanismState) – MechanismState giving current state of the negotiation.

Return type:

None

on_negotiation_success(contract, mechanism)

Called whenever a negotiation ends with agreement.

Parameters:
  • contract (Contract) – The Contract agreed upon.

  • mechanism (NegotiatorMechanismInterface) – The NegotiatorMechanismInterface instance containing all information about the negotiation that led to the Contract if any.

Return type:

None

on_notification(negotiator_id, notification, notifier)
on_preferences_changed(changes)

Called to inform the entity that its ufun has changed.

Parameters:

changes (list[PreferencesChange]) – An ordered list of changes that happened.

Remarks:

  • You MUST call the super() version of this function either before or after your code when you are overriding it.

  • The most general form of change is PreferencesChange.General which indicates that you cannot trust anything you knew about the ufun anymore

on_round_end(negotiator_id, state)

A call back called at each negotiation round end

Parameters:
  • negotiator_id (str) – The negotiator ID

  • state (MechanismState) – MechanismState giving current state of the negotiation.

Return type:

None

on_round_start(negotiator_id, state)

A call back called at each negotiation round start

Parameters:
  • negotiator_id (str) – The negotiator ID

  • state (MechanismState) – MechanismState giving current state of the negotiation.

Return type:

None

partner_agent_ids(negotiator_id)

Finds the agent ID negotiating with one of our negotiators.

Parameters:

negotiator_id (str) – Our negotiator ID

Return type:

Optional[list[str]]

partner_agent_names(negotiator_id)

Finds the negotiator names negotiating with one of our negotiators.

Parameters:

negotiator_id (str) – Our negotiator ID

Return type:

Optional[list[str]]

partner_negotiator_ids(negotiator_id)

Finds the negotiator ID negotiating with one of our negotiators.

Parameters:

negotiator_id (str) – Our negotiator ID

Return type:

Optional[list[str]]

partner_negotiator_names(negotiator_id)

Finds the negotiator names negotiating with one of our negotiators.

Parameters:

negotiator_id (str) – Our negotiator ID

Return type:

Optional[list[str]]

propose(negotiator_id, state)

Proposes an offer to one of the partners.

Parameters:
  • negotiator_id (str) – ID of the negotiator (and partner)

  • state (MechanismState) – Mechanism state including current step

Return type:

Optional[tuple]

Returns:

an outcome to offer.

reset()

Resets the controller and kills any negotiators it may have

respond(negotiator_id, state, source=None)

Responds to an offer from one of the partners.

Parameters:
  • negotiator_id (str) – ID of the negotiator (and partner)

  • state (SAOState) – Mechanism state including current step

Return type:

ResponseType

Returns:

A response type which can either be reject, accept, or end negotiation.

Remarks:

default behavior is to accept only if the current offer is the same or has a higher utility compared with what the agent would have proposed in the given state and reject otherwise

response_to_best_offer(negotiator, state, offer)

Return a response to the partner from which the best current offer was received

Parameters:
  • negotiator (str) – The negotiator from which the best offer was received

  • state (SAOState) – The state of the corresponding negotiation

  • offer (tuple) – The best offer received at this round.

Return type:

Optional[tuple]

Returns:

The offer to be sent back to negotiator

set_preferences(value, force=False)

Sets tha utility function/Preferences.

Parameters:
  • value (Optional[Preferences]) – The value to set to

  • force – If true, on_preferecnes_changed() will always be called even if value == self.preferences

Return type:

Optional[Preferences]

sign_all_contracts(contracts)

Signs all contracts (used internally)

Return type:

list[Optional[str]]

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

Called at the end of every step.

Remarks:
  • Use this for any proactive code that needs to be done every simulation step.

step_()

Called at every time-step. This function is called directly by the world.