コード例 #1
0
ファイル: rapt_fm.py プロジェクト: yasserfarouk/scml-agents
 def can_produce(self,
                 cfp: CFP,
                 assume_no_further_negotiations=False) -> bool:
     """Whether or not we can produce the required item in time"""
     if cfp.product not in self.producing.keys():
         return False
     agreement = SCMLAgreement(time=cfp.max_time,
                               unit_price=cfp.max_unit_price,
                               quantity=cfp.min_quantity)
     min_concluded_at = self.awi.current_step + 1 - int(
         self.immediate_negotiations)
     min_sign_at = min_concluded_at + self.awi.default_signing_delay
     if cfp.max_time < min_sign_at + 1:  # 1 is minimum time to produce the product
         return False
     with temporary_transaction(self.scheduler):
         schedule = self.scheduler.schedule(
             contracts=[
                 Contract(
                     partners=[self.id, cfp.publisher],
                     agreement=agreement,
                     annotation=self._create_annotation(cfp=cfp),
                     issues=cfp.issues,
                     signed_at=min_sign_at,
                     concluded_at=min_concluded_at,
                 )
             ],
             ensure_storage_for=self.transportation_delay,
             assume_no_further_negotiations=assume_no_further_negotiations,
             start_at=min_sign_at,
         )
     return schedule.valid and self.can_secure_needs(
         schedule=schedule, step=self.awi.current_step)
コード例 #2
0
    def sign_contract(self, contract: Contract):
        if any(self.awi.is_bankrupt(partner) for partner in contract.partners):
            return None
        product = contract.annotation['cfp'].product
        if self.cfp_records[product].stock < -self.maxdebt:
            return None

        signature = self.id
        with temporary_transaction(self.scheduler):
            schedule = self.scheduler.schedule(assume_no_further_negotiations=False, contracts=[contract]
                                               , ensure_storage_for=self.transportation_delay
                                               , start_at=self.awi.current_step + 1)

        if self.sign_only_guaranteed_contracts and (not schedule.valid or len(schedule.needs) > 1):
            self.awi.logdebug(f'{self.name} refused to sign contract {contract.id} because it cannot be scheduled')
            return None

        if schedule.valid:
            profit = schedule.final_balance - self.simulator.final_balance
            self.awi.logdebug(f'{self.name} singing contract {contract.id} expecting '
                              f'{-profit if profit < 0 else profit} {"loss" if profit < 0 else "profit"}')
        else:
            self.awi.logdebug(f'{self.name} singing contract {contract.id} expecting breach')
            return None

        self.contract_schedules[contract.id] = schedule
        return signature
コード例 #3
0
ファイル: rapt_fm.py プロジェクト: yasserfarouk/scml-agents
    def sign_contract(self, contract: Contract):  ###contact
        if any(self.awi.is_bankrupt(partner) for partner in contract.partners):
            return None
        signature = self.id
        with temporary_transaction(self.scheduler):
            schedule = self.scheduler.schedule(
                assume_no_further_negotiations=False,
                contracts=[contract],
                ensure_storage_for=self.transportation_delay,
                start_at=self.awi.current_step + 1,
            )

        if self.sign_only_guaranteed_contracts and (not schedule.valid or
                                                    len(schedule.needs) > 1):
            self.awi.logdebug(
                f"{self.name} refused to sign contract {contract.id} because it cannot be scheduled"
            )
            return None
        # if schedule.final_balance <= self.simulator.final_balance:
        #     self.awi.logdebug(f'{self.name} refused to sign contract {contract.id} because it is not expected '
        #                       f'to lead to profit')
        #     return None
        if schedule.valid:
            profit = schedule.final_balance - self.simulator.final_balance
            self.awi.logdebug(
                f"{self.name} singing contract {contract.id} expecting "
                f'{-profit if profit < 0 else profit} {"loss" if profit < 0 else "profit"}'
            )
        else:
            self.awi.logdebug(
                f"{self.name} singing contract {contract.id} expecting breach")
            return None

        self.contract_schedules[contract.id] = schedule
        return signature
コード例 #4
0
 def total_utility(self, contracts: Collection[Contract] = ()) -> float:
     """Calculates the total utility for the agent of a collection of contracts"""
     if self.scheduler is None:
         raise ValueError('Cannot calculate total utility without a scheduler')
     min_concluded_at = self.awi.current_step
     min_sign_at = min_concluded_at + self.awi.default_signing_delay
     with temporary_transaction(self.scheduler):
         schedule = self.scheduler.schedule(contracts=contracts, assume_no_further_negotiations=False
                                            , ensure_storage_for=self.transportation_delay
                                            , start_at=min_sign_at)
     if not schedule.valid:
         return INVALID_UTILITY
     return schedule.final_balance