scml.scml2019.factory_managers
Submodules
Package Contents
Classes
Base factory manager class that will be inherited by participant negmas in ANAC 2019. |
|
The default factory manager that will be implemented by the committee of ANAC-SCML 2019 |
|
The default factory manager that will be implemented by the committee of ANAC-SCML 2019 |
Attributes
- class scml.scml2019.factory_managers.FactoryManager(name=None, simulator_type: str | Type[scml.scml2019.simulators.FactorySimulator] = FastFactorySimulator)[source]
Bases:
scml.scml2019.agent.SCML2019Agent
,abc.ABC
Base factory manager class that will be inherited by participant negmas in ANAC 2019.
The agent can access the world simulation in one of two ways:
Attributes and methods available in the Agent-SCML2020World-Interface (See
SCMLAWI
documentation for those).Attributes and methods in the
FactoryManager
object itself. All factory managers will have the following attributes and methods that simplify the interaction with the world simulation. Some of these attributes/methods are convenient ways to access functionality already available in the agent’s internalSCMLAWI
.
Attributes
Agent information
id
: The unique ID assigned to this agent. This is unique system-wide and is what is used in contracts, CFPs, etc.name
: A name of the agent used for display purposes only. The simulator never accesses or uses this name except in printing and logging.type_name
: A string giving the type of the agent (as a fully qualified python class name).
Capabilities/Profiles
line_profiles
: A mapping specifying for each line index, all the profiles that can be run on itprocess_profiles
: A mapping specifying for eachProcess
index, all the profiles used to run it in the factoryproducing
: Mapping from a product index to all manufacturing processes that can generate itconsuming
: Mapping from a product index to all manufacturing processes that can consume itcompiled_profiles
: All the profiles to be used by the factory belonging to this agent compiled to use process indicesmax_storage
: Maximum storage available to the agent. Zero, None or float(‘inf’) all indicate unlimited storage.
Production Graph (also accessible through awi)
Helper Objects
awi
: TheSCMLAWI
instance assigned to this agent. It can be used to interact with the simulation (SeeSCMLAWI
documentation).simulator
: AFactorySimulator
object that can be used to simulate what happens in theFactory
assigned to this agent when given operations are conducted (e.g. production, paying money, etc).
Negotiations/Contracts
requested_negotiations
: A dynamic list of negotiations currently requested by the agent but not started. Correct management of this list is only possible if the agent **always* usesrequest_negotiation
method of this class (see methods later) rather than directly calling request_method on theSCMLAWI
(awi
) member.running_negotiations
: A dynamic list of negotiations currently running involving this agent. Correct management of this list is only possible if the agent **always* usesrequest_negotiation
method of this class (see methods later) rather than directly calling request_method on theSCMLAWI
(awi
) member.unsigned_contracts
: A dynamic list of negotiations contracts concluded involving this agent but not yet signed. Correct management of this list is only possible if the agent **always* usesrequest_negotiation
method of this class (see methods later) rather than directly calling request_method on theSCMLAWI
(awi
) member.
Simulation attributes (also accessible through awi)
transportation_delay
: The transportation delay in the system.current_step
: Current simulation step.immediate_negotiations
: Whether or not negotiations start immediately upon registration (default is to start on the next production step)negotiation_speed_multiple
: The number of negotiation rounds (steps) conducted in a single production steptransportation_delay
: Transportation delay in the system. Default is zero
Methods (Callable by the agent)
Actions on the world
request_negotiation
: Called to request a negotiation based on aCFP
.
Scheduling and simulation helpers
can_expect_agreement
: Checks if it is possible in principle to get an agreement on this CFP by the time it becomes executable.
Callbacks (Callable by the simulation)
Decision callbacks (Called to make decisions)
Negotiation and Contracts
respond_to_negotiation_request
: Decide whether or not to engage in a negotiation on aCFP
that was published earlier by this factory manager. If accepted, the agent should return aSAONegotiator
object.sign_contract
: Decide whether or not to sign the contract. If accepted, the agent should return its own ID.confirm_contract_execution
: Decide whether or not to go on with executing a contract that the agent already signed. If rejected (by returningFalse
), a refusal-to-execute breach will be recorded.
Breach related
confirm_partial_execution
: Decide whether the agent agrees to partial execution. Called only when the the partner of this agent commits a partial breach (of level < 1) and this agent commits no breaches.set_renegotiation_agenda
: Decide what are the issues and ranges of acceptable values to re-negotiate about. Called only in case of breaches.respond_to_renegotiation_request
: Decide whether or not to engage in a re-negotiation.
Financial
confirm_loan
: Decide whether or not to accept an offered loan. *In ANAC 2019 league, loans are not allowed and this callback will never be called by the simulator.
Time-dependent callbacks (Information callback called at predefined times)
Information callbacks (Called to inform the agent about events)
CFP related
on_new_cfp
: Called whenever aCFP
on aProduct
for which the agent has already registered interest (usingregister_interest
method of itsawi
) is published. By default all agents register interest in the products they can consume or produce according to their profiles.on_remove_cfp
: Called whenever aCFP
on aProduct
for which the agent has already registered interest (usingregister_interest
method of itsawi
) is removed from the bulletin-board.
Negotiation related
on_neg_request_accepted
: Called when a negotiation request of the agent is acceptedon_neg_request_rejected
: Called when a negotiation request of the agent is rejectedon_negotiation_success
: Called when a negotiation of which the agent is a party succeeds with an agreement.on_negotiation_failure
: Called when a negotiation of which the agent is a party ends without agreement.
Contract related
on_contract_cancelled
: Called whenever aContract
of which the agent is a party is cancelled because the other party refused to sign it.on_contract_signed
: Called whenever aContract
of which the agent is a party is signed by both patners.on_contract_nullified
: Called whenever aContract
of which the agent is a party is nullified by the simulator as a part of bankruptcy processing.on_contract_executed
: Called when a contract executes completely and successfully.on_contract_breached
: Called when a contract is breached after complete contract processing.
Production and factory related
on_production_failure
: Called whenever a scheduled production (seeSCMLAWI
for production commands) failson_inventory_change
: Called whenever there is a change in the inventory (something is moved in or out or out of storage due to an event other than production (e.g. contract execution).on_cash_transfer
: Called whenever cash is transferred to or from the factory’s wallet.
About other agents
on_agent_bankrupt
: Called whenever another agent goes bankrupton_new_report
: Called whenever a new report of another agent for which this agent has registered interest is published. Interest is registered using the agent’sawi
‘sreceive_financial_reports
method.
- transportation_delay = 0
Transportation delay in the world
- simulator: scml.scml2019.simulators.FactorySimulator | None
The simulator used by this agent
- simulator_type: Type[scml.scml2019.simulators.FactorySimulator]
Simulator type (as a class)
- current_step = 0
Current simulation step
- init_()[source]
The initialization function called by the world directly.
It does the following actions by default:
copies some of the static world settings to the agent to make them available without calling the AWI.
prepares production related properties like producing, consuming, line_profiles, compiled_profiles, etc.
registers interest in all products that the agent can produce or consume in its factory.
finally it calls any custom initialization logic implemented in `init`()
- abstract on_production_failure(failures: List[scml.scml2019.common.ProductionFailure]) None [source]
Called with a list of
ProductionFailure
records on production failure.
- abstract on_production_success(reports: List[scml.scml2019.common.ProductionReport]) None [source]
Called with a list of
ProductionReport
records on production success
- class scml.scml2019.factory_managers.DoNothingFactoryManager(name=None, simulator_type: str | Type[scml.scml2019.simulators.FactorySimulator] = FastFactorySimulator)[source]
Bases:
FactoryManager
The default factory manager that will be implemented by the committee of ANAC-SCML 2019
- init()[source]
Called to initialize the agent after the world is initialized. the AWI is accessible at this point.
- on_neg_request_rejected(req_id: str, by: List[str] | None)[source]
Called when a requested negotiation is rejected
- Parameters:
req_id – The request ID passed to _request_negotiation
by – A list of agents that refused to participate or None if the failure was for another reason
- on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface)[source]
Called when a requested negotiation is accepted
- on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) None [source]
Called whenever a negotiation ends without agreement
- on_negotiation_success(contract: negmas.Contract, mechanism: negmas.NegotiatorMechanismInterface) None [source]
Called whenever a negotiation ends with agreement
- on_contract_signed(contract: negmas.Contract) None [source]
Called whenever a contract is signed by all partners
- on_contract_cancelled(contract: negmas.Contract, rejectors: List[str]) None [source]
Called whenever at least a partner did not sign the contract
- on_contract_executed(contract: negmas.Contract) None [source]
Called after successful contract execution for which the agent is one of the partners.
- on_contract_breached(contract: negmas.Contract, breaches: List[negmas.Breach], resolution: negmas.Contract | None) None [source]
Called after complete processing of a contract that involved a breach.
- Parameters:
contract – The contract
breaches – All breaches committed (even if they were resolved)
resolution – The resolution contract if re-negotiation was successful. None if not.
- sign_contract(contract: negmas.Contract) str | None [source]
Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed.
- on_contract_nullified(contract: negmas.Contract, bankrupt_partner: str, compensation: float) None [source]
Will be called whenever a contract the agent is involved in is nullified because another partner went bankrupt
- on_agent_bankrupt(agent_id: str) None [source]
Will be called whenever any agent goes bankrupt
- Parameters:
agent_id – The ID of the agent that went bankrupt
Remarks:
Agents can go bankrupt in two cases:
Failing to pay one installments of a loan they bought and refusing (or being unable to) get another loan to pay it.
Failing to pay a penalty on a sell contract they failed to honor (and refusing or being unable to get a loan to pay for it).
All built-in agents ignore this call and they use the bankruptcy list ONLY to decide whether or not to negotiate in their
on_new_cfp
andrespond_to_negotiation_request
callbacks by pulling the bulletin-board using the helper functionis_bankrupt
of their AWI.
- confirm_partial_execution(contract: negmas.Contract, breaches: List[negmas.Breach]) bool [source]
Will be called whenever a contract cannot be fully executed due to breaches by the other partner.
- Parameters:
contract – The contract that was breached
breaches – A list of all the breaches committed.
Remarks:
Will not be called if both partners committed breaches.
- on_remove_cfp(cfp: scml.scml2019.common.CFP) None [source]
Called when a new CFP for a product for which the agent registered interest is removed
- on_production_failure(failures: List[scml.scml2019.common.ProductionFailure]) None [source]
Called with a list of
ProductionFailure
records on production failure.
- respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) negmas.Negotiator | None [source]
Called when a prospective partner requests a negotiation to start
- confirm_contract_execution(contract: negmas.Contract) bool [source]
Called before executing any agreement
- set_renegotiation_agenda(contract: negmas.Contract, breaches: List[negmas.Breach]) negmas.RenegotiationRequest | None [source]
Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails
- Parameters:
contract – The contract being breached
breaches – All breaches on
contract
- Returns:
Renegotiation agenda (issues to negotiate about to avoid reporting the breaches).
- respond_to_renegotiation_request(contract: negmas.Contract, breaches: List[negmas.Breach], agenda: negmas.RenegotiationRequest) negmas.Negotiator | None [source]
Called to respond to a renegotiation request
- Parameters:
agenda –
contract –
breaches –
Returns:
- confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) bool [source]
called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached
- on_new_cfp(cfp: scml.scml2019.common.CFP) None [source]
Called when a new CFP for a product for which the agent registered interest is published
- on_inventory_change(product: int, quantity: int, cause: str) None [source]
Received whenever something moves in or out of the factory’s storage
- Parameters:
product – Product index.
quantity – Negative value for products moving out and positive value for products moving in
cause –
The cause of the change. Possibilities include:
contract: Contract execution
insurance: Received from insurance company
bankruptcy: Liquidated due to bankruptcy
transport: Arrival of goods (when transportation delay in the system is > 0).
- on_production_success(reports: List[scml.scml2019.common.ProductionReport]) None [source]
Called with a list of
ProductionReport
records on production success
- on_cash_transfer(amount: float, cause: str) None [source]
Received whenever money is transferred to the factory or from it.
- Parameters:
amount – Amount of money (negative for transfers out of the factory, positive for transfers to it).
cause –
The cause of the change. Possibilities include:
contract: Contract execution
insurance: Received from insurance company
bankruptcy: Liquidated due to bankruptcy
transfer: Arrival of transferred money (when transfer delay in the system is > 0).
- on_new_report(report: scml.scml2019.common.FinancialReport)[source]
Called whenever a financial report is published.
- Parameters:
report – The financial report giving details of the standing of an agent at some time (see
FinancialReport
)
Remarks:
Agents must opt-in to receive these calls by calling
receive_financial_reports
on their AWI
- class scml.scml2019.factory_managers.GreedyFactoryManager(name=None, simulator_type: str | Type[scml.scml2019.simulators.FactorySimulator] = FastFactorySimulator, scheduler_type: str | Type[scml.scml2019.schedulers.Scheduler] = GreedyScheduler, scheduler_params: Dict[str, Any] | None = None, optimism: float = 0.0, negotiator_type: str | Type[negmas.Negotiator] = DEFAULT_NEGOTIATOR, negotiator_params: Dict[str, Any] | None = None, n_retrials=5, use_consumer=True, reactive=True, sign_only_guaranteed_contracts=False, riskiness=0.0, max_insurance_premium: float = 0.1, reserved_value: float = -float('inf'))[source]
Bases:
DoNothingFactoryManager
The default factory manager that will be implemented by the committee of ANAC-SCML 2019
- on_production_failure(failures: List[scml.scml2019.common.ProductionFailure]) None [source]
Called with a list of
ProductionFailure
records on production failure.
- on_production_success(reports: List[scml.scml2019.common.ProductionReport]) None [source]
Called with a list of
ProductionReport
records on production success
- confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) bool [source]
called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached
- confirm_contract_execution(contract: negmas.Contract) bool [source]
Called before executing any agreement
- set_renegotiation_agenda(contract: negmas.Contract, breaches: List[negmas.Breach]) negmas.RenegotiationRequest | None [source]
Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails
- Parameters:
contract – The contract being breached
breaches – All breaches on
contract
- Returns:
Renegotiation agenda (issues to negotiate about to avoid reporting the breaches).
- respond_to_renegotiation_request(contract: negmas.Contract, breaches: List[negmas.Breach], agenda: negmas.RenegotiationRequest) negmas.Negotiator | None [source]
Called to respond to a renegotiation request
- Parameters:
agenda –
contract –
breaches –
Returns:
- total_utility(contracts: Collection[negmas.Contract] = ()) float [source]
Calculates the total utility for the agent of a collection of contracts
- init()[source]
Called to initialize the agent after the world is initialized. the AWI is accessible at this point.
- respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) negmas.Negotiator | None [source]
Called when a prospective partner requests a negotiation to start
- on_negotiation_success(contract: negmas.Contract, mechanism: negmas.NegotiatorMechanismInterface)[source]
Called whenever a negotiation ends with agreement
- on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) None [source]
Called whenever a negotiation ends without agreement
- _execute_schedule(schedule: scml.scml2019.schedulers.ScheduleInfo, contract: negmas.Contract) None [source]
- sign_contract(contract: negmas.Contract)[source]
Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed.
- on_contract_signed(contract: negmas.Contract)[source]
Called whenever a contract is signed by all partners
- _process_buy_cfp(cfp: scml.scml2019.common.CFP) None [source]
- _process_sell_cfp(cfp: scml.scml2019.common.CFP)[source]
- on_new_cfp(cfp: scml.scml2019.common.CFP) None [source]
Called when a new CFP for a product for which the agent registered interest is published
- can_produce(cfp: scml.scml2019.common.CFP, assume_no_further_negotiations=False) bool [source]
Whether or not we can produce the required item in time
- can_secure_needs(schedule: scml.scml2019.schedulers.ScheduleInfo, step: int)[source]
Finds if it is possible in principle to arrange these needs at the given time.
- Parameters:
schedule –
step –
Returns: