SAOSingleAgreementRandomController
- class negmas.sao.SAOSingleAgreementRandomController(*args, p_acceptance=0.1, **kwargs)[source]
Bases:
SAOSingleAgreementControllerA single agreement controller that uses a random negotiation strategy.
- Parameters:
p_acceptance – The probability that an offer is accepted
Attributes Summary
Returns the negotiators whose negotiations running or did not start yet.
Returns the preferences if it is a CrispUtilityFunction else None
Returns the negotiators whose negotiations started and completed
Does the entity has an associated ufun?
Does the entity has an associated ufun?
Does the entity has an associated ufun?
The unique ID of this entity
A convenient name of the entity (intended primarily for printing/logging/debugging).
Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context.
The utility function attached to that object
Returns the preferences if it is a ProbUtilityFunction else None
Reserved outcome is the outcome that will be realized by default for this agent.
Reserved value is what the entity gets if no agreement is reached in the negotiation.
Returns the negotiators whose negotiations started
Gets the current states of all negotiations as a mapping from negotiator ID to mechanism.
Returns the negotiators whose negotiations did not start yet
Returns the preferences if it is a
BaseUtilityFunctionelse NoneReturns the negotiators whose negotiations started and did not complete yet
The unique ID of this entity
Methods Summary
add_negotiator(negotiator[, cntxt])Adds a negotiator to the controller.
after_join(negotiator_id, *args[, ufun, ...])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
best_offer(offers)Return the ID of the negotiator with the best offer
best_outcome(negotiator[, state])The best outcome for the negotiation
negotiatorengages in given thestate.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
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.
Gets a set of proposals to use for initializing the negotiation.
from_checkpoint(file_name[, return_info])Creates an object from a saved checkpoint
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
is_clean()Checks that the agent has no negotiators and that all its intermediate data-structures are reset
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_deathmessage.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
on_leave(negotiator_id, state)A call back called after leaving a negotiation.
on_mechanism_error(negotiator_id, state)on_negotiation_end(negotiator_id, state)A call back called at each negotiation end
on_negotiation_start(negotiator_id, state)A call back called at each negotiation start
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[, dest])reset()Resets the controller and kills any negotiators it may have
respond(negotiator_id, state[, source])response_to_best_offer(negotiator, state, offer)Return a response to the partner from which the best current offer was received
set_id(id)Sets the unique ID of this entity
set_preferences(value[, force, ...])Sets the utility function/Preferences.
spawn([spawn_as, spawn_params])spawn_object(*args, **kwargs)Attributes Documentation
- active_negotiators
Returns the negotiators whose negotiations running or did not start yet.
Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context
- crisp_ufun
Returns the preferences if it is a CrispUtilityFunction else None
- default_negotiator_type
- finished_negotiators
Returns the negotiators whose negotiations started and completed
Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context
- 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
- 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.
Remarks:
Reserved outcomes are defined for
OrdinalPreferences.
See also
- 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
Noneoutcome.
- short_type_name
- started_negotiators
Returns the negotiators whose negotiations started
Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context
- states
Gets the current states of all negotiations as a mapping from negotiator ID to mechanism.
- to_start_negotiators
Returns the negotiators whose negotiations did not start yet
Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context
- type_name
- ufun
Returns the preferences if it is a
BaseUtilityFunctionelse None
- unfinished_negotiators
Returns the negotiators whose negotiations started and did not complete yet
Returns a dictionary mapping negotiator ID to the a tuple containing the negotiator and its context
- uuid
The unique ID of this entity
Methods Documentation
- add_negotiator(negotiator: Negotiator, cntxt: Any = None) None
Adds a negotiator to the controller.
- Parameters:
negotaitor – The negotaitor to add
name – negotiator name
cntxt – The context to be associated with this negotiator.
**kwargs – any key-value pairs to be passed to the negotiator constructor
- after_join(negotiator_id, *args, ufun=None, preferences=None, **kwargs) None
Called by children negotiators after joining a negotiation to inform the controller
- Parameters:
negotiator_id – The negotiator ID
nmi (SAONMI) – The negotiation.
state (SAOState) – 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: str, nmi: SAONMI, state: SAOState, *, preferences: Preferences | None = None, role: str = 'negotiator') bool
Called by children negotiators to get permission to join negotiations
- Parameters:
negotiator_id – The negotiator ID
nmi (SAONMI) – The negotiation.
state (SAOState) – The current state of the negotiation
ufun (UtilityFunction) – The ufun function to use before any discounting.
role (str) – role of the agent.
- Returns:
True if the negotiator is allowed to join the negotiation otherwise False
- best_offer(offers: dict[str, tuple]) str | None[source]
Return the ID of the negotiator with the best offer
- Parameters:
offers – A mapping from negotiator ID to the offer it received
- 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: str, state: SAOState | None = None) tuple | None
The best outcome for the negotiation
negotiatorengages in given thestate.- Parameters:
negotiator – The negotiator for which the best outcome is to be found
state – If given, the state of the negotiation. If None, should return the absolute best outcome
- Returns:
The outcome with maximum utility.
Remarks:
The default implementation, just returns the best outcome for this negotiation without considering the
stateor 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: ControlledNegotiator, method: str, *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
method
*args
**kwargs
Returns:
- checkpoint(path: PathLike, file_name: str | None = None, info: dict[str, Any] | None = None, exist_ok: bool = False, single_checkpoint: bool = True, step_attribs: tuple[str, ...] = ('current_step', '_current_step', '_Entity__current_step', '_step')) Path
Saves a checkpoint of the current object at the given path.
- Parameters:
path – Full path to a directory to store the checkpoint
file_name – Name of the file to dump into. If not given, a unique name is created
info – Information to save with the checkpoint (must be json serializable)
exist_ok – If true, override existing dump
single_checkpoint – If true, keep a single checkpoint for the last step
step_attribs – 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
- Returns:
full path to the file used to save the checkpoint
- classmethod checkpoint_info(file_name: Path | str) dict[str, Any]
Returns the information associated with a dump of the object saved in the given file
- Parameters:
file_name – Name of the object
Returns:
- counter_all(offers: dict[str, tuple | None], states: dict[str, SAOState]) dict[str, SAOResponse]
Counters all responses
- Parameters:
offers – A dictionary mapping partner ID to offer
states – A dictionary mapping partner ID to mechanism state
- 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_offermethod.
- classmethod create(*args, **kwargs)
Creates an object and returns a proxy to it.
- create_negotiator(negotiator_type=None, name: str | None = None, cntxt: Any = None, **kwargs)
Creates a negotiator passing it the context
- Parameters:
negotiator_type – Type of the negotiator to be created
name – negotiator name
cntxt – The context to be associated with this negotiator.
**kwargs – any key-value pairs to be passed to the negotiator constructor
- Returns:
The negotiator to be controlled. None for failure
- first_offer(negotiator_id: str) tuple | None
Finds the first offer for this given negotiator. By default it will be the best offer
- Parameters:
negotiator_id – The ID of the negotiator
- 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() dict[str, tuple | None]
Gets a set of proposals to use for initializing the negotiation.
- classmethod from_checkpoint(file_name: Path | str, return_info: bool = False) NamedObject | tuple[NamedObject, dict[str, Any]]
Creates an object from a saved checkpoint
- Parameters:
file_name
return_info – If True, tbe information saved when the file was dumped are returned
- 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
- is_acceptable(offer: tuple, source: str, state: SAOState) bool[source]
Should decide if the given offer is acceptable
- Parameters:
offer – The offer being tested
source – The ID of the negotiator that received this offer
state – 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.
- is_better(a: tuple | None, b: tuple | None, negotiator: str, state: SAOState) bool[source]
Compares two outcomes of the same negotiation
- Parameters:
a – Outcome
b – Outcome
negotiator – The negotiator for which the comparison is to be made
state – Current state of the negotiation
- Returns:
True if utility(a) > utility(b)
- is_clean() bool
Checks that the agent has no negotiators and that all its intermediate data-structures are reset
- join(negotiator_id: str, nmi: TNMI, state: TState, *, preferences: Preferences | None = None, ufun: BaseUtilityFunction | None = None, role: str = 'negotiator') bool
Called by the mechanism when the agent is about to enter a negotiation. It can prevent the agent from entering
- Parameters:
negotiator_id – The negotiator ID
nmi (AgentMechanismInterface) – The negotiation.
state (TState) – 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.
- 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: str, force: bool = False) None
Kills the negotiator sending it an
before_deathmessage.- Parameters:
negotiator_id – The ID of the negotiator to kill.
force – 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.
- make_negotiator(negotiator_type: str | TControlledNegotiator | None = None, name: str | None = None, **kwargs) TControlledNegotiator
Creates a negotiator but does not add it to the controller. Call
add_negotiatorto add it.- Parameters:
negotiator_type – Type of the negotiator to be created. If None, A
ControlledNegotiatornegotiator will be controlled (which is fully controlled by the controller).name – negotiator name
**kwargs – any key-value pairs to be passed to the negotiator constructor
- Returns:
The negotiator to be controlled. None for failure
- make_offer(negotiator: str, state: SAOState, best_offer: tuple | None, best_from: str | None) tuple | None
Generate an offer for the given partner
- Parameters:
negotiator – The ID of the negotiator for who an offer is to be made.
state – The mechanism state of this partner
best_offer – The best offer received in this round. None means that no known best offers.
best_from – The ID of the negotiator that received the best offer
- Returns:
The outcome to be offered to
negotiator(None means no-offer)
Remarks:
Default behavior is to offer everyone
best_offerif available otherwise, it returns no offers (None). Thebest_fromnegotiator will be sending the result ofbest_outcome.
- on_leave(negotiator_id: str, state: TState) None
A call back called after leaving a negotiation.
- Parameters:
negotiator_id – The negotiator ID
state –
TStategiving current state of the negotiation.
- on_negotiation_end(negotiator_id: str, state: SAOState) None
A call back called at each negotiation end
- Parameters:
negotiator_id – The negotiator ID
state –
TStateor one of its descendants giving the state at which the negotiation ended.
- on_negotiation_start(negotiator_id: str, state: TState) None
A call back called at each negotiation start
- Parameters:
negotiator_id – The negotiator ID
state –
TStategiving current state of the negotiation.
- on_notification(negotiator_id: str, notification: Notification, notifier: str)
- on_preferences_changed(changes: list[PreferencesChange])
Called to inform the entity that its ufun has changed.
- Parameters:
changes – 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.Generalwhich indicates that you cannot trust anything you knew about the ufun anymore
- on_round_end(negotiator_id: str, state: TState) None
A call back called at each negotiation round end
- Parameters:
negotiator_id – The negotiator ID
state –
TStategiving current state of the negotiation.
- on_round_start(negotiator_id: str, state: TState) None
A call back called at each negotiation round start
- Parameters:
negotiator_id – The negotiator ID
state –
TStategiving current state of the negotiation.
- partner_agent_ids(negotiator_id: str) list[str] | None
Finds the agent ID negotiating with one of our negotiators.
- Parameters:
negotiator_id – Our negotiator ID
- partner_agent_names(negotiator_id: str) list[str] | None
Finds the negotiator names negotiating with one of our negotiators.
- Parameters:
negotiator_id – Our negotiator ID
- partner_negotiator_ids(negotiator_id: str) list[str] | None
Finds the negotiator ID negotiating with one of our negotiators.
- Parameters:
negotiator_id – Our negotiator ID
- partner_negotiator_names(negotiator_id: str) list[str] | None
Finds the negotiator names negotiating with one of our negotiators.
- Parameters:
negotiator_id – Our negotiator ID
- propose(negotiator_id: str, state: SAOState, dest: str | None = None) tuple | ExtendedOutcome | None
- reset()
Resets the controller and kills any negotiators it may have
- response_to_best_offer(negotiator: str, state: SAOState, offer: tuple) tuple | None
Return a response to the partner from which the best current offer was received
- Parameters:
negotiator – The negotiator from which the best offer was received
state – The state of the corresponding negotiation
offer – The best offer received at this round.
- Returns:
The offer to be sent back to
negotiator
- set_preferences(value: Preferences | None, force=False, ignore_exceptions: bool = False) Preferences | None
Sets the utility function/Preferences.
- Parameters:
value – The value to set to
force – If true,
on_preferecnes_changed()will always be called even ifvalue==self.preferences
- classmethod spawn_object(*args, **kwargs)