ChainNegotiationsMechanism
- class negmas.concurrent.ChainNegotiationsMechanism(initial_state=None, *args, **kwargs)[source]
Bases:
Mechanism
[MechanismState
,MechanismAction
,ChainNMI
,ChainNegotiator
]Attributes Summary
Ended without timing out (either with agreement or broken by a negotiator)
Ended in any way
Returns a positive number indicating elapsed relative time or steps.
Returns the expected remaining number of steps until the end of the mechanism run.
Returns remaining time in seconds (expectation).
The unique ID of this entity
Returns the issues of the outcome space (if defined).
A convenient name of the entity (intended primarily for printing/logging/debugging).
The total time consumed by every negotiator.
Returns a list of all participant names.
Returns a number between
0
and1
indicating elapsed relative time or steps.Returns the remaining number of steps until the end of the mechanism run.
Returns remaining time in seconds.
A dictionary specifying the requirements that must be in the capabilities of any negotiator to join the mechanism.
Returns the current state.
Returns the state as it should be stored in the history.
Elapsed time since mechanism started in seconds.
The unique ID of this entity
Verbosity level.
Methods Summary
__call__
(state[, action])Implements a single step of the mechanism.
abort
()Aborts the negotiation.
add
(negotiator, *[, preferences, role])Add an negotiator to the negotiation.
add_requirements
(requirements)Adds requirements.
announce
(event)Raises an event and informs all event sinks that are registered for notifications on this event type
Whether the mechanism can currently accept more negotiators.
can_enter
(negotiator)Whether the negotiator can enter the negotiation now.
can_leave
(negotiator)Can the negotiator leave now?
can_participate
(negotiator)Checks if the negotiator can participate in this type of negotiation in general.
checkpoint
(path[, file_name, info, ...])Saves a checkpoint of the current object at the given path.
Should be called at the end of the simulation to save the final state
checkpoint_info
(file_name)Returns the information associated with a dump of the object saved in the given file
checkpoint_init
([step_attrib, every, ...])Initializes the object to automatically save a checkpoint
Should be called on every step to save checkpoints as needed.
create
(*args, **kwargs)Creates an object and returns a proxy to it.
discrete_outcome_space
([levels, max_cardinality])Returns a stable discrete version of the given outcome-space.
discrete_outcomes
([levels, max_cardinality])A discrete set of outcomes that spans the outcome space.
from_checkpoint
(file_name[, return_info])Creates an object from a saved checkpoint
genius_id
(id)Gets the Genius ID corresponding to the given negotiator if known otherwise its normal ID
get_negotiator
(source)Returns the negotiator with the given ID if present in the negotiation.
get_negotiator_raise
(source)Returns the negotiator with the given ID if present in the negotiation otherwise it raises an exception.
is_satisfying
(capabilities)Checks if the given capabilities are satisfying mechanism requirements.
is_valid
(outcome)Checks whether the outcome is valid given the issues.
kalai_points
([max_cardinality, frontier, ...])log
(nid, data, level)Saves a log for a negotiator
log_critical
(nid, data)Logs at critical level
log_debug
(nid, data)Logs at debug level
log_error
(nid, data)Logs at error level
log_info
(nid, data)Logs at info level
log_warning
(nid, data)Logs at warning level
max_relative_welfare_points
([...])max_welfare_points
([max_cardinality, ...])modified_kalai_points
([max_cardinality, ...])nash_points
([max_cardinality, frontier, ...])negotiator_index
(source)Gets the negotiator index.
on_confirm
(level, left)Called by negotiators to confirm their temporary accepted agreements
Called when there is a mechanism error.
Called at the end of each negotiation.
Called before starting the negotiation.
pareto_frontier
([max_cardinality, ...])pareto_frontier_bf
([max_cardinality, ...])plot
(**kwargs)A method for plotting a negotiation session.
Returns a single random offer
random_outcomes
([n, with_replacement])Returns random offers.
register_listener
(event_type, listener)Registers a listener for the given event_type.
remove
(negotiator)Remove the negotiator from the negotiation.
remove_requirements
(requirements)Adds requirements.
run
([timeout])- rtype:
TypeVar
(TState
, bound=MechanismState
)
run_with_progress
([timeout])- rtype:
TypeVar
(TState
, bound=MechanismState
)
runall
(mechanisms[, keep_order, method])Runs all mechanisms.
set_id
(id)Sets the unique ID of this entity
spawn
([spawn_as, spawn_params])spawn_object
(*args, **kwargs)step
([action])Runs a single step of the mechanism.
stepall
(mechanisms[, keep_order])Step all mechanisms.
Attributes Documentation
- agent_ids
- agent_names
- agreement
- completed
Ended without timing out (either with agreement or broken by a negotiator)
- current_step
- dynamic_entry
- ended
Ended in any way
- expected_relative_time
Returns a positive number indicating elapsed relative time or steps.
- Remarks:
This is relative to the expected time/step at which the negotiation ends given all timing conditions (time_limit, n_step, pend, pend_per_second).
- expected_remaining_steps
Returns the expected remaining number of steps until the end of the mechanism run.
None if unlimited
- expected_remaining_time
Returns remaining time in seconds (expectation).
None if no time limit or pend_per_second is given.
- genius_negotiator_ids
- history
- id
The unique ID of this entity
- issues
Returns the issues of the outcome space (if defined).
Will raise an exception if the outcome space has no defined issues
- max_n_negotiators
- n_outcomes
- n_steps
- name
A convenient name of the entity (intended primarily for printing/logging/debugging).
- negotiator_ids
- negotiator_names
- negotiator_times
The total time consumed by every negotiator.
Each mechanism class is responsible of updating this for any activities of the negotiator it controls.
- negotiators
- outcome_space
- outcomes
- participants
Returns a list of all participant names.
- relative_time
Returns a number between
0
and1
indicating elapsed relative time or steps.- Remarks:
If pend or pend_per_second are defined in the
NegotiatorMechanismInterface
, and time_limit/n_steps are not given, this becomes an expectation that is limited above by one.
- remaining_steps
Returns the remaining number of steps until the end of the mechanism run.
None if unlimited
- remaining_time
Returns remaining time in seconds.
None if no time limit is given.
- requirements
A dictionary specifying the requirements that must be in the capabilities of any negotiator to join the mechanism.
- running
- short_type_name
- state
Returns the current state.
Override
extra_state
if you want to keep extra state
- state4history
Returns the state as it should be stored in the history.
- stats
- time
Elapsed time since mechanism started in seconds.
0.0 if the mechanism did not start running
- time_limit
- type_name
- uuid
The unique ID of this entity
- verbosity
Verbosity level.
Children of this class should only print if verbosity > 1
Methods Documentation
- __call__(state, action=None)[source]
Implements a single step of the mechanism. Override this!
- Parameters:
state – The mechanism state. When overriding, set the type of this to the specific
MechanismState
descendent for your mechanism.action – An optional action (value) of the next negotiator (key). If given, the call should just execute the action without calling the next negotiator.
- Return type:
- Returns:
MechanismStepResult
showing the result of the negotiation step
- abort()
Aborts the negotiation.
- Return type:
TypeVar
(TState
, bound=MechanismState
)
- add(negotiator, *, preferences=None, role=None, **kwargs)[source]
Add an negotiator to the negotiation.
- Parameters:
negotiator (
Negotiator
) – The negotiator to be added.preferences (
Preferences
|None
) – The utility function to use. If None, then the negotiator must already have a stored utility function otherwise it will fail to enter the negotiation.ufun – [depricated] same as preferences but must be a
UFun
object.role (
str
|None
) – The role the negotiator plays in the negotiation mechanism. It is expected that mechanisms inheriting from this class will check this parameter to ensure that the role is a valid role and is still possible for negotiators to join on that role. Roles may include things like moderator, representative etc based on the mechanism
- Return type:
- Returns:
True if the negotiator was added.
False if the negotiator was already in the negotiation.
None if the negotiator cannot be added. This can happen in the following cases:
The capabilities of the negotiator do not match the requirements of the negotiation
The outcome-space of the negotiator’s preferences do not contain the outcome-space of the negotiation
The negotiator refuses to join (by returning False from its
join
method) seeNegotiator.join
for possible reasons of that
- announce(event)
Raises an event and informs all event sinks that are registered for notifications on this event type
- can_accept_more_negotiators()
Whether the mechanism can currently accept more negotiators.
- Return type:
- can_participate(negotiator)
Checks if the negotiator can participate in this type of negotiation in general.
- Returns:
True if the negotiator can participate
- Return type:
- Remarks:
The only reason this may return
False
is if the mechanism requires some requirements that are not within the capabilities of the negotiator.When evaluating compatibility, the negotiator is considered incapable of participation if any of the following conditions hold: * A mechanism requirement is not in the capabilities of the negotiator * A mechanism requirement is in the capabilities of the negotiator by the values required for it
is not in the values announced by the negotiator.
An negotiator that lists a
None
value for a capability is announcing that it can work with all its values. On the other hand, a mechanism that lists a requirement as None announces that it accepts any value for this requirement as long as it exist in the negotiator
- 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
- checkpoint_final_step()
Should be called at the end of the simulation to save the final state
- Remarks:
Should be called after all processing of the final step is conducted.
- classmethod checkpoint_info(file_name)
Returns the information associated with a dump of the object saved in the given file
Returns:
- checkpoint_init(step_attrib='current_step', every=1, folder=None, filename=None, info=None, exist_ok=True, single=True)
Initializes the object to automatically save a checkpoint
- Parameters:
step_attrib (
str
) – The attribute that defines the current step. If None, there is no step conceptevery (
int
) – Number of steps per checkpoint. If < 1 no checkpoints will be savedfolder (
PathLike
|Path
|str
|None
) – The directory to store checkpoints underfilename (
str
|None
) – Name of the file to save the checkpoint under. If None, a unique name will be chosen. Ifsingle_checkpoint
was False, then multiple files will be used prefixed with the step numberinfo (
dict
[str
,Any
] |None
) – Any extra information to save in the json file associated with each checkpointexist_ok (
bool
) – Override existing files if anysingle (
bool
) – If True, only the most recent checkpoint will be kept
Remarks:
single_checkpoint implies exist_ok
- checkpoint_on_step_started()
Should be called on every step to save checkpoints as needed.
- Return type:
- Returns:
The path on which the checkpoint is stored if one is stored. None otherwise.
Remarks:
Should be called at the BEGINNING of every step before any processing takes place
- classmethod create(*args, **kwargs)
Creates an object and returns a proxy to it.
- discrete_outcome_space(levels=5, max_cardinality=10000000000)
Returns a stable discrete version of the given outcome-space.
- Return type:
- discrete_outcomes(levels=5, max_cardinality=inf)
A discrete set of outcomes that spans the outcome space.
- 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
- genius_id(id)
Gets the Genius ID corresponding to the given negotiator if known otherwise its normal ID
- get_negotiator(source)
Returns the negotiator with the given ID if present in the negotiation.
- Return type:
- get_negotiator_raise(source)
Returns the negotiator with the given ID if present in the negotiation otherwise it raises an exception.
- Return type:
- is_satisfying(capabilities)
Checks if the given capabilities are satisfying mechanism requirements.
- Parameters:
capabilities (
dict
) – capabilities to check- Return type:
- Returns:
bool are the requirements satisfied by the capabilities.
Remarks:
Requirements are also a dict with the following meanings:
tuple: Min and max acceptable values
list/set: Any value in the iterable is acceptable
Single value: The capability must match this value
Capabilities can also have the same three possibilities.
- is_valid(outcome)
Checks whether the outcome is valid given the issues.
- kalai_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
- max_relative_welfare_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
- max_welfare_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
- modified_kalai_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
- nash_points(max_cardinality=inf, frontier=None, frontier_outcomes=None)
- negotiator_index(source)
Gets the negotiator index.
- on_confirm(level, left)[source]
Called by negotiators to confirm their temporary accepted agreements
- on_mechanism_error()
Called when there is a mechanism error.
- Return type:
- Remarks:
When overriding this function you MUST call the base class version
- on_negotiation_end()
Called at the end of each negotiation.
- Return type:
- Remarks:
When overriding this function you MUST call the base class version
- on_negotiation_start()
Called before starting the negotiation.
If it returns False then negotiation will end immediately
- Return type:
- pareto_frontier(max_cardinality=inf, sort_by_welfare=True)
- pareto_frontier_bf(max_cardinality=inf, sort_by_welfare=True)
- random_outcomes(n=1, with_replacement=False)
Returns random offers.
- Parameters:
- Return type:
- Returns:
A list of outcomes of at most n outcomes.
Remarks:
If the number of outcomes
n
cannot be satisfied, a smaller number will be returnedSampling is done without replacement (i.e. returned outcomes are unique).
- register_listener(event_type, listener)
Registers a listener for the given event_type.
- remove(negotiator)
Remove the negotiator from the negotiation.
- run(timeout=None)
- Return type:
TypeVar
(TState
, bound=MechanismState
)
- run_with_progress(timeout=None)
- Return type:
TypeVar
(TState
, bound=MechanismState
)
- classmethod runall(mechanisms, keep_order=True, method='serial')
Runs all mechanisms.
- Parameters:
mechanisms (
list
[Mechanism
] |tuple
[Mechanism
,...
]) – list of mechanismskeep_order – if True, the mechanisms will be run in order every step otherwise the order will be randomized at every step. This is only allowed if the method is serial
method – the method to use for running all the sessions. Acceptable options are: serial, threads, processes
- Return type:
list
[Optional
[TypeVar
(TState
, bound=MechanismState
)]]- Returns:
list of states of all mechanisms after completion
None for any such states indicates disagreements
- set_id(id)
Sets the unique ID of this entity
- classmethod spawn(spawn_as='object', spawn_params=None, *args, **kwargs)
- classmethod spawn_object(*args, **kwargs)
- step(action=None)
Runs a single step of the mechanism.
- Returns:
The state of the negotiation after the round is conducted action: An optional action (value) for the next negotiator (key). If given, the call
should just execute the action without calling the next negotiator.
- Return type:
Remarks:
Every call yields the results of one round (see
round()
)If the mechanism was yet to start, it will start it and runs one round
There is another function (
run()
) that runs the whole mechanism in blocking mode
- classmethod stepall(mechanisms, keep_order=True)
Step all mechanisms.
- Parameters:
- Return type:
list
[TypeVar
(TState
, bound=MechanismState
)]- Returns:
list of states of all mechanisms after completion