计算柏拉图立体的邻接矩阵

计算科学 算法 矩阵
2021-12-15 18:56:46

我需要设计一种算法(在 Python 中)来计算柏拉图立体的邻接矩阵。输入到算法中的需要是在每个顶点处相遇的多边形的数量以及它们所基于的正多边形。欢迎任何想法,因为我尝试了一些途径并且没有提出任何远程成功的方法。

设边n数和连接到任何特定顶点的顶点数为m

取一个四面体,它有n = 3m = 3然后我的问题是从这个到建立以下邻接矩阵。

0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0

因此,这是四面体的邻接矩阵。使用立方体,它变得更加复杂

0 1 1 0 1 0 0 0
1 0 0 1 0 1 0 0
1 0 0 1 0 0 1 0
0 1 1 0 0 0 0 1 
1 0 0 0 0 1 1 0
0 1 0 0 1 0 0 1
0 0 1 0 1 0 0 1 
0 0 0 1 0 1 1 0     

等等。

所以我需要取 n 和 m 的值并计算这些矩阵。显然,取决于算法如何标记顶点,有许多可能的解决方案。有任何想法吗?

1个回答

正如@hardmath 所建议的,一个简单的Sage解决方案:

def platonic_solid_adjacency_matrix(n,m):
    """
    Adjacency matrix of the Platonic solid with `n` sides and in which each vertex has `m` neighbors.
    """

    d = {(6,3):graphs.TetrahedralGraph, (12,3):graphs.HexahedralGraph, 
        (12,4):graphs.OctahedralGraph, (30,3):graphs.DodecahedralGraph, (30,5):graphs.IcosahedralGraph}
    try:
        return d[(n,m)]().adjacency_matrix()
    except KeyError:
        raise ValueError, "There is no Platonic solid with the supplied parameters"