Ejemplo n.º 1
0
def min_crossing_path(G, u, v):

    D = G.dual()

    if len(G[u]) == 1:
        _, x = {0} | G[u]
        D.vertex_faces[u] = D.vertex_faces[x]
    if len(G[v]) == 1:
        _, x = {0} | G[v]
        D.vertex_faces[v] = D.vertex_faces[v]

    paths = [shortest_path(D, start, D.vertex_faces[v]) for start in D.vertex_faces[u]]

    best = min(paths, key = len)  # path of minimum length
    edge_path = []
    append = edge_path.append

    for f1_id, f2_id in pairwise(best):
        edges = tuple(D.faces_sets[f1_id - 1] & D.faces_sets[f2_id - 1])  # common edges to cross a face boundary
        append(edges[0])




    return edge_path
Ejemplo n.º 2
0
def planar_gadget(G, x = None, y = None):

    V = [G.add_named_vertex("dummy" + str(G.v_id.next())) for i in range(13)]
    # V = G + 13  # which notation is clearer?


    for u, v in pairwise(V):
        G.add_edge(u, v)

    G.add_edge(V[0], V[7])
    G.add_edge(V[0], V[8])

    G.add_edge(V[1], V[9])
    G.add_edge(V[2], V[9])

    G.add_edge(V[3], V[10])
    G.add_edge(V[4], V[10])

    G.add_edge(V[5], V[11])
    G.add_edge(V[6], V[11])

    for i in (V[8], V[9], V[10]):
        G.add_edge(V[12], i)

    G.add_edge(V[8], V[11])

    return G, V[0], V[2], V[4], V[6]
Ejemplo n.º 3
0
def random_connected_graph(n, m):
    """ Return the random connected graph G_{n,m}.

    Gives a graph picked randomly out of the set of all graphs
    with n nodes and m edges.

    Parameters
    ----------
    n : int
        The number of nodes.
    m : int
        The number of edges.

    """
    G = Graph()
    V = G + n  # add n vertices

    max_edges = int((n * (n - 1.0)) / 2.0)
    m = min(m, max_edges)


    # add the first connection line, (n-1) edges, assuring a connected graph
    for u, v in pairwise(V):
        G.add_edge(u, v)

    AddEdge = G.add_edge
    E_star = set_copy(combinations(G.vertices, 2))

    for u, v in random.sample(E_star - G.edges, m - n + 1):
        AddEdge(u, v)

    return G
Ejemplo n.º 4
0
def octahedron():
    G = Graph()

    v, w, x, y, z1, z2 = (G.add_vertex() for i in xrange(6))

    for i, j in pairwise((v, w, x, y, v)):
        G.add_edge(i, j)
        G.add_edge(i, z1)
        G.add_edge(i, z2)

    G.is_planar()
    return G
Ejemplo n.º 5
0
def phi_C(G):
    """
    for each vertex
    N increases by 4
    """
    u = random.sample(G.Vertices(), 1)
    u = u[0]  # u is actually a 1-element list!


    w, v, y, x = (G.subdivide(u, i) for i in G.embedding[u])

    for i, j in pairwise((w, v, y, x, w)):
        G.add_edge(i, j)


    return G