当前位置: 首页>>代码示例>>Python>>正文


Python Graph.connected_components_subgraphs方法代码示例

本文整理汇总了Python中sage.graphs.graph.Graph.connected_components_subgraphs方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.connected_components_subgraphs方法的具体用法?Python Graph.connected_components_subgraphs怎么用?Python Graph.connected_components_subgraphs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.graphs.graph.Graph的用法示例。


在下文中一共展示了Graph.connected_components_subgraphs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: recognize_coxeter_type_from_matrix

# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import connected_components_subgraphs [as 别名]

#.........这里部分代码省略.........
        sage: M.coxeter_type()
        Coxeter type of ['G', 2, 1] relabelled by {0: 'a', 1: 'b', 2: 'c'}

        sage: from sage.combinat.root_system.coxeter_matrix import recognize_coxeter_type_from_matrix
        sage: for C in CoxeterMatrix.samples():
        ....:     relabelling_perm = Permutations(C.index_set()).random_element()
        ....:     relabelling_dict = {C.index_set()[i]: relabelling_perm[i] for i in range(C.rank())}
        ....:     relabeled_matrix = C.relabel(relabelling_dict)._matrix
        ....:     recognized_type = recognize_coxeter_type_from_matrix(relabeled_matrix, relabelling_perm)
        ....:     if C.is_finite() or C.is_affine():
        ....:         assert recognized_type == C.coxeter_type()

    We check the rank 2 cases (:trac:`20419`)::

        sage: for i in range(2, 10):
        ....:     M = matrix([[1,i],[i,1]])
        ....:     CoxeterMatrix(M).coxeter_type()
        Coxeter type of A1xA1 relabelled by {1: 2}
        Coxeter type of ['A', 2]
        Coxeter type of ['B', 2]
        Coxeter type of ['I', 5]
        Coxeter type of ['G', 2]
        Coxeter type of ['I', 7]
        Coxeter type of ['I', 8]
        Coxeter type of ['I', 9]
        sage: CoxeterMatrix(matrix([[1,-1],[-1,1]]), index_set=[0,1]).coxeter_type()
        Coxeter type of ['A', 1, 1]
    """
    # First, we build the Coxeter graph of the group without the edge labels
    n = ZZ(coxeter_matrix.nrows())
    G = Graph(
        [
            [index_set[i], index_set[j], coxeter_matrix[i, j]]
            for i in range(n)
            for j in range(i, n)
            if coxeter_matrix[i, j] not in [1, 2]
        ]
    )
    G.add_vertices(index_set)

    types = []
    for S in G.connected_components_subgraphs():
        r = S.num_verts()
        # Handle the special cases first
        if r == 1:
            types.append(CoxeterType(["A", 1]).relabel({1: S.vertices()[0]}))
            continue
        if r == 2:  # Type B2, G2, or I_2(p)
            e = S.edge_labels()[0]
            if e == 3:  # Can't be 2 because it is connected
                ct = CoxeterType(["A", 2])
            elif e == 4:
                ct = CoxeterType(["B", 2])
            elif e == 6:
                ct = CoxeterType(["G", 2])
            elif e > 0 and e < float("inf"):  # Remaining non-affine types
                ct = CoxeterType(["I", e])
            else:  # Otherwise it is infinite dihedral group Z_2 \ast Z_2
                ct = CoxeterType(["A", 1, 1])
            if not ct.is_affine():
                types.append(ct.relabel({1: S.vertices()[0], 2: S.vertices()[1]}))
            else:
                types.append(ct.relabel({0: S.vertices()[0], 1: S.vertices()[1]}))
            continue

        test = [["A", r], ["B", r], ["A", r - 1, 1]]
        if r >= 3:
            if r == 3:
                test += [["G", 2, 1], ["H", 3]]
            test.append(["C", r - 1, 1])
        if r >= 4:
            if r == 4:
                test += [["F", 4], ["H", 4]]
            test += [["D", r], ["B", r - 1, 1]]
        if r >= 5:
            if r == 5:
                test.append(["F", 4, 1])
            test.append(["D", r - 1, 1])
        if r == 6:
            test.append(["E", 6])
        elif r == 7:
            test += [["E", 7], ["E", 6, 1]]
        elif r == 8:
            test += [["E", 8], ["E", 7, 1]]
        elif r == 9:
            test.append(["E", 8, 1])

        found = False
        for ct in test:
            ct = CoxeterType(ct)
            T = ct.coxeter_graph()
            iso, match = T.is_isomorphic(S, certify=True, edge_labels=True)
            if iso:
                types.append(ct.relabel(match))
                found = True
                break
        if not found:
            return None

    return CoxeterType(types)
开发者ID:imark83,项目名称:sage,代码行数:104,代码来源:coxeter_matrix.py


注:本文中的sage.graphs.graph.Graph.connected_components_subgraphs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。