scml.scml2020.factory ===================== .. py:module:: scml.scml2020.factory .. autoapi-nested-parse:: Implements the world class for the SCML2020 world Classes ------- .. autoapisummary:: scml.scml2020.factory.Factory Module Contents --------------- .. py:class:: Factory(profile: scml.scml2020.common.FactoryProfile, initial_balance: int, inputs: numpy.ndarray, outputs: numpy.ndarray, catalog_prices: numpy.ndarray, world: scml.scml2020.world.SCML2020World, compensate_before_past_debt: bool, buy_missing_products: bool, production_buy_missing: bool, production_penalty: float, production_no_bankruptcy: bool, production_no_borrow: bool, agent_id: str, agent_name: Optional[str] = None, confirm_production: bool = True, initial_inventory: Optional[numpy.ndarray] = None, disallow_concurrent_negs_with_same_partners=False) A simulated factory .. py:attribute:: confirm_production :value: True .. py:attribute:: production_buy_missing .. py:attribute:: compensate_before_past_debt .. py:attribute:: buy_missing_products .. py:attribute:: production_penalty .. py:attribute:: production_no_bankruptcy .. py:attribute:: production_no_borrow .. py:attribute:: catalog_prices .. py:attribute:: initial_balance .. py:attribute:: __profile .. py:attribute:: world .. py:attribute:: profile .. py:attribute:: _disallow_concurrent_negs_with_same_partners :value: False The readonly factory profile (See `FactoryProfile` ) .. py:attribute:: commands An n_steps * n_lines array giving the process scheduled for each line at every step. -1 indicates an empty line. .. py:attribute:: _balance Current balance .. py:attribute:: _inventory Current inventory .. py:attribute:: agent_id A unique ID for the agent owning the factory .. py:attribute:: inputs An n_process array giving the number of inputs needed for each process (of the product with the same index) .. py:attribute:: outputs An n_process array giving the number of outputs produced by each process (of the product with the next index) .. py:attribute:: inventory_changes Changes in the inventory in the last step .. py:attribute:: balance_change :value: 0 Change in the balance in the last step .. py:attribute:: min_balance The minimum balance possible .. py:attribute:: is_bankrupt :value: False Will be true when the factory is bankrupt .. py:attribute:: agent_name SCML2020Agent names used for logging purposes .. py:attribute:: contracts :type: List[List[scml.scml2020.common.ContractInfo]] A list of lists of contracts per time-step (len == n_steps) .. py:property:: state :type: scml.scml2020.common.FactoryState .. py:property:: current_inventory :type: numpy.ndarray Current inventory contents .. py:property:: current_balance :type: int Current wallet balance .. py:method:: schedule_production(process: int, repeats: int, step: Union[int, Tuple[int, int]] = ANY_STEP, line: int = ANY_LINE, override: bool = True, method: str = 'latest', partial_ok: bool = False) -> Tuple[numpy.ndarray, numpy.ndarray] Orders production of the given process on the given step and line. :param process: The process index :param repeats: How many times to repeat the process :param step: The simulation step or a range of steps. The special value ANY_STEP gives the factory the freedom to schedule production at any step in the present or future. :param line: The production line. The special value ANY_LINE gives the factory the freedom to use any line :param override: Whether to override any existing commands at that line at that time. :param method: When to schedule the command if step was set to a range. Options are latest, earliest, all :param partial_ok: If true, it is OK to produce only a subset of repeats :returns: Tuple[np.ndarray, np.ndarray] The steps and lines at which production is scheduled. Remarks: - You cannot order production in the past or in the current step - Ordering production, will automatically update inventory and balance for all simulation steps assuming that this production will be carried out. At the indicated `step` if production was not possible (due to insufficient funds or insufficient inventory of the input product), the predictions for the future will be corrected. .. py:method:: order_production(process: int, steps: numpy.ndarray, lines: numpy.ndarray) -> None Orders production of the given process :param process: The process to run :param steps: The time steps to run the process at as an np.ndarray :param lines: The corresponding lines to run the process at Remarks: - len(steps) must equal len(lines) - No checks are done in this function. It is expected to be used after calling `available_for_production` .. py:method:: available_for_production(repeats: int, step: Union[int, Tuple[int, int]] = ANY_STEP, line: int = ANY_LINE, override: bool = True, method: str = 'latest') -> Tuple[numpy.ndarray, numpy.ndarray] Finds available times and lines for scheduling production. :param repeats: How many times to repeat the process :param step: The simulation step or a range of steps. The special value ANY_STEP gives the factory the freedom to schedule production at any step in the present or future. :param line: The production line. The special value ANY_LINE gives the factory the freedom to use any line :param override: Whether to override any existing commands at that line at that time. :param method: When to schedule the command if step was set to a range. Options are latest, earliest, all :returns: Tuple[np.ndarray, np.ndarray] The steps and lines at which production is scheduled. Remarks: - You cannot order production in the past or in the current step - Ordering production, will automatically update inventory and balance for all simulation steps assuming that this production will be carried out. At the indicated `step` if production was not possible (due to insufficient funds or insufficient inventory of the input product), the predictions for the future will be corrected. .. py:method:: cancel_production(step: int, line: int) -> bool Cancels pre-ordered production given that it did not start yet. :param step: Step to cancel at :param line: Line to cancel at :returns: True if step >= self.current_step Remarks: - Cannot cancel a process in the past or present. .. py:method:: step() -> List[scml.scml2020.common.Failure] Override this method to modify stepping logic. .. py:method:: spot_price(product: int, spot_loss: float) -> int Get the current spot price for buying the given product on the spot market :param product: Product :param spot_loss: Spot loss specific to that agent :returns: The unit price .. py:method:: store(product: int, quantity: int, buy_missing: bool, spot_price: float, no_bankruptcy: bool = False, no_borrowing: bool = False) -> int Stores the given amount of product (signed) to the factory. :param product: Product :param quantity: quantity to store/take out (-ve means take out) :param buy_missing: If the quantity is negative and not enough product exists in the market, it buys the product from the spot-market at an increased price of penalty :param spot_price: The fraction of unit_price added because we are buying from the spot market. Only effective if quantity is negative and not enough of the product exists in the inventory :param no_bankruptcy: Never bankrupt the agent on this transaction :param no_borrowing: Never borrow for this transaction :returns: The quantity actually stored or taken out (always positive) .. py:method:: buy(product: int, quantity: int, unit_price: int, buy_missing: bool, penalty: float, no_bankruptcy: bool = False, no_borrowing: bool = False) -> Tuple[int, int] Executes a transaction to buy/sell involving adding quantity and paying price (both are signed) :param product: The product transacted on :param quantity: The quantity (added) :param unit_price: The unit price (paid) :param buy_missing: If true, attempt buying missing products from the spot market :param penalty: The penalty as a fraction to be paid for breaches :param no_bankruptcy: If true, this transaction can never lead to bankruptcy :param no_borrowing: If true, this transaction can never lead to borrowing :returns: Tuple[int, int] The actual quantities bought and the total cost .. py:method:: pay(money: int, no_bankruptcy: bool = False, no_borrowing: bool = False, unit: int = 0) -> int Pays money :param money: amount to pay :param no_bankruptcy: If true, this transaction can never lead to bankruptcy :param no_borrowing: If true, this transaction can never lead to borrowing :param unit: If nonzero then an integer multiple of unit will be paid :returns: The amount actually paid .. py:method:: bankrupt(required: int) -> int Bankruptcy processing for the given agent :param required: The money required after the bankruptcy is processed :returns: The amount of money to pay back to the entity that should have been paid `money`