Exemplo n.º 1
0
    def apply(self,
              graph: Graph,
              prod_input: List[str],
              orientation: int = 0,
              **kwargs) -> List[str]:
        # Production based on P6
        prod_input = self.__sort_prod_input(graph, prod_input)
        self.__check_prod_input(graph, prod_input)

        up_layer = graph.nodes()[prod_input[0]]['layer']
        down_layer = graph.nodes()[prod_input[3]]['layer']
        v1_up, v2_up = get_common_neighbors(graph, prod_input[0],
                                            prod_input[1], up_layer)
        pos_v1 = graph.nodes()[v1_up]['position']
        pos_v2 = graph.nodes()[v2_up]['position']

        to_merge = [[], []]
        for interior in prod_input[2:]:
            for v in get_neighbors_at(graph, interior, down_layer):
                if graph.nodes()[v]['position'] == pos_v1:
                    to_merge[0].append(v)
                elif graph.nodes()[v]['position'] == pos_v2:
                    to_merge[1].append(v)

        for v1, v2 in to_merge:
            join_overlapping_vertices(graph, v1, v2, down_layer)

        return []
Exemplo n.º 2
0
    def apply(self,
              graph: Graph,
              prod_input: List[str],
              orientation: int = 0,
              **kwargs) -> List[str]:

        self.__check_prod_input(graph, prod_input)

        overlapping_vertices = find_overlapping_vertices(graph)[0]
        layer = graph.nodes()[prod_input[0]]['layer']

        neighbours = set()
        for interior in prod_input:
            neighbours |= set(get_neighbors_at(graph, interior, layer))

        vertices_to_join = [
            neighbour for neighbour in neighbours if graph.nodes()[neighbour]
            ['position'] == graph.nodes()[overlapping_vertices[0]]['position']
        ]

        if len(vertices_to_join) == 2:
            join_overlapping_vertices(graph, vertices_to_join[0],
                                      vertices_to_join[1], layer)

        return prod_input
Exemplo n.º 3
0
    def apply(self,
              graph: Graph,
              prod_input: List[str],
              orientation: int = 0,
              **kwargs) -> List[str]:
        layer, to_merge = self.__check_prod_input(graph, prod_input)

        for v1, v2 in to_merge:
            join_overlapping_vertices(graph, v1, v2, layer)

        return []
Exemplo n.º 4
0
    def apply(self,
              graph: Graph,
              prod_input: List[str],
              orientation: int = 0,
              **kwargs) -> List[str]:
        to_merge = self.__check_prod_input(graph, prod_input)
        lower_layer = graph.nodes()[prod_input[2]]['layer']

        v1, v2 = to_merge
        join_overlapping_vertices(graph, v1, v2, lower_layer)

        return []
Exemplo n.º 5
0
    def apply(self,
              graph: Graph,
              prod_input: List[str],
              orientation: int = 0,
              **kwargs) -> List[str]:
        """
        Apply 6th production on graph

        `prod_input` is list of 6 interiors as follows: `[upper, upper, lower, lower, lower, lower]`,
        where `upper` is vertex on upper layer and `lower` on lower layer. Order of vertices in one
        layer is irrelevant.

        `orientation` and `**kwargs` are ignored

        Returns empty list, as no new vertices were added.
        """

        self.__check_prod_input(graph, prod_input)

        up_layer = graph.nodes()[prod_input[0]]['layer']
        down_layer = graph.nodes()[prod_input[2]]['layer']
        v1_up, v2_up = get_common_neighbors(graph, prod_input[0],
                                            prod_input[1], up_layer)
        pos_v1 = graph.nodes()[v1_up]['position']
        pos_v2 = graph.nodes()[v2_up]['position']

        x = (pos_v1[0] + pos_v2[0]) / 2
        y = (pos_v1[1] + pos_v2[1]) / 2
        pos_center = (x, y)

        to_merge = [[], [], []]
        for interior in prod_input[2:]:
            for v in get_neighbors_at(graph, interior, down_layer):
                if graph.nodes()[v]['position'] == pos_v1:
                    to_merge[0].append(v)
                elif graph.nodes()[v]['position'] == pos_v2:
                    to_merge[1].append(v)
                elif graph.nodes()[v]['position'] == pos_center:
                    if v not in to_merge[2]:
                        to_merge[2].append(v)

        for v1, v2 in to_merge:
            join_overlapping_vertices(graph, v1, v2, down_layer)

        return []
Exemplo n.º 6
0
    def apply(self,
              graph: Graph,
              prod_input: List[str],
              orientation: int = 0,
              **kwargs) -> List[str]:
        self.__check_prod_input(graph, prod_input)

        layer = graph.nodes()[prod_input[0]]['layer']
        overlapping_vertices = find_overlapping_vertices(graph)
        vertices_to_join = set()
        for overlapping_vertice1, overlapping_vertice2 in overlapping_vertices:
            vertices_to_join.add(overlapping_vertice1)
            vertices_to_join.add(overlapping_vertice2)

        vertices_to_join_group1 = [
            vertice for vertice in vertices_to_join
            if graph.nodes()[vertice]['position'] == graph.nodes()[list(
                vertices_to_join)[0]]['position']
        ]
        vertices_to_join_group2 = [
            vertice for vertice in vertices_to_join
            if vertice not in vertices_to_join_group1
        ]

        vertice1_group1_neighbours = get_neighbors_at(
            graph, vertices_to_join_group1[0], layer)
        vertice2_group1_neighbours = get_neighbors_at(
            graph, vertices_to_join_group1[1], layer)
        vertice1_group2_neighbours = get_neighbors_at(
            graph, vertices_to_join_group2[0], layer)
        vertice2_group2_neighbours = get_neighbors_at(
            graph, vertices_to_join_group2[1], layer)

        vertice1_group1_I_neighbours = [
            neighbour for neighbour in vertice1_group1_neighbours
            if graph.nodes()[neighbour]['label'] == "I"
        ]
        vertice2_group1_I_neighbours = [
            neighbour for neighbour in vertice2_group1_neighbours
            if graph.nodes()[neighbour]['label'] == "I"
        ]
        vertice1_group2_I_neighbours = [
            neighbour for neighbour in vertice1_group2_neighbours
            if graph.nodes()[neighbour]['label'] == "I"
        ]
        vertice2_group2_I_neighbours = [
            neighbour for neighbour in vertice2_group2_neighbours
            if graph.nodes()[neighbour]['label'] == "I"
        ]

        common_I_neighbour_vertices_to_join = []
        if vertice1_group1_I_neighbours == vertice1_group2_I_neighbours:
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group1[0])
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group2[0])
        elif vertice1_group1_I_neighbours == vertice2_group2_I_neighbours:
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group1[0])
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group2[1])
        elif vertice2_group1_I_neighbours == vertice1_group2_I_neighbours:
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group1[1])
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group2[0])
        elif vertice2_group1_I_neighbours == vertice2_group2_I_neighbours:
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group1[1])
            common_I_neighbour_vertices_to_join.append(
                vertices_to_join_group2[1])

        if graph.has_edge(common_I_neighbour_vertices_to_join[0],
                          common_I_neighbour_vertices_to_join[1]):
            graph.remove_edge(common_I_neighbour_vertices_to_join[0],
                              common_I_neighbour_vertices_to_join[1])

        join_overlapping_vertices(graph, vertices_to_join_group1[0],
                                  vertices_to_join_group1[1], layer)
        join_overlapping_vertices(graph, vertices_to_join_group2[0],
                                  vertices_to_join_group2[1], layer)

        return prod_input