ControlledSAONegotiator
- class negmas.sao.ControlledSAONegotiator(preferences: Preferences | None = None, ufun: BaseUtilityFunction | None = None, name: str | None = None, parent: Controller | None = None, owner: Agent | None = None, id: str | None = None, type_name: str | None = None, can_propose: bool = True, **kwargs)[source]
Bases:
SAOPRNegotiator,ControlledNegotiatorA negotiator that acts as an end point to a parent Controller.
This negotiator simply calls its controler for everything.
Attributes Summary
Returns the private information (annotation) not shared with other negotiators
Agent capabilities
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 the owner agent of the negotiator
Returns the parent controller
The utility function attached to that object
Returns the private information (annotation) not shared with other negotiators
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 preferences if it is a
BaseUtilityFunctionelse NoneThe unique ID of this entity
Methods Summary
__call__(state[, dest])Called by
Negotiator.__call__(which is called by the mechanism) to counter the offer.add_capabilities(capabilities)Adds named capabilities to the negotiator.
add_handler(notification_type, callback)Adds a notification handler to the list of handlers of the given type.
before_death(cntxt)Called whenever the parent is about to kill this negotiator.
cancel([reason])A method that may be called by a mechanism to make the negotiator cancel whatever it is currently processing.
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.
from_checkpoint(file_name[, return_info])Creates an object from a saved checkpoint
handlers(notification_type)Gets the list of handlers registered for some notification type.
is_acceptable_as_agreement(outcome)Whether the given outcome is acceptable as a final agreement of a negotiation.
isin(negotiation_id)Is that agent participating in the given negotiation? Tests if the agent is participating in the given negotiation.
join(nmi, state, *[, preferences, ufun, role])Joins a negotiation.
on_leave(state)A call back called after leaving a negotiation.
on_mechanism_error(state)A call back called whenever an error happens in the mechanism.
on_negotiation_end(state)Calls parent controller
on_negotiation_start(state)Calls parent controller
on_notification(notification, notifier)Called whenever a notification is received
on_notification_(notification, notifier)Called when a notification is received.
on_partner_ended(partner)Called when a partner ends the negotiation.
on_partner_proposal(state, partner_id, offer)A callback called by the mechanism when a partner proposes something
on_partner_response(state, partner_id, ...)A callback called by the mechanism when a partner responds to some offer
on_preferences_changed(changes)Called to inform the entity that its ufun has changed.
on_round_end(state)A call back called at each negotiation round end
on_round_start(state)A call back called at each negotiation round start
propose(state[, dest])Calls parent controller
propose_(state[, dest])The method directly called by the mechanism (through
counter) to ask for a proposalremove_capability(name)Removes named capability from the negotiator
remove_handler(notification_type, callback)Removes a notification handler from the list of handlers of the given type.
respond(state[, source])Calls parent controller
respond_(state[, source])The method to be called directly by the mechanism (through
counter) to respond to an offer.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
- ami
- annotation
Returns the private information (annotation) not shared with other negotiators
- capabilities
Agent capabilities
- 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).
- nmi
- opponent_ufun
- owner
Returns the owner agent of the negotiator
- parent
Returns the parent controller
- preferences
The utility function attached to that object
- private_info
Returns the private information (annotation) not shared with other negotiators
- 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
- type_name
- ufun
Returns the preferences if it is a
BaseUtilityFunctionelse None
- uuid
The unique ID of this entity
Methods Documentation
- __call__(state: SAOState, dest: str | None = None) SAOResponse
Called by
Negotiator.__call__(which is called by the mechanism) to counter the offer. It just callsrespond_andpropose_as needed.- Parameters:
state –
SAOStategiving current state of the negotiation.dest – The ID of the destination of the response. May be empty under
SAOMechanism
- Returns:
The response to the given offer with a counter offer if the response is REJECT
- Return type:
Tuple[ResponseType, Outcome]
- Remarks:
The current offer is accessible through state.current_offer
- add_capabilities(capabilities: dict) None
Adds named capabilities to the negotiator.
- Parameters:
capabilities – The capabilities to be added as a dict
- Returns:
None
- Remarks:
It is the responsibility of the caller to be really capable of added capabilities.
- add_handler(notification_type: str, callback: Callable[[Notification, str], bool])
Adds a notification handler to the list of handlers of the given type. These handlers will be called in the order in which they are received
- Parameters:
notification_type – Notification type as specificed in the type member of the Notification class
callback – The callback which must receive a Notification object and a string and returns a boolean. If True is returned from one callback, the remaining callbacks will not be called
Returns:
- before_death(cntxt: dict[str, Any]) bool
Called whenever the parent is about to kill this negotiator.
It should return False if the negotiator does not want to be killed but the controller can still force-kill it
- cancel(reason=None) None
A method that may be called by a mechanism to make the negotiator cancel whatever it is currently processing.
Negotiators can just ignore this message (default behavior) but if there is a way to actually cancel work, it should be implemented here to improve the responsiveness of the negotiator.
- 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:
- classmethod create(*args, **kwargs)
Creates an object and returns a proxy to it.
- 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
- handlers(notification_type: str) list[Callable[[Notification, str], bool]]
Gets the list of handlers registered for some notification type. This list can be modified in place to change the order of handlers for example. It is NOT a copy.
- is_acceptable_as_agreement(outcome: Outcome) bool
Whether the given outcome is acceptable as a final agreement of a negotiation.
The default behavior is to reject only if a reserved value is defined for the agent and is known to be higher than the utility of the outcome.
- isin(negotiation_id: str | None) bool
Is that agent participating in the given negotiation? Tests if the agent is participating in the given negotiation.
- join(nmi, state, *, preferences=None, ufun=None, role: str = 'negotiator') bool[source]
Joins a negotiation.
Remarks:
This method first gets permission from the parent controller by calling
before_joinon it and confirming the result isTrue, it then joins the negotiation and callsafter_joinof the controller to inform it that joining is completed if joining was successful.
- on_leave(state: TState) None
A call back called after leaving a negotiation.
- Parameters:
state –
MechanismStategiving current state of the negotiation.
- on_mechanism_error(state: TState) None
A call back called whenever an error happens in the mechanism. The error and its explanation are accessible in
state- Parameters:
state –
MechanismStategiving current state of the negotiation.
- Remarks:
The default behavior is to do nothing.
Override this to hook some action
- on_notification(notification: Notification, notifier: str)
Called whenever a notification is received
- Parameters:
notification – The notification
notifier – The notifier entity
- Remarks:
The default implementation only responds to end_negotiation by ending the negotiation
- on_notification_(notification: Notification, notifier: str) bool
Called when a notification is received. Do NOT directly override this method
- Parameters:
notification
notifier
Returns:
- on_partner_ended(partner: str)
Called when a partner ends the negotiation.
Note that the negotiator owning this component may never receive this offer. This is only received if the mechanism is sending notifications on every offer.
- on_partner_proposal(state: GBState, partner_id: str, offer: tuple) None
A callback called by the mechanism when a partner proposes something
- Parameters:
state –
GBStategiving the state of the negotiation when the offer was porposed.partner_id – The ID of the agent who proposed
offer – The proposal.
- Remarks:
Will only be called if
enable_callbacksis set for the mechanism
- on_partner_response(state: GBState, partner_id: str, outcome: tuple, response: ResponseType) None
A callback called by the mechanism when a partner responds to some offer
- Parameters:
state –
GBStategiving the state of the negotiation when the partner responded.partner_id – The ID of the agent who responded
outcome – The proposal being responded to.
response – The response
- Remarks:
Will only be called if
enable_callbacksis set for the mechanism
- 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(state: TState) None
A call back called at each negotiation round end
- Parameters:
state –
MechanismStategiving current state of the negotiation.
- Remarks:
The default behavior is to do nothing.
Override this to hook some action
- on_round_start(state: TState) None
A call back called at each negotiation round start
- Parameters:
state –
MechanismStategiving current state of the negotiation.
- Remarks:
The default behavior is to do nothing.
Override this to hook some action.
- propose_(state: SAOState, dest: str | None = None) tuple | ExtendedOutcome | None
The method directly called by the mechanism (through
counter) to ask for a proposal- Parameters:
state – The mechanism state
dest – the destination (can be ignored in AOP, SAOP, MAOP)
- Returns:
An outcome to offer or None to refuse to offer
- Remarks:
Depending on the
SAOMechanismsettings, refusing to offer may be interpreted as ending the negotiationThe negotiator will only receive this call if it has the ‘propose’ capability.
- remove_capability(name: str) None
Removes named capability from the negotiator
- Parameters:
capabilities – The capabilities to be added as a dict
- Returns:
None
- Remarks:
It is the responsibility of the caller to be really capable of added capabilities.
- remove_handler(notification_type: str, callback: Callable[[Notification, str], bool]) bool
Removes a notification handler from the list of handlers of the given type.
- Parameters:
notification_type – Notification type as specificed in the type member of the Notification class
callback – The callback which must receive a Notification object and a string and returns a boolean. If True is returned from one callback, the remaining callbacks will not be called
- Returns:
Whether or not the handler was in the list of handlers for this type. In all cases, the handler will not be called after this call (either it was not there or it will be removed).
- respond(state, source: str | None = None) ResponseType[source]
Calls parent controller
- respond_(state: SAOState, source: str | None = None) ResponseType
The method to be called directly by the mechanism (through
counter) to respond to an offer.- Parameters:
state – a
SAOStategiving current state of the negotiation.source – The ID of the negotiator that gave the offer.
- Returns:
The response to the offer. Possible values are:
- NO_RESPONSE: refuse to offer. Depending on the mechanism settings this may be interpreted as ending
the negotiation.
ACCEPT_OFFER: Accepting the offer.
- REJECT_OFFER: Rejecting the offer. The negotiator will be given the chance to counter this
offer through a call of
propose_later if this was not the last offer to be evaluated by the mechanism.
END_NEGOTIATION: End the negotiation
WAIT: Instructs the mechanism to wait for this negotiator more. It may lead to cycles so use with care.
- Return type:
- Remarks:
The default implementation never ends the negotiation except if an earler end_negotiation notification is sent to the negotiator
The default implementation asks the negotiator to
propose`() and accepts the `offerif its utility was at least as good as the offer that it would have proposed (and above the reserved value).
- 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)