Esempio n. 1
0
    def _process_cfp(self, cfp: 'CFP'):
        if not self.can_expect_agreement(cfp=cfp, margin=0):
            return
        profile = self.profiles.get(cfp.product, None)
        if profile is None:
            return
        if profile.cv == 0:
            alpha_u, alpha_q, alpha_t = profile.alpha_u, profile.alpha_q, profile.alpha_t
        else:
            alpha_u, alpha_q, alpha_t = tuple(
                dirichlet((profile.alpha_u, profile.alpha_q, profile.alpha_t),
                          size=1)[0])
        beta_u = pos_gauss(profile.beta_u, profile.cv)
        beta_t = pos_gauss(profile.beta_t, profile.cv)
        beta_q = pos_gauss(profile.beta_q, profile.cv)

        tau_u = pos_gauss(profile.tau_u, profile.cv)
        tau_t = pos_gauss(profile.tau_t, profile.cv)
        tau_q = pos_gauss(profile.tau_q, profile.cv)

        ufun = normalize(LinearUtilityAggregationFunction(issue_utilities={
            'time':
            lambda x: x**tau_t / beta_t,
            'quantity':
            lambda x: x**tau_q / beta_q,
            'unit_price':
            lambda x: x**tau_u / beta_u if x > 1e-7 else -2000.0,
        },
                                                          weights={
                                                              'time': alpha_t,
                                                              'quantity':
                                                              alpha_q,
                                                              'unit_price':
                                                              alpha_u
                                                          }),
                         outcomes=cfp.outcomes,
                         infeasible_cutoff=-1500)
        if self.negotiator_type == AspirationNegotiator:
            negotiator = self.negotiator_type(assume_normalized=True,
                                              name=self.name + '*' +
                                              cfp.publisher,
                                              dynamic_ufun=False,
                                              aspiration_type='boulware')
        else:
            negotiator = self.negotiator_type(assume_normalized=True,
                                              name=self.name + '*' +
                                              cfp.publisher)
        negotiator.utility_function = normalize(ufun,
                                                outcomes=cfp.outcomes,
                                                infeasible_cutoff=None)
        self.n_neg_trials[cfp.id] += 1
        self.request_negotiation(partners=[cfp.publisher, self.id],
                                 issues=cfp.issues,
                                 negotiator=negotiator,
                                 annotation=self._create_annotation(cfp=cfp),
                                 extra=None,
                                 mechanism_name='negmas.sao.SAOMechanism',
                                 roles=None)
Esempio n. 2
0
    def _process_sell_cfp(self, cfp: "CFP"):
        if self.awi.is_bankrupt(cfp.publisher):
            return None
        if self.awi.n_steps - 4 <= self.awi.current_step:
            return None
        cfp.unit_price = self.generate_price_ranges(
            0,
            self.cfp_records[cfp.product].MinPrice +
            self.cfp_records[cfp.product].MinPrice *
            self.cfp_records[cfp.product].BuyThreshold,
        )

        if self.negotiator_type == AspirationNegotiator:
            neg = self.negotiator_type(assume_normalized=True,
                                       name=self.name + ">" + cfp.publisher)
        else:
            neg = self.negotiator_type(name=self.name + ">" + cfp.publisher)
        self.request_negotiation(
            negotiator=neg,
            cfp=cfp,
            ufun=normalize(
                self.ufun_factory(self, self._create_annotation(cfp=cfp)),
                outcomes=cfp.outcomes,
                infeasible_cutoff=-1500,
            ),
        )
Esempio n. 3
0
    def _process_buy_cfp(self, cfp: 'CFP') -> None:
        if self.awi.is_bankrupt(cfp.publisher):
            return None

        """if self.simulator is None or not self.can_expect_agreement(cfp=cfp, margin=self.negotiation_margin):
            return
        if not self.can_produce(cfp=cfp):
            return"""

        if self.awi.n_steps - 3 <= self.awi.current_step and self.cfp_records[cfp.product].stock < cfp.min_quantity:
            return None
        if self.cfp_records[cfp.product].stock < -self.maxdebt:
            return None

        if cfp.max_time < 4 + (2 * cfp.product) or self.firstArrival >= cfp.max_time:
            return None

        cfp.unit_price = self.generate_price_ranges(self.cfp_records[cfp.product].MaxPrice - self.cfp_records[cfp.product].MaxPrice * self.cfp_records[cfp.product].BuyThreshold,
                                                 self.cfp_records[cfp.product].MaxPrice + self.cfp_records[cfp.product].MaxPrice * self.cfp_records[cfp.product].SellThreshold)

        if self.negotiator_type == AspirationNegotiator:
            neg = self.negotiator_type(assume_normalized=True, name=self.name + '>' + cfp.publisher)
        else:
            neg = self.negotiator_type(name=self.name + '>' + cfp.publisher)
        self.request_negotiation(negotiator=neg, cfp=cfp
                                 , ufun=normalize(self.ufun_factory(self, self._create_annotation(cfp=cfp))
                                                  , outcomes=cfp.outcomes, infeasible_cutoff=-1500))
