from typing import Set


def compute_number_of_edge_types(
    tied_fwd_bkwd_edge_types: Set[int], num_fwd_edge_types: int, add_self_loop_edges: bool
) -> int:
    """Computes the number of edge types after adding backward edges and possibly self loops."""
    return 2 * num_fwd_edge_types - len(tied_fwd_bkwd_edge_types) + int(add_self_loop_edges)