GeniusNegotiator

class negmas.genius.GeniusNegotiator(preferences=None, name=None, parent=None, owner=None, java_class_name=None, domain_file_name=None, utility_file_name=None, can_propose=True, auto_load_java=True, port=25337, genius_bridge_path=None, strict=None, id=None)[source]

Bases: SAONegotiator

Encapsulates a Genius Negotiator

Parameters:
  • preferences (UtilityFunction | None) – The ufun of the negotiator [optional]

  • name (str | None) – Negotiator name [optional]

  • parent (Controller | None) – Parent Controller

  • owner (Agent) – The agent that owns the negotiator (if any)

  • java_class_name (str | None) – The java class name of the Geinus underlying agent

  • domain_file_name (str | Path | None) – Optional domain file name (containing the negotiation issues or agenda)

  • utility_file_name (str | Path | None) – Optional ufun file name (xml) from which a ufun will be loaded for the agent

  • can_propose – The negotiator can propose

  • auto_load_java (bool) – Load the genius bridge if needed

  • port (int) – The port to load the genius bridge to (or use if it is already loaded)

  • genius_bridge_path (str | None) – The path to the genius bridge

  • strict (bool | None) – If True, raise exceptions if any exception is thrown by the agent or the bridge (or if the agent could not choose an action). If false, ignore these exceptions and assume a None return. If None use strict for n_steps limited negotiations and not strict for time_limit limited ones.

Attributes Summary

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

is_connected

java_name

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

port

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

relative_time

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.

short_type_name

strict

type_name

ufun

Returns the preferences if it is a BaseUtilityFunction else None

uuid

The unique ID of this entity

Methods Summary

__call__(state)

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.

destroy_java_counterpart([state])

rtype:

None

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])

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

negotiators([agent_based, party_based])

Returns a list of all available agents in genius 8.4.0

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)

called when a negotiation is ended

on_negotiation_start(state)

Called when the info starts.

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

parse(action)

Parses an action into a ResponseType and an Outcome (if one is included) :type action: str :param action:

propose(state)

Propose an offer or None to refuse.

propose_(state)

The method directly called by the mechanism (through counter ) to ask for a proposal

propose_sao(state)

rtype:

SAOResponse

random_negotiator([agent_based, ...])

Returns an agent with a random class name

random_negotiator_name([agent_based, ...])

remove_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])

Called to respond to an offer.

respond_(state[, source])

The method to be called directly by the mechanism (through counter ) to respond to an offer.

respond_sao(state)

rtype:

None

robust_negotiators()

Returns a list of genius agents that were tested and seem to be robustly working with negmas

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

is_connected
java_name
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

port
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

relative_time
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

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
strict
type_name
ufun

Returns the preferences if it is a BaseUtilityFunction else None

uuid

The unique ID of this entity

Methods Documentation

__call__(state)[source]

Called by Negotiator.__call__ (which is called by the mechanism) to counter the offer. It just calls respond_ and propose_ as needed.

Parameters:

state (SAOState) – SAOState giving current state of the negotiation.

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)

Adds named capabilities to the negotiator.

Parameters:

capabilities (dict) – The capabilities to be added as a dict

Return type:

None

Returns:

None

Remarks:

It is the responsibility of the caller to be really capable of added capabilities.

add_handler(notification_type, callback)

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 (str) – Notification type as specificed in the type member of the Notification class

  • callback (Callable[[Notification, str], bool]) – 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)

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

Return type:

bool

cancel(reason=None)[source]

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.

Return type:

None

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

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:

classmethod create(*args, **kwargs)

Creates an object and returns a proxy to it.

destroy_java_counterpart(state=None)[source]
Return type:

None

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

handlers(notification_type)

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.

Return type:

list[Callable[[Notification, str], bool]]

is_acceptable_as_agreement(outcome)

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.

Return type:

bool

isin(negotiation_id)

Is that agent participating in the given negotiation? Tests if the agent is participating in the given negotiation.

Parameters:

negotiation_id (Optional[str]) – The negotiation ID tested. If None, it means ANY negotiation

Returns:

True if participating in the given negotiation (or any

negotiation if it was None)

Return type:

bool

join(nmi, state, *, preferences=None, ufun=None, role='negotiator')[source]

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

Parameters:
  • nmi – The negotiation.

  • state – The current state of the negotiation

  • preferences – The preferences used by the negotiator (see ufun )

  • ufun – The ufun function to use (overrides preferences )

  • role – role of the negotiator.

Return type:

bool

Returns:

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

Remarks:

  • Joining a neogiation will fail in the following conditions:

    1. The negotiator already has preferences and is asked to join with new ones

    2. The negotiator is already in a negotiation

classmethod negotiators(agent_based=True, party_based=True)[source]

Returns a list of all available agents in genius 8.4.0

Parameters:
  • agent_based – Old agents based on the Java class Negotiator

  • party_based – Newer agents based on the Java class AbstractNegotiationParty

Return type:

list[str]

Returns:

on_leave(state)

A call back called after leaving a negotiation.

Parameters:

state (TypeVar(TState, bound= MechanismState)) – MechanismState giving current state of the negotiation.

Return type:

None

Remarks:
  • MUST call the baseclass on_leave using super () if you are going to override this.

  • The default behavior is to do nothing.

  • Override this to hook some action

on_mechanism_error(state)

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

Parameters:

state (TypeVar(TState, bound= MechanismState)) – MechanismState giving current state of the negotiation.

Return type:

None

Remarks:
  • The default behavior is to do nothing.

  • Override this to hook some action

