Beispiel #1
0
    def generate_and_annotations(self, fig: FluidInteractionGraph) -> None:
        m = self._connectivity_matrix
        shape = m.shape
        n_cols = shape[1]

        # Find all the different columns which are equal
        all_candidates = []
        skip_list = []
        for i in range(n_cols):
            candidate = []
            candidate.append(self.get_fig(i))
            found_flag = False
            if i in skip_list:
                continue
            for j in range(i + 1, n_cols):
                if j in skip_list:
                    continue

                col_i = m[:, i]
                col_j = m[:, j]
                if np.array_equal(col_i, col_j):
                    skip_list.append(i)
                    skip_list.append(j)
                    candidate.append(self.get_edge(j))
                    found_flag = True

            if found_flag is True:
                all_candidates.append(candidate)

        print(all_candidates)
        # Generate all the different AND annotations necessary
        for candidate in all_candidates:
            for edge in candidate:
                # TODO - Figure out if the edge needs any additional markup here
                source_node = fig.get_fignode(edge[0])
                target_node = fig.get_fignode(edge[1])
                if source_node is None:
                    raise Exception(
                        "Could not find the corresponding nodes {}".format(
                            source_node))
                if target_node is None:
                    raise Exception(
                        "could not find the corresponding nodes {}".format(
                            target_node))
                fig.connect_fignodes(source_node, target_node)

            origin_nodes = [fig.get_fignode(edge[0]) for edge in candidate]
            print("Added AND annotation on FIG: {}".format(str(origin_nodes)))
            assert (origin_nodes is not None)
            annotation = fig.add_and_annotation(origin_nodes)
            self._and_annotations.append(annotation)
Beispiel #2
0
    def generate_and_annotations(self, fig: FluidInteractionGraph) -> None:
        m = self._connectivity_matrix
        shape = m.shape
        n_cols = shape[1]

        # Find all the different columns which are equal
        all_candidates = []
        skip_list = []
        for i in range(n_cols):
            candidate = []
            candidate.append(self.get_connectivity_edge(i))
            found_flag = False
            if i in skip_list:
                continue
            for j in range(i + 1, n_cols):
                if j in skip_list:
                    continue

                col_i = m[:, i]
                col_j = m[:, j]
                if np.array_equal(col_i, col_j):
                    skip_list.append(i)
                    skip_list.append(j)
                    candidate.append(self.get_connectivity_edge(j))
                    found_flag = True

            if found_flag is True:
                all_candidates.append(candidate)

        print("DISTRIBUTE-AND CANDIDATES:")
        print(all_candidates)

        # Populating this skip list is important to make sure
        # that all the nodes with the AND annotation are zero'ed
        # This will simplify how the or-compuation can be done
        for candidate in all_candidates:
            # Skip the first one and add the rest of
            # the edges into the skip list
            for i in range(1, len(candidate)):
                self.add_to_column_skip_list(candidate[i])

        # Add all the annotated edges to the list that keeps
        # track of used edges, this way we can ensrue that all
        # used edges are accounted for when we need to use the
        # NOTAnnotation

        for candidate in all_candidates:
            self._annotated_connectivity_edges.extend(candidate)

        # Generate all the different AND annotations necessary
        for candidate in all_candidates:
            for edge in candidate:
                # TODO - Figure out if the edge needs any additional markup here
                source_node = fig.get_fignode(edge[0])
                target_node = fig.get_fignode(edge[1])
                if source_node is None:
                    raise Exception(
                        "Could not find the corresponding nodes {}".format(
                            source_node))
                if target_node is None:
                    raise Exception(
                        "could not find the corresponding nodes {}".format(
                            target_node))
                fig.connect_fignodes(source_node, target_node)

            origin_nodes = [fig.get_fignode(edge[0]) for edge in candidate]
            print("Added AND annotation on FIG: {}".format(str(origin_nodes)))
            assert origin_nodes is not None
            annotation = fig.add_and_annotation(origin_nodes)
            self._and_annotations.append(annotation)