def _append_to_path(prev_path, new_back_id):

    target_node_label = prev_path.source_graph.node[new_back_id]['label']
    target_edge_label = prev_path.source_graph.edge[
        prev_path.back_node_id][new_back_id]['label']

    # edge1 = tuple(prev_path.embedding_list[:2]) # (l(v1), l(e1))
    # new_edge = (target_node_label, target_edge_label)
    # embedding_list = prev_path.embedding_list + (target_edge_label, target_node_label)

    # Needs to be changed if using the O(1) method for finding new path symmetries
    # total_symmetry, front_symmetry, back_symmetry = Path.new_path_symmetries(embedding_list)

    # Check if refinement is allowed
    # append is allowed if total_symmetry == 0
    # (l(v'), l(e')) > (l(v1), l(e1))
    # if (l(v'), l(e')) == (l(v1), l(e1)) and back_symmetry >= 0

    # if total_symmetry == -1 or edge1 == new_edge and back_symmetry == -1:
    #     return None

    current_graph = graph_module.extend_nx_graph(prev_path.current_graph,
                                                 prev_path.back_node_id,
                                                 new_back_id,
                                                 target_node_label,
                                                 target_edge_label)

    # Find the embedding that begins at the previous path's back node
    # The alt embedding beginning from the new back node will be created from a different fragment
    embedding_list = embedding.create_embedding_list_if_unique(
        current_graph,
        source_id=prev_path.source_node_id,
        alt_source_id=new_back_id)
    if embedding_list is None:
        return None

    # embedding_list = embedding.create_embedding_list(current_graph, prev_path.source_node_id)

    return Path(prev_path.source_node_id,
                new_back_id,
                current_graph,
                prev_path.source_graph,
                embedding_list,
                total_symmetry=0,
                front_symmetry=0,
                back_symmetry=0)
def _create_path_from_node(node_fragment, appending_node_id):
    source_node_id, source_graph = node_fragment.source_node_id, node_fragment.source_graph

    start_node_label = source_graph.node[source_node_id]['label']
    appending_node_label = source_graph.node[appending_node_id]['label']
    edge_label = source_graph.edge[source_node_id][appending_node_id]['label']

    # Check if refinement is allowed
    if appending_node_label < start_node_label:
        return None

    current_graph = graph_module.create_nx_graph(source_node_id,
                                                 start_node_label,
                                                 appending_node_id,
                                                 appending_node_label,
                                                 edge_label)

    # Find the embedding that begins at the previous path's back node
    # The alt embedding beginning from the new back node will be created from a different fragment
    embedding_list = embedding.create_embedding_list_if_unique(
        current_graph,
        source_id=source_node_id,
        alt_source_id=appending_node_id)
    if embedding_list is None:
        return None

    # embedding_list = embedding.create_embedding_list(current_graph, node_fragment.source_node_id)

    # total_symmetry = 0 if appending_node_label == start_node_label else 1

    return Path(source_node_id,
                appending_node_id,
                current_graph,
                source_graph,
                embedding_list,
                total_symmetry=0,
                front_symmetry=0,
                back_symmetry=0)
def _create_cycle(prev_fragment, origin_id, target_id):

    source_graph = prev_fragment.source_graph
    prev_graph = prev_fragment.current_graph

    new_node_label = source_graph.node[target_id]['label']
    new_edge_label = source_graph.edge[origin_id][target_id]['label']

    current_graph = graph_module.extend_nx_graph(prev_graph, origin_id,
                                                 target_id, new_node_label,
                                                 new_edge_label)

    embedding_list = embedding.create_embedding_list_if_unique(
        current_graph,
        source_id=prev_fragment.source_node_id,
        alt_source_id=target_id)
    if embedding_list is None:
        return None

    # embedding_list = embedding.create_embedding_list(current_graph, prev_fragment.source_node_id)

    return Cycle(prev_fragment.source_node_id, current_graph, source_graph,
                 embedding_list)
 def test_labels_are_identical_and_source_has_larger_node_ids(self):
     # Use ids to select embedding when labels are identical
     embedding = emb_module.create_embedding_list_if_unique(
         self.small_graph, 2, 1)
     self.assertEqual(embedding, None)
 def test_labels_are_identical_and_source_has_smaller_node_ids(self):
     # Use ids to select embedding when labels are identical
     embedding = emb_module.create_embedding_list_if_unique(
         self.small_graph, 1, 2)
     self.assertEqual(embedding, (0, 0, 0, 13, 3, 34, 4))
 def test_initial_source_label_is_less_than_alt_label(self):
     # if source_label < alt_label, should jump to create_embedding()
     embedding = emb_module.create_embedding_list_if_unique(
         self.small_graph, 1, 4)
     self.assertEqual(embedding, (0, 0, 0, 13, 3, 34, 4))
 def test_initial_source_label_is_greater_than_alt_label(self):
     # if source_label > alt_label, should return None
     embedding = emb_module.create_embedding_list_if_unique(
         self.small_graph, 4, 1)
     self.assertEqual(embedding, None)