@staticmethod
def undirected_edges(weighted_edges):
    """Turn every edge into an undirected one."""
    undirected_weighted_edges = {}
    for (tail, head), (weight, relative_distance) in weighted_edges.items():
        assert not ((head, tail) in weighted_edges and (tail, head) in
            weighted_edges)
        undirected_weighted_edges[tail, head] = weight, relative_distance
        undirected_weighted_edges[head, tail] = weight, -relative_distance
    return undirected_weighted_edges
