IndependentNegotiationsAgent¶
- class scml.scml2020.IndependentNegotiationsAgent(*args, **kwargs)[source]¶
Bases:
IndependentNegotiationsManager
,FixedTradePredictionStrategy
,ReactiveTradingStrategy
,SCML2020Agent
Implements the base class for agents that negotiate independently with different partners.
These agents do not take production capacity, availability of materials or any other aspects of the simulation into account. They are to serve only as baselines.
Remarks:
IndependentNegotiationsAgent
agents assume that each production process has one input type with the sameindex as itself and one output type with one added to the index (i.e. process $i$ takes product $i$ as input and creates product $i+1$ as output.
It does not assume that all lines have the same production cost (it uses the average cost though).
It does not assume that the agent has a single production process.
Attributes Summary
A list of negotiation requests sent to this agent that are already accepted by it.
Gets the Agent-world interface.
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
Was the agent initialized (i.e.
Returns the internal state of the agent for debugging purposes
A convenient name of the entity (intended primarily for printing/logging/debugging).
A list of the negotiation requests sent by this agent that are not yet accepted or rejected.
The utility function attached to that object
Returns the preferences if it is a ProbUtilityFunction else None
The negotiations currently requested by the agent.
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.
The negotiations currently requested by the agent.
Returns a short name of the type of this entity
Returns the name of the type of this entity
Returns the preferences if it is a
BaseUtilityFunction
else NoneAll contracts that are not yet signed.
The unique ID of this entity
Methods Summary
acceptable_unit_price
(step, sell)Returns the maximum/minimum acceptable unit price for buying/selling at the given time-step
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
confirm_production
(commands, balance, inventory)Called just before production starts at every time-step allowing the agent to change what is to be produced in its factory
create
(*args, **kwargs)Creates an object and returns a proxy to it.
create_negotiation_request
(issues, partners, ...)Creates a new
NegotiationRequestInfo
record and returns itS IDcreate_ufun
(is_seller[, issues, outcomes])Creates a utility function
from_checkpoint
(file_name[, return_info])Creates an object from a saved checkpoint
from_config
(config[, section, ...])Creates an object of this class given the configuration info.
init
()Called to initialize the agent after the world is initialized.
init_
()Called to initialize the agent after the world is initialized.
negotiator
(is_seller[, issues, outcomes, ...])Creates a negotiator
notify
(notifiable, notification)on_agent_bankrupt
(agent, contracts, ...)Called whenever a contract is nullified (because the partner is bankrupt)
on_contract_breached
(contract, breaches, ...)Called after complete processing of a contract that involved a breach.
on_contract_cancelled
(contract, rejectors)Called whenever at least a partner did not sign the contract
on_contract_cancelled_
(contract, rejectors)Called whenever at least a partner did not sign the contract
on_contract_executed
(contract)Called after successful contract execution for which the agent is one of the partners.
on_contract_signed
(contract)Called whenever a contract is signed by all partners
on_contract_signed_
(contract)Called whenever a contract is signed by all partners
on_contracts_finalized
(signed, cancelled, ...)Called for all contracts in a single step to inform the agent about which were finally signed and which were rejected by any agents (including itself)
on_event
(event, sender)on_failures
(failures)Called whenever there are failures either in production or in execution of guaranteed transactions
on_neg_request_accepted
(req_id, mechanism)Called when a requested negotiation is accepted
on_neg_request_accepted_
(req_id, mechanism)Called when a requested negotiation is accepted
on_neg_request_rejected
(req_id, by)Called when a requested negotiation is rejected
on_neg_request_rejected_
(req_id, by)Called when a requested negotiation is rejected
on_negotiation_failure
(partners, annotation, ...)Called whenever a negotiation ends without agreement
on_negotiation_failure_
(partners, ...)Called whenever a negotiation ends without agreement
on_negotiation_success
(contract, mechanism)Called whenever a negotiation ends with agreement
on_negotiation_success_
(contract, mechanism)Called whenever a negotiation ends with agreement
on_preferences_changed
(changes)Called to inform the entity that its ufun has changed.
Will be called at the end of the simulation step after everything else
Will be called at the beginning of the simulation step before everything else (except init)
read_config
(config[, section])Reads the configuration from a file or a dict and prepares it for parsing.
respond_to_negotiation_request
(initiator, ...)Called whenever another agent requests a negotiation with this agent.
respond_to_negotiation_request_
(initiator, ...)Called when a negotiation request is received
respond_to_renegotiation_request
(contract, ...)Called to respond to a renegotiation request
set_preferences
(value[, force])Sets tha utility function/Preferences.
set_renegotiation_agenda
(contract, breaches)Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails
sign_all_contracts
(contracts)Signs all contracts
sign_contract
(contract)Called after the signing delay from contract conclusion to sign the contract.
spawn
([spawn_as, spawn_params])spawn_object
(*args, **kwargs)start_negotiations
(product, quantity, ...[, ...])Starts a set of negotiations to buy/sell the product with the given limits
step
()Generates buy and sell negotiations as needed
step_
()Called at every time-step.
target_quantities
(steps, sell)Returns the target quantity to negotiate about for each step in the range given (beginning included and ending excluded) for buying/selling
target_quantity
(step, sell)Returns the target quantity to sell/buy at a given time-step
to_dict
()Will be called at the beginning of every step to update the prediction
Will be called to update expected_outputs, expected_inputs, input_cost, output_cost during init()
Will be called at the end of every step to update the prediction
Attributes Documentation
- accepted_negotiation_requests¶
A list of negotiation requests sent to this agent that are already accepted by it.
- Remarks:
These negotiations did not start yet as they are still not accepted by all partners. Once that happens, they will be moved to
running_negotiations
- Return type:
list
[NegotiationRequestInfo
]
- awi¶
Gets the Agent-world interface.
- Return type:
AgentWorldInterface
- crisp_ufun¶
Returns the preferences if it is a CrispUtilityFunction else None
- Return type:
Optional
[UtilityFunction
]
- id¶
The unique ID of this entity
- internal_state¶
- name¶
A convenient name of the entity (intended primarily for printing/logging/debugging).
- negotiation_requests¶
A list of the negotiation requests sent by this agent that are not yet accepted or rejected.
- Remarks:
These negotiations did not start yet as they are still not accepted by all partners. Once that happens, they will be moved to
running_negotiations
- Return type:
list
[NegotiationRequestInfo
]
- preferences¶
The utility function attached to that object
- Return type:
Optional
[Preferences
]
- prob_ufun¶
Returns the preferences if it is a ProbUtilityFunction else None
- Return type:
Optional
[ProbUtilityFunction
]
- requested_negotiations¶
The negotiations currently requested by the agent.
- Return type:
list
[NegotiationRequestInfo
]- Returns:
A list of negotiation request information objects (
NegotiationRequestInfo
)
- 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
- Return type:
Optional
[tuple
]
- 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.- Return type:
- running_negotiations¶
The negotiations currently requested by the agent.
- Return type:
list
[RunningNegotiationInfo
]- Returns:
A list of negotiation information objects (
RunningNegotiationInfo
)
- short_type_name¶
Returns a short name of the type of this entity
- type_name¶
Returns the name of the type of this entity
- type_postfix¶
- ufun¶
Returns the preferences if it is a
BaseUtilityFunction
else None- Return type:
Optional
[BaseUtilityFunction
]
- use_trading¶
- uuid¶
The unique ID of this entity
Methods Documentation
- acceptable_unit_price(step, sell)[source]¶
Returns the maximum/minimum acceptable unit price for buying/selling at the given time-step
- before_step()¶
- 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 (
Optional
[str
]) – Name of the file to dump into. If not given, a unique name is createdinfo (
Optional
[dict
[str
,Any
]]) – 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:
- confirm_production(commands, balance, inventory)¶
Called just before production starts at every time-step allowing the agent to change what is to be produced in its factory
- Parameters:
- Return type:
- Returns:
an n_lines vector giving the process to be run at every line (NO_COMMAND indicates nothing to be processed
Remarks:
Not called in SCML2020 competition.
The inventory will contain zero items of all products that the factory does not buy or sell
The default behavior is to just retrun commands confirming production of everything.
- classmethod create(*args, **kwargs)¶
Creates an object and returns a proxy to it.
- create_negotiation_request(issues, partners, annotation, negotiator, extra)¶
Creates a new
NegotiationRequestInfo
record and returns itS ID- Parameters:
- Return type:
- Returns:
A unique identifier for this negotiation info structure
- create_ufun(is_seller, issues=None, outcomes=None)¶
Creates a utility function
- Return type:
UtilityFunction
- 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
- classmethod from_config(config, section=None, ignore_children=True, try_parsing_children=True, scope=None)¶
Creates an object of this class given the configuration info.
- Parameters:
section (
Optional
[str
]) – A section in the file or a key in the dictionary to use for loading paramsignore_children (
bool
) – If true then children will be ignored and there will be a single returntry_parsing_children (
bool
) – If true the children will first be parsed asConfigReader
classes if they are notint (simple types (e.g.) –
str –
float –
Iterable[int|str|float] –
scope – The scope at which to evaluate any child classes. This MUST be passed as scope=globals() if you are
parsed. (having any children that are to be) –
- Returns:
An object of cls if ignore_children is True or a tuple with an object of cls and a dictionary with children that were not parsed.
Remarks:
This function will return an object of its class after passing the key-value pairs found in the config to the init function.
Requiring passing scope=globals() to this function is to get around the fact that in python eval() will be called with a globals dictionary based on the module in which the function is defined not called. This means that in general when eval() is called to create the children, it will not have access to the class definitions of these children (except if they happen to be imported in this file). To avoid this problem causing an undefined_name exception, the caller must pass her globals() as the scope.
- init()¶
Called to initialize the agent after the world is initialized. the AWI is accessible at this point.
- init_()¶
Called to initialize the agent after the world is initialized. the AWI is accessible at this point.
- negotiator(is_seller, issues=None, outcomes=None, partner=None)¶
Creates a negotiator
- Return type:
SAONegotiator
- notify(notifiable, notification)¶
- on_agent_bankrupt(agent, contracts, quantities, compensation_money)¶
Called whenever a contract is nullified (because the partner is bankrupt)
- Parameters:
agent (
str
) – The ID of the agent that went bankrupt.contracts (
List
[Contract
]) – All future contracts between this agent and the bankrupt agent.quantities (
List
[int
]) – The actual quantities that these contracts will be executed at.compensation_money (
int
) – The compensation money that is already added to the agent’s wallet (if ANY).
Remarks:
compensation_money will be nonzero iff immediate_compensation is enabled for this world
- Return type:
- on_contract_breached(contract, breaches, resolution)¶
Called after complete processing of a contract that involved a breach.
- on_contract_cancelled(contract, rejectors)¶
Called whenever at least a partner did not sign the contract
- Return type:
- on_contract_cancelled_(contract, rejectors)¶
Called whenever at least a partner did not sign the contract
- Return type:
- on_contract_executed(contract)¶
Called after successful contract execution for which the agent is one of the partners.
- Return type:
- on_contract_signed(contract)¶
Called whenever a contract is signed by all partners
- Return type:
- on_contract_signed_(contract)¶
Called whenever a contract is signed by all partners
- Return type:
- on_contracts_finalized(signed, cancelled, rejectors)¶
Called for all contracts in a single step to inform the agent about which were finally signed and which were rejected by any agents (including itself)
- Parameters:
signed (
List
[Contract
]) – A list of signed contracts. These are bindingcancelled (
List
[Contract
]) – A list of cancelled contracts. These are not bindingrejectors (
List
[List
[str
]]) – A list of lists where each of the internal lists gives the rejectors of one of the cancelled contracts. Notice that it is possible that this list is empty which means that the contract other than being rejected by any agents (if that was possible in the specific world).
Remarks:
The default implementation is to call
on_contract_signed
for singed contracts andon_contract_cancelled
for cancelled contracts- Return type:
- on_event(event, sender)¶
- on_failures(failures)¶
Called whenever there are failures either in production or in execution of guaranteed transactions
- on_neg_request_accepted(req_id, mechanism)¶
Called when a requested negotiation is accepted
- on_neg_request_accepted_(req_id, mechanism)¶
Called when a requested negotiation is accepted
- on_neg_request_rejected(req_id, by)¶
Called when a requested negotiation is rejected
- on_neg_request_rejected_(req_id, by)¶
Called when a requested negotiation is rejected
- on_negotiation_failure(partners, annotation, mechanism, state)¶
Called whenever a negotiation ends without agreement
- Return type:
- on_negotiation_failure_(partners, annotation, mechanism, state)¶
Called whenever a negotiation ends without agreement
- Return type:
- on_negotiation_success(contract, mechanism)¶
Called whenever a negotiation ends with agreement
- Return type:
- on_negotiation_success_(contract, mechanism)¶
Called whenever a negotiation ends with agreement
- Return type:
- 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_simulation_step_ended()¶
Will be called at the end of the simulation step after everything else
- on_simulation_step_started()¶
Will be called at the beginning of the simulation step before everything else (except init)
- classmethod read_config(config, section=None)¶
Reads the configuration from a file or a dict and prepares it for parsing.
- Parameters:
- Return type:
- Returns:
A dict ready to be parsed by from_config
Remarks:
- respond_to_negotiation_request(initiator, issues, annotation, mechanism)¶
Called whenever another agent requests a negotiation with this agent.
- Parameters:
initiator (
str
) – The ID of the agent that requested this negotiationissues (
List
[Issue
]) – Negotiation issuesannotation (
Dict
[str
,Any
]) – Annotation attached with this negotiationmechanism (
NegotiatorMechanismInterface
) – TheNegotiatorMechanismInterface
interface to the mechanism to be used for this negotiation.
- Return type:
Optional
[Negotiator
]- Returns:
None to reject the negotiation, otherwise a negotiator
- respond_to_negotiation_request_(initiator, partners, issues, annotation, mechanism, role, req_id)¶
Called when a negotiation request is received
- Return type:
Optional
[Negotiator
]
- respond_to_renegotiation_request(contract, breaches, agenda)¶
Called to respond to a renegotiation request
- Parameters:
agenda (
RenegotiationRequest
) –contract (
Contract
) –breaches (
List
[Breach
]) –
Returns:
- Return type:
Optional
[Negotiator
]
- set_preferences(value, force=False)¶
Sets tha utility function/Preferences.
- Parameters:
value (
Optional
[Preferences
]) – The value to set toforce – If true,
on_preferecnes_changed()
will always be called even ifvalue
==self.preferences
- Return type:
Optional
[Preferences
]
- set_renegotiation_agenda(contract, breaches)¶
Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails
- sign_contract(contract)¶
Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed.
- Return type:
Optional
[str
]
- classmethod spawn(spawn_as='object', spawn_params=None, *args, **kwargs)¶
- classmethod spawn_object(*args, **kwargs)¶
- start_negotiations(product, quantity, unit_price, step, partners=None)¶
Starts a set of negotiations to buy/sell the product with the given limits
- Parameters:
Remarks:
This method assumes that product is either my_input_product or my_output_product
- Return type:
- step()¶
Generates buy and sell negotiations as needed
- step_()¶
Called at every time-step. This function is called directly by the world.
- target_quantities(steps, sell)¶
Returns the target quantity to negotiate about for each step in the range given (beginning included and ending excluded) for buying/selling
- to_dict()¶
- trade_prediction_before_step()¶
Will be called at the beginning of every step to update the prediction
- Return type:
- trade_prediction_init()¶
Will be called to update expected_outputs, expected_inputs, input_cost, output_cost during init()