Esempio n. 4
0
 def on_negotiation_request(self, cfp: "CFP",
                            partner: str) -> Optional[NegotiatorProxy]:
     profile = self.profiles[cfp.product]
     if profile.cv == 0:
         alpha_u, alpha_q = profile.alpha_u, profile.alpha_q
     else:
         alpha_u, alpha_q = tuple(
             dirichlet((profile.alpha_u, profile.alpha_q), size=1)[0])
     beta_u = pos_gauss(profile.beta_u, profile.cv)
     tau_u = pos_gauss(profile.tau_u, profile.cv)
     tau_q = pos_gauss(profile.tau_q, profile.cv)
     ufun = normalize(ComplexWeightedUtilityFunction(
         ufuns=[
             MappingUtilityFunction(
                 mapping=lambda x: 1 - x['unit_price']**tau_u / beta_u),
             MappingUtilityFunction(mapping=functools.partial(
                 ScheduleDrivenConsumer._qufun, tau=tau_q, profile=profile))
         ],
         weights=[alpha_u, alpha_q],
         name=self.name + '_' + partner),
                      outcomes=cfp.outcomes,
                      infeasible_cutoff=-1500)
     if self.negotiator_type == AspirationNegotiator:
         negotiator = self.negotiator_type(assume_normalized=True,
                                           name=self.name + '*' + partner,
                                           aspiration_type='boulware')
     else:
         negotiator = self.negotiator_type(name=self.name + '*' + partner)
     negotiator.name = self.name + '_' + partner
     negotiator.utility_function = ufun
     return negotiator
Esempio n. 5
0
 def _process_buy_cfp(self, cfp: 'CFP') -> None:
     # TODO5: Condition1: use the awi interface to check the bank situation of publisher, if is bankrupt, then ignore this specical cfp
     if self.awi.is_bankrupt(cfp.publisher):
         return None
     # TODO5: total insufficient funds breaches above 10,  can not except agreement, directly ignore this cfp
     # TODO5.1: what is self.simulator???
     if self.simulator is None or not self.can_expect_agreement(
             cfp=cfp, margin=self.negotiation_margin):
         return
     # TODO5: Conidtion2: if the factory can not producte the  product of this cfp, then ignore this cfp
     # TODO5.1 :requires securing input products in less than one step
     if not self.can_produce(cfp=cfp):
         return
     # TODO5: satisfy all the condition, then process this buy cfp, request **negotiation**
     if self.negotiator_type == AspirationNegotiator:
         # TODO5.1: what is the mean of assume_normalized, why when use AspirationNegotiator, set this paramters to True
         neg = self.negotiator_type(assume_normalized=True,
                                    name=self.name + '>' + cfp.publisher)
     else:
         neg = self.negotiator_type(name=self.name + '>' + cfp.publisher)
     self.request_negotiation(negotiator=neg,
                              cfp=cfp,
                              ufun=normalize(self.ufun_factory(
                                  self, self._create_annotation(cfp=cfp)),
                                             outcomes=cfp.outcomes,
                                             infeasible_cutoff=-1500))
Esempio n. 6
0
 def _unorm(self, u: UtilityFunction, mn, mx):
     if not isinstance(u, LinearUtilityAggregationFunction) and not isinstance(
         u, LinearUtilityFunction
     ):
         return normalize(u, outcomes=Issue.enumerate(issues, max_n_outcomes=1000))
     # _, mx = self._urange(u, issues)
     if mx < 0:
         return None
     u.weights = {k: _ / mx for k, _ in u.weights.items()}
     return u
Esempio n. 7
0
 def _update_ordered_outcomes(self):
     outcomes = self.mechanism_info.discrete_outcomes()
     if not self.assume_normalized:
         self.utility_function = normalize(self.utility_function,
                                           outcomes=outcomes,
                                           infeasible_cutoff=-1e-6)
     self.ordered_outcomes = sorted([(self.ufun(outcome), outcome)
                                     for outcome in outcomes],
                                    key=lambda x: x[0],
                                    reverse=True)
Esempio n. 8
0
    def respond_to_negotiation_request(self, cfp: "CFP", partner: str) -> Optional[Negotiator]:

        if self.awi.is_bankrupt(partner):
            return None
        if self.use_consumer:
            return self.consumer.respond_to_negotiation_request(cfp=cfp, partner=partner)
        else:
            neg = self.negotiator_type(name=self.name + '*' + partner, **self.negotiator_params)
            ufun = self.ufun_factory(self, self._create_annotation(cfp=cfp))
            neg.utility_function = normalize(ufun,
                                             outcomes=cfp.outcomes, infeasible_cutoff=0)
            return neg
Esempio n. 9
0
 def on_negotiation_request(self, cfp: "CFP",
                            partner: str) -> Optional[NegotiatorProxy]:
     if self.use_consumer:
         return self.consumer.on_negotiation_request(cfp=cfp,
                                                     partner=partner)
     else:
         neg = self.negotiator_type(name=self.name + '*' + partner,
                                    **self.negotiator_params)
         neg.utility_function = normalize(self.ufun_factory(
             self, self._create_annotation(cfp=cfp)),
                                          outcomes=cfp.outcomes,
                                          infeasible_cutoff=0)
         return neg
Esempio n. 10
0
 def _process_buy_cfp(self, cfp: 'CFP') -> None:
     if self.simulator is None or not self.can_expect_agreement(
             cfp=cfp, margin=self.negotiation_margin):
         return
     if not self.can_produce(cfp=cfp):
         return
     if self.negotiator_type == AspirationNegotiator:
         neg = self.negotiator_type(assume_normalized=True,
                                    name=self.name + '>' + cfp.publisher)
     else:
         neg = self.negotiator_type(name=self.name + '>' + cfp.publisher)
     neg.utility_function = normalize(self.ufun_factory(
         self, self._create_annotation(cfp=cfp)),
                                      outcomes=cfp.outcomes,
                                      infeasible_cutoff=-1500)
     self.request_negotiation(negotiator=neg,
                              extra=None,
                              partners=[cfp.publisher, self.id],
                              issues=cfp.issues,
                              annotation=self._create_annotation(cfp=cfp),
                              mechanism_name='negmas.sao.SAOMechanism')