scml.scml2020.awi ================= .. py:module:: scml.scml2020.awi .. autoapi-nested-parse:: Implements the Agent-World-Interface for SCML2020 worlds Classes ------- .. autoapisummary:: scml.scml2020.awi.AWI Module Contents --------------- .. py:class:: AWI(world: negmas.situated.world.World, agent: negmas.situated.agent.Agent) Bases: :py:obj:`negmas.AgentWorldInterface` The Agent SCML2020World Interface for SCML2020 world. This class contains all the methods needed to access the simulation to extract information which are divided into 5 groups: Static World Information: Information about the world and the agent that does not change over time. These include: A. Market Information: - *n_products*: Number of products in the production chain. - *n_processes*: Number of processes in the production chain. - *n_competitors*: Number of other factories on the same production level. - *all_suppliers*: A list of all suppliers by product. - *all_consumers*: A list of all consumers by product. - *catalog_prices*: A list of the catalog prices (by product). - *inputs*: Inputs to every manufacturing process. - *outputs*: Outputs to every manufacturing process. - *is_system*: Is the given system ID corresponding to a system agent? - *is_bankrupt*: Is the given agent bankrupt (None asks about self)? - *current_step*: Current simulation step (inherited from `negmas.situated.AgentWorldInterface` ). - *n_steps*: Number of simulation steps (inherited from `negmas.situated.AgentWorldInterface` ). - *relative_time*: fraction of the simulation completed (inherited from `negmas.situated.AgentWorldInterface`). - *settings*: The system settings (inherited from `negmas.situated.AgentWorldInterface` ). B. Agent Information: - *profile*: Gives the agent profile including its production cost, number of production lines, input product index, mean of its delivery penalties, mean of its disposal costs, standard deviation of its shortfall penalties and standard deviation of its disposal costs. See `OneShotProfile` for full description. This information is private information and no other agent knows it. - *n_lines*: the number of production lines in the factory (private information). - *is_first_level*: Is the agent in the first production level (i.e. it is an input agent that buys the raw material). - *is_last_level*: Is the agent in the last production level (i.e. it is an output agent that sells the final product). - *is_middle_level*: Is the agent neither a first level nor a last level agent - *my_input_product*: The input product to the factory controlled by the agent. - *my_output_product*: The output product from the factory controlled by the agent. - *my_input_products*: All input products of a factory controlled by the agent. Currently, it is always a list of one item. For future compatibility. - *my_output_products*: All output products of a factory controlled by the agent. Currently, it is always a list of one item. For future compatibility. - *available_for_production*: Returns the line-step slots available for production. - *level*: The production level which is numerically the same as the input product. - *my_suppliers*: A list of IDs for all suppliers to the agent (i.e. agents that can sell the input product of the agent). - *my_consumers*: A list of IDs for all consumers to the agent (i.e. agents that can buy the output product of the agent). - *penalties_scale*: The scale at which to calculate disposal cost/delivery penalties. "trading" and "catalog" mean trading and catalog prices. "unit" means the contract's unit price while "none" means that disposal cost/shortfall penalty are absolute. - *n_input_negotiations*: Number of negotiations with suppliers. - *n_output_negotiations*: Number of negotiations with consumers. - *state*: The full state of the agent ( `FactoryState` ). - *current_balance*: The current balance of the agent - *current_inventory*: The current inventory of the agent (quantity per product) Dynamic World Information: Information about the world and the agent that changes over time. A. Market Information: - *trading_prices*: The trading prices of all products. This information is only available if `publish_trading_prices` is set in the world. - *exogenous_contract_summary*: A list of n_products tuples each giving the total quantity and average price of exogenous contracts for a product. This information is only available if `publish_exogenous_summary` is set in the world. B. Other Agents' Information: - *reports_of_agent*: Gives all past financial reports of a given agent. See `FinancialReport` for details. - *reports_at_step*: Gives all reports of all agents at a given step. See `FinancialReport` for details. C. Current Negotiations Information: - *current_input_issues*: The current issues for all negotiations to buy the input product of the agent. If the agent is at level zero, this will be empty. - *current_output_issues*: The current issues for all negotiations to buy the output product of the agent. If the agent is at level n_products - 1, this will be empty. D. Agent Information: - *spot_market_quantity*: The quantity the agent bought from the spot market at a given step - *spot_market_loss*: The spot market loss for the agent. Actions: A. Negotiation Control: - *request_negotiations*: Requests a set of negotiations controlled by a single controller. - *request_negotiation*: Requests a negotiation controlled by a single negotiator. B. Production Control: - *schedule_production*: Schedules production using one of the predefined scheduling strategies. - *order_production*: Orders production directly for the current step. - *set_commands*: Sets production commands directly on the factory. - *cancel_production*: Cancels a scheduled production command. Services (All inherited from `negmas.situated.AgentWorldInterface`): - *logdebug/loginfo/logwarning/logerror*: Logs to the world log at the given log level. - *logdebug_agent/loginf_agnet/...*: Logs to the agent specific log at the given log level. - *bb_query*: Queries the bulletin-board. - *bb_read*: Read a section of the bulletin-board. .. py:method:: request_negotiations(is_buy: bool, product: int, quantity: Union[int, Tuple[int, int]], unit_price: Union[int, Tuple[int, int]], time: Union[int, Tuple[int, int]], controller: Optional[negmas.SAOController] = None, negotiators: List[negmas.Negotiator] = None, partners: List[str] = None, extra: Dict[str, Any] = None, copy_partner_id=True) -> bool Requests a negotiation :param is_buy: If True the negotiation is about buying otherwise selling. :param product: The product to negotiate about :param quantity: The minimum and maximum quantities. Passing a single value q is equivalent to passing (q,q) :param unit_price: The minimum and maximum unit prices. Passing a single value u is equivalent to passing (u,u) :param time: The minimum and maximum delivery step. Passing a single value t is equivalent to passing (t,t) :param controller: The controller to manage the complete set of negotiations :param negotiators: An optional list of negotiators to use for negotiating with the given partners (in the same order). :param partners: ID of all the partners to negotiate with. :param extra: Extra information accessible through the negotiation annotation to the caller :param copy_partner_id: If true, the partner ID will be copied to the negotiator ID :returns: `True` if the partner accepted and the negotiation is ready to start Remarks: - You can either use controller or negotiators. One of them must be None. - All negotiations will use the following issues **in order**: quantity, time, unit_price - Negotiations with bankrupt agents or on invalid products (see next point) will be automatically rejected - Valid products for a factory are the following (any other products are not valid): 1. Buying an input product (i.e. product $\in$ `my_input_products` ) and an output product if the world settings allows it (see `allow_buying_output`) 1. Selling an output product (i.e. product $\in$ `my_output_products` ) and an input product if the world settings allows it (see `allow_selling_input`) .. py:method:: request_negotiation(is_buy: bool, product: int, quantity: Union[int, Tuple[int, int]], unit_price: Union[int, Tuple[int, int]], time: Union[int, Tuple[int, int]], partner: str, negotiator: negmas.SAONegotiator, extra: Dict[str, Any] = None) -> bool Requests a negotiation :param is_buy: If True the negotiation is about buying otherwise selling. :param product: The product to negotiate about :param quantity: The minimum and maximum quantities. Passing a single value q is equivalent to passing (q,q) :param unit_price: The minimum and maximum unit prices. Passing a single value u is equivalent to passing (u,u) :param time: The minimum and maximum delivery step. Passing a single value t is equivalent to passing (t,t) :param partner: ID of the partner to negotiate with. :param negotiator: The negotiator to use for this negotiation (if the partner accepted to negotiate) :param extra: Extra information accessible through the negotiation annotation to the caller :returns: `True` if the partner accepted and the negotiation is ready to start Remarks: - All negotiations will use the following issues **in order**: quantity, time, unit_price - Negotiations with bankrupt agents or on invalid products (see next point) will be automatically rejected - Valid products for a factory are the following (any other products are not valid): 1. Buying an input product (i.e. product $\in$ `my_input_products` ) and an output product if the world settings allows it (see `allow_buying_output`) 1. Selling an output product (i.e. product $\in$ `my_output_products` ) and an input product if the world settings allows it (see `allow_selling_input`) .. 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 the factory to run the given process at the given line at the given step :param process: The process to run :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 existing production commands or not :param method: When to schedule the command if step was set to a range. Options are latest, earliest :param partial_ok: If true, allows partial scheduling :returns: Tuple[int, int] giving the steps and lines at which production is scheduled. Remarks: - The step cannot be in the past. Production can only be ordered for current and future steps - ordering production of process -1 is equivalent of `cancel_production` only if both step and line are given .. 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:: set_commands(commands: numpy.ndarray, step: int = -1) -> None Sets the production commands for all lines in the given step :param commands: n_lines vector of commands. A command is either a process number to run or `NO_COMMAND` to keep the line idle :param step: The step to set the commands at. If < 0, it means current step .. py:method:: cancel_production(step: int, line: int) -> bool Cancels any production commands on that line at this step :param step: The step to cancel production at (must be in the future). :param line: The production line :returns: success/failure Remarks: - The step cannot be in the past or the current step. Cancellation can only be ordered for future steps .. py:property:: trading_prices :type: numpy.ndarray Returns the current trading prices of all products .. py:property:: exogenous_contract_summary :type: List[Tuple[int, int]] The exogenous contracts in the current step for all products :returns: A list of tuples giving the total quantity and total price of all revealed exogenous contracts of all products at the current step. .. py:property:: allow_zero_quantity :type: bool Does negotiations allow zero quantity? .. py:property:: state :type: scml.scml2020.common.FactoryState Receives the factory state .. py:property:: current_balance Current balance of the agent .. py:property:: current_inventory Current inventory of the agent .. py:method:: reports_of_agent(aid: str) -> Dict[int, scml.scml2020.common.FinancialReport] Returns a dictionary mapping time-steps to financial reports of the given agent .. py:method:: reports_at_step(step: int) -> Dict[str, scml.scml2020.common.FinancialReport] Returns a dictionary mapping agent ID to its financial report for the given time-step .. py:property:: profile :type: scml.scml2020.common.FactoryProfile Gets the profile (static private information) associated with the agent .. py:property:: all_suppliers :type: List[List[str]] Returns a list of agent IDs for all suppliers for every product .. py:property:: all_consumers :type: List[List[str]] Returns a list of agent IDs for all consumers for every product .. py:property:: inputs :type: numpy.ndarray Returns the number of inputs to every production process .. py:property:: outputs :type: numpy.ndarray Returns the number of outputs to every production process .. py:property:: n_competitors :type: int Returns the number of factories/agents in the same production level .. py:property:: my_input_product :type: int Returns a list of products that are inputs to at least one process the agent can run .. py:property:: my_output_product :type: int Returns a list of products that are outputs to at least one process the agent can run .. py:property:: my_input_products :type: numpy.ndarray Returns a list of products that are inputs to at least one process the agent can run .. py:property:: my_output_products :type: numpy.ndarray Returns a list of products that are outputs to at least one process the agent can run .. py:property:: my_suppliers :type: List[str] Returns a list of IDs for all of the agent's suppliers (agents that can supply at least one product it may need). Remarks: - If the agent have multiple input products, suppliers of a specific product $p$ can be found using: **self.all_suppliers[p]**. .. py:property:: my_consumers :type: List[str] Returns a list of IDs for all the agent's consumers (agents that can consume at least one product it may produce). Remarks: - If the agent have multiple output products, consumers of a specific product $p$ can be found using: **self.all_consumers[p]**. .. py:property:: n_lines :type: int The number of lines in the corresponding factory. You can read `state` to get this among other information .. py:property:: catalog_prices :type: numpy.ndarray Returns the catalog prices of all products .. py:property:: n_products :type: int Number of products in the world .. py:property:: n_processes :type: int Returns the number of processes in the system .. py:property:: is_first_level Whether this agent is in the first production level .. py:property:: is_last_level Whether this agent is in the last production level .. py:property:: level The production level which is the index of the process for this factory (or the index of its input product) .. py:property:: is_middle_level Whether this agent is in neither in the first nor in the last level .. py:method:: is_system(aid: str) -> bool Checks whether an agent is a system agent or not :param aid: Agent ID .. py:method:: is_bankrupt(aid: Optional[str] = None) -> bool Checks whether the agent is bankrupt :param aid: Agent ID (None means self) .. py:method:: spot_market_quantity(step: Optional[int]) -> int The quantity bought by the agent from the spot market at the given step. :param step: The simulation step (day) Remarks: If step is `None`, the current step will be used .. py:method:: spot_market_loss(step: Optional[int]) -> int The spot market loss of the agent at the given step. :param step: The simulation step (day) Remarks: If step is `None`, the current step will be used