Esempio n. 1
0
    def valid_delete(self, x, y, H, na_y_x):

        if self.knowledge is not None:
            for h in H:
                if self.knowledge.is_forbidden(x, h):
                    return False
                if self.knowledge.is_forbidden(y, h):
                    return False

        diff = set(na_y_x)
        diff = diff - H
        return graph_util.is_clique(self.graph, diff)
Esempio n. 2
0
    def valid_insert(self, x, y, T, na_y_x):
        union = set(T)

        if self.knowledge is not None:
            if self.knowledge.is_forbidden(x, y):
                return False
            for node in union:
                if self.knowledge.is_forbidden(node, y):
                    return False

        if na_y_x != set([]):
            union.update(na_y_x)
        return graph_util.is_clique(self.graph, union) and \
               not graph_util.exists_unblocked_semi_directed_path(
                   self.graph, y, x, union, self.cycle_bound)
Esempio n. 3
0
        def outer_loop():
            previous_cliques = set()  # set of sets of nodes
            previous_cliques.add(frozenset())
            new_cliques = set()  # set of sets of nodes
            for i in range(len_T + 1):

                choices = itertools.combinations(range(len_T), i)
                choices2 = itertools.combinations(range(len_T), i)
                # print("All choices: ", list(choices2), " TNeighbors: ", t_neighbors)
                for choice in choices:
                    T = frozenset([t_neighbors[k] for k in choice])
                    # print("Choice:", T)
                    union = set(na_y_x)
                    union.update(T)

                    found_a_previous_clique = False

                    for clique in previous_cliques:
                        # basically if clique is a subset of union
                        if union >= clique:
                            found_a_previous_clique = True
                            break

                    if not found_a_previous_clique:
                        # Break out of the outer for loop
                        return

                    if not graph_util.is_clique(self.graph, union):
                        continue

                    new_cliques.add(frozenset(union))

                    bump = self.insert_eval(a, b, T, na_y_x)
                    # print("Evaluated arrow " + str(a) + " -> " + str(b) + " with T: " + str(T) + " and bump: " + str(bump));

                    if bump > 0:
                        self.add_arrow(a, b, na_y_x, T, bump)

                previous_cliques = new_cliques
                new_cliques = set()
Esempio n. 4
0
    def calculate_arrows_forward(self, a, b):
        # print("Calculate Arrows Forward: " + str(a) + " " + str(b))
        if b not in self.effect_edges_graph[a] and self.mode == "heuristic":
            print("Returning early...")
            return

        if self.knowledge is not None and self.knowledge.is_forbidden(a, b):
            return

        # print("Get neighbors for " + str(b) + " returns " + str(graph_util.neighbors(self.graph, b)))

        self.stored_neighbors[b] = graph_util.neighbors(self.graph, b)

        na_y_x = graph_util.get_na_y_x(self.graph, a, b)
        _na_y_x = list(na_y_x)

        if not graph_util.is_clique(self.graph, na_y_x):
            return

        t_neighbors = list(graph_util.get_t_neighbors(self.graph, a, b))
        # print("tneighbors for " + str(a) + ", " + str(b) + " returns " + str(t_neighbors))
        len_T = len(t_neighbors)

        def outer_loop():
            previous_cliques = set()  # set of sets of nodes
            previous_cliques.add(frozenset())
            new_cliques = set()  # set of sets of nodes
            for i in range(len_T + 1):

                choices = itertools.combinations(range(len_T), i)
                choices2 = itertools.combinations(range(len_T), i)
                # print("All choices: ", list(choices2), " TNeighbors: ", t_neighbors)
                for choice in choices:
                    T = frozenset([t_neighbors[k] for k in choice])
                    # print("Choice:", T)
                    union = set(na_y_x)
                    union.update(T)

                    found_a_previous_clique = False

                    for clique in previous_cliques:
                        # basically if clique is a subset of union
                        if union >= clique:
                            found_a_previous_clique = True
                            break

                    if not found_a_previous_clique:
                        # Break out of the outer for loop
                        return

                    if not graph_util.is_clique(self.graph, union):
                        continue

                    new_cliques.add(frozenset(union))

                    bump = self.insert_eval(a, b, T, na_y_x)
                    # print("Evaluated arrow " + str(a) + " -> " + str(b) + " with T: " + str(T) + " and bump: " + str(bump));

                    if bump > 0:
                        self.add_arrow(a, b, na_y_x, T, bump)

                previous_cliques = new_cliques
                new_cliques = set()

        outer_loop()