Beispiel #1
0
    def get_criterion_value_for_item(self, item: Item) -> dict:
        result = dict()

        for elmt in self.__criterion_value_list:
            if elmt.get_item().get_name() == item.get_name():
                result[elmt.get_criterion_name()] = elmt.get_value()

        return result
def init_items(args):
    """TODO.
    """
    if args.random:
        items = []
        for k in range(args.n_items):
            items.append(Item(f"Item{k + 1}", f"Item number {k + 1}"))
        return items
    else:
        items = DEFAULT_ITEMS
    return items
Beispiel #3
0
# Imports #
###########


from preferences.Item import Item
from preferences.Criterion import Criterion
from preferences.CriterionName import CriterionName
from preferences.CriterionValue import CriterionValue


#########
# ITEMS #
#########


diesel_engine = Item("ICED", "A super cool diesel engine")
electric_engine = Item("E", "A very quiet engine")
DEFAULT_ITEMS = [diesel_engine, electric_engine]


##############
# CRITERIONS #
##############


DEFAULT_CRITERIONS = [
    Criterion(
        diesel_engine,
        CriterionName.PRODUCTION_COST,
        CriterionValue.VERY_GOOD),
    Criterion(
Beispiel #4
0
        return self._negotiations

    def step(self):
        self.__messages_service.dispatch_messages()
        self.schedule.step()

    def run_n_step(self, number_of_steps: int):
        for i in range(number_of_steps):
            self.__messages_service.dispatch_messages()
            self.schedule.step()


if __name__ == "__main__":
    # Creating a list that will contain the different engines used
    engines = [
        Item("Electric Engine", "An engine that works with electricity"),
        Item("Diesel Engine", "An engine that works with fuel"),
        Item("Hydrogen Engine", "An engine that works with hydrogen"),
        Item("Nuclear Engine", "To be used with caution"),
        Item("Flat6", "The best engine built by Porsche"),
        Item("V8AMG", "A very powerful engine"),
        Item("RollsRoyce", "Engine used by the airbus A380"),
        Item("WaterEngine", "A very interesting engine"),
        Item("Clockwork engines",
             "An engine that relies on stored mechanical energy"),
        Item("Ion drives",
             "A mix between a jet engine and an electrostatic one")
    ]

    # Creating our agents
    agents_name = ["Alice", "Bob"]
Beispiel #5
0
        """

        tuple_ = Negotiation._get_tuple(agent_1, agent_2)

        for agent, engine_ in self._negotiations[tuple_][
                "engines_mentioned"].items():

            if engine_ == engine:
                return True
        return False


if __name__ == '__main__':
    agents = ["Alice", "Bob", "Hugo"]
    item = Item("Electric Engine", "An engine that works with electricity")
    negotiations = Negotiation(agents)

    # Testing structure of the dictionary
    dict_ = negotiations._negotiations
    assert len(list(dict_.keys())) == len(agents)

    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)
Beispiel #6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.__preference = Preferences()
     self.__diesel_engine = Item("ICED", "A super cool diesel engine")
     self.__electric_engine = Item("E", "A very quiet engine")
     self.setup()
Beispiel #7
0
class TestPreferences(unittest.TestCase):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.__preference = Preferences()
        self.__diesel_engine = Item("ICED", "A super cool diesel engine")
        self.__electric_engine = Item("E", "A very quiet engine")
        self.setup()

    def setup(self):
        # Set criterion name list
        self.__preference.set_criterion_order([
            CriterionName.PRODUCTION_COST,
            CriterionName.CONSUMPTION,
            CriterionName.DURABILITY,
            CriterionName.ENVIRONMENT_IMPACT,
            CriterionName.NOISE,
        ])

        # Set criterions
        self.__preference.add_criterion(
            Criterion(self.__diesel_engine, CriterionName.PRODUCTION_COST,
                      CriterionValue.VERY_GOOD))
        self.__preference.add_criterion(
            Criterion(self.__diesel_engine, CriterionName.CONSUMPTION,
                      CriterionValue.GOOD))
        self.__preference.add_criterion(
            Criterion(self.__diesel_engine, CriterionName.DURABILITY,
                      CriterionValue.VERY_GOOD))
        self.__preference.add_criterion(
            Criterion(self.__diesel_engine, CriterionName.ENVIRONMENT_IMPACT,
                      CriterionValue.VERY_BAD))
        self.__preference.add_criterion(
            Criterion(self.__diesel_engine, CriterionName.NOISE,
                      CriterionValue.VERY_BAD))
        self.__preference.add_criterion(
            Criterion(self.__electric_engine, CriterionName.PRODUCTION_COST,
                      CriterionValue.BAD))
        self.__preference.add_criterion(
            Criterion(self.__electric_engine, CriterionName.CONSUMPTION,
                      CriterionValue.VERY_BAD))
        self.__preference.add_criterion(
            Criterion(self.__electric_engine, CriterionName.DURABILITY,
                      CriterionValue.GOOD))
        self.__preference.add_criterion(
            Criterion(self.__electric_engine, CriterionName.ENVIRONMENT_IMPACT,
                      CriterionValue.VERY_GOOD))
        self.__preference.add_criterion(
            Criterion(self.__electric_engine, CriterionName.NOISE,
                      CriterionValue.VERY_GOOD))

    def test_item_value(self):
        value = self.__diesel_engine.get_value(self.__preference,
                                               CriterionName.PRODUCTION_COST)
        self.assertEqual(value, CriterionValue.VERY_GOOD)

    def test_is_preferred_criterion(self):
        is_preferred = self.__preference.is_preferred_criterion(
            CriterionName.CONSUMPTION, CriterionName.NOISE)
        self.assertTrue(is_preferred)

    def test_score(self):
        score1 = self.__preference.compute_item_score(self.__diesel_engine)
        score2 = self.__preference.compute_item_score(self.__electric_engine)
        self.assertEqual(score1, 28)
        self.assertEqual(score2, 7)

    def test_is_preferred_item(self):
        is_preferred1 = self.__preference.is_preferred_item(
            self.__diesel_engine, self.__electric_engine)
        is_preferred2 = self.__preference.is_preferred_item(
            self.__electric_engine, self.__diesel_engine)
        self.assertTrue(is_preferred1)
        self.assertFalse(is_preferred2)

    def test_most_preferred(self):
        most_preferred_item = self.__preference.most_preferred(
            [self.__diesel_engine, self.__electric_engine])
        self.assertTrue(most_preferred_item == self.__diesel_engine)
Beispiel #8
0
        max_pos = int(0.10 * len(item_list))

        return idx_item <= max_pos


if __name__ == '__main__':
    """Testing the Preferences class.
    """
    agent_pref = Preferences()
    agent_pref.set_criterion_name_list([
        CriterionName.PRODUCTION_COST, CriterionName.ENVIRONMENT_IMPACT,
        CriterionName.CONSUMPTION, CriterionName.DURABILITY,
        CriterionName.NOISE
    ])

    diesel_engine = Item("Diesel Engine", "A super cool diesel engine")
    agent_pref.add_criterion_value(
        CriterionValue(diesel_engine, CriterionName.PRODUCTION_COST,
                       Value.VERY_GOOD))
    agent_pref.add_criterion_value(
        CriterionValue(diesel_engine, CriterionName.CONSUMPTION, Value.GOOD))
    agent_pref.add_criterion_value(
        CriterionValue(diesel_engine, CriterionName.DURABILITY,
                       Value.VERY_GOOD))
    agent_pref.add_criterion_value(
        CriterionValue(diesel_engine, CriterionName.ENVIRONMENT_IMPACT,
                       Value.VERY_BAD))
    agent_pref.add_criterion_value(
        CriterionValue(diesel_engine, CriterionName.NOISE, Value.VERY_BAD))

    electric_engine = Item("Electric Engine", "A very quiet engine")
Beispiel #9
0
        string = f"ARGUE({not_in_favor} {self.__item} <= "

        for item in self.__couple_values_list:
            string += f"{item.__str__()}, "

        for item in self.__comparison_list:
            string += f"{item.__str__()}"

        string = string.rstrip(', ')
        string += ")"

        return string


if __name__ == "__main__":
    engine = Item("Porsche", "An engine from Stuttgart")

    argument_1 = Argument(True, engine)
    argument_2 = Argument(False, engine)

    assert argument_1 != argument_2
    argument_2 = Argument(True, engine)
    assert argument_1 == argument_2
    print("[INFO] Simple equality check ... OK!")

    argument_1.add_premiss_couple_values(CriterionName.ENVIRONMENT_IMPACT,
                                         Value.VERY_GOOD)
    argument_2.add_premiss_couple_values(CriterionName.ENVIRONMENT_IMPACT,
                                         Value.GOOD)

    assert argument_1 != argument_2