scml.scml2019 ============= .. py:module:: scml.scml2019 .. autoapi-nested-parse:: The implementation file for all entities needed for ANAC-SCML 2019. Participants need to provide a class inherited from `FactoryManager` that implements all of its abstract functions. Participants can optionally override any other methods of this class or implement new `NegotiatorUtility` class. Simulation steps: ----------------- #. prepare custom stats (call `_pre_step_stats`) #. sign contracts that are to be signed at this step calling `on_contract_signed` as needed #. step all existing negotiations `negotiation_speed_multiple` times handling any failed negotiations and creating contracts for any resulting agreements #. run all `Entity` objects registered (i.e. all agents). `Consumer` s run first then `FactoryManager` s then `Miner` s #. execute contracts that are executable at this time-step handling any breaches #. Custom Simulation Steps: #. step all factories (`Factory` objects) running any pre-scheduled commands #. Apply interests and pay loans #. remove expired `CFP` s #. Deliver any products that are in transportation #. remove any negotiations that are completed! #. update basic stats #. update custom stats (call `_post_step_stats`) Remarks about re-negotiation on breaches: ----------------------------------------- - The victim is asked first to specify the negotiation agenda (issues) then the perpetrator - renegotiations for breaches run immediately to completion independent from settings of `negotiation_speed_multiplier` and `immediate_negotiations`. That include conclusion and signing of any resulting agreements. Remarks about timing: --------------------- - The order of events within a single time-step are as follows: #. Contracts scheduled to be signed are signed. #. Scheduled negotiations run for the predefined number of steps. Any negotiation that result in a contract or fail may trigger other negotiations. #. If `immediate_negotiations`, some of the newly added negotiations may be concluded/failed. #. Any newly concluded contracts that are to be signed at this step are signed #. Contracts are executed including full execution of any re-negotiations and breaches are handled. Notice that if re-negotiation leads to new contracts, these will be concluded and signed immediately at this step. Please note the following about contract execution: - Products are moved from the seller's storage to a temporary *truck* as long as they are available at the time of contract execution. Because contract execution happens *before* actual production, outputs from production processes *CANNOT* be sold at the same time-step. #. Production is executed on all factories. For a `Process` to start/continue on a `Line`, all its inputs required at this time-step **MUST** be available in storage of the corresponding factory *by this point*. This implies that it is impossible for any processes to start at time-step *0* except if initial storage was nonzero. `FactoryManager` s are informed about processes that cannot start due to storage or fund shortage (or cannot continue due to storage shortage) through an `on_production_failure` call. #. Outputs of the `Process` are generated at *the end* of the corresponding time-step. It is immediately moved to storage. Because outputs are generated at the *end* of the step and inputs are consumed at the beginning, a factory cannot use outputs of a process as inputs to another process that starts at the same time-step. #. Products are moved from the temporary *truck* to the buyer's storage after the `transportation_delay` have passed at the *end* of the time-step. Transportation completes at the *end* of the time-step no matter what is the value for `transportation_delay`. This means that if a `FactoryManager` believes that it can produce some product at time *t*, it should never contract to sell it before *t+d + 1* where *d* is the `transportation_delay` (the *1* comes from the fact that contract execution happens *before* production). Even for a zero transportation delay, you cannot produce something and sell it in the same time-step. Moreover, the buyer should never use the product to be delivered at time *t* as an input to a production process that needs it before step *t+1*. #. When contracts are executed, the funds are deducted from the buyer's wallet at the *beginning* of the simulation step and deposited in the seller's wallet at the *end* of that step (similar to what happens to the products). This means that a factory manager cannot use funds it receives from sales at time *t* for buying products before *t + 1*. Remarks about ANAC 2019 SCML League: ------------------------------------ Given the information above, and settings for the ANAC 2019 SCML you can confirm for yourself that the following rules are all correct: #. No agents except miners should contract on delivery at time *0*. #. `FactoryManager` s should never sign contracts to sell the output of their production with delivery at *t* except if this production starts at step *t* and the contract is signed no later than than *t-1*. #. If not all inputs are available in storage, `FactoryManager` s should never sign contracts to sell the output of production with delivery at *t* later than *t-2* (and that is optimistic). Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/scml/scml2019/agent/index /autoapi/scml/scml2019/awi/index /autoapi/scml/scml2019/bank/index /autoapi/scml/scml2019/common/index /autoapi/scml/scml2019/consumers/index /autoapi/scml/scml2019/factory_managers/index /autoapi/scml/scml2019/helpers/index /autoapi/scml/scml2019/insurance/index /autoapi/scml/scml2019/miners/index /autoapi/scml/scml2019/schedulers/index /autoapi/scml/scml2019/simulators/index /autoapi/scml/scml2019/utils19/index /autoapi/scml/scml2019/visualizers/index /autoapi/scml/scml2019/world/index Attributes ---------- .. autoapisummary:: scml.scml2019.UNIT_PRICE scml.scml2019.TIME scml.scml2019.QUANTITY scml.scml2019.INVALID_STEP scml.scml2019.NO_PRODUCTION scml.scml2019.DEFAULT_NEGOTIATOR scml.scml2019.__all__ scml.scml2019.__all__ Classes ------- .. autoapisummary:: scml.scml2019.SCML2019Agent scml.scml2019.SCMLAWI scml.scml2019.DefaultBank scml.scml2019.Bank scml.scml2019.Product scml.scml2019.Process scml.scml2019.InputOutput scml.scml2019.RunningCommandInfo scml.scml2019.ManufacturingProfile scml.scml2019.ManufacturingProfileCompiled scml.scml2019.ProductManufacturingInfo scml.scml2019.FactoryStatusUpdate scml.scml2019.Job scml.scml2019.ProductionNeed scml.scml2019.MissingInput scml.scml2019.ProductionReport scml.scml2019.ProductionFailure scml.scml2019.FinancialReport scml.scml2019.SCMLAgreement scml.scml2019.SCMLAction scml.scml2019.CFP scml.scml2019.Loan scml.scml2019.InsurancePolicy scml.scml2019.Factory scml.scml2019.FactoryState scml.scml2019.Consumer scml.scml2019.ConsumptionProfile scml.scml2019.JustInTimeConsumer scml.scml2019.FactoryManager scml.scml2019.DoNothingFactoryManager scml.scml2019.GreedyFactoryManager scml.scml2019.DefaultInsuranceCompany scml.scml2019.InsuranceCompany scml.scml2019.Miner scml.scml2019.MiningProfile scml.scml2019.ReactiveMiner scml.scml2019.ScheduleInfo scml.scml2019.Scheduler scml.scml2019.GreedyScheduler scml.scml2019.FactorySimulator scml.scml2019.SlowFactorySimulator scml.scml2019.FastFactorySimulator scml.scml2019.DefaultGreedyManager scml.scml2019.SCML2019World scml.scml2019.Factory Functions --------- .. autoapisummary:: scml.scml2019.pos_gauss scml.scml2019._safe_max scml.scml2019.zero_runs scml.scml2019.transaction scml.scml2019.temporary_transaction scml.scml2019.anac2019_world scml.scml2019.anac2019_tournament scml.scml2019.anac2019_collusion scml.scml2019.anac2019_std scml.scml2019.balance_calculator scml.scml2019.anac2019_sabotage scml.scml2019.builtin_agent_types Package Contents ---------------- .. py:class:: SCML2019Agent(name: Optional[str] = None, ufun: Optional[negmas.UtilityFunction] = None) Bases: :py:obj:`negmas.situated.Agent` The base for all SCM Agents .. py:attribute:: line_profiles :type: Dict[int, scml.scml2019.common.ManufacturingProfileCompiled] A mapping specifying for each `Line` index, all the profiles used to run it in the factory .. py:attribute:: process_profiles :type: Dict[int, scml.scml2019.common.ManufacturingProfileCompiled] A mapping specifying for each `Process` index, all the profiles used to run it in the factory .. py:attribute:: producing :type: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]] Mapping from a product to all manufacturing processes that can generate it .. py:attribute:: consuming :type: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]] Mapping from a product to all manufacturing processes that can consume it .. py:attribute:: compiled_profiles :type: List[scml.scml2019.common.ManufacturingProfileCompiled] :value: [] All the profiles to be used by the factory belonging to this agent compiled to use indices .. py:attribute:: immediate_negotiations :value: False Whether or not negotiations start immediately upon registration (default is to start on the next production step) .. py:attribute:: negotiation_speed_multiple :type: int :value: 1 The number of negotiation rounds (steps) conducted in a single production step .. py:attribute:: transportation_delay :type: int :value: 0 Transportation delay in the system. Default is zero .. py:attribute:: products :type: List[scml.scml2019.common.Product] :value: [] List of products in the system .. py:attribute:: processes :type: List[scml.scml2019.common.Process] :value: [] List of processes in the system .. py:property:: awi :type: scml.scml2019.awi.SCMLAWI Returns the Agent-SCML2020World-Interface through which the agent does all of its actions in the world. A single excption is request_negotiation for which it is recommended to actually call the helper method on the agent itself instead of directly calling the AWI version. .. py:method:: reset() .. py:method:: is_clean() -> bool .. py:method:: init_() The initialization function called by the world directly. It does the following actions by default: 1. copies some of the static world settings to the agent to make them available without calling the AWI. 2. prepares production related properties like producing, consuming, line_profiles, compiled_profiles, etc. 3. registers interest in all products that the agent can produce or consume in its factory. 4. finally it calls any custom initialization logic implemented in `init`() .. seealso:: `init`, `step` .. py:method:: can_expect_agreement(cfp: scml.scml2019.common.CFP, margin: int) Checks if it is possible in principle to get an agreement on this CFP by the time it becomes executable :param margin: :param cfp: Returns: .. py:method:: _create_annotation(cfp: scml.scml2019.common.CFP, partner: str = None) Creates full annotation based on a cfp that the agent is receiving :param cfp: The call for proposal to create annotation about :param partner: The partner who requested the negotiation Remarks: - If the annotation is to be created for a CFP that was published by self, partner must be passed .. py:method:: _respond_to_negotiation_request(initiator: str, partners: List[str], issues: List[negmas.outcomes.Issue], annotation: Dict[str, Any], mechanism: negmas.common.NegotiatorMechanismInterface, role: Optional[str], req_id: Optional[str]) -> Optional[negmas.negotiators.Negotiator] Called by the mechanism to ask for joining a negotiation. The agent can refuse by returning a None :param initiator: The ID of the agent that initiated the negotiation request :param partners: The partner list (will include this agent) :param issues: The list of issues :param annotation: Any annotation specific to this negotiation. :param mechanism: The mechanism that started the negotiation :param role: The role of this agent in the negotiation :param req_id: The req_id passed to the AWI when starting the negotiation (only to the initiator). :returns: None to refuse the negotiation or a `Negotiator` object appropriate to the given mechanism to accept it. Remarks: - It is expected that world designers will introduce a better way to respond and override this function to call it .. py:method:: request_negotiation(cfp: scml.scml2019.common.CFP, negotiator: negmas.negotiators.Negotiator = None, ufun: negmas.UtilityFunction = None) -> bool Requests a negotiation from the AWI while keeping track of available negotiation requests :param cfp: :param negotiator: :param ufun: :returns: Whether the negotiation request was successful indicating that the partner accepted the negotiation .. py:method:: on_contract_executed(contract: negmas.situated.Contract) -> None :abstractmethod: Called after successful contract execution for which the agent is one of the partners. .. py:method:: on_contract_breached(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], resolution: Optional[negmas.situated.Contract]) -> None :abstractmethod: Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:method:: confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) -> bool :abstractmethod: called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached .. py:method:: on_contract_nullified(contract: negmas.situated.Contract, bankrupt_partner: str, compensation: float) -> None :abstractmethod: Will be called whenever a contract the agent is involved in is nullified because another partner went bankrupt .. py:method:: on_agent_bankrupt(agent_id: str) -> None :abstractmethod: Will be called whenever any agent goes bankrupt :param agent_id: The ID of the agent that went bankrupt Remarks: - Agents can go bankrupt in two cases: 1. Failing to pay one installments of a loan they bought and refusing (or being unable to) get another loan to pay it. 2. 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` and `respond_to_negotiation_request` callbacks by pulling the bulletin-board using the helper function `is_bankrupt` of their AWI. .. py:method:: confirm_partial_execution(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach]) -> bool :abstractmethod: Will be called whenever a contract cannot be fully executed due to breaches by the other partner. :param contract: The contract that was breached :param breaches: A list of all the breaches committed. Remarks: - Will not be called if both partners committed breaches. .. py:method:: confirm_contract_execution(contract: negmas.situated.Contract) -> bool :abstractmethod: Called before executing any agreement .. py:method:: respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) -> Optional[negmas.negotiators.Negotiator] :abstractmethod: Called when a prospective partner requests a negotiation to start .. py:method:: on_new_cfp(cfp: scml.scml2019.common.CFP) :abstractmethod: Called when a new CFP for a product for which the agent registered interest is published .. py:method:: on_remove_cfp(cfp: scml.scml2019.common.CFP) :abstractmethod: Called when a new CFP for a product for which the agent registered interest is removed .. py:method:: on_new_report(report: scml.scml2019.common.FinancialReport) :abstractmethod: Called whenever a financial report is published. :param 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 .. py:method:: on_inventory_change(product: int, quantity: int, cause: str) -> None :abstractmethod: Received whenever something moves in or out of the factory's storage :param product: Product index. :param quantity: Negative value for products moving out and positive value for products moving in :param 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). .. py:method:: on_cash_transfer(amount: float, cause: str) -> None :abstractmethod: Received whenever money is transferred to the factory or from it. :param amount: Amount of money (negative for transfers out of the factory, positive for transfers to it). :param 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). .. py:class:: SCMLAWI(world: negmas.situated.world.World, agent: negmas.situated.agent.Agent) Bases: :py:obj:`negmas.situated.AgentWorldInterface` A single contact point between SCML agents and the world simulation. The agent can access the world simulation in one of two ways: 1. Attributes and methods available in this Agent-SCML2020World-Interface 2. Attributes and methods in the `FactoryManager` object itself which provide handy shortcuts to the agent-world interface **Attributes** *Simulation settings* - `current_step` : Current simulation step - `default_signing_delay` : The grace period allowed between contract conclusion and signature by default (i.e. if not agreed upon during the negotiation) - `n_steps` : Total number of simulation steps. - `relative_time` : The fraction of total simulation time elapsed (it will be a number between 0 and 1) *Production Graph* - `products` : A list of `Product` objects giving all products defined in the world simulation - `processes` : A list of `Process` objects giving all products defined in the world simulation *Agent Related* - `state` : The current private state available to the agent. In SCML it is a `FactoryState` object. **Methods** *Production Control* - `schedule_job` : Schedules a `Job` for production sometime in the future - `schedule_production` : Schedules production using profile number instead of a `Job` object - `cancel_production` : Cancels already scheduled production (if it did not start yet) or stop a running production. - `execute` : A general function to execute any command on the factory. There is no need to directly call this function as the SCMLAWI provides convenient functions (e.g. `schedule_job` , `hide_funds` , etc) to achieve the same goal without having to worry about creating `Action` objects *Storage and Wallet Control* - `hide_funds` : Hides funds from the view of the simulator. Note that when bankruptcy is considered, hidden funds are visible to the simulator. - `hide_inventory` : Hides inventory from the view of the simulator. Note that when bankruptcy is considered, hidden funds are visible to the simulator. - `unhide_funds` : Un-hides funds hidden earlier with a call to `hide_funds` - `unhide_inventory` : Un-hides inventory hidden earlier with a call to `hide_inventory` *Negotiation and CFP Control* - `register_cfp` : Registers a Call-for-Proposals on the bulletin board. - `remove_cfp` : Removes a Call-for-Proposals from the bulletin board. - `request_negotiation` : Requests a negotiation based on the content of a CFP published on the bulletin-board. *It is recommended not to use this method directly and to request negotiations using the request_negotiation method of `FactoryManager` (i.e. use self.request_negotiation instead of self.awi.request_negotiation). This makes it possible for NegMAS to keep track of existing `requested_negotiations` and `running_negotiations` for you. *Notification Control* - `receive_financial_reports` : Register/unregisters interest in receiving financial reports for an agent, a set of agents or all agents. - `register_interest` : registers interest in receiving CFPs about a set of products. By default all `FactoryManager` objects are registered to receive all CFPs for any product they can produce or need to consumer according to their line-profiles. - `unregister_interest` : unregisters interest in receiving CFPs about a set of products. *Information about Other Agents* - `is_bankrupt` : Asks about the bankruptcy status of an agent - `receive_financial_reports` : Register/unregisters interest in receiving financial reports for an agent, a set of agents or all agents. - `reports_at` : reads *all* financial reports produced at a given time-step - `reports_for` : reads *all* financial reports of a given agent *Financial Control* - `evaluate_insurance` : Asks for the premium to be paid for insuring against partner breaches for a given contract - `buy_insurance` : Buys an insurance against partner breaches for a given contract *Bulletin-Board* The bulletin-board is a key-value store. These methods allows the agent to interact with it. *The `SCMLAWI` provides convenient functions for recording to the bulletin-board so you mostly need to use read/query functions*. - `bb_read` : Reads a complete section or a single value from the bulletin-board - `bb_query` : Returns all records in the given section/sections of the bulletin-board that satisfy a query - `bb_record` : Registers a record in the bulletin-board. - `bb_remove` : Removes a record from the bulletin-board. The following list of sections are available in the SCML Bulletin-Board (Use the exact string for the ``section`` parameter of any method starting with ``bb_``): - **cfps**: All CFPs currently on the board. The key is the CFP ID - **products**: A list of all products. The key is the product index/ID - **processes**: A list of all processes. The key is the product index/ID - **bankruptcy**: The bankruptcy list giving names of all bankrupt agents. - **reports_time**: Financial reports indexed by time. - **reports_agent**: Financial reports indexed by agent - **breaches**: Breach-list indexed by breach ID giving all breaches committed in the system - **settings**: Static settings of the simulation. The following settings are currently available: - *breach_penalty_society*: Penalty of breaches paid to society (as a fraction of contract value). This is always paid for every breach whether or not there is a negotiated breach. - *breach_penalty_victim*: Penalty of breaches paid to victim (as a fraction of contract value). This is always paid for every breach whether or not there is a negotiated breach. - *immediate_negotiations*: Whether negotiations start immediately when registered (the other possibility -- which is the default -- is for them to start at the next production step). - *negotiation_speed_multiple*: Number of negotiation steps that finish in a single production step. - *negotiation_n_steps*: Maximum allowed number of steps (rounds) in any negotiation - *negotiation_step_time_limit*: The maximum real-time allowed for each negotiation step (round) - *negotiation_time_limit*: The time limit for a complete negotiation. - *transportation_delay*: Transportation delay when products are moved between factories. Default is zero. - *transfer_delay*: The delay in transferring funds between factories when executing a contract. Default is zero. - *n_steps*: Number of simulation steps - *time_limit*: Time limit for the complete simulation - stats: Global statistics about the simulation. **Not available for SCML 2019 league**. *Logging* - `logerror` : Logs an error in the world simulation log file - `logwarning` : Logs a warning in the world simulation log file - `loginfo` : Logs information in the world simulation log file - `logdebug` : Logs debug information in the world simulation log file .. py:method:: register_cfp(cfp: scml.scml2019.common.CFP) -> None Registers a CFP .. py:method:: register_interest(products: List[int]) -> None registers interest in receiving callbacks about CFPs related to these products .. py:method:: unregister_interest(products: List[int]) -> None registers interest in receiving callbacks about CFPs related to these products .. py:method:: remove_cfp(cfp: scml.scml2019.common.CFP) -> bool Removes a CFP .. py:method:: evaluate_insurance(contract: negmas.situated.Contract, t: int = None) -> Optional[float] Can be called to evaluate the premium for insuring the given contract against breaches committed by others :param contract: hypothetical contract :param t: time at which the policy is to be bought. If None, it means current step .. py:method:: buy_insurance(contract: negmas.situated.Contract) -> bool Buys insurance for the contract by the premium calculated by the insurance company. Remarks: The agent can call `evaluate_insurance` to find the premium that will be used. .. py:method:: _create_annotation(cfp: scml.scml2019.common.CFP, partner: str = None) Creates full annotation based on a cfp that the agent is receiving .. py:method:: request_negotiation(cfp: scml.scml2019.common.CFP, req_id: str, roles: List[str] = None, mechanism_name: str = None, mechanism_params: Dict[str, Any] = None) -> bool Requests a negotiation with the publisher of a given CFP :param cfp: The CFP to negotiate about :param req_id: A string that is passed back to the caller in all callbacks related to this negotiation :param roles: The roles of the CFP publisher and the agent (in that order). By default no roles are passed (None) :param mechanism_name: The mechanism type to use. If not given the default mechanism from the world will be used :param mechanism_params: Parameters of the mechanism :returns: Success of failure of the negotiation request Remarks: - The `SCML2019Agent` class implements another request_negotiation method that does not receive a `req_id`. This helper method is recommended as it generates the required req_id and passes it keeping track of requested negotiations (and later of running negotiations). Call this method direclty *only* if you do not intend to use the `requested_negotiations` and `running_negotiations` properties of the `SCML2019Agent` class .. py:method:: request_negotiation_about(issues: List[negmas.Issue], partners: List[str], req_id: str, roles: List[str] = None, annotation: Optional[Dict[str, Any]] = None, mechanism_name: str = None, mechanism_params: Dict[str, Any] = None) Overrides the method of the same name in the base class to disable it in SCM Worlds. **Do not call this method** .. py:method:: is_bankrupt(agent_id: str) -> bool Checks whether the given agent is bankrupt :param agent_id: Agent ID :returns: The bankruptcy state of the agent .. py:method:: reports_for(agent_id: str) -> List[scml.scml2019.common.FinancialReport] Gets all financial reports of an agent (in the order of their publication) :param agent_id: Agent ID Returns: .. py:method:: reports_at(step: int = None) -> Dict[str, scml.scml2019.common.FinancialReport] Gets all financial reports of all agents at a given step :param step: Step at which the reports are required. If None, the last set of reports is returned :returns: A dictionary with agent IDs in keys and their financial reports at the given time as values .. py:method:: receive_financial_reports(receive: bool = True, agents: Optional[List[str]] = None) -> None Registers/unregisters interest in receiving financial reports :param receive: True to receive and False to stop receiving :param agents: If given reception is enabled/disabled only for the given set of agents. Remarks: - by default financial reports are not sent to any agents. To opt-in to receive financial reports, call this method. .. py:property:: state :type: scml.scml2019.common.FactoryState Returns the private state of the agent in that world. In the SCML world, that is a reference to its factory. You are allowed to read information from the returned `Factory` but **not to modify it or call ANY methods on it that modify the state**. .. py:property:: products :type: List[scml.scml2019.common.Product] Products in the world .. py:property:: processes :type: List[scml.scml2019.common.Process] Processes in the world .. py:method:: schedule_production(profile: int, step: int, contract: Optional[negmas.situated.Contract] = None, override: bool = True) -> None Schedules production on the agent's factory :param profile: Index of the profile in the agent's `compiled_profiles` list :param step: The step to start production according to the given profile :param contract: The contract for which the production is scheduled (optional) :param override: Whether to override existing production jobs schedules at the same time. .. py:method:: stop_production(line: int, step: int, contract: Optional[negmas.situated.Contract], override: bool = True) Stops/cancels production scheduled at the given line at the given time. :param line: One of the factory lines (index) :param step: Step to stop/cancel production at :param contract: The contract for which the job is scheduled (optional) :param override: Whether to override existing production jobs schedules at the same time. .. py:attribute:: cancel_production Stops/cancels production scheduled at the given line at the given time. :param line: One of the factory lines (index) :param step: Step to stop/cancel production at .. py:method:: schedule_job(job: scml.scml2019.common.Job, contract: Optional[negmas.situated.Contract]) Schedules production using a `Job` object. This can be used to schedule any kind of job :param job: The job description :param contract: The contract for which the job is scheduled (optional) Remarks: - Notice that actions that require the profile member of Job (run) never use the line member and vice versa. .. py:method:: hide_inventory(product: int, quantity: int) -> None Hides the given quantity of the given product so that it is not accessible by the simulator and does not appear in reports etc. :param product: product index :param quantity: the amount of the product to hide Remarks: - if the current quantity in storage of the product is less than the amount to be hidden, whatever quantity exists is hidden - hiding is always immediate .. py:method:: hide_funds(amount: float) -> None Hides the given amount of money so that it is not accessible by the simulator and does not appear in reports etc. :param amount: The amount of money to hide Remarks: - if the current cash in the agent's wallet is less than the amount to be hidden, all the cash is hidden. - hiding is always immediate .. py:method:: unhide_inventory(product: int, quantity: int) -> None Un-hides the given quantity of the given product so that it is not accessible by the simulator and does not appear in reports etc. :param product: product index :param quantity: the amount of the product to hide Remarks: - if the current quantity in storage of the product is less than the amount to be hidden, whatever quantity exists is hidden - hiding is always immediate .. py:method:: unhide_funds(amount: float) -> None Un-hides the given amount of money so that it is not accessible by the simulator and does not appear in reports etc. :param amount: The amount of money to unhide Remarks: - if the current cash in the agent's wallet is less than the amount to be hidden, all the cash is hidden. - hiding is always immediate .. py:class:: DefaultBank(minimum_balance: float, interest_rate: float, interest_max: float, balance_at_max_interest: float, installment_interest: float, time_increment: float, a2f: dict[str, scml.scml2019.common.Factory], disabled: bool = False, name: str | None = None) Bases: :py:obj:`Bank` Represents a bank in the world .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: respond_to_negotiation_request(initiator: str, partners: list[str], issues: list[negmas.Issue], annotation: dict[str, Any], mechanism: negmas.Mechanism, role: Optional[str], req_id: str) -> Optional[negmas.Negotiator] .. py:attribute:: storage :type: dict[int, int] .. py:attribute:: wallet :type: float :value: 0.0 .. py:attribute:: disabled :value: False .. py:attribute:: loans :type: dict[scml.scml2019.agent.SCML2019Agent, list[scml.scml2019.common.Loan]] .. py:attribute:: minimum_balance .. py:attribute:: interest_rate .. py:attribute:: interest_max .. py:attribute:: installment_interest .. py:attribute:: time_increment .. py:attribute:: balance_at_max_interest .. py:attribute:: _credit_rating :type: dict[str, float] .. py:attribute:: a2f .. py:method:: set_renegotiation_agenda(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach]) -> Optional[negmas.situated.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract being breached :param breaches: All breaches on `contract` :returns: Renegotiation agenda (issues to negotiate about to avoid reporting the breaches). .. py:method:: respond_to_renegotiation_request(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach], agenda: negmas.situated.RenegotiationRequest) -> Optional[negmas.Negotiator] Called to respond to a renegotiation request :param agenda: :param contract: :param breaches: Returns: .. py:method:: _evaluate_loan(agent: scml.scml2019.agent.SCML2019Agent, amount: float, n_installments: int, starts_at: int, installment_loan=False) -> Optional[scml.scml2019.common.Loan] Evaluates the interest that will be imposed on the agent to buy_loan that amount .. py:method:: evaluate_loan(agent: scml.scml2019.agent.SCML2019Agent, amount: float, start_at: int, n_installments: int) -> Optional[scml.scml2019.common.Loan] Evaluates the interest that will be imposed on the agent to buy_loan that amount .. py:method:: _buy_loan(agent: scml.scml2019.agent.SCML2019Agent, loan: scml.scml2019.common.Loan, beneficiary: negmas.situated.Agent, contract: Optional[negmas.situated.Contract], bankrupt_if_rejected=False) -> Optional[scml.scml2019.common.Loan] .. py:method:: buy_loan(agent: scml.scml2019.agent.SCML2019Agent, amount: float, n_installments: int, beneficiary: negmas.situated.Agent, contract: Optional[negmas.situated.Contract], force: bool = False) -> Optional[scml.scml2019.common.Loan] Gives a loan of amount to agent at the interest calculated using `evaluate_loan` .. py:method:: step() Takes payments from agents .. py:method:: _reduce_credit_rating(agent: negmas.situated.Agent, unavailable: float) Updates the credit rating when the agent fails to pay an installment .. py:method:: credit_rating(agent_id: str) -> float .. py:class:: Bank(*args, **kwargs) Bases: :py:obj:`negmas.situated.Agent`, :py:obj:`abc.ABC` Base class for all banks .. py:attribute:: _world :value: None .. py:method:: _respond_to_negotiation_request(initiator: str, partners: list[str], issues: list[negmas.Issue], annotation: dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, role: Optional[str], req_id: Optional[str]) -> Optional[negmas.Negotiator] Called by the mechanism to ask for joining a negotiation. The agent can refuse by returning a None :param initiator: The ID of the agent that initiated the negotiation request :param partners: The partner list (will include this agent) :param issues: The list of issues :param annotation: Any annotation specific to this negotiation. :param mechanism: The mechanism that started the negotiation :param role: The role of this agent in the negotiation :param req_id: The req_id passed to the AWI when starting the negotiation (only to the initiator). :returns: None to refuse the negotiation or a `Negotiator` object appropriate to the given mechanism to accept it. Remarks: - It is expected that world designers will introduce a better way to respond and override this function to call it .. py:method:: on_neg_request_rejected(req_id: str, by: Optional[list[str]]) Called when a requested negotiation is rejected :param req_id: The request ID passed to _request_negotiation :param by: A list of agents that refused to participate or None if the failure was for another reason .. py:method:: on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface) Called when a requested negotiation is accepted .. py:method:: on_negotiation_failure(partners: list[str], annotation: dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: on_negotiation_success(contract: negmas.situated.Contract, mechanism: negmas.NegotiatorMechanismInterface) -> None Called whenever a negotiation ends with agreement .. py:method:: on_contract_signed(contract: negmas.situated.Contract) -> None Called whenever a contract is signed by all partners .. py:method:: on_contract_cancelled(contract: negmas.situated.Contract, rejectors: list[str]) -> None Called whenever at least a partner did not sign the contract .. py:method:: sign_contract(contract: negmas.situated.Contract) -> Optional[str] Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed. .. py:method:: respond_to_negotiation_request(initiator: str, partners: list[str], issues: list[negmas.Issue], annotation: dict[str, Any], mechanism: negmas.Mechanism, role: Optional[str], req_id: str) -> Optional[negmas.Negotiator] .. py:method:: on_contract_executed(contract: negmas.situated.Contract) -> None Called after successful contract execution for which the agent is one of the partners. .. py:method:: on_contract_breached(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach], resolution: Optional[negmas.situated.Contract]) -> None Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:data:: UNIT_PRICE :value: 2 Index of unit price in negotiation issues .. py:data:: TIME :value: 1 Index of time in negotiation issues .. py:data:: QUANTITY :value: 0 Index of quantity in negotiation issues .. py:class:: Product .. py:attribute:: __slots__ :value: ['id', 'production_level', 'name', 'expires_in', 'catalog_price'] A product that can be transacted in. .. py:attribute:: id :type: int Product index. Must be set during construction and **MUST** be unique for products in the same world .. py:attribute:: production_level :type: int The level of this product in the production graph. .. py:attribute:: name :type: str Object name .. py:attribute:: expires_in :type: Optional[int] Number of steps within which the product must be consumed. None means never .. py:attribute:: catalog_price :type: Optional[float] Catalog price of the product. .. py:method:: __str__() String representation is simply the name .. py:method:: __post_init__() .. py:method:: __hash__() .. py:class:: Process .. py:attribute:: __slots__ :value: ['id', 'production_level', 'name', 'inputs', 'outputs', 'historical_cost'] .. py:attribute:: id :type: int A manufacturing process. .. py:attribute:: production_level :type: int The level of this process in the production graph .. py:attribute:: name :type: str Object name .. py:attribute:: inputs :type: List[InputOutput] list of input product name + quantity required and time of consumption relative to the time required for production (value from 0 to 1) .. py:attribute:: outputs :type: List[InputOutput] list of output product names, quantity required and when it becomes available relative to the time required for production (value from 0 to 1) .. py:attribute:: historical_cost :type: Optional[float] Average cost for running this process in some world. Filled by the world .. py:method:: __str__() String representation is simply the name .. py:method:: __post_init__() .. py:method:: __hash__() The hash depends only on the name .. py:class:: InputOutput An input/output to a production process .. py:attribute:: __slots__ :value: ['product', 'quantity', 'step'] .. py:attribute:: product :type: int Index of the product used as input or output .. py:attribute:: quantity :type: int Quantity needed/produced .. py:attribute:: step :type: float Relative time within the production at which the input is needed (output is produced) .. py:class:: RunningCommandInfo .. py:attribute:: __slots__ :value: ['profile', 'beg', 'end', 'action', 'updates', 'step', 'paused'] .. py:attribute:: profile :type: ManufacturingProfile The manufacturing profile associated with this command. Most importantly, it gives the process and line .. py:attribute:: beg :type: int The time the command is to be executed .. py:attribute:: end :type: int The number of steps starting at `beg` for this command to end (it ends at end - 1) .. py:attribute:: step :type: int The time-step relative to `beg` at the factory is currently executing the `Process` indicated in `profile`. `step` will always go up by one every simulation step except if the command is paused where it does not change .. py:attribute:: paused :type: bool True if the command is paused .. py:attribute:: action :type: str The command type. For the current implementation it will always be run or none for no command .. py:attribute:: updates :type: Dict[int, FactoryStatusUpdate] The status updates implied by this command with their times relative to `beg` .. py:property:: n_steps :type: int .. py:method:: ended_before(t: int) .. py:method:: started_on_or_after(t: int) .. py:method:: __str__() .. py:property:: is_none .. py:method:: do_nothing() :classmethod: .. py:data:: INVALID_STEP :value: -1000 .. py:data:: NO_PRODUCTION :value: -1 .. py:class:: ManufacturingProfile The costs/time required for running a process on a line (with associated cancellation costs etc). This data-structure carries full information about the `Process` es instead of just its index as in `ManufacturingProfileCompiled`. It is intended to be used to construct factories .. seealso:: `Factory` .. py:attribute:: __slots__ :value: ['n_steps', 'cost', 'initial_pause_cost', 'running_pause_cost', 'resumption_cost',... .. py:attribute:: n_steps :type: int Number of steps needed to complete the manufacturing .. py:attribute:: cost :type: float Cost of manufacturing .. py:attribute:: initial_pause_cost :type: float Cost of pausing incurred only at the step a pause is started .. py:attribute:: running_pause_cost :type: float Running cost of pausing .. py:attribute:: resumption_cost :type: float Cost of resuming a process .. py:attribute:: cancellation_cost :type: float Cost of cancelling the process before the last step .. py:attribute:: line :type: int The line index .. py:attribute:: process :type: Process The `Process` associated with this profile .. py:class:: ManufacturingProfileCompiled The costs/time required for running a process on a line (with associated cancellation costs etc). .. seealso:: `Factory` .. py:attribute:: __slots__ :value: ['n_steps', 'cost', 'initial_pause_cost', 'running_pause_cost', 'resumption_cost',... .. py:attribute:: n_steps :type: int Number of steps needed to complete the manufacturing .. py:attribute:: cost :type: float Cost of manufacturing .. py:attribute:: initial_pause_cost :type: float Cost of pausing incurred only at the step a pause is started .. py:attribute:: running_pause_cost :type: float Running cost of pausing .. py:attribute:: resumption_cost :type: float Cost of resuming a process .. py:attribute:: cancellation_cost :type: float Cost of cancelling the process before the last step .. py:attribute:: line :type: int The line index .. py:attribute:: process :type: int The `Process` index .. py:method:: from_manufacturing_profile(profile: ManufacturingProfile, process2ind: Dict[Process, int]) :classmethod: .. py:class:: ProductManufacturingInfo Gives full information about a manufacturing process that can generate or consume a product. .. seealso:: `consuming` and `producing` of `Factory` .. py:attribute:: __slots__ :value: ['profile', 'quantity', 'step'] .. py:attribute:: profile :type: int The `ManufacturingProfile` index .. py:attribute:: quantity :type: int The quantity generated/consumed by running this manufacturing info .. py:attribute:: step :type: int The step from the beginning at which the `Product` is received/consumed .. py:class:: FactoryStatusUpdate .. py:attribute:: __slots__ :value: ['balance', 'storage'] .. py:attribute:: balance :type: float The update to the balance .. py:attribute:: storage :type: Dict[int, int] The updates to be applied to the storage after this step .. py:method:: __post_init__() .. py:method:: make_empty() -> None Makes the update an empty one. .. py:method:: combine(other: FactoryStatusUpdate) -> None Combines this status update with another one in place :param other: The other status update :returns: None .. py:method:: combine_sets(dst: Dict[int, FactoryStatusUpdate], src: Dict[int, FactoryStatusUpdate]) :classmethod: Combines a set of updates over time with another in place (overriding `first`) :param dst: First set of updates to be combined into :param src: second set of updates to be combined from Returns: .. py:property:: is_empty .. py:method:: empty() :classmethod: .. py:method:: __str__() .. py:class:: Job Describes a job to be run on one production line of a `Factory`. .. py:attribute:: __slots__ :value: ['profile', 'time', 'line', 'action', 'contract', 'override'] .. py:attribute:: profile :type: int The process for run commands .. py:attribute:: time :type: int The time the command is to be executed .. py:attribute:: line :type: int Index of the line on which the job is to be scheduled. Notice that it will be ignored for `run` actions. .. py:attribute:: action :type: str The command type. For the current implementation it can be run/pause/resume/stop/cancel with `cancel` cancelling any other command type. .. py:attribute:: contract :type: Optional[negmas.situated.Contract] The sell contract associated with the command .. py:attribute:: override :type: bool Whether to override existing commands when the job is to be executed. .. py:method:: __str__() .. py:method:: is_cancelling(job: Job) -> bool Determines if the given jobs cancels this one :param job: Returns: .. py:class:: ProductionNeed Describes some quantity of a product that is needed to honor a (sell) contract. .. py:attribute:: __slots__ :value: ['product', 'needed_for', 'quantity_to_buy', 'quantity_in_storage', 'step'] .. py:attribute:: product :type: int The product needed .. py:attribute:: needed_for :type: negmas.situated.Contract The contract for which the product is needed .. py:attribute:: quantity_to_buy :type: int The quantity need to be bought .. py:attribute:: quantity_in_storage :type: int The quantity already found in storage .. py:attribute:: step :type: int The time step at which the product is needed .. py:method:: __str__() String representation is simply the name .. py:class:: MissingInput .. py:attribute:: __slots__ :value: ['product', 'quantity'] .. py:attribute:: product :type: int .. py:attribute:: quantity :type: int .. py:method:: __str__() .. py:class:: ProductionReport .. py:attribute:: line :type: int ID of the line .. py:attribute:: started :type: Optional[RunningCommandInfo] Commands started .. py:attribute:: continuing :type: Optional[RunningCommandInfo] Command that is continuing .. py:attribute:: finished :type: Optional[RunningCommandInfo] Command finished .. py:attribute:: failure :type: Optional[ProductionFailure] Failures .. py:attribute:: updates :type: FactoryStatusUpdate Updates applied to the factory .. py:property:: failed .. py:property:: is_empty .. py:property:: no_production .. py:method:: __str__() .. py:class:: ProductionFailure .. py:attribute:: __slots__ :value: ['line', 'command', 'missing_inputs', 'missing_money', 'missing_space'] .. py:attribute:: line :type: int ID of the line that failed .. py:attribute:: command :type: RunningCommandInfo Information about the command that failed .. py:attribute:: missing_inputs :type: List[MissingInput] The missing inputs if any with their quantities .. py:attribute:: missing_money :type: float The amount of money needed for production that is not available .. py:attribute:: missing_space :type: int The amount space needed in storage but not found .. py:method:: __str__() .. py:class:: FinancialReport Reports that financial standing of an agent at a given time in the simulation .. py:attribute:: agent :type: str Agent ID .. py:attribute:: step :type: int Time of the report .. py:attribute:: cash :type: float Cash at hand .. py:attribute:: liabilities :type: float Total liabilities (loans) .. py:attribute:: inventory :type: float Value of everything in the inventory priced at catalog prices. .. py:attribute:: credit_rating :type: float The agent's credit rating as a fraction of the maximum credit rating (1 indicates highest credit rating). .. py:property:: balance The balance of the agent defined as the difference between its available cash + inventory and its liabilities Remarks: - If the inventory was not calculated (due to having at least one product with unknown catalog price), it is used as zero in the equation. .. py:class:: SCMLAgreement .. py:attribute:: time :type: int delivery time .. py:attribute:: unit_price :type: float unit price .. py:attribute:: quantity :type: int quantity .. py:attribute:: penalty :type: Optional[float] :value: None penalty .. py:attribute:: signing_delay :type: int :value: -1 Delay between agreement conclusion and signing it to be binding .. py:method:: __getitem__(k) .. py:method:: get(k, default=None) .. py:method:: asdict() .. py:method:: to_dict() .. py:method:: keys() .. py:method:: values() .. py:method:: items() .. py:class:: SCMLAction .. py:attribute:: line :type: str Line to execute the action on (need not be given if the profile is given .. py:attribute:: profile :type: Optional[int] Index of the profile to execute .. py:attribute:: action :type: str The action which may be start, stop, pause, resume .. py:attribute:: time :type: int :value: 0 Time to execute the action at .. py:class:: CFP A Call for proposal upon which a negotiation can start .. py:attribute:: is_buy :type: bool If true, the author wants to buy otherwise to sell. Non-negotiable. .. py:attribute:: publisher :type: str the publisher name. Non-negotiable. .. py:attribute:: product :type: int product ID. Non-negotiable. .. py:attribute:: time :type: Union[int, Tuple[int, int], List[int]] delivery time. May be negotiable. .. py:attribute:: unit_price :type: Union[float, Tuple[float, float], List[float]] unit price. May be negotiable. .. py:attribute:: quantity :type: Union[int, Tuple[int, int], List[int]] quantity. May be negotiable. .. py:attribute:: penalty :type: Optional[Union[float, Tuple[float, float], List[float]]] :value: None penalty per missing item in case the seller cannot provide the required quantity. May be negotiable. .. py:attribute:: signing_delay :type: Optional[Union[int, Tuple[int, int], List[int]]] :value: None The grace period after which the agents are asked to confirm signing the contract .. py:attribute:: money_resolution :type: Optional[float] :value: None If not None then it is the minimum unit of money (e.g. 1 for dollar, 0.01 for cent, etc) .. py:attribute:: id :type: str :value: '' Unique CFP ID .. py:method:: __str__() .. py:method:: satisfies(query: Dict[str, Any]) -> bool Tests whether the CFP satisfies the conditions set by the query :param query: A dictionary given the conditions. See `Remarks` for details Remarks: - The query dictionary can be used to specify any conditions that are required in the CFP. Only CFPs that satisfy ALL the conditions specified in the query are considered satisfying the query. The following keys can be set with corresponding meanings: is_buy True or False. If both are OK, just do not add this key publisher A string or `SCML2019Agent` specifying a specific publisher publishers A list of publishers (see publisher key) product A string specifying a product name products A list of products (see product key) time A number, list or 2-items-tuple (range) specifying possible times to consider satisfactory unit_price A number, list or 2-items-tuple (range) specifying possible prices to consider satisfactory quantity A number, list or 2-items-tuple (range) specifying possible quantities to consider OK penalty A number, list or 2-items-tuple (range) specifying possible penalties to consider satisfactory .. py:property:: issues Returns the set of issues associated with this CFP. Notice that some of the issues may have a single value .. py:property:: outcomes .. py:property:: min_time .. py:property:: max_time .. py:property:: min_quantity .. py:property:: max_quantity .. py:property:: min_unit_price .. py:property:: max_unit_price .. py:property:: min_signing_delay .. py:property:: max_signing_delay .. py:property:: min_penalty .. py:property:: max_penalty .. py:method:: to_dict() .. py:method:: from_dict(idict: Dict[str, Any], class_name: Optional[str] = None) -> CFP :classmethod: .. py:class:: Loan .. py:attribute:: amount :type: float Loan amount .. py:attribute:: starts_at :type: int The time-step at which payment starts .. py:attribute:: total :type: float The total to be paid including the amount + interests .. py:attribute:: interest :type: float The interest rate per step .. py:attribute:: installment :type: float The amount to be paid in one installment .. py:attribute:: n_installments :type: int The number of installments .. py:method:: __str__() .. py:class:: InsurancePolicy .. py:attribute:: premium :type: float .. py:attribute:: contract :type: negmas.situated.Contract .. py:attribute:: at_time :type: int .. py:attribute:: against :type: scml.scml2019.agent.SCML2019Agent .. py:class:: Factory Represents a factory within an SCML world. It is only accessed by the SCML2020World so it need not be made public. .. py:attribute:: initial_storage :type: dataclasses.InitVar[Dict[int, int]] Initial storage .. py:attribute:: initial_wallet :type: dataclasses.InitVar[float] :value: 0.0 Initial Wallet .. py:attribute:: id :type: str :value: '' Object name .. py:attribute:: profiles :type: List[ManufacturingProfile] :value: [] A list of profiles used to initialize the factory .. py:attribute:: max_storage :type: int :value: 9223372036854775807 Maximum storage allowed in this factory .. py:attribute:: min_storage :type: int :value: 0 Minimum allowed storage per product .. py:attribute:: min_balance :type: int | float :value: 0 Minimum allowed balance .. py:attribute:: initial_balance :type: float :value: 0.0 Initial balance of the factory .. py:attribute:: _commands :type: numpy.ndarray The production command currently running .. py:attribute:: _line_schedules :type: numpy.ndarray .. py:attribute:: _storage :type: Dict[int, int] Mapping from product index to the amount available in the inventory .. py:attribute:: _total_storage :type: int :value: 0 Total storage .. py:attribute:: _wallet :type: float :value: 0 Money available for purchases .. py:attribute:: _hidden_money :type: float :value: 0 Amount of money hidden by the agent .. py:attribute:: _hidden_storage :type: Dict[int, int] Mapping from product index to the amount hidden by the agent .. py:attribute:: _loans :type: float :value: 0.0 The total money owned as loans .. py:attribute:: _n_lines :type: int The number of lines in the factory, will be set using the `profiles` input .. py:attribute:: _jobs :type: Dict[Tuple[int, int], Job] The jobs waiting to be run on the factory indexed by (time, line) tuples .. py:attribute:: _next_step :type: int :value: 0 Current simulation step .. py:attribute:: _carried_updates :type: FactoryStatusUpdate Carried updates from last executed command .. py:attribute:: _world :type: negmas.situated.World :value: None .. py:method:: attach_to_world(world) .. py:method:: __post_init__(initial_storage: Dict[int, int], initial_wallet=0.0) .. py:property:: hidden_money :type: float .. py:property:: hidden_storage :type: Dict[int, int] .. py:property:: n_lines :type: int .. py:property:: jobs :type: Dict[Tuple[int, int], Job] .. py:property:: commands :type: numpy.ndarray .. py:property:: line_schedules :type: numpy.ndarray .. py:property:: wallet :type: float .. py:property:: storage :type: Dict[int, int] .. py:property:: loans :type: float .. py:property:: total_storage :type: int .. py:property:: balance :type: float The total balance of the factory .. py:property:: total_balance :type: float total balance including hidden money .. py:property:: next_step :type: int .. py:method:: add_loan(total: float) -> None .. py:method:: receive(payment: float) -> None .. py:method:: pay(payment: float) -> None .. py:method:: transport_to(product: int, quantity: int) -> None .. py:method:: buy(product: int, quantity: int, price: float) -> None .. py:method:: sell(product: int, quantity: int, price: float) -> None .. py:method:: transport_from(product: int, quantity: int) -> None .. py:method:: hide_funds(amount: float) -> None .. py:method:: hide_product(product: int, quantity: int) -> None .. py:method:: unhide_funds(amount: float) -> None .. py:method:: unhide_product(product: int, quantity: int) -> None .. py:method:: schedule(job: Job, override=False) -> None Schedules the given job at its `time` and `line` optionally overriding whatever was already scheduled :param job: :param override: :returns: Success/failure .. py:method:: _apply_updates(updates: FactoryStatusUpdate) -> None .. py:method:: step() -> List[ProductionReport] .. py:method:: _run(profile: ManufacturingProfile, override=True) -> None running is executed at the beginning of the step t :param profile: the profile to start giving both the line and process :param override: If true, override any running processes paying cancellation cost for these processes Remarks: - The output of a process that runs from step t to step t + n - 1 will only be in storage at step t + n .. py:method:: _pause(line: int) -> None pausing is executed at the end of the step :param line: the line on which the process is running :returns: The status updated for all times that need to be updated to cancel the command if it is not None. If None is returned then scheduling failed. :rtype: Optional[Dict[int, FactoryStatusUpdate]] Remarks: - Not implemented yet - pausing when nothing is running is not an error and will return an empty status update .. py:method:: _resume(line: int) -> None resumption is executed at the end of the step (starting next step count down) :param line: the line on which the process is running :returns: The status updated for all times that need to be updated to cancel the command if it is not None. If None is returned then scheduling failed. :rtype: Optional[Dict[int, FactoryStatusUpdate]] Remarks: - Not implemented yet - resuming when nothing is paused is not an error and will return an empty status update .. py:method:: _stop(line: int) -> None stopping is executed at the beginning of the current step :param line: the line on which the process is running :returns: The status updated for all times that need to be updated to cancel the command if it is not None. If None is returned then scheduling failed. :rtype: Optional[Dict[int, FactoryStatusUpdate]] Remarks: - stopping when nothing is running is not an error and will just return an empty schedule .. py:method:: _step_line(line: int) -> ProductionReport Steps the line to the time-step `t` assuming that it is already stepped to time-step t-1 given the storage :param line: the line to step :returns: ProductionReport .. py:class:: FactoryState Read Only State of a factory .. py:attribute:: max_storage :type: int Maximum storage allowed in this factory .. py:attribute:: line_schedules :type: numpy.ndarray An array of n_lines * n_steps giving the line schedules .. py:attribute:: storage :type: Dict[int, int] Mapping from product index to the amount available in the inventory .. py:attribute:: wallet :type: float Money available for purchases .. py:attribute:: hidden_money :type: float Amount of money hidden by the agent .. py:attribute:: hidden_storage :type: Dict[int, int] Mapping from product index to the amount hidden by the agent .. py:attribute:: loans :type: float The total money owned as loans .. py:attribute:: n_lines :type: int The number of lines in the factory, will be set using the `profiles` input .. py:attribute:: profiles :type: List[ManufacturingProfile] A list of profiles used to initialize the factory .. py:attribute:: next_step :type: int Next simulation step for this factory .. py:attribute:: commands :type: numpy.ndarray The production command currently running .. py:attribute:: jobs :type: Dict[Tuple[int, int], Job] The jobs waiting to be run on the factory indexed by (time, line) tuples .. py:data:: DEFAULT_NEGOTIATOR :value: 'negmas.sao.AspirationNegotiator' .. py:class:: Consumer(name: Optional[str] = None, ufun: Optional[negmas.UtilityFunction] = None) Bases: :py:obj:`scml.scml2019.agent.SCML2019Agent`, :py:obj:`abc.ABC` Base class of all consumer classes .. py:class:: ConsumptionProfile .. py:attribute:: schedule :type: Union[int, List[int]] :value: 0 .. py:attribute:: underconsumption :type: float :value: 0.1 .. py:attribute:: overconsumption :type: float :value: 0.01 .. py:attribute:: dynamicity :type: float :value: 0.0 .. py:attribute:: cv :type: float :value: 0.1 .. py:attribute:: alpha_q :type: float :value: 0.5 .. py:attribute:: alpha_u :type: float :value: 1.0 .. py:attribute:: beta_q :type: float :value: 10.0 .. py:attribute:: beta_u :type: float :value: 10.0 .. py:attribute:: tau_q :type: float :value: 2 .. py:attribute:: tau_u :type: float :value: 0.25 .. py:method:: random() :classmethod: .. py:method:: schedule_at(time: int) -> int .. py:method:: schedule_within(time: Union[int, List[int], Tuple[int, int]]) -> int .. py:method:: set_schedule_at(time: int, value: int, n_steps: int) -> None .. py:class:: JustInTimeConsumer(profiles: Dict[int, ConsumptionProfile] = None, negotiator_type=DEFAULT_NEGOTIATOR, consumption_horizon: Optional[int] = 20, immediate_cfp_update: bool = True, name=None) Bases: :py:obj:`Consumer` Consumer class .. py:method:: on_contract_executed(contract: negmas.situated.Contract) -> None Called after successful contract execution for which the agent is one of the partners. .. py:method:: on_contract_breached(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], resolution: Optional[negmas.situated.Contract]) -> None Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:method:: on_inventory_change(product: int, quantity: int, cause: str) -> None Received whenever something moves in or out of the factory's storage :param product: Product index. :param quantity: Negative value for products moving out and positive value for products moving in :param 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). .. py:method:: on_cash_transfer(amount: float, cause: str) -> None Received whenever money is transferred to the factory or from it. :param amount: Amount of money (negative for transfers out of the factory, positive for transfers to it). :param 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). .. py:method:: on_new_report(report: scml.scml2019.common.FinancialReport) Called whenever a financial report is published. :param 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 .. py:method:: on_neg_request_rejected(req_id: str, by: Optional[List[str]]) Called when a requested negotiation is rejected :param req_id: The request ID passed to _request_negotiation :param by: A list of agents that refused to participate or None if the failure was for another reason .. py:method:: on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface) Called when a requested negotiation is accepted .. py:method:: on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: on_negotiation_success(contract: negmas.situated.Contract, mechanism: negmas.NegotiatorMechanismInterface) -> None Called whenever a negotiation ends with agreement .. py:method:: on_contract_cancelled(contract: negmas.situated.Contract, rejectors: List[str]) -> None Called whenever at least a partner did not sign the contract .. py:method:: on_contract_nullified(contract: negmas.situated.Contract, bankrupt_partner: str, compensation: float) -> None Will be called whenever a contract the agent is involved in is nullified because another partner went bankrupt .. py:method:: on_agent_bankrupt(agent_id: str) -> None Will be called whenever any agent goes bankrupt :param agent_id: The ID of the agent that went bankrupt Remarks: - Agents can go bankrupt in two cases: 1. Failing to pay one installments of a loan they bought and refusing (or being unable to) get another loan to pay it. 2. 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` and `respond_to_negotiation_request` callbacks by pulling the bulletin-board using the helper function `is_bankrupt` of their AWI. .. py:method:: confirm_partial_execution(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach]) -> bool Will be called whenever a contract cannot be fully executed due to breaches by the other partner. :param contract: The contract that was breached :param breaches: A list of all the breaches committed. Remarks: - Will not be called if both partners committed breaches. .. py:method:: on_remove_cfp(cfp: scml.scml2019.common.CFP) Called when a new CFP for a product for which the agent registered interest is removed .. py:attribute:: MAX_UNIT_PRICE :value: 100.0 .. py:attribute:: RELATIVE_MAX_PRICE :value: 1.5 .. py:attribute:: negotiator_type :value: 'negmas.sao.AspirationNegotiator' .. py:attribute:: profiles :type: Dict[int, ConsumptionProfile] .. py:attribute:: secured_quantities :type: Dict[int, int] .. py:attribute:: consumption_horizon :value: 20 .. py:attribute:: immediate_cfp_update :value: True .. py:method:: on_new_cfp(cfp: scml.scml2019.common.CFP) -> None Called when a new CFP for a product for which the agent registered interest is published .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: set_profiles(profiles: Dict[int, ConsumptionProfile]) .. py:method:: register_product_cfps(p: int, t: int, profile: ConsumptionProfile) .. py:method:: step() Called by the simulator at every simulation step .. py:method:: confirm_contract_execution(contract: negmas.situated.Contract) -> bool Called before executing any agreement .. py:method:: _qufun(outcome: Dict[str, Any], tau: float, profile: ConsumptionProfile) :staticmethod: The ufun value for quantity .. py:method:: respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) -> Optional[negmas.negotiators.Negotiator] Called when a prospective partner requests a negotiation to start .. py:method:: set_renegotiation_agenda(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach]) -> Optional[negmas.situated.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract that was breached about which re-negotiation is offered :param breaches: The list of breaches by all parties for the breached contract. :returns: None if renegotiation is not to be started, otherwise a re-negotiation agenda. .. py:method:: respond_to_renegotiation_request(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], agenda: negmas.situated.RenegotiationRequest) -> Optional[negmas.negotiators.Negotiator] Called to respond to a renegotiation request :param agenda: Renegotiation agenda (issues to renegotiate about). :param contract: The contract that was breached :param breaches: All breaches on that contract :returns: None to refuse to enter the negotiation, otherwise, a negotiator to use for this negotiation. .. py:method:: confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) -> bool called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached .. py:method:: sign_contract(contract: negmas.situated.Contract) -> Optional[str] Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed. .. py:method:: on_contract_signed(contract: negmas.situated.Contract) Called whenever a contract is signed by all partners .. py:data:: __all__ .. py:class:: FactoryManager(name=None, simulator_type: Union[str, Type[scml.scml2019.simulators.FactorySimulator]] = FastFactorySimulator) Bases: :py:obj:`scml.scml2019.agent.SCML2019Agent`, :py:obj:`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: 1. Attributes and methods available in the Agent-SCML2020World-Interface (See `SCMLAWI` documentation for those). 2. 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 internal `SCMLAWI`. **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. - `uuid` : Another name of the `id` . - `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 it - `process_profiles` : A mapping specifying for each `Process` index, all the profiles used to run it in the factory - `producing` : Mapping from a product index to all manufacturing processes that can generate it - `consuming` : Mapping from a product index to all manufacturing processes that can consume it - `compiled_profiles` : All the profiles to be used by the factory belonging to this agent compiled to use process indices - `max_storage` : Maximum storage available to the agent. Zero, None or float('inf') all indicate unlimited storage. *Production Graph* (also accessible through *awi*) - `products` : List of products in the system - `processes` : List of processes in the system *Helper Objects* - `awi` : The `SCMLAWI` instance assigned to this agent. It can be used to interact with the simulation (See `SCMLAWI` documentation). - `simulator` : A `FactorySimulator` object that can be used to simulate what happens in the `Factory` 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** uses `request_negotiation` method of this class (see methods later) rather than directly calling request_method on the `SCMLAWI` ( `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** uses `request_negotiation` method of this class (see methods later) rather than directly calling request_method on the `SCMLAWI` ( `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** uses `request_negotiation` method of this class (see methods later) rather than directly calling request_method on the `SCMLAWI` ( `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 step - `transportation_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 a `CFP` . *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 a `CFP` that was published earlier by this factory manager. If accepted, the agent should return a `SAONegotiator` 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 returning `False` ), 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) - `init` : Called once before any production or negotiations to initiate the agent. - `step` : Called at every production step. *Information callbacks* (Called to inform the agent about events) - CFP related - `on_new_cfp` : Called whenever a `CFP` on a `Product` for which the agent has already registered interest (using `register_interest` method of its `awi`) 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 a `CFP` on a `Product` for which the agent has already registered interest (using `register_interest` method of its `awi`) is removed from the bulletin-board. - Negotiation related - `on_neg_request_accepted` : Called when a negotiation request of the agent is accepted - `on_neg_request_rejected` : Called when a negotiation request of the agent is rejected - `on_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 a `Contract` of which the agent is a party is cancelled because the other party refused to sign it. - `on_contract_signed` : Called whenever a `Contract` of which the agent is a party is signed by both patners. - `on_contract_nullified` : Called whenever a `Contract` 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 (see `SCMLAWI` for production commands) fails - `on_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 bankrupt - `on_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's `awi` 's `receive_financial_reports` method. .. py:attribute:: transportation_delay :value: 0 Transportation delay in the world .. py:attribute:: simulator :type: Optional[scml.scml2019.simulators.FactorySimulator] :value: None The simulator used by this agent .. py:attribute:: simulator_type :type: Type[scml.scml2019.simulators.FactorySimulator] Simulator type (as a class) .. py:attribute:: current_step :value: 0 Current simulation step .. py:attribute:: max_storage :type: int :value: 0 Maximum storage available to the agent .. py:method:: init_() The initialization function called by the world directly. It does the following actions by default: 1. copies some of the static world settings to the agent to make them available without calling the AWI. 2. prepares production related properties like producing, consuming, line_profiles, compiled_profiles, etc. 3. registers interest in all products that the agent can produce or consume in its factory. 4. finally it calls any custom initialization logic implemented in `init`() .. seealso:: `init`, `step` .. py:method:: step_() Called at every time-step. This function is called directly by the world. .. py:method:: on_production_failure(failures: List[scml.scml2019.common.ProductionFailure]) -> None :abstractmethod: Called with a list of `ProductionFailure` records on production failure. .. py:method:: on_production_success(reports: List[scml.scml2019.common.ProductionReport]) -> None :abstractmethod: Called with a list of `ProductionReport` records on production success .. py:class:: DoNothingFactoryManager(name=None, simulator_type: Union[str, Type[scml.scml2019.simulators.FactorySimulator]] = FastFactorySimulator) Bases: :py:obj:`FactoryManager` The default factory manager that will be implemented by the committee of ANAC-SCML 2019 .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: step() Called by the simulator at every simulation step .. py:method:: on_neg_request_rejected(req_id: str, by: Optional[List[str]]) Called when a requested negotiation is rejected :param req_id: The request ID passed to _request_negotiation :param by: A list of agents that refused to participate or None if the failure was for another reason .. py:method:: on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface) Called when a requested negotiation is accepted .. py:method:: on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: on_negotiation_success(contract: negmas.Contract, mechanism: negmas.NegotiatorMechanismInterface) -> None Called whenever a negotiation ends with agreement .. py:method:: on_contract_signed(contract: negmas.Contract) -> None Called whenever a contract is signed by all partners .. py:method:: on_contract_cancelled(contract: negmas.Contract, rejectors: List[str]) -> None Called whenever at least a partner did not sign the contract .. py:method:: on_contract_executed(contract: negmas.Contract) -> None Called after successful contract execution for which the agent is one of the partners. .. py:method:: on_contract_breached(contract: negmas.Contract, breaches: List[negmas.Breach], resolution: Optional[negmas.Contract]) -> None Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:method:: sign_contract(contract: negmas.Contract) -> Optional[str] Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed. .. py:method:: on_contract_nullified(contract: negmas.Contract, bankrupt_partner: str, compensation: float) -> None Will be called whenever a contract the agent is involved in is nullified because another partner went bankrupt .. py:method:: on_agent_bankrupt(agent_id: str) -> None Will be called whenever any agent goes bankrupt :param agent_id: The ID of the agent that went bankrupt Remarks: - Agents can go bankrupt in two cases: 1. Failing to pay one installments of a loan they bought and refusing (or being unable to) get another loan to pay it. 2. 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` and `respond_to_negotiation_request` callbacks by pulling the bulletin-board using the helper function `is_bankrupt` of their AWI. .. py:method:: confirm_partial_execution(contract: negmas.Contract, breaches: List[negmas.Breach]) -> bool Will be called whenever a contract cannot be fully executed due to breaches by the other partner. :param contract: The contract that was breached :param breaches: A list of all the breaches committed. Remarks: - Will not be called if both partners committed breaches. .. py:method:: on_remove_cfp(cfp: scml.scml2019.common.CFP) -> None Called when a new CFP for a product for which the agent registered interest is removed .. py:method:: on_production_failure(failures: List[scml.scml2019.common.ProductionFailure]) -> None Called with a list of `ProductionFailure` records on production failure. .. py:method:: respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) -> Optional[negmas.Negotiator] Called when a prospective partner requests a negotiation to start .. py:method:: confirm_contract_execution(contract: negmas.Contract) -> bool Called before executing any agreement .. py:method:: set_renegotiation_agenda(contract: negmas.Contract, breaches: List[negmas.Breach]) -> Optional[negmas.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract being breached :param breaches: All breaches on `contract` :returns: Renegotiation agenda (issues to negotiate about to avoid reporting the breaches). .. py:method:: respond_to_renegotiation_request(contract: negmas.Contract, breaches: List[negmas.Breach], agenda: negmas.RenegotiationRequest) -> Optional[negmas.Negotiator] Called to respond to a renegotiation request :param agenda: :param contract: :param breaches: Returns: .. py:method:: confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) -> bool called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached .. py:method:: on_new_cfp(cfp: scml.scml2019.common.CFP) -> None Called when a new CFP for a product for which the agent registered interest is published .. py:method:: on_inventory_change(product: int, quantity: int, cause: str) -> None Received whenever something moves in or out of the factory's storage :param product: Product index. :param quantity: Negative value for products moving out and positive value for products moving in :param 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). .. py:method:: on_production_success(reports: List[scml.scml2019.common.ProductionReport]) -> None Called with a list of `ProductionReport` records on production success .. py:method:: on_cash_transfer(amount: float, cause: str) -> None Received whenever money is transferred to the factory or from it. :param amount: Amount of money (negative for transfers out of the factory, positive for transfers to it). :param 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). .. py:method:: on_new_report(report: scml.scml2019.common.FinancialReport) Called whenever a financial report is published. :param 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 .. py:class:: GreedyFactoryManager(name=None, simulator_type: Union[str, Type[scml.scml2019.simulators.FactorySimulator]] = FastFactorySimulator, scheduler_type: Union[str, Type[scml.scml2019.schedulers.Scheduler]] = GreedyScheduler, scheduler_params: Optional[Dict[str, Any]] = None, optimism: float = 0.0, negotiator_type: Union[str, Type[negmas.Negotiator]] = DEFAULT_NEGOTIATOR, negotiator_params: Optional[Dict[str, Any]] = 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')) Bases: :py:obj:`DoNothingFactoryManager` The default factory manager that will be implemented by the committee of ANAC-SCML 2019 .. py:method:: on_production_failure(failures: List[scml.scml2019.common.ProductionFailure]) -> None Called with a list of `ProductionFailure` records on production failure. .. py:method:: on_production_success(reports: List[scml.scml2019.common.ProductionReport]) -> None Called with a list of `ProductionReport` records on production success .. py:method:: confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) -> bool called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached .. py:method:: confirm_contract_execution(contract: negmas.Contract) -> bool Called before executing any agreement .. py:method:: set_renegotiation_agenda(contract: negmas.Contract, breaches: List[negmas.Breach]) -> Optional[negmas.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract being breached :param breaches: All breaches on `contract` :returns: Renegotiation agenda (issues to negotiate about to avoid reporting the breaches). .. py:method:: respond_to_renegotiation_request(contract: negmas.Contract, breaches: List[negmas.Breach], agenda: negmas.RenegotiationRequest) -> Optional[negmas.Negotiator] Called to respond to a renegotiation request :param agenda: :param contract: :param breaches: Returns: .. py:attribute:: negotiator_type :value: 'negmas.sao.AspirationNegotiator' .. py:attribute:: negotiator_params :value: None .. py:attribute:: optimism :value: 0.0 .. py:attribute:: ufun_factory :type: Union[Type[NegotiatorUtility], Callable[[Any, Any], NegotiatorUtility]] .. py:attribute:: __reserved_value .. py:attribute:: max_insurance_premium :value: 0.1 .. py:attribute:: n_retrials :value: 5 .. py:attribute:: n_neg_trials :type: Dict[str, int] .. py:attribute:: consumer :value: None .. py:attribute:: use_consumer :value: True .. py:attribute:: reactive :value: True .. py:attribute:: sign_only_guaranteed_contracts :value: False .. py:attribute:: contract_schedules :type: Dict[str, scml.scml2019.schedulers.ScheduleInfo] .. py:attribute:: riskiness :value: 0.0 .. py:attribute:: negotiation_margin .. py:attribute:: scheduler_type :type: Type[scml.scml2019.schedulers.Scheduler] .. py:attribute:: scheduler :type: scml.scml2019.schedulers.Scheduler :value: None .. py:attribute:: scheduler_params :type: Dict[str, Any] :value: None .. py:method:: total_utility(contracts: Collection[negmas.Contract] = ()) -> float Calculates the total utility for the agent of a collection of contracts .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) -> Optional[negmas.Negotiator] Called when a prospective partner requests a negotiation to start .. py:method:: on_negotiation_success(contract: negmas.Contract, mechanism: negmas.NegotiatorMechanismInterface) Called whenever a negotiation ends with agreement .. py:method:: on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: _execute_schedule(schedule: scml.scml2019.schedulers.ScheduleInfo, contract: negmas.Contract) -> None .. py:method:: sign_contract(contract: negmas.Contract) Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed. .. py:method:: on_contract_signed(contract: negmas.Contract) Called whenever a contract is signed by all partners .. py:method:: _process_buy_cfp(cfp: scml.scml2019.common.CFP) -> None .. py:method:: _process_sell_cfp(cfp: scml.scml2019.common.CFP) .. py:method:: on_new_cfp(cfp: scml.scml2019.common.CFP) -> None Called when a new CFP for a product for which the agent registered interest is published .. py:method:: step() Called by the simulator at every simulation step .. py:method:: can_produce(cfp: scml.scml2019.common.CFP, assume_no_further_negotiations=False) -> bool Whether or not we can produce the required item in time .. py:method:: can_secure_needs(schedule: scml.scml2019.schedulers.ScheduleInfo, step: int) Finds if it is possible in principle to arrange these needs at the given time. :param schedule: :param step: Returns: .. py:function:: pos_gauss(mu, sigma) Returns a sample from a rectified gaussian .. py:function:: _safe_max(a, b) .. py:function:: zero_runs(a: numpy.array) -> numpy.array Finds all runs of zero in an array :param a: Input array (assumed to be 1D) :returns: A 2D array giving beginning and end (exclusive) of zero stretches in the input array. :rtype: np.array .. py:class:: DefaultInsuranceCompany(premium: float, premium_breach_increment: float, premium_time_increment: float, a2f: Dict[str, scml.scml2019.common.Factory], disabled=False, name: str = None) Bases: :py:obj:`InsuranceCompany` Represents an insurance company in the world .. py:attribute:: premium_breach_increment .. py:attribute:: premium .. py:attribute:: disabled :value: False .. py:attribute:: premium_time_increment .. py:attribute:: insured_contracts :type: Dict[Tuple[negmas.situated.Contract, str], scml.scml2019.common.InsurancePolicy] .. py:attribute:: storage :type: Dict[int, int] .. py:attribute:: wallet :type: float :value: 0.0 .. py:attribute:: a2f .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: set_renegotiation_agenda(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach]) -> Optional[negmas.situated.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract being breached :param breaches: All breaches on `contract` :returns: Renegotiation agenda (issues to negotiate about to avoid reporting the breaches). .. py:method:: respond_to_renegotiation_request(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], agenda: negmas.situated.RenegotiationRequest) -> Optional[negmas.negotiators.Negotiator] Called to respond to a renegotiation request :param agenda: :param contract: :param breaches: Returns: .. py:method:: evaluate_insurance(contract: negmas.situated.Contract, insured: scml.scml2019.agent.SCML2019Agent, against: scml.scml2019.agent.SCML2019Agent, t: int = None) -> Optional[float] Can be called to evaluate the premium for insuring the given contract against breaches committed by others :param against: The `SCML2019Agent` to insure against :param contract: hypothetical contract :param insured: The `SCML2019Agent` to buy the insurance :param t: time at which the policy is to be bought. If None, it means current step Remarks: - The premium returned is relative to the contract price. To actually calculate the cost of buying this insurance, you need to multiply this by the contract value (quantity * unit_price). .. py:method:: buy_insurance(contract: negmas.situated.Contract, insured: scml.scml2019.agent.SCML2019Agent, against: scml.scml2019.agent.SCML2019Agent) -> Optional[scml.scml2019.common.InsurancePolicy] Buys insurance for the contract at the premium calculated by the insurance company. Remarks: The agent can call `evaluate_insurance` to find the premium that will be used. .. seealso:: `evaluate_premium` .. py:method:: is_insured(contract: negmas.situated.Contract, perpetrator: scml.scml2019.agent.SCML2019Agent) -> bool :param contract: :param perpetrator: Returns: .. py:method:: step() does nothing .. py:class:: InsuranceCompany(*args, **kwargs) Bases: :py:obj:`negmas.situated.Agent`, :py:obj:`abc.ABC` Base class for all insurance companies .. py:attribute:: _world :type: Optional[scml.scml2019.world.SCML2019World] :value: None .. py:method:: _respond_to_negotiation_request(initiator: str, partners: List[str], issues: List[negmas.outcomes.Issue], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, role: Optional[str], req_id: Optional[str]) -> Optional[negmas.negotiators.Negotiator] Called by the mechanism to ask for joining a negotiation. The agent can refuse by returning a None :param initiator: The ID of the agent that initiated the negotiation request :param partners: The partner list (will include this agent) :param issues: The list of issues :param annotation: Any annotation specific to this negotiation. :param mechanism: The mechanism that started the negotiation :param role: The role of this agent in the negotiation :param req_id: The req_id passed to the AWI when starting the negotiation (only to the initiator). :returns: None to refuse the negotiation or a `Negotiator` object appropriate to the given mechanism to accept it. Remarks: - It is expected that world designers will introduce a better way to respond and override this function to call it .. py:method:: on_neg_request_rejected(req_id: str, by: Optional[List[str]]) Called when a requested negotiation is rejected :param req_id: The request ID passed to _request_negotiation :param by: A list of agents that refused to participate or None if the failure was for another reason .. py:method:: on_neg_request_accepted(req_id: str, mechanism: negmas.NegotiatorMechanismInterface) Called when a requested negotiation is accepted .. py:method:: on_negotiation_failure(partners: List[str], annotation: Dict[str, Any], mechanism: negmas.NegotiatorMechanismInterface, state: negmas.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: on_negotiation_success(contract: negmas.situated.Contract, mechanism: negmas.NegotiatorMechanismInterface) -> None Called whenever a negotiation ends with agreement .. py:method:: on_contract_signed(contract: negmas.situated.Contract) -> None Called whenever a contract is signed by all partners .. py:method:: on_contract_cancelled(contract: negmas.situated.Contract, rejectors: List[str]) -> None Called whenever at least a partner did not sign the contract .. py:method:: sign_contract(contract: negmas.situated.Contract) -> Optional[str] Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed. .. py:method:: respond_to_negotiation_request(initiator: str, partners: List[str], issues: List[negmas.outcomes.Issue], annotation: Dict[str, Any], mechanism: negmas.Mechanism, role: Optional[str], req_id: str) -> Optional[negmas.negotiators.Negotiator] .. py:method:: on_contract_breached(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], resolution: Optional[negmas.situated.Contract]) -> None Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:method:: on_contract_executed(contract: negmas.situated.Contract) -> None Called after successful contract execution for which the agent is one of the partners. .. py:class:: Miner(name: Optional[str] = None, ufun: Optional[negmas.UtilityFunction] = None) Bases: :py:obj:`scml.scml2019.agent.SCML2019Agent`, :py:obj:`abc.ABC` Base class of all miners .. py:class:: MiningProfile .. py:attribute:: cv :type: float :value: 0.05 .. py:attribute:: alpha_t :type: float :value: 1.0 .. py:attribute:: alpha_q :type: float :value: 1.0 .. py:attribute:: alpha_u :type: float :value: 1.0 .. py:attribute:: beta_t :type: float :value: 1.0 .. py:attribute:: beta_q :type: float :value: 100.0 .. py:attribute:: beta_u :type: float :value: 100.0 .. py:attribute:: tau_t :type: float :value: -0.25 .. py:attribute:: tau_q :type: float :value: 0.25 .. py:attribute:: tau_u :type: float :value: 1.0 .. py:method:: random() :classmethod: .. py:class:: ReactiveMiner(profiles: dict[int, MiningProfile] | None = None, negotiator_type=DEFAULT_NEGOTIATOR, n_retrials=0, reactive=True, name=None) Bases: :py:obj:`Miner` Raw Material Generator .. py:method:: on_contract_executed(contract: negmas.situated.Contract) -> None Called after successful contract execution for which the agent is one of the partners. .. py:method:: on_contract_breached(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach], resolution: Optional[negmas.situated.Contract]) -> None Called after complete processing of a contract that involved a breach. :param contract: The contract :param breaches: All breaches committed (even if they were resolved) :param resolution: The resolution contract if re-negotiation was successful. None if not. .. py:method:: on_inventory_change(product: int, quantity: int, cause: str) -> None Received whenever something moves in or out of the factory's storage :param product: Product index. :param quantity: Negative value for products moving out and positive value for products moving in :param 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). .. py:method:: on_cash_transfer(amount: float, cause: str) -> None Received whenever money is transferred to the factory or from it. :param amount: Amount of money (negative for transfers out of the factory, positive for transfers to it). :param 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). .. py:method:: on_new_report(report: scml.scml2019.common.FinancialReport) Called whenever a financial report is published. :param 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 .. py:method:: on_neg_request_rejected(req_id: str, by: Optional[list[str]]) Called when a requested negotiation is rejected :param req_id: The request ID passed to _request_negotiation :param by: A list of agents that refused to participate or None if the failure was for another reason .. py:method:: on_neg_request_accepted(req_id: str, mechanism: negmas.common.NegotiatorMechanismInterface) Called when a requested negotiation is accepted .. py:method:: on_negotiation_success(contract: negmas.situated.Contract, mechanism: negmas.common.NegotiatorMechanismInterface) -> None Called whenever a negotiation ends with agreement .. py:method:: on_contract_signed(contract: negmas.situated.Contract) -> None Called whenever a contract is signed by all partners .. py:method:: on_contract_cancelled(contract: negmas.situated.Contract, rejectors: list[str]) -> None Called whenever at least a partner did not sign the contract .. py:method:: sign_contract(contract: negmas.situated.Contract) -> Optional[str] Called after the signing delay from contract conclusion to sign the contract. Contracts become binding only after they are signed. .. py:method:: on_contract_nullified(contract: negmas.situated.Contract, bankrupt_partner: str, compensation: float) -> None Will be called whenever a contract the agent is involved in is nullified because another partner went bankrupt .. py:method:: on_agent_bankrupt(agent_id: str) -> None Will be called whenever any agent goes bankrupt :param agent_id: The ID of the agent that went bankrupt Remarks: - Agents can go bankrupt in two cases: 1. Failing to pay one installments of a loan they bought and refusing (or being unable to) get another loan to pay it. 2. 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` and `respond_to_negotiation_request` callbacks by pulling the bulletin-board using the helper function `is_bankrupt` of their AWI. .. py:method:: confirm_partial_execution(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach]) -> bool Will be called whenever a contract cannot be fully executed due to breaches by the other partner. :param contract: The contract that was breached :param breaches: A list of all the breaches committed. Remarks: - Will not be called if both partners committed breaches. .. py:method:: on_remove_cfp(cfp: scml.scml2019.common.CFP) Called when a new CFP for a product for which the agent registered interest is removed .. py:attribute:: negotiator_type :value: 'negmas.sao.AspirationNegotiator' .. py:attribute:: profiles :type: dict[int, MiningProfile] .. py:attribute:: n_neg_trials :type: dict[str, int] .. py:attribute:: n_retrials :value: 0 .. py:attribute:: reactive :value: True .. py:method:: init() Called to initialize the agent **after** the world is initialized. the AWI is accessible at this point. .. py:method:: on_negotiation_failure(partners: list[str], annotation: dict[str, Any], mechanism: negmas.common.NegotiatorMechanismInterface, state: negmas.common.MechanismState) -> None Called whenever a negotiation ends without agreement .. py:method:: set_profiles(profiles: dict[int, MiningProfile]) .. py:method:: _process_cfp(cfp: scml.scml2019.common.CFP) .. py:method:: on_new_cfp(cfp: scml.scml2019.common.CFP) Called when a new CFP for a product for which the agent registered interest is published .. py:method:: step() Called by the simulator at every simulation step .. py:method:: confirm_contract_execution(contract: negmas.situated.Contract) -> bool Called before executing any agreement .. py:method:: respond_to_negotiation_request(cfp: scml.scml2019.common.CFP, partner: str) -> Optional[negmas.negotiators.Negotiator] Called when a prospective partner requests a negotiation to start .. py:method:: set_renegotiation_agenda(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach]) -> Optional[negmas.situated.RenegotiationRequest] Received by partners in ascending order of their total breach levels in order to set the renegotiation agenda when contract execution fails :param contract: The contract being breached :param breaches: All breaches on `contract` :returns: Renegotiation agenda (issues to negotiate about to avoid reporting the breaches). .. py:method:: respond_to_renegotiation_request(contract: negmas.situated.Contract, breaches: list[negmas.situated.Breach], agenda: negmas.situated.RenegotiationRequest) -> Optional[negmas.negotiators.Negotiator] Called to respond to a renegotiation request :param agenda: :param contract: :param breaches: Returns: .. py:method:: confirm_loan(loan: scml.scml2019.common.Loan, bankrupt_if_rejected: bool) -> bool called by the world manager to confirm a loan if needed by the buyer of a contract that is about to be breached .. py:class:: ScheduleInfo .. py:attribute:: final_balance :type: float balance at the end of the schedule .. py:attribute:: valid :type: bool :value: True Is this a valid schedule? .. py:attribute:: start :type: Optional[int] :value: None The starting step of this schedule .. py:attribute:: end :type: Optional[int] :value: None The step after the last step in this simulation .. py:attribute:: needs :type: List[scml.scml2019.common.ProductionNeed] :value: [] The products needed but not still in storage needed to complete this schedule. .. py:attribute:: jobs :type: List[scml.scml2019.common.Job] :value: [] The jobs that need to be scheduled .. py:attribute:: failed_contracts :type: List[negmas.situated.Contract] :value: [] A list of contracts that failed to be scheduled. .. py:attribute:: ignored_contracts :type: List[negmas.situated.Contract] :value: [] A list of contracts ignored for this schedule because they are in the past. .. py:method:: __str__() .. py:method:: combine(other: ScheduleInfo) -> None .. py:class:: Scheduler(manager_id: str, awi: scml.scml2019.awi.SCMLAWI, max_insurance_premium: float = float('inf'), horizon: Optional[int] = None) Bases: :py:obj:`abc.ABC` Base class for all schedulers .. py:attribute:: horizon :value: None .. py:attribute:: n_steps :value: 0 .. py:attribute:: n_lines :value: 0 .. py:attribute:: simulator :type: scml.scml2019.simulators.FactorySimulator | None :value: None .. py:attribute:: products :type: List[scml.scml2019.common.Product] :value: [] .. py:attribute:: processes :type: List[scml.scml2019.common.Process] :value: [] .. py:attribute:: profiles :type: List[scml.scml2019.common.ManufacturingProfileCompiled] :value: [] .. py:attribute:: producing :type: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]] .. py:attribute:: manager_id .. py:attribute:: awi .. py:attribute:: max_insurance_premium .. py:method:: bookmark() -> int Sets a bookmark to the current location :returns: bookmark ID .. py:method:: rollback(bookmark_id: int) -> bool Rolls back to the given bookmark ID :param bookmark_id The bookmark ID returned from bookmark: Remarks: - You can only rollback in the reverse order of bookmarks. If the bookmark ID given here is not the one at the top of the bookmarks stack, the rollback will fail (return False) .. py:method:: delete_bookmark(bookmark_id: int) -> bool Commits everything since the bookmark so it cannot be rolled back :param bookmark_id The bookmark ID returned from bookmark: Remarks: - You can only rollback in the reverse order of bookmarks. If the bookmark ID given here is not the one at the top of the bookmarks stack, the deletion will fail (return False) .. py:method:: init(simulator: scml.scml2019.simulators.FactorySimulator, products: List[scml.scml2019.common.Product], processes: List[scml.scml2019.common.Process], profiles: List[scml.scml2019.common.ManufacturingProfileCompiled], producing: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]]) Called by the FactoryManager after it is initialized .. py:method:: schedule(contracts: Collection[negmas.situated.Contract] = (), assume_no_further_negotiations=False, ensure_storage_for: int = 0, start_at: int = 0) -> ScheduleInfo Schedules a set of contracts and returns either the search_for_schedule or None if infeasible :param whatever it has scheduled before. If the state is given: :param it is taken as the initial state for scheduling: :param contracts: The contracts to be scheduled :param assume_no_further_negotiations: whether to assume that more negotiations can take place (to secure :param production needs): :param ensure_storage_for: A minimum time to ensure that products are available in storage before contract delivery :param times: :type times: sell contracts :param start_at: The time at which to start scheduling. No jobs will be scheduled before this time. :returns: `ScheduleInfo` describing the schedulo and any production needs and updates to be carried out. .. py:method:: find_schedule(contracts: Collection[negmas.situated.Contract], start: int, end: int, assume_no_further_negotiations=False, ensure_storage_for: int = 0, start_at: int = 0) -> ScheduleInfo :abstractmethod: Schedules a set of contracts and returns either the search_for_schedule or None if infeasible :param start: :param end: :param contracts: :param assume_no_further_negotiations: :param ensure_storage_for: :param start_at: The time at which to start scheduling. No jobs will be scheduled before this time. :returns: Schedule information (See `ScheduleInfo` for its contents). .. py:class:: GreedyScheduler(manager_id: str, awi: scml.scml2019.awi.SCMLAWI, max_insurance_premium: float = float('inf'), horizon: Optional[int] = None, add_catalog_prices=True, strategy: str = 'latest', profile_sorter: str = 'total-cost>time') Bases: :py:obj:`Scheduler` Default scheduler used by the DefaultFactoryManager .. py:method:: __getstate__() .. py:method:: __setstate__(state) .. py:attribute:: add_catalog_prices :value: True .. py:attribute:: strategy :value: 'latest' .. py:attribute:: fields :type: List[Callable[[scml.scml2019.common.ProductManufacturingInfo], float]] .. py:attribute:: field_order :type: List[int] :value: [] .. py:attribute:: producing :type: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]] .. py:method:: init(simulator: scml.scml2019.simulators.FactorySimulator, products: List[scml.scml2019.common.Product], processes: List[scml.scml2019.common.Process], profiles: List[scml.scml2019.common.ManufacturingProfileCompiled], producing: Dict[int, List[scml.scml2019.common.ProductManufacturingInfo]]) Called by the FactoryManager after it is initialized .. py:method:: _profile_sorter(info: scml.scml2019.common.ProductManufacturingInfo) -> Any .. py:method:: unit_time(info: scml.scml2019.common.ProductManufacturingInfo) -> float .. py:method:: total_cost(info: scml.scml2019.common.ProductManufacturingInfo) -> float .. py:method:: total_unit_cost(info: scml.scml2019.common.ProductManufacturingInfo) -> float .. py:method:: production_cost(info: scml.scml2019.common.ProductManufacturingInfo) -> float .. py:method:: production_unit_cost(info: scml.scml2019.common.ProductManufacturingInfo) -> float .. py:method:: input_cost(info: scml.scml2019.common.ProductManufacturingInfo) .. py:method:: input_unit_cost(info: scml.scml2019.common.ProductManufacturingInfo) -> float .. py:method:: schedule_contract(contract: negmas.situated.Contract, assume_no_further_negotiations=False, end: int = None, ensure_storage_for: int = 0, start_at: int = 0) -> ScheduleInfo Schedules this contract if possible and returns information about the resulting schedule :param contract: The contract being scheduled :param assume_no_further_negotiations: If true no further negotiations will be assumed possible :param end: The scheduling horizon (None for the default). :param ensure_storage_for: The number of steps all needs must be in storage before they are consumed in production :param start_at: No jobs will be scheduled before that time. :returns: Full schedule information including validity, line schedulers, production needs, etc (see `SchedulerInfo`). .. py:method:: schedule_contracts(contracts: Collection[negmas.situated.Contract], end: int = None, assume_no_further_negotiations=False, ensure_storage_for: int = 0, start_at: int = 0) -> ScheduleInfo Schedules a set of contracts and returns the `ScheduleInfo`. :param contracts: Contracts to schedule :param assume_no_further_negotiations: If true, no further negotiations will be assumed to be possible :param end: The end of the simulation for the schedule (exclusive) :param ensure_storage_for: Ensure that the outcome will be at the storage for at least this time :param start_at: The timestep at which to start scheduling :returns: ScheduleInfo giving the schedule after these contracts is included. `valid` member can be used to check whether this is a valid contract .. py:method:: find_schedule(contracts: Collection[negmas.situated.Contract], start: int, end: int, assume_no_further_negotiations=False, ensure_storage_for: int = 0, start_at: int = 0) Schedules a set of contracts and returns either the search_for_schedule or None if infeasible :param start: :param end: :param contracts: :param assume_no_further_negotiations: :param ensure_storage_for: :param start_at: The time at which to start scheduling. No jobs will be scheduled before this time. :returns: Schedule information (See `ScheduleInfo` for its contents). .. py:class:: FactorySimulator(initial_wallet: float, initial_storage: Dict[int, int], n_steps: int, n_products: int, profiles: List[scml.scml2019.common.ManufacturingProfile], max_storage: Optional[int] = None) Bases: :py:obj:`abc.ABC` Simulates a factory allowing for prediction of storage/balance in the future. :param initial_wallet: The initial amount of cash in the wallet :param initial_storage: initial inventory :param n_steps: number of simulation steps :param n_products: number of products in the world :param profiles: all profiles that the factory being simulated can run :param max_storage: maximum available storage space. .. py:attribute:: _n_steps .. py:attribute:: _max_storage :value: None .. py:attribute:: _initial_wallet .. py:attribute:: _initial_storage .. py:attribute:: _profiles .. py:attribute:: _n_products .. py:attribute:: _reserved_storage .. py:method:: _as_array(storage: Dict[int, int]) .. py:property:: max_storage :type: Optional[int] Maximum storage available .. py:property:: n_steps :type: int Number of steps to predict ahead. .. py:property:: initial_wallet :type: float Initial cash in wallet .. py:property:: initial_storage :type: numpy.array Initial inventory .. py:property:: n_lines :abstractmethod: Number of lines .. py:property:: final_balance :type: float :abstractmethod: Final balance given everything scheduled so-far .. py:method:: wallet_to(t: int) -> numpy.array :abstractmethod: Returns the cash in wallet up to and including time t. :param t: Time Returns: .. py:method:: wallet_at(t: int) -> float Returns the cash in wallet *at* a given timestep (given all simulated actions) :param t: Returns: .. py:method:: storage_to(t: int) -> numpy.array :abstractmethod: Returns the storage of all products *up to* time t :param t: Time :returns: An array of size `n_products` * `t` giving the quantity of each product in storage at every step up to `t`. .. py:method:: storage_at(t: int) -> numpy.array Returns the storage of all products *at* time t :param t: Time :returns: An array of size `n_products` giving the quantity of each product in storage at time-step `t`. .. seealso:: `storage_to` `wallet_at` .. py:method:: line_schedules_to(t: int) -> numpy.array :abstractmethod: Returns the schedule of each line up to a given timestep :param t: time :returns: An array of `n_lines` * `t` values giving the schedule up to `t`. Remarks: - A `NO_PRODUCTION` value means no production, otherwise the index of the process being run .. py:method:: line_schedules_at(t: int) -> numpy.array Returns the schedule of each line at a given timestep :param t: time :returns: An array of `n_lines` values giving the schedule up at `t`. Remarks: - A `NO_PRODUCTION` value means no production, otherwise the index of the process being run .. py:method:: total_storage_to(t: int) -> numpy.array The total storage *up to* a given time :param t: time :returns: an array of size `t` giving the total quantity of stored products in the inventory up to timestep `t` .. seealso:: `total_storage_at` `storage_to` .. py:method:: total_storage_at(t: int) -> int The total storage *at* a given time :param t: time :returns: an integer giving the total quantity of stored products in the inventory at timestep `t` .. seealso:: `total_storage_to` `storage_at` .. py:method:: reserved_storage_to(t: int) -> numpy.array Returns the *reserved* storage of all products *up to* time t :param t: Time :returns: An array of size `n_products` * `t` giving the quantity of each product reserved at every step up to `t`. Remarks: - Reserved storage *is counted* in calls to `storage_at` , `total_storage_at` , `storage_to` , `total_storage_to` - Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts. .. seealso:: `total_storage_at` `storage_at` `reserved_storage_at` .. py:method:: reserved_storage_at(t: int) -> numpy.array Returns the *reserved* storage of all products *at* time t :param t: Time :returns: An array of size `n_products` giving the quantity of each product reserved at time-step `t`. Remarks: - Reserved storage *is counted* in calls to `storage_at` , `total_storage_at` , `storage_to` , `total_storage_to` - Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts. .. seealso:: `total_storage_to` `storage_to` `reserved_storage_at` .. py:method:: available_storage_to(t: int) -> numpy.array Returns the *available* storage of all products *up to* time t. :param t: Time :returns: An array of size `n_products` * `t` giving the quantity of each product available at every step up to `t`. Remarks: - Available storage is defined as the difference between storage and reserved storage. - Reserved storage *is counted* in calls to `storage_at` , `total_storage_at` , `storage_to` , `total_storage_to` - Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts. .. seealso:: `total_storage_to` `storage_to` `reserved_storage_to` .. py:method:: available_storage_at(t: int) -> numpy.array Returns the *available* storage of all products *at* time t :param t: Time :returns: An array of size `n_products` giving the quantity of each product available at time-step `t`. Remarks: - Available storage is defined as the difference between storage and reserved storage. - Reserved storage *is counted* in calls to `storage_at` , `total_storage_at` , `storage_to` , `total_storage_to` - Reserving quantities of products is a tool that can be used to avoid double counting availability of given products in the inventory for multiple contracts. .. seealso:: `total_storage_to` `storage_to` `reserved_storage_at` .. py:method:: loans_to(t: int) -> numpy.array :abstractmethod: Returns loans up to time t :param t: time :returns: An array of `t` real numbers giving the loans registered at time-steps up to `t` .. py:method:: loans_at(t: int) -> float Returns loans at time t :param t: time .. py:method:: balance_at(t: int) -> float Returns the balance fo the factory at time t. :param t: time Remarks: - The balance is defined as the cash in wallet minus loans .. seealso:: `loans_at` `wallet_at` .. py:method:: balance_to(t: int) -> numpy.array Returns the balance fo the factory *up to* time t. :param t: time Remarks: - The balance is defined as the cash in wallet minus loans .. seealso:: `loans_to` `wallet_to` .. py:property:: fixed_before :abstractmethod: Gives the time before which the schedule is fixed. .. seealso:: `fix_before` .. py:method:: set_state(t: int, storage: numpy.array, wallet: float, loans: float, line_schedules: numpy.array) -> None :abstractmethod: Sets the current state at the given time-step. It implicitly causes a fix_before(t + 1) :param t: Time step to set the state at :param storage: quantity of every product (array of integers of size `n_products`) :param wallet: Cash in wallet :param loans: Loans :param line_schedules: Line schedules (array of process numbers/NO_PRODUCTION of size `n_lines`) .. py:method:: add_loan(total: float, t: int) -> bool :abstractmethod: Adds a loan at the given time :param total: Total amount of the loan :param t: time step to take the loan :returns: Success or failure Remarks: - Taking a loan is simulated as reception of money. Payment back of the loan is not simulated in this call. To simulate paying back the loan, use `pay` at the times of installment payments. .. py:method:: receive(payment: float, t: int) -> bool Simulates receiving payment at time t :param payment: Amount received :param t: time :returns: Success or failure .. py:method:: pay(payment: float, t: int, ignore_money_shortage: bool = True) -> bool :abstractmethod: Simulate payment at time t :param payment: Amount payed :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :returns: Success or failure .. py:method:: transport_to(product: int, quantity: int, t: int, ignore_inventory_shortage: bool = True, ignore_space_shortage: bool = True) -> bool :abstractmethod: Simulates transporting products to/from storage at time t :param product: product ID (index) :param quantity: quantity to transport :param t: time :param ignore_inventory_shortage: Ignore shortage in the `product` which may lead to negative storage[product] :param ignore_space_shortage: Ignore the limit on total storage which may lead to total_storage > max_storage :returns: Success or failure .. py:method:: buy(product: int, quantity: int, price: int, t: int, ignore_money_shortage: bool = True, ignore_space_shortage: bool = True) -> bool :abstractmethod: Buy a given quantity of a product for a given price at some time t :param product: Product to buy (ID/index) :param quantity: quantity to buy :param price: unit price :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :param ignore_space_shortage: Ignore the limit on total storage which may lead to total_storage > max_storage :returns: Success or failure Remarks: - buy cannot ever have inventory shortage .. seealso:: `sell` .. py:method:: sell(product: int, quantity: int, price: int, t: int, ignore_money_shortage: bool = True, ignore_inventory_shortage: bool = True) -> bool :abstractmethod: sell a given quantity of a product for a given price at some time t :param product: Index/ID of the product to be sold :param quantity: quantity to be sold :param price: unit price :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :param ignore_inventory_shortage: Ignore shortage in the `product` which may lead to negative storage[product] :returns: Success or failure Remarks: - sell cannot ever have space shortage .. seealso:: `buy` .. py:method:: schedule(job: scml.scml2019.common.Job, ignore_inventory_shortage=True, ignore_money_shortage=True, ignore_space_shortage=True, override=True) -> bool :abstractmethod: Simulates scheduling the given job at its `time` and `line` optionally overriding whatever was already scheduled :param job: Production job :param ignore_inventory_shortage: If true shortages in inputs will be ignored :param ignore_money_shortage: If true, shortage in money will be ignored :param ignore_space_shortage: If true, shortage in space will be ignored :param override: Whether the job should override any already registered job at its time-step :returns: Success/failure .. py:method:: reserve(product: int, quantity: int, t: int) -> bool Simulates reserving the given quantity of the given product at times >= t. :param product: Index/ID of the product being reserved :param quantity: quantity being reserved :param t: time :returns: Success/failure Remarks: - Reserved products show in calls to `storage_at` , `total_storage_at` etc. - Reserving a product does nothing more than mark some quantity as reserved for calls to `reserved_storage_at` and `available_storage_at`. - This feature can be used to simulate inventory hiding commands in the real factory and to avoid double counting of inventory when calculating needs for future contracts. .. py:method:: fix_before(t: int) -> bool :abstractmethod: Fix the history before this point :param t: time :returns: Success/failure Remarks: - After this function is called at any time-step `t`, there is no way to change any component of the factory state at any timestep before `t`. - This function is useful for *fixing* any difference between the simulator and the real state (in conjunction with `set_state`). .. seealso:: `set_state` `fixed_before` .. py:method:: bookmark() -> int :abstractmethod: Sets a bookmark to the current location :returns: bookmark ID Remarks: - Bookmarks can be used to implement transactions. .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: rollback(bookmark_id: int) -> bool :abstractmethod: Rolls back to the given bookmark ID :param bookmark_id The bookmark ID returned from bookmark: Remarks: - You can only rollback in the reverse order of bookmarks. If the bookmark ID given here is not the one at the top of the bookmarks stack, the rollback will fail (return False) .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: delete_bookmark(bookmark_id: int) -> bool :abstractmethod: Commits everything since the bookmark so it cannot be rolled back :param bookmark_id The bookmark ID returned from bookmark: :returns: Success/failure Remarks: - You can delete bookmarks in the reverse order of their creation only. If the bookmark ID given here is not the one at the top of the bookmarks stack, the deletion will fail (return False). .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:class:: SlowFactorySimulator(initial_wallet: float, initial_storage: Dict[int, int], n_steps: int, n_products: int, profiles: List[scml.scml2019.common.ManufacturingProfile], max_storage: Optional[int]) Bases: :py:obj:`FactorySimulator` A slow factory simulator that runs an internal factory to find-out what will happen in the future Remarks: - It is *much* faster to always access the properties/methods of this class in ascending time. If that is not the case, each time reversal will cause a complete reset. - It is recommended to call `fix_before` () to fix the past once a production step is completed. That will speed up operations .. py:method:: set_state(t: int, storage: numpy.array, wallet: float, loans: float, line_schedules: numpy.array) -> None Sets the current state at the given time-step. It implicitly causes a fix_before(t + 1) :param t: Time step to set the state at :param storage: quantity of every product (array of integers of size `n_products`) :param wallet: Cash in wallet :param loans: Loans :param line_schedules: Line schedules (array of process numbers/NO_PRODUCTION of size `n_lines`) .. py:method:: delete_bookmark(bookmark_id: int) -> bool Commits everything since the bookmark so it cannot be rolled back :param bookmark_id The bookmark ID returned from bookmark: :returns: Success/failure Remarks: - You can delete bookmarks in the reverse order of their creation only. If the bookmark ID given here is not the one at the top of the bookmarks stack, the deletion will fail (return False). .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: bookmark() -> int Sets a bookmark to the current location :returns: bookmark ID Remarks: - Bookmarks can be used to implement transactions. .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: rollback(bookmark_id: int) -> bool Rolls back to the given bookmark ID :param bookmark_id The bookmark ID returned from bookmark: Remarks: - You can only rollback in the reverse order of bookmarks. If the bookmark ID given here is not the one at the top of the bookmarks stack, the rollback will fail (return False) .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:property:: final_balance :type: float Final balance given everything scheduled so-far .. py:property:: n_lines Number of lines .. py:method:: fix_before(t: int) -> bool Fix the history before this point :param t: time :returns: Success/failure Remarks: - After this function is called at any time-step `t`, there is no way to change any component of the factory state at any timestep before `t`. - This function is useful for *fixing* any difference between the simulator and the real state (in conjunction with `set_state`). .. seealso:: `set_state` `fixed_before` .. py:attribute:: _factory .. py:attribute:: _jobs :type: Dict[int, List[scml.scml2019.common.Job, bool, bool, bool, bool]] .. py:attribute:: _buy_contracts :type: Dict[int, List[int, int, float]] .. py:attribute:: _sell_contracts :type: Dict[int, List[int, int, float]] .. py:attribute:: _payment_updates :type: Dict[int, float] .. py:attribute:: _loans_updates :type: Dict[int, float] .. py:attribute:: _storage_updates :type: Dict[int, Dict[int, int]] .. py:attribute:: _wallet .. py:attribute:: _loans .. py:attribute:: _storage .. py:attribute:: _line_schedules .. py:attribute:: _fixed_before :value: 0 .. py:attribute:: _bookmarks :type: List[_Bookmark] :value: [] .. py:attribute:: _active_bookmark :type: Optional[_Bookmark] :value: None .. py:attribute:: _active_bookmarked_at :type: int :value: -1 .. py:attribute:: _bookmarked_at :type: List[int] :value: [] .. py:attribute:: _saved_states :type: Dict[int, List[_State]] .. py:method:: _update_state() -> None .. py:method:: reset_to(t: int) -> None .. py:method:: goto(t: int) -> None Steps the factory to the end of step t :param t: time Returns: .. py:method:: wallet_to(t: int) -> numpy.array Returns the cash in wallet up to and including time t. :param t: Time Returns: .. py:method:: line_schedules_to(t: int) -> numpy.array Returns the schedule of each line up to a given timestep :param t: time :returns: An array of `n_lines` * `t` values giving the schedule up to `t`. Remarks: - A `NO_PRODUCTION` value means no production, otherwise the index of the process being run .. py:method:: storage_to(t: int) -> numpy.array Returns the storage of all products *up to* time t :param t: Time :returns: An array of size `n_products` * `t` giving the quantity of each product in storage at every step up to `t`. .. py:method:: loans_to(t: int) -> float Returns loans up to time t :param t: time :returns: An array of `t` real numbers giving the loans registered at time-steps up to `t` .. py:method:: add_loan(total: float, t: int) -> bool Adds a loan at the given time :param total: Total amount of the loan :param t: time step to take the loan :returns: Success or failure Remarks: - Taking a loan is simulated as reception of money. Payment back of the loan is not simulated in this call. To simulate paying back the loan, use `pay` at the times of installment payments. .. py:method:: pay(payment: float, t: int, ignore_money_shortage: bool = True) -> bool Simulate payment at time t :param payment: Amount payed :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :returns: Success or failure .. py:method:: transport_to(product: int, quantity: int, t: int, ignore_inventory_shortage: bool = True, ignore_space_shortage: bool = True) -> bool Simulates transporting products to/from storage at time t :param product: product ID (index) :param quantity: quantity to transport :param t: time :param ignore_inventory_shortage: Ignore shortage in the `product` which may lead to negative storage[product] :param ignore_space_shortage: Ignore the limit on total storage which may lead to total_storage > max_storage :returns: Success or failure .. py:method:: schedule(job: scml.scml2019.common.Job, ignore_inventory_shortage=True, ignore_money_shortage=True, ignore_space_shortage=True, override=True) -> bool Simulates scheduling the given job at its `time` and `line` optionally overriding whatever was already scheduled :param job: Production job :param ignore_inventory_shortage: If true shortages in inputs will be ignored :param ignore_money_shortage: If true, shortage in money will be ignored :param ignore_space_shortage: If true, shortage in space will be ignored :param override: Whether the job should override any already registered job at its time-step :returns: Success/failure .. py:method:: buy(product: int, quantity: int, price: int, t: int, ignore_money_shortage: bool = True, ignore_space_shortage: bool = True) -> bool Buy a given quantity of a product for a given price at some time t :param product: Product to buy (ID/index) :param quantity: quantity to buy :param price: unit price :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :param ignore_space_shortage: Ignore the limit on total storage which may lead to total_storage > max_storage :returns: Success or failure Remarks: - buy cannot ever have inventory shortage .. seealso:: `sell` .. py:method:: sell(product: int, quantity: int, price: int, t: int, ignore_money_shortage: bool = True, ignore_inventory_shortage: bool = True) -> bool sell a given quantity of a product for a given price at some time t :param product: Index/ID of the product to be sold :param quantity: quantity to be sold :param price: unit price :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :param ignore_inventory_shortage: Ignore shortage in the `product` which may lead to negative storage[product] :returns: Success or failure Remarks: - sell cannot ever have space shortage .. seealso:: `buy` .. py:property:: fixed_before Gives the time before which the schedule is fixed. .. seealso:: `fix_before` .. py:class:: FastFactorySimulator(initial_wallet: float, initial_storage: Dict[int, int], n_steps: int, n_products: int, profiles: List[scml.scml2019.common.ManufacturingProfile], max_storage: Optional[int]) Bases: :py:obj:`FactorySimulator` A faster implementation of the `FactorySimulator` interface (compared with `SlowFactorySimulator`. .. py:method:: _as_array(storage: Dict[int, int]) -> numpy.array .. py:attribute:: _wallet .. py:attribute:: _loans .. py:attribute:: _storage .. py:attribute:: _total_storage .. py:attribute:: _profiles :value: [] .. py:attribute:: _n_lines .. py:attribute:: _line_schedules .. py:attribute:: _has_jobs .. py:attribute:: _fixed_before :value: 0 .. py:attribute:: _bookmarks :type: List[_FullBookmark] :value: [] .. py:attribute:: _active_bookmark :type: Optional[_FullBookmark] :value: None .. py:method:: init(*args, **kwargs) .. py:property:: fixed_before Gives the time before which the schedule is fixed. .. seealso:: `fix_before` .. py:property:: n_lines Number of lines .. py:property:: final_balance :type: float Final balance given everything scheduled so-far .. py:method:: wallet_to(t: int) -> numpy.array Returns the cash in wallet up to and including time t. :param t: Time Returns: .. py:method:: storage_to(t: int) -> numpy.array Returns the storage of all products *up to* time t :param t: Time :returns: An array of size `n_products` * `t` giving the quantity of each product in storage at every step up to `t`. .. py:method:: line_schedules_to(t: int) -> numpy.array Returns the schedule of each line up to a given timestep :param t: time :returns: An array of `n_lines` * `t` values giving the schedule up to `t`. Remarks: - A `NO_PRODUCTION` value means no production, otherwise the index of the process being run .. py:method:: loans_to(t: int) -> numpy.array Returns loans up to time t :param t: time :returns: An array of `t` real numbers giving the loans registered at time-steps up to `t` .. py:method:: add_loan(total: float, t: int) -> bool Adds a loan at the given time :param total: Total amount of the loan :param t: time step to take the loan :returns: Success or failure Remarks: - Taking a loan is simulated as reception of money. Payment back of the loan is not simulated in this call. To simulate paying back the loan, use `pay` at the times of installment payments. .. py:method:: pay(payment: float, t: int, ignore_money_shortage: bool = True) -> bool Simulate payment at time t :param payment: Amount payed :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :returns: Success or failure .. py:method:: transport_to(product: int, quantity: int, t: int, ignore_inventory_shortage: bool = True, ignore_space_shortage: bool = True) -> bool Simulates transporting products to/from storage at time t :param product: product ID (index) :param quantity: quantity to transport :param t: time :param ignore_inventory_shortage: Ignore shortage in the `product` which may lead to negative storage[product] :param ignore_space_shortage: Ignore the limit on total storage which may lead to total_storage > max_storage :returns: Success or failure .. py:method:: buy(product: int, quantity: int, price: int, t: int, ignore_money_shortage: bool = True, ignore_space_shortage: bool = True) -> bool Buy a given quantity of a product for a given price at some time t :param product: Product to buy (ID/index) :param quantity: quantity to buy :param price: unit price :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :param ignore_space_shortage: Ignore the limit on total storage which may lead to total_storage > max_storage :returns: Success or failure Remarks: - buy cannot ever have inventory shortage .. seealso:: `sell` .. py:method:: sell(product: int, quantity: int, price: int, t: int, ignore_money_shortage: bool = True, ignore_inventory_shortage: bool = True) -> bool sell a given quantity of a product for a given price at some time t :param product: Index/ID of the product to be sold :param quantity: quantity to be sold :param price: unit price :param t: time :param ignore_money_shortage: If True, shortage in money will be ignored and the wallet can go negative :param ignore_inventory_shortage: Ignore shortage in the `product` which may lead to negative storage[product] :returns: Success or failure Remarks: - sell cannot ever have space shortage .. seealso:: `buy` .. py:method:: schedule(job: scml.scml2019.common.Job, ignore_inventory_shortage=True, ignore_money_shortage=True, ignore_space_shortage=True, override=True) -> bool Simulates scheduling the given job at its `time` and `line` optionally overriding whatever was already scheduled :param job: Production job :param ignore_inventory_shortage: If true shortages in inputs will be ignored :param ignore_money_shortage: If true, shortage in money will be ignored :param ignore_space_shortage: If true, shortage in space will be ignored :param override: Whether the job should override any already registered job at its time-step :returns: Success/failure .. py:method:: fix_before(t: int) -> bool Fix the history before this point :param t: time :returns: Success/failure Remarks: - After this function is called at any time-step `t`, there is no way to change any component of the factory state at any timestep before `t`. - This function is useful for *fixing* any difference between the simulator and the real state (in conjunction with `set_state`). .. seealso:: `set_state` `fixed_before` .. py:method:: delete_bookmark(bookmark_id: int) -> bool Commits everything since the bookmark so it cannot be rolled back :param bookmark_id The bookmark ID returned from bookmark: :returns: Success/failure Remarks: - You can delete bookmarks in the reverse order of their creation only. If the bookmark ID given here is not the one at the top of the bookmarks stack, the deletion will fail (return False). .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: bookmark() -> int Sets a bookmark to the current location :returns: bookmark ID Remarks: - Bookmarks can be used to implement transactions. .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: rollback(bookmark_id: int) -> bool Rolls back to the given bookmark ID :param bookmark_id The bookmark ID returned from bookmark: Remarks: - You can only rollback in the reverse order of bookmarks. If the bookmark ID given here is not the one at the top of the bookmarks stack, the rollback will fail (return False) .. seealso:: `delete_bookmark` `rollback` `transaction` `temporary_transaction` .. py:method:: set_state(t: int, storage: numpy.array, wallet: float, loans: float, line_schedules: numpy.array) -> None Sets the current state at the given time-step. It implicitly causes a fix_before(t + 1) :param t: Time step to set the state at :param storage: quantity of every product (array of integers of size `n_products`) :param wallet: Cash in wallet :param loans: Loans :param line_schedules: Line schedules (array of process numbers/NO_PRODUCTION of size `n_lines`) .. py:function:: transaction(simulator) Runs the simulated actions then confirms them if they are not rolled back .. py:function:: temporary_transaction(simulator) Runs the simulated actions then rolls them back .. py:function:: anac2019_world(competitors: Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]] = (), params: Sequence[Dict[str, Any]] = (), randomize: bool = True, log_file_name: str = None, name: str = None, agent_names_reveal_type: bool = False, n_intermediate: Tuple[int, int] = (1, 4), n_miners=5, n_factories_per_level=11, n_agents_per_competitor=1, n_consumers=5, n_lines_per_factory=10, guaranteed_contracts=False, use_consumer=True, max_insurance_premium=float('inf'), n_retrials=5, negotiator_type: str = DEFAULT_NEGOTIATOR, transportation_delay=0, default_signing_delay=0, max_storage=sys.maxsize, consumption_horizon=15, consumption=(3, 5), negotiation_speed=21, neg_time_limit=60 * 4, neg_n_steps=20, n_steps=100, time_limit=90 * 90, n_default_per_level: int = 5, compact: bool = False, **kwargs) -> scml.scml2019.world.SCML2019World Creates a world compatible with the ANAC 2019 competition. Note that :param n_agents_per_competitor: Number of instantiations of each competing type. :param name: SCML2020World name to use :param agent_names_reveal_type: If true, a snake_case version of the agent_type will prefix agent names :param randomize: If true, managers are assigned to factories randomly otherwise in the order :param they are giving: :type they are giving: cycling :param n_intermediate: :param n_default_per_level: :param competitors: A list of class names for the competitors :param params: A list of dictionaries giving parameters to pass to the competitors :param n_miners: number of miners of the single raw material :param n_factories_per_level: number of factories at every production level :param n_consumers: number of consumers of the final product :param n_steps: number of simulation steps :param n_lines_per_factory: number of lines in each factory :param negotiation_speed: The number of negotiation steps per simulation step. None means infinite :param default_signing_delay: The number of simulation between contract conclusion and signature :param neg_n_steps: The maximum number of steps of a single negotiation (that is double the number of rounds) :param neg_time_limit: The total time-limit of a single negotiation :param time_limit: The total time-limit of the simulation :param transportation_delay: The transportation delay :param n_retrials: The number of retrials the `Miner` and `GreedyFactoryManager` will try if negotiations fail :param max_insurance_premium: The maximum insurance premium accepted by `GreedyFactoryManager` (-1 to disable) :param use_consumer: If true, the `GreedyFactoryManager` will use an internal consumer for buying its needs :param guaranteed_contracts: If true, the `GreedyFactoryManager` will only sign contracts that it can guaratnee not to :param break.: :param consumption_horizon: The number of steps for which `Consumer` publishes `CFP` s :param consumption: The consumption schedule will be sampled from a uniform distribution with these limits inclusive :param log_file_name: File name to store the logs :param negotiator_type: The negotiation factory used to create all negotiators :param max_storage: maximum storage capacity for all factory managers If None then it is unlimited :param compact: If True, then compact logs will be created to reduce memory footprint :param kwargs: key-value pairs to be passed as argument to chain_world() and then to SCML2019World() :returns: SCML2019World ready to run Remarks: - Every production level n has one process only that takes n steps to complete .. py:function:: anac2019_tournament(competitors: Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]], agent_names_reveal_type=False, n_configs: int = 5, max_worlds_per_config: int = 1000, n_runs_per_world: int = 5, n_agents_per_competitor: int = 5, tournament_path: str = None, total_timeout: Optional[int] = None, parallelism='parallel', scheduler_ip: Optional[str] = None, scheduler_port: Optional[str] = None, tournament_progress_callback: Callable[[Optional[negmas.tournaments.WorldRunResults]], None] = None, world_progress_callback: Callable[[Optional[scml.scml2019.world.SCML2019World]], None] = None, name: str = None, verbose: bool = False, configs_only=False, compact=False, **kwargs) -> Union[negmas.tournaments.TournamentResults, os.PathLike] The function used to run ANAC 2019 SCML tournament (collusion track). :param name: Tournament name :param competitors: A list of class names for the competitors :param agent_names_reveal_type: If true then the type of an agent should be readable in its name (most likely at its beginning). :param n_configs: The number of different world configs (up to competitor assignment) to be generated. :param max_worlds_per_config: The maximum number of worlds to run per config. If None, then all possible assignments of competitors within each config will be tried (all permutations). :param n_runs_per_world: Number of runs per world. All of these world runs will have identical competitor assignment and identical world configuration. :param n_agents_per_competitor: Number of agents per competitor :param total_timeout: Total timeout for the complete process :param tournament_path: Path at which to store all results. A scores.csv file will keep the scores and logs folder will keep detailed logs :param parallelism: Type of parallelism. Can be 'serial' for serial, 'parallel' for parallel and 'distributed' for distributed :param scheduler_port: Port of the dask scheduler if parallelism is dask, dist, or distributed :param scheduler_ip: IP Address of the dask scheduler if parallelism is dask, dist, or distributed :param world_progress_callback: A function to be called after everystep of every world run (only allowed for serial evaluation and should be used with cautious). :param tournament_progress_callback: A function to be called with `WorldRunResults` after each world finished processing :param verbose: Verbosity :param configs_only: If true, a config file for each :param compact: If true, effort will be made to reduce memory footprint including disableing most logs :param kwargs: Arguments to pass to the `world_generator` function :returns: `TournamentResults` The results of the tournament or a `PathLike` giving the location where configs were saved Remarks: Default parameters will be used in the league with the exception of `parallelism` which may use distributed processing .. py:function:: anac2019_collusion(competitors: Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]], competitor_params: Optional[Sequence[Dict[str, Any]]] = None, agent_names_reveal_type=False, n_configs: int = 5, max_worlds_per_config: Optional[int] = 1000, n_runs_per_world: int = 5, n_agents_per_competitor: int = 5, min_factories_per_level: int = 5, tournament_path: str = None, total_timeout: Optional[int] = None, parallelism='parallel', scheduler_ip: Optional[str] = None, scheduler_port: Optional[str] = None, tournament_progress_callback: Callable[[Optional[negmas.tournaments.WorldRunResults]], None] | None = None, world_progress_callback: Callable[[Optional[scml.scml2019.world.SCML2019World]], None] | None = None, non_competitors: Optional[Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]]] = None, non_competitor_params: Optional[Sequence[Dict[str, Any]]] = None, name: str | None = None, verbose: bool = False, configs_only=False, compact=False, **kwargs) -> Union[negmas.tournaments.TournamentResults, os.PathLike] The function used to run ANAC 2019 SCML tournament (collusion track). :param name: Tournament name :param competitors: A list of class names for the competitors :param competitor_params: A list of competitor parameters (used to initialize the competitors). :param agent_names_reveal_type: If true then the type of an agent should be readable in its name (most likely at its beginning). :param n_configs: The number of different world configs (up to competitor assignment) to be generated. :param max_worlds_per_config: The maximum number of worlds to run per config. If None, then all possible assignments of competitors within each config will be tried (all permutations). :param n_runs_per_world: Number of runs per world. All of these world runs will have identical competitor assignment and identical world configuration. :param n_agents_per_competitor: Number of agents per competitor :param min_factories_per_level: Minimum number of factories for each production level :param total_timeout: Total timeout for the complete process :param tournament_path: Path at which to store all results. A scores.csv file will keep the scores and logs folder will keep detailed logs :param parallelism: Type of parallelism. Can be 'serial' for serial, 'parallel' for parallel and 'distributed' for distributed :param scheduler_port: Port of the dask scheduler if parallelism is dask, dist, or distributed :param scheduler_ip: IP Address of the dask scheduler if parallelism is dask, dist, or distributed :param world_progress_callback: A function to be called after everystep of every world run (only allowed for serial evaluation and should be used with cautious). :param tournament_progress_callback: A function to be called with `WorldRunResults` after each world finished processing :param non_competitors: A list of agent types that will not be competing in the sabotage competition but will exist in the world :param non_competitor_params: parameters of non competitor agents :param verbose: Verbosity :param configs_only: If true, a config file for each :param compact: If true, compact logs will be created and effort will be made to reduce the memory footprint :param kwargs: Arguments to pass to the `world_generator` function :returns: `TournamentResults` The results of the tournament or a `PathLike` giving the location where configs were saved Remarks: Default parameters will be used in the league with the exception of `parallelism` which may use distributed processing .. py:function:: anac2019_std(competitors: Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]], competitor_params: Optional[Sequence[Dict[str, Any]]] = None, agent_names_reveal_type=False, n_configs: int = 5, max_worlds_per_config: Optional[int] = 1000, n_runs_per_world: int = 5, min_factories_per_level: int = 5, tournament_path: str = None, total_timeout: Optional[int] = None, parallelism='parallel', scheduler_ip: Optional[str] = None, scheduler_port: Optional[str] = None, tournament_progress_callback: Callable[[Optional[negmas.tournaments.WorldRunResults]], None] = None, world_progress_callback: Callable[[Optional[scml.scml2019.world.SCML2019World]], None] = None, non_competitors: Optional[Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]]] = None, non_competitor_params: Optional[Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]]] = None, name: str = None, verbose: bool = False, configs_only=False, compact=False, **kwargs) -> Union[negmas.tournaments.TournamentResults, os.PathLike] The function used to run ANAC 2019 SCML tournament (standard track). :param name: Tournament name :param competitors: A list of class names for the competitors :param competitor_params: A list of competitor parameters (used to initialize the competitors). :param agent_names_reveal_type: If true then the type of an agent should be readable in its name (most likely at its beginning). :param n_configs: The number of different world configs (up to competitor assignment) to be generated. :param max_worlds_per_config: The maximum number of worlds to run per config. If None, then all possible assignments of competitors within each config will be tried (all permutations). :param n_runs_per_world: Number of runs per world. All of these world runs will have identical competitor assignment and identical world configuration. :param min_factories_per_level: Minimum number of factories for each production level :param total_timeout: Total timeout for the complete process :param tournament_path: Path at which to store all results. A scores.csv file will keep the scores and logs folder will keep detailed logs :param parallelism: Type of parallelism. Can be 'serial' for serial, 'parallel' for parallel and 'distributed' for distributed :param scheduler_port: Port of the dask scheduler if parallelism is dask, dist, or distributed :param scheduler_ip: IP Address of the dask scheduler if parallelism is dask, dist, or distributed :param world_progress_callback: A function to be called after everystep of every world run (only allowed for serial evaluation and should be used with cautious). :param tournament_progress_callback: A function to be called with `WorldRunResults` after each world finished processing :param non_competitors: A list of agent types that will not be competing in the sabotage competition but will exist in the world :param non_competitor_params: parameters of non competitor agents :param verbose: Verbosity :param configs_only: If true, a config file for each :param compact: If true, compact logs will be created and effort will be made to reduce the memory footprint :param kwargs: Arguments to pass to the `world_generator` function :returns: `TournamentResults` The results of the tournament or a `PathLike` giving the location where configs were saved Remarks: Default parameters will be used in the league with the exception of `parallelism` which may use distributed processing .. py:function:: balance_calculator(worlds: List[scml.scml2019.world.SCML2019World], scoring_context: Dict[str, Any], dry_run: bool, ignore_default=True) -> negmas.tournaments.WorldRunResults A scoring function that scores factory managers' performance by the final balance only ignoring whatever still in their inventory. :param worlds: The world which is assumed to be run up to the point at which the scores are to be calculated. :param scoring_context: A dict of context parameters passed by the world generator or assigner. :param dry_run: A boolean specifying whether this is a dry_run. For dry runs, only names and types are expected in the returned `WorldRunResults` :returns: WorldRunResults giving the names, scores, and types of factory managers. .. py:function:: anac2019_sabotage(competitors: Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]], competitor_params: Optional[Sequence[Dict[str, Any]]] = None, agent_names_reveal_type=False, n_configs: int = 5, max_worlds_per_config: Optional[int] = 1000, n_runs_per_world: int = 5, n_agents_per_competitor: int = 5, min_factories_per_level: int = 5, tournament_path: str | pathlib.Path | None = None, total_timeout: Optional[int] = None, parallelism='parallel', scheduler_ip: Optional[str] = None, scheduler_port: Optional[str] = None, tournament_progress_callback: Callable[[Optional[negmas.tournaments.WorldRunResults]], None] = None, world_progress_callback: Callable[[Optional[scml.scml2019.world.SCML2019World]], None] = None, non_competitors: Optional[Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]]] = None, non_competitor_params: Optional[Sequence[Union[str, Type[scml.scml2019.factory_managers.builtins.FactoryManager]]]] = None, name: str = None, verbose: bool = False, configs_only=False, compact=False, **kwargs) -> Union[negmas.tournaments.TournamentResults, os.PathLike] The function used to run ANAC 2019 SCML tournament (collusion track). :param name: Tournament name :param competitors: A list of class names for the competitors :param competitor_params: A list of competitor parameters (used to initialize the competitors). :param agent_names_reveal_type: If true then the type of an agent should be readable in its name (most likely at its beginning). :param n_configs: The number of different world configs (up to competitor assignment) to be generated. :param max_worlds_per_config: The maximum number of worlds to run per config. If None, then all possible assignments of competitors within each config will be tried (all permutations). :param n_runs_per_world: Number of runs per world. All of these world runs will have identical competitor assignment and identical world configuration. :param n_agents_per_competitor: Number of agents per competitor :param min_factories_per_level: Minimum number of factories for each production level :param total_timeout: Total timeout for the complete process :param tournament_path: Path at which to store all results. A scores.csv file will keep the scores and logs folder will keep detailed logs :param parallelism: Type of parallelism. Can be 'serial' for serial, 'parallel' for parallel and 'distributed' for distributed :param scheduler_port: Port of the dask scheduler if parallelism is dask, dist, or distributed :param scheduler_ip: IP Address of the dask scheduler if parallelism is dask, dist, or distributed :param world_progress_callback: A function to be called after every step of every world run (only allowed for serial evaluation and should be used with cautious). :param tournament_progress_callback: A function to be called with `WorldRunResults` after each world finished processing :param non_competitors: A list of agent types that will not be competing in the sabotage competition but will exist in the world :param non_competitor_params: parameters of non competitor agents :param verbose: Verbosity :param configs_only: If true, a config file for each :param compact: If true, compact logs will be created and effort will be made to reduce the memory footprint :param kwargs: Arguments to pass to the `world_generator` function :returns: `TournamentResults` The results of the tournament or a `PathLike` giving the location where configs were saved Remarks: Default parameters will be used in the league with the exception of `parallelism` which may use distributed processing .. py:class:: DefaultGreedyManager(*args, reserved_value=0.0, negotiator_params=None, optimism=0.0, negotiator_type=DEFAULT_NEGOTIATOR, n_retrials=5, use_consumer=True, reactive=True, sign_only_guaranteed_contracts=False, riskiness=0.0, max_insurance_premium: float = float('inf'), **kwargs) Bases: :py:obj:`scml.scml2019.factory_managers.builtins.GreedyFactoryManager` The default factory manager that will be implemented by the committee of ANAC-SCML 2019 .. py:class:: SCML2019World(products: Collection[scml.scml2019.common.Product], processes: Collection[scml.scml2019.common.Process], factories: List[scml.scml2019.common.Factory], consumers: List[scml.scml2019.consumers.Consumer], miners: List[scml.scml2019.miners.Miner], factory_managers: Optional[List[scml.scml2019.factory_managers.builtins.FactoryManager]] = None, n_steps=100, time_limit=60 * 90, mechanisms: Optional[Dict[str, Dict[str, Any]]] = None, neg_n_steps=20, neg_time_limit=2 * 60, neg_step_time_limit=60, negotiation_speed=21, no_bank=False, minimum_balance=0, interest_rate=0.1, interest_max=0.3, installment_interest=0.2, interest_time_increment=0.02, balance_at_max_interest=None, loan_installments=1, no_insurance=False, premium=0.03, premium_time_increment=0.03, premium_breach_increment=0.001, max_allowed_breach_level=None, breach_processing=BreachProcessing.VICTIM_THEN_PERPETRATOR, breach_penalty_society=0.1, breach_penalty_society_min=0.0, breach_penalty_victim=0.0, breach_move_max_product=True, initial_wallet_balances: Optional[int] = None, money_resolution=0.5, default_signing_delay=0, transportation_delay: int = 0, transfer_delay: int = 0, start_negotiations_immediately=False, catalog_profit=0.15, avg_process_cost_is_public=True, catalog_prices_are_public=True, strip_annotations=True, financial_reports_period=10, ignore_negotiated_penalties=False, prevent_cfp_tampering=False, default_price_for_products_without_one=1, compensation_fraction=0.5, compact=False, log_folder=None, log_to_file: bool = False, log_to_screen: bool = False, log_file_level=logging.DEBUG, log_screen_level=logging.ERROR, log_file_name: str = 'log.txt', log_ufuns: bool = False, log_negotiations: bool = False, save_mechanism_state_in_contract=False, save_signed_contracts: bool = True, save_cancelled_contracts: bool = True, save_negotiations: bool = True, save_resolved_breaches: bool = True, save_unresolved_breaches: bool = True, ignore_agent_exceptions: bool = False, ignore_contract_execution_exceptions: bool = False, name: str | None = None, **kwargs) Bases: :py:obj:`negmas.situated.TimeInAgreementMixin`, :py:obj:`negmas.situated.World` The `SCML2020World` class running a simulation of supply chain management. .. py:attribute:: compact :value: False .. py:attribute:: prevent_cfp_tampering :value: False .. py:attribute:: ignore_negotiated_penalties :value: False .. py:attribute:: compensation_fraction :value: 0.5 .. py:attribute:: save_mechanism_state_in_contract :value: False .. py:attribute:: default_price_for_products_without_one :value: 1 .. py:attribute:: agents :type: Dict[str, scml.scml2019.agent.SCML2019Agent] .. py:attribute:: strip_annotations :value: True .. py:attribute:: minimum_balance :value: 0 .. py:attribute:: money_resolution :value: 0.5 .. py:attribute:: transportation_delay :value: 0 .. py:attribute:: breach_penalty_society :value: 0.1 .. py:attribute:: breach_move_max_product :value: True .. py:attribute:: breach_penalty_society_min :value: 0.0 .. py:attribute:: penalties :value: 0.0 .. py:attribute:: financial_reports_period :value: 10 .. py:attribute:: max_allowed_breach_level :value: None .. py:attribute:: catalog_profit :value: 0.15 .. py:attribute:: loan_installments :value: 1 .. py:attribute:: breach_penalty_victim :value: 0.0 .. py:attribute:: avg_process_cost_is_public :value: True .. py:attribute:: catalog_prices_are_public :value: True .. py:attribute:: initial_wallet_balances :value: None .. py:attribute:: products :type: List[scml.scml2019.common.Product] :value: [] .. py:attribute:: processes :type: List[scml.scml2019.common.Process] :value: [] .. py:attribute:: factory_managers :type: List[scml.scml2019.factory_managers.builtins.FactoryManager] :value: [] .. py:attribute:: miners :type: List[scml.scml2019.miners.Miner] :value: [] .. py:attribute:: consumers :type: List[scml.scml2019.consumers.Consumer] :value: [] .. py:attribute:: factories .. py:attribute:: _report_receivers :type: Dict[str, Set[scml.scml2019.agent.SCML2019Agent]] .. py:attribute:: f2a :type: Dict[str, scml.scml2019.agent.SCML2019Agent] .. py:attribute:: a2f :type: Dict[str, scml.scml2019.common.Factory] .. py:attribute:: __interested_agents :type: List[List[scml.scml2019.agent.SCML2019Agent]] .. py:attribute:: n_new_cfps :value: 0 .. py:attribute:: __n_nullified :value: 0 .. py:attribute:: __n_bankrupt :value: 0 .. py:attribute:: _transport :type: Dict[int, List[Tuple[scml.scml2019.agent.SCML2019Agent, int, int]]] .. py:attribute:: _transfer :type: Dict[int, List[Tuple[scml.scml2019.agent.SCML2019Agent, float]]] .. py:attribute:: transfer_delay :value: 0 .. py:attribute:: _n_production_failures :value: 0 .. py:attribute:: bank .. py:attribute:: insurance_company .. py:attribute:: traders .. py:method:: join(x: negmas.situated.Agent, simulation_priority: int = 0) Add an agent to the world. :param x: The agent to be registered :param simulation_priority: The simulation priority. Entities with lower priorities will be stepped first during Returns: .. py:method:: save_config(file_name: str) -> None Saves the config of the world as a yaml file :param file_name: Name of file to save the config to Returns: .. py:method:: assign_managers(factory_managers=Iterable[Union[str, Type[FactoryManager], FactoryManager]], params: Optional[Iterable[Dict[str, Any]]] = None) -> None Assigns existing factories to new factory managers created from the given types and parameters or manager objects. :param factory_managers: An iterable of `FactoryManager` objects type names or `FactoryManager` types to assign to :param params: parameters of the newly created managers Remarks: - factories are assigned in the same order they exist in the local `factories` attribute cycling through the input managers or types/params - If a `FactoryManager` object is given instead of a type or a string in the `factory_managers` collection, and the number of `factory_managers` is less than the number of factories in the world causing this object to cycle for more than one factory, it is assigned to the first such factory but then deep copies of it with new ids and names are assigned to the rest of the factories. That ensures that each manager has exactly one factory and that all factories are assigned exactly one unique manager. .. py:method:: random_small(n_production_levels: int = 1, n_factories: int = 10, factory_kwargs: Dict[str, Any] = None, miner_kwargs: Dict[str, Any] = None, consumer_kwargs: Dict[str, Any] = None, **kwargs) :classmethod: .. py:method:: chain_world(n_intermediate_levels=0, n_miners=5, n_factories_per_level=5, n_consumers: Union[int, Tuple[int, int], List[int]] = 5, n_steps=100, n_lines_per_factory=10, n_max_assignable_factories=None, log_file_name: str = None, agent_names_reveal_type: bool = False, negotiator_type: str = DEFAULT_NEGOTIATOR, miner_type: Union[str, Type[scml.scml2019.miners.Miner]] = ReactiveMiner, consumer_type: Union[str, Type[scml.scml2019.consumers.Consumer]] = JustInTimeConsumer, max_storage: int = sys.maxsize, default_manager_params: Dict[str, Any] = None, miner_kwargs: Dict[str, Any] = None, consumption: Union[int, Tuple[int, int]] = (0, 5), consumer_kwargs: Dict[str, Any] = None, negotiation_speed: Optional[int] = 21, manager_types: Sequence[Type[scml.scml2019.factory_managers.builtins.FactoryManager]] = (GreedyFactoryManager, ), manager_params: Optional[Sequence[Dict[str, Any]]] = None, n_default_per_level: int = 0, default_factory_manager_type: Type[scml.scml2019.factory_managers.builtins.FactoryManager] = GreedyFactoryManager, randomize: bool = True, initial_wallet_balances=1000, process_cost: Union[float, Tuple[float, float]] = (1.0, 5.0), process_time: Union[int, Tuple[int, int]] = 1, interest_rate=float('inf'), interest_max=float('inf'), shared_profile_per_factory=False, **kwargs) :classmethod: Creates a very small world in which only one raw material and one final product. The production graph is a series with `n_intermediate_levels` intermediate levels between the single raw material and single final product :param n_max_assignable_factories: The maximum number of factories assigned to managers other than the default :param randomize: If true, the factory assignment is randomized :param n_default_per_level: The number of `GreedyFactoryManager` objects guaranteed at every level :param default_factory_manager_type: The `FactoryManager` type to use as the base for default_factory_managers. You can specify how many of this type exist at every level by specifying `n_default_per_level`. If `n_default_per_level` is zero, this parameter has no effect. :param manager_types: A sequence of factory manager types to control the factories. :param manager_params: An optional sequence of dictionaries giving the parameters to pass to `manager_types`. :param consumer_type: Consumer type to use for all consumers :param miner_type: Miner type to use for all miners :param consumption: Consumption schedule :param n_intermediate_levels: The number of intermediate products :param n_miners: number of miners of the single raw material :param n_factories_per_level: number of factories at every production level :param n_consumers: number of consumers of the final product :param n_steps: number of simulation steps :param n_lines_per_factory: number of lines in each factory :param process_cost: The range of process costs. A uniform distribution will be used :param process_time: The range of process times. A uniform distribution will be used :param log_file_name: File name to store the logs :param agent_names_reveal_type: If true, agent names will start with a snake_case version of their type name :param negotiator_type: The negotiation factory used to create all negotiators :param max_storage: maximum storage capacity for all factory managers If None then it is unlimited :param default_manager_params: keyword arguments to be used for constructing factory managers :param consumer_kwargs: keyword arguments to be used for constructing consumers :param miner_kwargs: keyword arguments to be used for constructing miners :param negotiation_speed: The number of negotiation steps per simulation step. None means infinite :param interest_max: Maximum interest rate :param interest_rate: Minimum interest rate :param initial_wallet_balances: initial wallet balances for all factories :param shared_profile_per_factory: If true, all lines in the same factory will have the same profile costs :param kwargs: Any other parameters are just passed to the world constructor :returns: SCML2019World ready to run Remarks: - Every production level n has one process only that takes n steps to complete .. py:method:: random(n_raw_materials: Union[int, Tuple[int, int]] = (5, 10), raw_material_price: Union[float, Tuple[float, float]] = (1.0, 30.0), n_final_products: Union[int, Tuple[int, int]] = (3, 5), n_production_levels: Union[int, Tuple[int, int]] = (3, 5), n_products_per_level: Union[int, Tuple[int, int]] = (3, 5), n_processes_per_level: Union[int, Tuple[int, int]] = (6, 10), n_inputs_per_process: Union[int, Tuple[int, int]] = (2, 5), bias_toward_last_level_products: float = 0.0, quantity_per_input: Union[int, Tuple[int, int]] = (1, 10), input_step: Union[float, Tuple[float, float]] = 0.0, quantity_per_output: Union[int, Tuple[int, int]] = (1, 1), output_step: Union[float, Tuple[float, float]] = 1.0, process_relative_cost: Union[float, Tuple[float, float]] = (0.05, 0.4), n_outputs_per_process: Union[int, Tuple[int, int]] = (1, 1), n_lines: Union[int, Tuple[int, int]] = (3, 5), lines_are_similar: bool = False, n_processes_per_line: Union[int, Tuple[int, int]] = None, cost_for_line: Union[float, Tuple[float, float]] = (5.0, 50.0), n_production_steps: Union[int, Tuple[int, int]] = (2, 10), max_storage: Union[int, Tuple[int, int]] = 2000, n_factories: Union[int, Tuple[int, int]] = 20, n_consumers: Union[int, Tuple[int, int]] = 5, n_products_per_consumer: Union[int, Tuple[int, int]] = None, n_miners: Union[int, Tuple[int, int]] = 5, n_products_per_miner: Optional[Union[int, Tuple[int, int]]] = None, factory_manager_types: Union[Type[scml.scml2019.factory_managers.builtins.FactoryManager], List[Type[scml.scml2019.factory_managers.builtins.FactoryManager]]] = GreedyFactoryManager, consumer_types: Union[Type[scml.scml2019.consumers.Consumer], List[Type[scml.scml2019.consumers.Consumer]]] = JustInTimeConsumer, miner_types: Union[Type[scml.scml2019.miners.Miner], List[Type[scml.scml2019.miners.Miner]]] = ReactiveMiner, negotiator_type=DEFAULT_NEGOTIATOR, initial_wallet_balance: Union[float, Tuple[float, float]] = 1000, factory_kwargs: Dict[str, Any] = None, miner_kwargs: Dict[str, Any] = None, consumer_kwargs: Dict[str, Any] = None, **kwargs) :classmethod: Creates a random SCML scenario with adjustable parameters. :param n_raw_materials: Number of raw materials. Can be a value or a range. :param raw_material_price: Catalog prices for raw materials. Can be a value or a range. :param n_final_products: Number of final products. Can be a value or a range. :param n_production_levels: How deep is the production graph (number of intermediate products). Can be a value or :param a range.: :param n_products_per_level: How many intermediate products per intermediate level. Can be a value or a range. :param n_processes_per_level: Number of processes in intermediate levels. Can be a value or a range. :param n_inputs_per_process: Number of inputs per process. Can be a value or a range. :param bias_toward_last_level_products: How biased are production processes toward using products from the last :param level below them: :type level below them: 0 means not bias, 1 means only sample from this last level :param quantity_per_input: How many items are needed for each input to a process. Can be a value or a range. :param input_step: When are inputs consumed during the production process. Can be a value or a range. Default 0 :param quantity_per_output: How many items are produced per output. Can be a value or a range. :param output_step: When are outputs created during the production process. Can be a value or a range. Default 1 :param process_relative_cost: Intrinsic relative cost of processes [Outputs will be produced :param at a cost of sum: :type at a cost of sum: input costs) * (1 + process_relative_cost :param n_outputs_per_process: Number of outputs per process. Can be a value or a range. :param n_lines: Number of lines per factory. Can be a value or a range. :param lines_are_similar: If true then all lins of the same factory will have the same production processes. :param n_processes_per_line: Number of processes that can be run on each line per factory. Can be a value or a :param range.: :param cost_for_line: Cost for running a process on a line. Can be a value or a range. :param n_production_steps: Number of production steps per line. Can be a value or a range. :param max_storage: Maximum storage per factory. Can be a value or a range. :param n_factories: Number of factories. Can be a value or a range. :param n_consumers: Number of consumers. Can be a value or a range. :param n_products_per_consumer: Number of products per miner. If None then all final products will be assigned to :param every customer. Can be a value or a range.: :param n_miners: Number of miners. Can be a value or a range. :param n_products_per_miner: Number of products per miner. If None then all raw materials will be assigned to every :param miner. Can be a value or a range.: :param factory_manager_types: A callable for creating factory managers for the factories :param consumer_types: A callable for creating `Consumer` objects :param miner_types: A callable for creating `Miner` objects :param negotiator_type: A string that can be `eval`uated to a negotiator. :param initial_wallet_balance: The initial balance of all wallets :param factory_kwargs: keyword arguments to be used for constructing factory managers :param consumer_kwargs: keyword arguments to be used for constructing consumers :param miner_kwargs: keyword arguments to be used for constructing miners :param \*\*kwargs: :returns: `SCML2019World` The random world generated Remarks: - Most parameters accept either a single value or a 2-valued tuple. In the later case, it will sample a value within the range specified by the tuple (low, high) inclusive. For example the number of lines (n_lines) follows this pattern .. py:method:: _update_dynamic_product_process_info() Updates the catalog prices of all products based on the prices of their inputs .. py:method:: set_consumers(consumers: List[scml.scml2019.consumers.Consumer]) .. py:method:: set_miners(miners: List[scml.scml2019.miners.Miner]) .. py:method:: set_factory_managers(factory_managers: Optional[List[scml.scml2019.factory_managers.builtins.FactoryManager]]) .. py:method:: set_processes(processes: Collection[scml.scml2019.common.Process]) .. py:method:: set_products(products: Collection[scml.scml2019.common.Product]) .. py:method:: order_contracts_for_execution(contracts: Collection[negmas.situated.Contract]) Orders the contracts in a specific time-step that are about to be executed .. py:method:: execute_action(action: negmas.situated.Action, agent: negmas.situated.Agent, callback: Callable[[negmas.situated.Action, bool], Any] = None) -> bool Executes the given action by the given agent .. py:method:: get_private_state(agent: negmas.situated.Agent) -> scml.scml2019.common.FactoryState Reads the private state of the given agent .. py:method:: receive_financial_reports(agent: scml.scml2019.agent.SCML2019Agent, receive: bool, agents: Optional[List[str]]) Registers interest/disinterest in receiving financial reports .. py:method:: simulation_step(stage) A step of SCML simulation .. py:method:: pre_step_stats() Called at the beginning of the simulation step to prepare stats or update them Kept for backward compatibility and will be dropped. Override `update_stats` instead .. py:method:: post_step_stats() Saves relevant stats .. py:method:: start_contract_execution(contract: negmas.situated.Contract) -> Set[negmas.situated.Breach] Tries to execute the contract :param contract: :returns: The set of breaches committed if any. If there are no breaches return an empty set :rtype: Set[Breach] Remarks: - You must call super() implementation of this method before doing anything - It is possible to return None which indicates that the contract was nullified (i.e. not executed due to a reason other than an execution exeception). .. py:method:: _move_product(buyer: scml.scml2019.agent.SCML2019Agent, seller: scml.scml2019.agent.SCML2019Agent, product_id: int, quantity: int, money: float) Moves as much product and money between the buyer and seller .. py:method:: complete_contract_execution(contract: negmas.situated.Contract, breaches: List[negmas.situated.Breach], resolution: Optional[negmas.situated.Contract]) The resolution can either be None or a contract with the following items: The issues can be any or all of the following: immediate_quantity: int immediate_unit_price: float later_quantity: int later_unit_price: int later_penalty: float later_time: int .. py:method:: _move_product_force(buyer: scml.scml2019.agent.SCML2019Agent, seller: scml.scml2019.agent.SCML2019Agent, product_id: int, quantity: int, money: float) Moves as much product and money between the buyer and seller .. py:method:: register_interest(agent: scml.scml2019.agent.SCML2019Agent, products: List[int]) -> None .. py:method:: unregister_interest(agent: scml.scml2019.agent.SCML2019Agent, products: List[int]) -> None .. py:method:: make_bankrupt(agent: scml.scml2019.agent.SCML2019Agent, amount: float, beneficiary: negmas.situated.Agent, contract: Optional[negmas.situated.Contract]) -> None Marks the agent as bankrupt .. py:method:: nullify_contract(contract: negmas.situated.Contract) .. py:method:: evaluate_insurance(contract: negmas.situated.Contract, agent: scml.scml2019.agent.SCML2019Agent, t: int = None) -> Optional[float] Can be called to evaluate the premium for insuring the given contract against breachs committed by others :param agent: The agent buying the contract :param contract: hypothetical contract :param t: time at which the policy is to be bought. If None, it means current step .. py:method:: buy_insurance(contract: negmas.situated.Contract, agent: scml.scml2019.agent.SCML2019Agent) -> bool Buys insurance for the contract by the premium calculated by the insurance company. Remarks: The agent can call `evaluate_insurance` to find the premium that will be used. .. py:method:: _process_annotation(annotation: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]] Processes an annotation stripping any extra information not allowed if necessary. Will return None if the annotation is suspecious .. py:method:: run_negotiation(caller: negmas.situated.Agent, issues: Collection[negmas.outcomes.Issue], partners: Collection[negmas.situated.Agent], negotiator: negmas.Negotiator, ufun: negmas.UtilityFunction = None, caller_role: str = None, roles: Collection[str] = None, annotation: Optional[Dict[str, Any]] = None, mechanism_name: str = None, mechanism_params: Dict[str, Any] = None) -> Optional[Tuple[negmas.situated.Contract, negmas.NegotiatorMechanismInterface]] Runs a negotiation until completion :param caller: The agent requesting the negotiation :param partners: A list of partners to participate in the negotiation. Note that the caller itself may not be in this list which makes it possible for an agent to request a negotaition that it does not participate in. If that is not to be allowed in some world, override this method and explicitly check for these kinds of negotiations and return False. If partners is passed as a single string/`Agent` or as a list containing a single string/`Agent`, then he caller will be added at the beginning of the list. This will only be done if `roles` was passed as None. :param negotiator: The negotiator to be used in the negotiation :param preferences: The utility function. Only needed if the negotiator does not already know it :param caller_role: The role of the caller in the negotiation :param issues: Negotiation issues :param annotation: Extra information to be passed to the `partners` when asking them to join the negotiation :param partners: A list of partners to participate in the negotiation :param roles: The roles of different partners. If None then each role for each partner will be None :param mechanism_name: Name of the mechanism to use. It must be one of the mechanism_names that are supported by the :param `World` or None which means that the `World` should select the mechanism. If None: :param then `roles` and `my_role`: :param must also be None: :param mechanism_params: A dict of parameters used to initialize the mechanism object :returns: A Tuple of a contract and the nmi of the mechanism used to get it in case of success. None otherwise .. py:method:: run_negotiations(caller: negmas.situated.Agent, issues: Union[List[negmas.outcomes.Issue], List[List[negmas.outcomes.Issue]]], partners: List[List[negmas.situated.Agent]], negotiators: List[negmas.Negotiator], ufuns: List[negmas.UtilityFunction] = None, caller_roles: List[str] = None, roles: Optional[List[Optional[List[str]]]] = None, annotations: Optional[List[Optional[Dict[str, Any]]]] = None, mechanism_names: Optional[Union[str, List[str]]] = None, mechanism_params: Optional[Union[Dict[str, Any], List[Dict[str, Any]]]] = None, all_or_none: bool = False) -> List[Tuple[negmas.situated.Contract, negmas.NegotiatorMechanismInterface]] Requests to run a set of negotiations simultaneously. Returns after all negotiations are run to completion :param caller: The agent requesting the negotiation :param partners: A list of list of partners to participate in the negotiation. Note that the caller itself may not be in this list which makes it possible for an agent to request a negotaition that it does not participate in. If that is not to be allowed in some world, override this method and explicitly check for these kinds of negotiations and return False. If partners[i] is passed as a single string/`Agent` or as a list containing a single string/`Agent`, then he caller will be added at the beginning of the list. This will only be done if `roles` was passed as None. :param issues: Negotiation issues :param negotiators: The negotiator to be used in the negotiation :param ufuns: The utility function. Only needed if the negotiator does not already know it :param caller_roles: The role of the caller in the negotiation :param annotations: Extra information to be passed to the `partners` when asking them to join the negotiation :param partners: A list of partners to participate in the negotiation :param roles: The roles of different partners. If None then each role for each partner will be None :param mechanism_names: Name of the mechanism to use. It must be one of the mechanism_names that are supported by the :param `World` or None which means that the `World` should select the mechanism. If None: :param then `roles` and `my_role`: :param must also be None: :param mechanism_params: A dict of parameters used to initialize the mechanism object :param all_of_none: If True, ALL partners must agree to negotiate to go through. :returns: contract (None for failure) and nmi (The mechanism info [None if the partner refused the negotiation]) :rtype: A list of tuples each with two values .. py:method:: request_negotiation_about(req_id: str, caller: negmas.situated.Agent, issues: List[negmas.outcomes.Issue], partners: List[negmas.situated.Agent], roles: List[str] = None, annotation: Optional[Dict[str, Any]] = None, mechanism_name: str = None, mechanism_params: Dict[str, Any] = None, group=None) Requests to start a negotiation with some other agents :param req_id: An ID For the request that is unique to the caller :param caller: The agent requesting the negotiation :param partners: A list of partners to participate in the negotiation. Note that the caller itself may not be in this list which makes it possible for an agent to request a negotaition that it does not participate in. If that is not to be allowed in some world, override this method and explicitly check for these kinds of negotiations and return False. If partners is passed as a single string/`Agent` or as a list containing a single string/`Agent`, then he caller will be added at the beginning of the list. This will only be done if `roles` was passed as None. :param issues: Negotiation issues :param annotation: Extra information to be passed to the `partners` when asking them to join the negotiation :param partners: A list of partners to participate in the negotiation :param roles: The roles of different partners. If None then each role for each partner will be None :param mechanism_name: Name of the mechanism to use. It must be one of the mechanism_names that are supported by the :param `World` or None which means that the `World` should select the mechanism. If None: :param then `roles` and `my_role`: :param must also be None: :param mechanism_params: A dict of parameters used to initialize the mechanism object :param group: An identifier for the group to which the negotiation belongs. This is not not used by the system. :returns: None. The caller will be informed by a callback function `on_neg_request_accepted` or `on_neg_request_rejected` about the status of the negotiation. .. py:property:: winners The winners of this world (factory managers with maximum wallet balance .. py:method:: on_event(event: negmas.events.Event, sender: negmas.events.EventSource) -> None Called whenever an event is raised for which the `SCML2020World` is registered asa listener :param event: The event :param sender: The sender :returns: None .. py:method:: contract_record(contract: negmas.situated.Contract) -> Dict[str, Any] Converts a contract to a record suitable for permanent storage .. py:method:: breach_record(breach: negmas.situated.Breach) -> Dict[str, Any] Converts a breach to a record suitable for storage during the simulation .. py:method:: contract_size(contract: negmas.situated.Contract) -> float Returns an estimation of the **activity level** associated with this contract. Higher is better :param contract: Returns: .. py:class:: Factory Represents a factory within an SCML world. It is only accessed by the SCML2020World so it need not be made public. .. py:attribute:: initial_storage :type: dataclasses.InitVar[Dict[int, int]] Initial storage .. py:attribute:: initial_wallet :type: dataclasses.InitVar[float] :value: 0.0 Initial Wallet .. py:attribute:: id :type: str :value: '' Object name .. py:attribute:: profiles :type: List[ManufacturingProfile] :value: [] A list of profiles used to initialize the factory .. py:attribute:: max_storage :type: int :value: 9223372036854775807 Maximum storage allowed in this factory .. py:attribute:: min_storage :type: int :value: 0 Minimum allowed storage per product .. py:attribute:: min_balance :type: int | float :value: 0 Minimum allowed balance .. py:attribute:: initial_balance :type: float :value: 0.0 Initial balance of the factory .. py:attribute:: _commands :type: numpy.ndarray The production command currently running .. py:attribute:: _line_schedules :type: numpy.ndarray .. py:attribute:: _storage :type: Dict[int, int] Mapping from product index to the amount available in the inventory .. py:attribute:: _total_storage :type: int :value: 0 Total storage .. py:attribute:: _wallet :type: float :value: 0 Money available for purchases .. py:attribute:: _hidden_money :type: float :value: 0 Amount of money hidden by the agent .. py:attribute:: _hidden_storage :type: Dict[int, int] Mapping from product index to the amount hidden by the agent .. py:attribute:: _loans :type: float :value: 0.0 The total money owned as loans .. py:attribute:: _n_lines :type: int The number of lines in the factory, will be set using the `profiles` input .. py:attribute:: _jobs :type: Dict[Tuple[int, int], Job] The jobs waiting to be run on the factory indexed by (time, line) tuples .. py:attribute:: _next_step :type: int :value: 0 Current simulation step .. py:attribute:: _carried_updates :type: FactoryStatusUpdate Carried updates from last executed command .. py:attribute:: _world :type: negmas.situated.World :value: None .. py:method:: attach_to_world(world) .. py:method:: __post_init__(initial_storage: Dict[int, int], initial_wallet=0.0) .. py:property:: hidden_money :type: float .. py:property:: hidden_storage :type: Dict[int, int] .. py:property:: n_lines :type: int .. py:property:: jobs :type: Dict[Tuple[int, int], Job] .. py:property:: commands :type: numpy.ndarray .. py:property:: line_schedules :type: numpy.ndarray .. py:property:: wallet :type: float .. py:property:: storage :type: Dict[int, int] .. py:property:: loans :type: float .. py:property:: total_storage :type: int .. py:property:: balance :type: float The total balance of the factory .. py:property:: total_balance :type: float total balance including hidden money .. py:property:: next_step :type: int .. py:method:: add_loan(total: float) -> None .. py:method:: receive(payment: float) -> None .. py:method:: pay(payment: float) -> None .. py:method:: transport_to(product: int, quantity: int) -> None .. py:method:: buy(product: int, quantity: int, price: float) -> None .. py:method:: sell(product: int, quantity: int, price: float) -> None .. py:method:: transport_from(product: int, quantity: int) -> None .. py:method:: hide_funds(amount: float) -> None .. py:method:: hide_product(product: int, quantity: int) -> None .. py:method:: unhide_funds(amount: float) -> None .. py:method:: unhide_product(product: int, quantity: int) -> None .. py:method:: schedule(job: Job, override=False) -> None Schedules the given job at its `time` and `line` optionally overriding whatever was already scheduled :param job: :param override: :returns: Success/failure .. py:method:: _apply_updates(updates: FactoryStatusUpdate) -> None .. py:method:: step() -> List[ProductionReport] .. py:method:: _run(profile: ManufacturingProfile, override=True) -> None running is executed at the beginning of the step t :param profile: the profile to start giving both the line and process :param override: If true, override any running processes paying cancellation cost for these processes Remarks: - The output of a process that runs from step t to step t + n - 1 will only be in storage at step t + n .. py:method:: _pause(line: int) -> None pausing is executed at the end of the step :param line: the line on which the process is running :returns: The status updated for all times that need to be updated to cancel the command if it is not None. If None is returned then scheduling failed. :rtype: Optional[Dict[int, FactoryStatusUpdate]] Remarks: - Not implemented yet - pausing when nothing is running is not an error and will return an empty status update .. py:method:: _resume(line: int) -> None resumption is executed at the end of the step (starting next step count down) :param line: the line on which the process is running :returns: The status updated for all times that need to be updated to cancel the command if it is not None. If None is returned then scheduling failed. :rtype: Optional[Dict[int, FactoryStatusUpdate]] Remarks: - Not implemented yet - resuming when nothing is paused is not an error and will return an empty status update .. py:method:: _stop(line: int) -> None stopping is executed at the beginning of the current step :param line: the line on which the process is running :returns: The status updated for all times that need to be updated to cancel the command if it is not None. If None is returned then scheduling failed. :rtype: Optional[Dict[int, FactoryStatusUpdate]] Remarks: - stopping when nothing is running is not an error and will just return an empty schedule .. py:method:: _step_line(line: int) -> ProductionReport Steps the line to the time-step `t` assuming that it is already stepped to time-step t-1 given the storage :param line: the line to step :returns: ProductionReport .. py:function:: builtin_agent_types(as_str=False) Returns all built-in agents. :param as_str: If true, the full type name will be returned otherwise the type object itself. .. py:data:: __all__