Exemplo n.º 1
0
Arquivo: moves.py Projeto: raylee/CDT
def try_1_to_3(simplex_id_or_simplex):
    """
    Tries a 1->3 move and returns the move data that the metropolis
    algorithm will use to decide whether or not to accept a move. Also
    returns useful information for applying the move.
    """
    # The complex
    cmpx = complex_1_to_3(simplex_id_or_simplex)

    # The triangle id. There should only be one.
    if len(cmpx.get_triangles()) == 1:
        triangle_id = list(cmpx.get_triangles())[0]
    else:
        raise ValueError("There should be only one "+
                         "triangle for the 1->3 complex.")

    # The triangle
    triangle = sd.triangle.instances[triangle_id]

    # The original vertices
    original_vertices = [sd.vertex.instances[p] for p in triangle.vertices]

    # We're adding 1 vertex, but each of 3 other vertices is connected
    # to 1 additional triangle each.

    # "replace" the 3 original vertices
    removed_vertices = [st.imaginary_vertex(len(v),False) \
                            for v in original_vertices]
    added_vertices = [st.imaginary_vertex(len(v)+1,True) \
                          for v in original_vertices]
    # Add the center vertex
    added_vertices.append(st.imaginary_vertex(3,True))

    return st.move_data(removed_vertices + added_vertices,
                        cmpx,move_1_to_3,2)
Exemplo n.º 2
0
Arquivo: moves.py Projeto: raylee/CDT
def try_2_to_2(simplex_id_or_simplex):
    """
    Tries a 2->2 move and returns the data that the metropolis
    algorithm will use to decide whether ornot to accept the
    move. Also returns useful information for applying the move.
    """
    # The complex
    cmpx = complex_2_to_2(simplex_id_or_simplex)

    # If no complex is possible, immediately return false
    if not cmpx:
        return False

    # The triangles in the complex. There should be 2.
    triangles = [sd.triangle.parse_input(t) for t in cmpx.get_triangles()]
    if len(triangles) != 2:
        raise ValueError("There should be 2 triangles in this complex!")

    # The unshared vertices. There should be 2, but complex22 does
    # this error checking for us. It also returns instances rather
    # than values in the case of the vertices.
    unshared_vertices = cmpx.get_unshared_vertices()
    # The shared vertices. Similar to the unshared
    shared_vertices = cmpx.get_shared_vertices()

    # All 4 of the original vertices will be replaced.
    original_vertices = unshared_vertices + shared_vertices
    assert len(set(original_vertices)) == 4
    removed_vertices = [st.imaginary_vertex(len(v),False) \
                            for v in original_vertices]

    # The unshared vertices will become shared, so each one will
    # become attached to one additional triangle.
    added_vertices = [st.imaginary_vertex(len(v)+1,True) \
                          for v in unshared_vertices]
    # The shared vertices will become unshared, so each one will
    # become attached to one less triangle.
    added_vertices += [st.imaginary_vertex(len(v)-1,True) \
                           for v in shared_vertices]

    return st.move_data(removed_vertices + added_vertices,
                        cmpx, move_2_to_2,0)
Exemplo n.º 3
0
Arquivo: moves.py Projeto: raylee/CDT
def try_3_to_1(simplex_id_or_simplex):
    """
    Tries a 3->1 move and returns the move data that the metropolis
    algorithm will use to decide whether or not to accept the move. If
    the move is simply not topologically acceptable, returns false.
    """
    # The complex
    cmpx = complex_3_to_1(simplex_id_or_simplex)
    
    # If there are no topologically acceptable complices, stop right
    # now and return False. Otherwise, extract the triangles.
    if cmpx:
        triangles = cmpx.get_triangles()
    else:
        return False

    # Now that we have the triangle, extract the list of points of
    # each triangle.
    old_vertices = [sd.triangle.instances[t].get_vertices() \
                        for t in triangles]
    # The central vertex is the intersection of all the vertices in
    # the old triangles
    central_vertex = ut.set_intersection([set(t) for t in old_vertices])
    # The boundary vertices are the union of the vertices of the old
    # triangles minus the intersection:
    boundary_vertices = ut.set_union([set(t) for t in old_vertices]) \
        - central_vertex

    # We're removing the central vertex, but each boundary vertex will
    # be attached to 1 fewer triangle.
    
    # "Replace" the 3 original vertices
    removed_vertices = [st.imaginary_vertex(len(v),False) \
                            for v in boundary_vertices]
    added_vertices = [st.imaginary_vertex(len(v)-1,True) \
                          for v in boundary_vertices]
    # "Remove" the center vertex
    removed_vertices.append(st.imaginary_vertex(3,False))

    return st.move_data(removed_vertices + added_vertices,cmpx,
                        move_3_to_1,-2)