コード例 #1
0
ファイル: main.py プロジェクト: lkhamsurenl/research
def main():
    m, n = 6, 6
    # Set deeper recursion level to avoid max recursion depth exceeded.
    if m > 5 or n > 5:
        sys.setrecursionlimit(10000)

    grid = Grid(2, m, n)

    # Get vertices in the boundary face.
    vertices = grid.get_vertices([(1, 1), (0, 1), (0, 0), (1, 0)])

    # Create a new pdf file with current timestamp.
    now = datetime.datetime.now()
    #primal_pdf = PdfPages('../resources/{}-primal.pdf'.format(now.strftime("%m-%d-%H:%M")))
    #dual_pdf = PdfPages('../resources/{}-dual.pdf'.format(now.strftime("%m-%d-%H:%M")))
    primal_pdf = None
    dual_pdf = None

    vertex_mapping = get_vertex_mapping(grid.genus, grid.width, grid.height)
    face_mapping = get_face_mapping(grid.genus, grid.width, grid.height)

    # Wrap all visualization related parameters in tuple.
    visual_params = (vertex_mapping, face_mapping, primal_pdf, dual_pdf)

    move_around_face(grid, vertices, visual_params)

    # Close the pdf files, if created.
    if primal_pdf is not None:
        primal_pdf.close()
    if dual_pdf is not None:
        dual_pdf.close()
コード例 #2
0
    def test_vertex_mapping_g2(self):
        g = 2
        m, n = 6, 6
        vertex_mapping = get_vertex_mapping(g, m, n)

        correct_mapping = {
            (0, 0): [(0, 0), (3, 0), (6, 0), (0, 3), (3, 6), (0, 6), (6, 3), (6, 6)],
            (0, 1): [(0, 1), (6, 4)],
            (0, 2): [(0, 2), (6, 5)],
            (0, 4): [(0, 4), (6, 1)],
            (0, 5): [(0, 5), (6, 2)],
            (1, 0): [(1, 0), (4, 6)],
            (2, 0): [(2, 0), (5, 6)],
            (4, 0): [(4, 0), (1, 6)],
            (5, 0): [(5, 0), (2, 6)]
        }

        # All the internal nodes should have only itself as boundary duplicate.
        for i in range(m):
            for j in range(n):
                if (i, j) not in correct_mapping:
                    correct_mapping[(i, j)] = [(i, j)]
                else:
                    correct_mapping[(i, j)] += [(i, j)]

        for v in vertex_mapping:
            assert Set(vertex_mapping[v]) == Set(correct_mapping[v]), \
                "vertex_mapping_g2({}) = {}; want: {}".format(v, vertex_mapping[v], correct_mapping[v])
コード例 #3
0
    def test_vertex_mapping_g1(self):
        g = 1
        m, n = 3, 3
        vertex_mapping = get_vertex_mapping(g, m, n)

        correct_mapping = {
            (0, 0): [(0, 0), (3, 0), (0, 3), (3, 3)],
            (0, 1): [(0, 1), (3, 1)],
            (0, 2): [(0, 2), (3, 2)],
            (1, 0): [(1, 0), (1, 3)],
            (2, 0): [(2, 0), (2, 3)]
        }

        # All the internal nodes should have only itself as boundary duplicate.
        for i in range(1, m):
            for j in range(1, n):
                correct_mapping[(i, j)] = [(i, j)]

        for v in vertex_mapping:
            assert Set(vertex_mapping[v]) == Set(correct_mapping[v]), \
                "vertex_mapping_g1({}) = {}; want: {}".format(v, vertex_mapping[v], correct_mapping[v])