SAORandomController
- class negmas.sao.SAORandomController(*args, p_acceptance=0.1, **kwargs)[source]
Bases:
SAOController
A controller that returns random offers.
- Parameters:
p_acceptance (
float
) – The probability of accepting an offer.
Attributes Summary
Returns the negotiators whose negotiations are running.
Returns the preferences if it is a CrispUtilityFunction else None
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.
Gets the current states of all negotiations as a mapping from negotiator ID to mechanism.
Returns the preferences if it is a
BaseUtilityFunction
else NoneThe 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
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
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
from_checkpoint
(file_name[, return_info])Creates an object from a saved checkpoint
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_death
message.make_negotiator
([negotiator_type, name])Creates a negotiator but does not add it to the controller.
on_leave
(negotiator_id, state)A call back called after leaving a negotiation.
on_mechanism_error
(negotiator_id, state)- rtype:
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)reset
()Resets the controller and kills any negotiators it may have
respond
(negotiator_id, state[, source])- rtype:
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 are running.
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
- 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
None
outcome.
- short_type_name
- states
Gets the current states of all negotiations as a mapping from negotiator ID to mechanism.
- type_name
- ufun
Returns the preferences if it is a
BaseUtilityFunction
else None
- uuid
The unique ID of this entity
Methods Documentation
- add_negotiator(negotiator, cntxt=None)
Adds a negotiator to the controller.
- after_join(negotiator_id, *args, ufun=None, preferences=None, **kwargs)
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.
- Return type:
- 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 IDnmi (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.
- Return type:
- Returns:
True if the negotiator is allowed to join the negotiation otherwise False
- 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 checkpointfile_name (
str
|None
) – Name of the file to dump into. If not given, a unique name is createdinfo (
dict
[str
,Any
] |None
) – Information to save with the checkpoint (must be json serializable)exist_ok (
bool
) – If true, override existing dumpsingle_checkpoint (
bool
) – If true, keep a single checkpoint for the last stepstep_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:
- 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
Returns:
- 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:
- Returns:
The negotiator to be controlled. None for failure
- classmethod from_checkpoint(file_name, return_info=False)
Creates an object from a saved checkpoint
- Parameters:
- Return type:
- 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_clean()
Checks that the agent has no negotiators and that all its intermediate data-structures are reset
- Return type:
- 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 IDnmi (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.
- Return type:
- 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:
- Return type:
Remarks:
Killing a negotiator amounts to nothing more than removing it form the list of negotiators maintained by the controller.
- 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
(TControlledNegotiator
, bound=Negotiator
),None
]) – Type of the negotiator to be created. If None, AControlledNegotiator
negotiator will be controlled (which is fully controlled by the controller).**kwargs – any key-value pairs to be passed to the negotiator constructor
- Return type:
TypeVar
(TControlledNegotiator
, bound=Negotiator
)- Returns:
The negotiator to be controlled. None for failure
- on_leave(negotiator_id, state)
A call back called after leaving a negotiation.
- Parameters:
negotiator_id (
str
) – The negotiator IDstate (
TypeVar
(TState
, bound=MechanismState
)) –TState
giving current state of the negotiation.
- Return type:
- on_negotiation_end(negotiator_id, state)
A call back called at each negotiation end
- Parameters:
negotiator_id (
str
) – The negotiator IDstate (
TypeVar
(TState
, bound=MechanismState
)) –TState
or one of its descendants giving the state at which the negotiation ended.
- Return type:
- on_negotiation_start(negotiator_id, state)
A call back called at each negotiation start
- Parameters:
negotiator_id (
str
) – The negotiator IDstate (
TypeVar
(TState
, bound=MechanismState
)) –TState
giving current state of the negotiation.
- Return type:
- 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 IDstate (
TypeVar
(TState
, bound=MechanismState
)) –TState
giving current state of the negotiation.
- Return type:
- on_round_start(negotiator_id, state)
A call back called at each negotiation round start
- Parameters:
negotiator_id (
str
) – The negotiator IDstate (
TypeVar
(TState
, bound=MechanismState
)) –TState
giving current state of the negotiation.
- Return type:
- 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.
- reset()
Resets the controller and kills any negotiators it may have
- set_id(id)
Sets the unique ID of this entity
- set_preferences(value, force=False, ignore_exceptions=False)
Sets the utility function/Preferences.
- Parameters:
value (
Preferences
|None
) – The value to set toforce – If true,
on_preferecnes_changed()
will always be called even ifvalue
==self.preferences
- Return type:
- classmethod spawn(spawn_as='object', spawn_params=None, *args, **kwargs)
- classmethod spawn_object(*args, **kwargs)