on_negotiation_end(state)[source]

called when a negotiation is ended

Return type:

None

on_negotiation_start(state)[source]

Called when the info starts. Connects to the JVM.

Return type:

None

on_notification(notification, notifier)

Called whenever a notification is received

Parameters:
  • notification (Notification) – The notification

  • notifier (str) – The notifier entity

Remarks:
  • The default implementation only responds to end_negotiation by ending the negotiation

on_notification_(notification, notifier)

Called when a notification is received. Do NOT directly override this method

Parameters:
Return type:

bool

Returns:

on_partner_ended(partner)

Called when a partner ends the negotiation.

Note that the negotiator owning this component may never receive this offer. This is only receivd if the mechanism is sending notifications on every offer.

on_partner_proposal(state, partner_id, offer)

A callback called by the mechanism when a partner proposes something

Parameters:
  • state (GBState) – GBState giving the state of the negotiation when the offer was porposed.

  • partner_id (str) – The ID of the agent who proposed

  • offer (tuple) – The proposal.

Return type:

None

Remarks:
  • Will only be called if enable_callbacks is set for the mechanism

on_partner_response(state, partner_id, outcome, response)

A callback called by the mechanism when a partner responds to some offer

Parameters:
  • state (GBState) – GBState giving the state of the negotiation when the partner responded.

  • partner_id (str) – The ID of the agent who responded

  • outcome (tuple) – The proposal being responded to.

  • response (ResponseType) – The response

Return type:

None

Remarks:
  • Will only be called if enable_callbacks is set for the mechanism

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(state)

A call back called at each negotiation round end

Parameters:

state (TypeVar(TState, bound= MechanismState)) – MechanismState giving current state of the negotiation.

Return type:

None

Remarks:
  • The default behavior is to do nothing.

  • Override this to hook some action

on_round_start(state)

A call back called at each negotiation round start

Parameters:

state (TypeVar(TState, bound= MechanismState)) – MechanismState giving current state of the negotiation.

Return type:

None

Remarks:
  • The default behavior is to do nothing.

  • Override this to hook some action.

parse(action)[source]

Parses an action into a ResponseType and an Outcome (if one is included) :type action: str :param action:

Returns:

Return type:

tuple[ResponseType, tuple | None]

propose(state)[source]

Propose an offer or None to refuse.

Parameters:

state (GBState) – GBState giving current state of the negotiation.

Return type:

tuple | None

Returns:

The outcome being proposed or None to refuse to propose

Remarks:
  • This function guarantees that no agents can propose something with a utility value

propose_(state)

The method directly called by the mechanism (through counter ) to ask for a proposal

Parameters:

state (SAOState) – The mechanism state

Return type:

tuple | None

Returns:

An outcome to offer or None to refuse to offer

Remarks:
  • Depending on the SAOMechanism settings, refusing to offer may be interpreted as ending the negotiation

  • The negotiator will only receive this call if it has the ‘propose’ capability.

propose_sao(state)[source]
Return type:

SAOResponse

classmethod random_negotiator(agent_based=True, party_based=True, port=25337, domain_file_name=None, utility_file_name=None, auto_load_java=False, can_propose=True, name=None)[source]

Returns an agent with a random class name

Parameters:
  • name (str | None) – negotiator name

  • can_propose – Can this negotiator propose?

  • auto_load_java (bool) – load the JVM if needed

  • utility_file_name (str | None) – Name of the utility xml file

  • domain_file_name (str | None) – Name of the domain XML file

  • port (int) – port number to use if the JVM is to be started

  • agent_based – Old agents based on the Java class Negotiator

  • party_based – Newer agents based on the Java class AbstractNegotiationParty

Return type:

GeniusNegotiator

Returns:

GeniusNegotiator an agent with a random java class

classmethod random_negotiator_name(agent_based=True, party_based=True)[source]
remove_capability(name)

Removes named capability from the negotiator

Parameters:

capabilities – The capabilities to be added as a dict

Return type:

None

Returns:

None

Remarks:

It is the responsibility of the caller to be really capable of added capabilities.

remove_handler(notification_type, callback)

Removes a notification handler from the list of handlers of the given type.

Parameters:
  • notification_type (str) – Notification type as specificed in the type member of the Notification class

  • callback (Callable[[Notification, str], bool]) – 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

Return type:

bool

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=None)[source]

Called to respond to an offer. This is the method that should be overriden to provide an acceptance strategy.

Parameters:
  • state (GBState) – a SAOState giving current state of the negotiation.

  • source (str | None) – The ID of the negotiator that gave this offer

Returns:

The response to the offer

Return type:

ResponseType

Remarks:
  • The default implementation never ends the negotiation

  • The default implementation asks the negotiator to propose`() and accepts the `offer if its utility was at least as good as the offer that it would have proposed (and above the reserved value).

  • The current offer to respond to can be accessed through state.current_offer

respond_(state, source=None)

The method to be called directly by the mechanism (through counter ) to respond to an offer.

Parameters:
  • state (SAOState) – a SAOState giving current state of the negotiation.

  • source (str | None) – 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:

ResponseType

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 `offer if its utility was at least as good as the offer that it would have proposed (and above the reserved value).

respond_sao(state)[source]
Return type:

None

classmethod robust_negotiators()[source]

Returns a list of genius agents that were tested and seem to be robustly working with negmas

Return type:

list[str]

set_id(id)

Sets the unique ID of this entity

set_preferences(value, force=False)

Sets the utility function/Preferences.

Parameters:
  • value (Preferences | None) – The value to set to

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

Return type:

None

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