示例#1
0
    def update_proposition_layer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        current_layer_actions is the set of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.proposition_layer.add_proposition(prop) adds the proposition prop to the current layer

        """
        current_layer_actions = self.action_layer.get_actions()
        props_and_producers = {}
        for a in current_layer_actions:
            added_propositions = a.get_add()
            for added in added_propositions:
                if added not in props_and_producers:
                    props_and_producers[added] = [a]
                else:
                    props_and_producers[added].append(a)
        for key, value in props_and_producers.items():
            new_prop = Proposition(key.name)
            new_prop.set_producers(value)
            self.proposition_layer.add_proposition(new_prop)
    def update_proposition_layer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        current_layer_actions is the set of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.proposition_layer.add_proposition(prop) adds the proposition prop to the current layer

        """
        current_layer_actions = self.action_layer.get_actions()
        new_props_set = set()
        for action1 in current_layer_actions:
            list_of_propo = action1.get_add()
            for propo in list_of_propo:
                new_props_set.add(propo.name)
        props_dict = dict.fromkeys(new_props_set, set())
        for action2 in current_layer_actions:
            list_of_propo2 = action2.get_add()
            for propo2 in list_of_propo2:
                props_dict[propo2.get_name()].add(action2)
        for prop in props_dict:
            my_prop = Proposition(prop)
            my_prop.set_producers(list(props_dict[prop]))
            self.proposition_layer.add_proposition(my_prop)
示例#3
0
    def update_proposition_layer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        current_layer_actions is the set of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.proposition_layer.add_proposition(prop) adds the proposition prop to the current layer

        """
        current_layer_actions = self.action_layer.get_actions()

        updated_props = {}

        # checks for every action and adds to the dictionary of updated props the acts that led to is
        for act in current_layer_actions:
            for prop in act.get_add():
                if prop not in updated_props:
                    updated_props[prop] = list()
                updated_props[prop].append(act)

        # create new Proposition and add it to the new layer
        for proposition in updated_props:

            # create new prop
            new_prop = Proposition(proposition.get_name())
            # add its producers
            new_prop.set_producers(updated_props[proposition][:])
            # add to new layer
            self.proposition_layer.add_proposition(new_prop)