def criterion_argument(premiss: CoupleValue, engine: Item, interlocutor_id: str) -> \ Union[Argument, None]: """ Try to return a counter argument that is built on the fact that the agent has found a criterion for which the value for the engine is not good and the criterion is ranked higher in the list of preferences of the agent compared to the one mentioned in the premiss. :param premiss: CoupleValue - the premiss used by the agent with the identifier: interlocutor_id :param engine: Item - The engine that is currently being discussed by the two agents :param interlocutor_id: str - The identifier of the agent that has proposed the argument object. :return: Possibly a counter argument to the one proposed by the agent with the identifier: interlocutor_id. """ bad_criteria = Argument.list_attacking_proposal( engine, self.preference) base_criterion = premiss.get_criterion_name() # We iterate through our possible counter arguments to find if we could use one of them for criterion_name, criterion_val in bad_criteria: if self.preference.is_preferred_criterion( criterion_name, base_criterion) and base_criterion != criterion_name: argument = Argument(False, engine) # One has to remember that list_attacking_proposal and list_proposal both return a tuple of # the form (preference, value) argument.add_premiss_couple_values(criterion_name, criterion_val) argument.add_premiss_comparison( criterion_name, premiss.get_criterion_name()) if not self._negotiations.is_argument_already_used( self.get_name(), interlocutor_id, argument): return argument return None
def criterion_value(premiss: CoupleValue, interlocutor_id: str, better_value: bool, engine: Item = None) -> \ Union[Argument, None]: """ Try to return a counter argument that is built either on the fact that the agent has found that its preferred engine has a better value for the criterion mentioned in the premiss used by its interlocutor or because the engine that is currently being discussed has a value that is worst than the one mentioned in the premiss. :param premiss: CoupleValue - the premiss used by the agent with the identifier: interlocutor_id :param interlocutor_id: int - The identifier of the agent that has proposed the argument object. :param better_value: str - A boolean to determine which approach to use. :param engine: Item - The engine currently being discussed. :return: Possibly a counter argument to the one proposed by the agent with the identifier: interlocutor_id. """ argument = None preferred_engine = self.preference.most_preferred(self._engines) value_for_criterion = self.preference.get_criterion_value_for_item( preferred_engine if better_value else engine)[ premiss.get_criterion_name()] if better_value: if value_for_criterion > premiss.get_value(): argument = Argument(True, preferred_engine) argument.add_premiss_couple_values( premiss.get_criterion_name(), value_for_criterion) argument.add_premiss_comparison(value_for_criterion, premiss.get_value()) else: assert engine is not None, "You forgot to specify the engine!" if value_for_criterion < premiss.get_value(): argument = Argument(False, engine) argument.add_premiss_couple_values( premiss.get_criterion_name(), value_for_criterion) argument.add_premiss_comparison(premiss.get_value(), value_for_criterion) if argument and self._negotiations.is_argument_already_used( self.get_name(), interlocutor_id, argument): return None return argument
print("[INFO] Structure of the dictionary is correct ... OK!") # Trying to start a negotiation negotiations.start_negotiation(agents[0], agents[1]) assert dict_[(agents[0], agents[1])]["initiator"] == agents[0] print("[INFO] Starting a negotiation with Alice... OK!") # Trying to add an argument argument_1 = Argument(False, item) argument_1.add_premiss_couple_values(CriterionName.ENVIRONMENT_IMPACT, Value.VERY_BAD) argument_2 = Argument(False, item) argument_2.add_premiss_couple_values(CriterionName.ENVIRONMENT_IMPACT, Value.VERY_BAD) argument_2.add_premiss_comparison(CriterionName.ENVIRONMENT_IMPACT, CriterionName.CONSUMPTION) negotiations.add_argument(agents[0], agents[1], argument_1) negotiations.add_argument(agents[0], agents[1], argument_2) assert len(dict_[(agents[0], agents[1])]["arguments"]) print("[INFO] Adding an argument to the list... OK!") # Testing function to determine if a negotiation has started with a specific interlocutor res = negotiations.has_started_negotiation(agents[0], agents[2]) res_2 = negotiations.has_started_negotiation(agents[0], agents[1]) assert res is False assert res_2 is True print("[INFO] Function has_started_negotiation works correctly... OK!") # Testing ending a negotiation