コード例 #1
0
ファイル: strategy.py プロジェクト: 8ball030/agents-aea
    def get_proposal_for_query(self, query: Query,
                               is_seller: bool) -> Optional[Description]:
        """
        Generate proposal (in the form of a description) which matches the query.

        :param query: the query for which to build the proposal
        :is_seller: whether the agent making the proposal is a seller or not

        :return: a description
        """
        own_service_description = self.get_own_service_description(
            is_supply=is_seller)
        if not query.check(own_service_description):
            logger.debug(
                "[{}]: Current holdings do not satisfy CFP query.".format(
                    self.context.agent_name))
            return None
        else:
            proposal_description = self._get_proposal_for_query(
                query, is_seller=is_seller)
            if proposal_description is None:
                logger.debug(
                    "[{}]: Current strategy does not generate proposal that satisfies CFP query."
                    .format(self.context.agent_name))
            return proposal_description
コード例 #2
0
 def test_query_check(self):
     """Test that the query.check() method works."""
     attribute_foo = Attribute("foo", int, True, "a foo attribute.")
     attribute_bar = Attribute("bar", str, True, "a bar attribute.")
     data_model_foobar = DataModel("foobar", [attribute_foo, attribute_bar], "A foobar data model.")
     description_foobar = Description({"foo": 1, "bar": "baz"}, data_model=data_model_foobar)
     query = Query([
         And([
             Or([
                 Not(Constraint("foo", ConstraintType("==", 1))),
                 Not(Constraint("bar", ConstraintType("==", "baz")))
             ]),
             Constraint("foo", ConstraintType("<", 2)),
         ])
     ],
         data_model_foobar)
     assert not query.check(description=description_foobar)
コード例 #3
0
ファイル: strategy.py プロジェクト: 8ball030/agents-aea
    def _get_proposal_for_query(self, query: Query,
                                is_seller: bool) -> Optional[Description]:
        """
        Generate proposal (in the form of a description) which matches the query.

        :param query: the query for which to build the proposal
        :is_seller: whether the agent making the proposal is a seller or not

        :return: a description
        """
        candidate_proposals = self._generate_candidate_proposals(is_seller)
        proposals = []
        for proposal in candidate_proposals:
            if not query.check(proposal): continue
            proposals.append(proposal)
        if not proposals:
            return None
        else:
            return random.choice(proposals)
コード例 #4
0
    def get_proposal_for_query(self, query: Query, preferences: Preferences,
                               ownership_state_after_locks: OwnershipState,
                               is_seller: bool,
                               tx_fee: float) -> Optional[Description]:
        """
        Generate proposal (in the form of a description) which matches the query.

        :param query: the query for which to build the proposal
        :param ownership_state_after_locks: the ownership state after the transaction messages applied.
        :is_seller: whether the agent making the proposal is a seller or not
        :tx_fee: the transaction fee

        :return: a description
        """
        candidate_proposals = self._generate_candidate_proposals(
            preferences, ownership_state_after_locks, is_seller, tx_fee)
        proposals = []
        for proposal in candidate_proposals:
            if not query.check(proposal): continue
            proposals.append(proposal)
        if not proposals:
            return None
        else:
            return random.choice(proposals)