Ejemplo n.º 1
0
    def schedule_production(
        self,
        profile: int,
        step: int,
        contract: Optional[Contract] = None,
        override: bool = True,
    ) -> None:
        """
        Schedules production on the agent's factory

        Args:
            profile: Index of the profile in the agent's `compiled_profiles` list
            step: The step to start production according to the given profile
            contract: The contract for which the production is scheduled (optional)
            override: Whether to override existing production jobs schedules at the same time.

        """
        self.execute(
            action=Action(
                type="run",
                params={
                    "profile": profile,
                    "time": step,
                    "contract": contract,
                    "override": override,
                },
            )
        )
Ejemplo n.º 2
0
    def stop_production(
        self, line: int, step: int, contract: Optional[Contract], override: bool = True
    ):
        """
        Stops/cancels production scheduled at the given line at the given time.

        Args:
            line: One of the factory lines (index)
            step: Step to stop/cancel production at
            contract: The contract for which the job is scheduled (optional)
            override: Whether to override existing production jobs schedules at the same time.
        """
        self.execute(action=Action(type="stop", params={"line": line, "time": step}))
Ejemplo n.º 3
0
    def unhide_funds(self, 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.

        Args:
            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
        """
        self.execute(action=Action(type="unhide_funds", params={"amount": amount}))
Ejemplo n.º 4
0
    def unhide_inventory(self, 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.

        Args:
            product: product index
            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
        """
        self.execute(
            action=Action(
                type="unhide_product", params={"product": product, "quantity": quantity}
            )
        )
Ejemplo n.º 5
0
    def schedule_job(self, job: Job, contract: Optional[Contract]):
        """
        Schedules production using a `Job` object. This can be used to schedule any kind of job

        Args:
            job: The job description
            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.
        """
        self.execute(action=Action(
            type=job.action,
            params={
                "profile": job.profile,
                "time": job.time,
                "line": job.line,
                "contract": contract,
                "override": job.override,
            },
        ))
Ejemplo n.º 6
0
 def _execute_schedule(self, schedule: ScheduleInfo,
                       contract: Contract) -> None:
     if self.simulator is None:
         raise ValueError('No factory simulator is defined')
     awi: SCMLAWI = self.awi
     total = contract.agreement['unit_price'] * contract.agreement[
         'quantity']
     product = contract.annotation['cfp'].product
     if contract.annotation['buyer'] == self.id:
         self.simulator.buy(product=product,
                            quantity=contract.agreement['quantity'],
                            price=total,
                            t=contract.agreement['time'])
         if total <= 0 or self.max_insurance_premium < 0.0 or contract is None:
             return
         premium = awi.evaluate_insurance(contract=contract)
         if premium is None:
             return
         relative_premium = premium / total
         if relative_premium <= self.max_insurance_premium:
             awi.buy_insurance(contract=contract)
             self.simulator.pay(premium, self.awi.current_step)
         return
     # I am a seller
     self.simulator.sell(product=product,
                         quantity=contract.agreement['quantity'],
                         price=total,
                         t=contract.agreement['time'])
     for job in schedule.jobs:
         if job.action == 'run':
             awi.execute(action=Action(type=job.action,
                                       params={
                                           'profile': job.profile,
                                           'time': job.time,
                                           'contract': contract,
                                           'override': job.override
                                       }))
         else:
             awi.execute(action=Action(type=job.action,
                                       params={
                                           'line': job.line,
                                           'time': job.time,
                                           'contract': contract,
                                           'override': job.override
                                       }))
         self.simulator.schedule(job=job, override=False)
     for need in schedule.needs:
         if need.quantity_to_buy <= 0:
             continue
         product_id = need.product
         # self.simulator.reserve(product=product_id, quantity=need.quantity_to_buy, t=need.step)
         if self.use_consumer:
             self.consumer.profiles[product_id].schedule[
                 need.step] += need.quantity_to_buy
             self.consumer.register_product_cfps(
                 p=product_id,
                 t=need.step,
                 profile=self.consumer.profiles[product_id])
             continue
         product = self.products[product_id]
         if product.catalog_price is None:
             price_range = (0.0, 100.0)
         else:
             price_range = (0.5, 1.5 * product.catalog_price)
         # @todo check this. This error is raised sometimes
         if need.step < awi.current_step:
             continue
             # raise ValueError(f'need {need} at {need.step} while running at step {awi.current_step}')
         time = need.step if self.max_storage is not None else (
             awi.current_step, need.step)
         cfp = CFP(is_buy=True,
                   publisher=self.id,
                   product=product_id,
                   time=time,
                   unit_price=price_range,
                   quantity=(1, int(1.1 * need.quantity_to_buy)))
         awi.register_cfp(cfp)