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


Python DiGraph.relabel方法代码示例

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


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

示例1: plot

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
    def plot(self, label_elements=True, element_labels=None,
            label_font_size=12,label_font_color='black', layout = "acyclic", **kwds):
        """
        Returns a Graphics object corresponding to the Hasse diagram.

        EXAMPLES::

            sage: uc = [[2,3], [], [1], [1], [1], [3,4]]
            sage: elm_lbls = Permutations(3).list()
            sage: P = Poset(uc,elm_lbls)
            sage: H = P._hasse_diagram
            sage: levels = H.level_sets()
            sage: heights = dict([[i, levels[i]] for i in range(len(levels))])
            sage: type(H.plot(label_elements=True))
            <class 'sage.plot.graphics.Graphics'>

        ::

            sage: P = Posets.SymmetricGroupBruhatIntervalPoset([1,2,3,4], [3,4,1,2])
            sage: P._hasse_diagram.plot()
        """
        # Set element_labels to default to the vertex set.
        if element_labels is None:
            element_labels = range(self.num_verts())

        # Create the underlying graph.
        graph = DiGraph(self)
        graph.relabel(element_labels)

        return graph.plot(layout = layout, **kwds)
开发者ID:sageb0t,项目名称:testsage,代码行数:32,代码来源:hasse_diagram.py

示例2: relabel

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
    def relabel(self, relabelling, inplace=False, **kwds):
        """
        Return the relabelling Dynkin diagram of ``self``.

        EXAMPLES::

            sage: D = DynkinDiagram(['C',3])
            sage: D.relabel({1:0, 2:4, 3:1})
            O---O=<=O
            0   4   1
            C3 relabelled by {1: 0, 2: 4, 3: 1}
            sage: D
            O---O=<=O
            1   2   3
            C3
        """
        if inplace:
            DiGraph.relabel(self, relabelling, inplace, **kwds)
            G = self
        else:
            # We must make a copy of ourselves first because of DiGraph's
            #   relabel default behavior is to do so in place, and if not
            #   then it recurses on itself with no argument for inplace
            G = self.copy().relabel(relabelling, inplace=True, **kwds)
        if self._cartan_type is not None:
            G._cartan_type = self._cartan_type.relabel(relabelling)
        return G
开发者ID:bukzor,项目名称:sage,代码行数:29,代码来源:dynkin_diagram.py

示例3: bhz_poset

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
        def bhz_poset(self):
            r"""
            Return the Bergeron-Hohlweg-Zabrocki partial order on the Coxeter
            group.

            This is a partial order on the elements of a finite
            Coxeter group `W`, which is distinct from the Bruhat
            order, the weak order and the shard intersection order. It
            was defined in [BHZ05]_.

            This partial order is not a lattice, as there is no unique
            maximal element. It can be succintly defined as follows.

            Let `u` and `v` be two elements of the Coxeter group `W`. Let
            `S(u)` be the support of `u`. Then `u \leq v` if and only
            if `v_{S(u)} = u` (here `v = v^I v_I` denotes the usual
            parabolic decomposition with respect to the standard parabolic
            subgroup `W_I`).

            .. SEEALSO::

                :meth:`bruhat_poset`, :meth:`shard_poset`, :meth:`weak_poset`

            EXAMPLES::

                sage: W = CoxeterGroup(['A',3], base_ring=ZZ)
                sage: P = W.bhz_poset(); P
                Finite poset containing 24 elements
                sage: P.relations_number()
                103
                sage: P.chain_polynomial()
                34*q^4 + 90*q^3 + 79*q^2 + 24*q + 1
                sage: len(P.maximal_elements())
                13

            REFERENCE:

            .. [BHZ05] \N. Bergeron, C. Hohlweg, and M. Zabrocki, *Posets
               related to the Connectivity Set of Coxeter Groups*.
               :arxiv:`math/0509271v3`
            """
            from sage.graphs.digraph import DiGraph
            from sage.combinat.posets.posets import Poset

            def covered_by(ux, vy):
                u, iu, Su = ux
                v, iv, Sv = vy
                if len(Sv) != len(Su) + 1:
                    return False
                if not all(u in Sv for u in Su):
                    return False
                return all((v * iu).has_descent(x, positive=True) for x in Su)

            vertices = [(u, u.inverse(),
                         tuple(set(u.reduced_word_reverse_iterator())))
                        for u in self]
            dg = DiGraph([vertices, covered_by])
            dg.relabel(lambda x: x[0])
            return Poset(dg, cover_relations=True)
开发者ID:mcognetta,项目名称:sage,代码行数:61,代码来源:finite_coxeter_groups.py

示例4: relabel

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
    def relabel(self, relabelling, inplace=False, **kwds):
        """
        Return the relabelling Dynkin diagram of ``self``.

        EXAMPLES::

            sage: D = DynkinDiagram(['C',3])
            sage: D.relabel({1:0, 2:4, 3:1})
            O---O=<=O
            0   4   1
            C3 relabelled by {1: 0, 2: 4, 3: 1}
            sage: D
            O---O=<=O
            1   2   3
            C3

            sage: D = DynkinDiagram(['A', [1,2]])
            sage: Dp = D.relabel({-1:4, 0:-3, 1:3, 2:2}); Dp
            O---X---O---O
            4   -3  3   2
            A1|2 relabelled by {0: -3, 1: 3, 2: 2, -1: 4}
            sage: Dp.odd_isotropic_roots()
            (-3,)
        """
        if inplace:
            DiGraph.relabel(self, relabelling, inplace, **kwds)
            G = self
        else:
            # We must make a copy of ourselves first because of DiGraph's
            #   relabel default behavior is to do so in place, and if not
            #   then it recurses on itself with no argument for inplace
            G = self.copy().relabel(relabelling, inplace=True, **kwds)
        if isinstance(relabelling, dict):
            relabelling = relabelling.__getitem__
        new_odds = [relabelling(i) for i in self._odd_isotropic_roots]
        G._odd_isotropic_roots = tuple(new_odds)
        if self._cartan_type is not None:
            G._cartan_type = self._cartan_type.relabel(relabelling)
        return G
开发者ID:saraedum,项目名称:sage-renamed,代码行数:41,代码来源:dynkin_diagram.py

示例5: relabel

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
    def relabel(self, *args, **kwds):
        """
        Return the relabelled Dynkin diagram of ``self``.

        INPUT: see :meth:`~sage.graphs.generic_graph.GenericGraph.relabel`

        There is one difference: the default value for ``inplace`` is
        ``False`` instead of ``True``.

        EXAMPLES::

            sage: D = DynkinDiagram(['C',3])
            sage: D.relabel({1:0, 2:4, 3:1})
            O---O=<=O
            0   4   1
            C3 relabelled by {1: 0, 2: 4, 3: 1}
            sage: D
            O---O=<=O
            1   2   3
            C3

            sage: _ = D.relabel({1:0, 2:4, 3:1}, inplace=True)
            sage: D
            O---O=<=O
            0   4   1
            C3 relabelled by {1: 0, 2: 4, 3: 1}

            sage: D = DynkinDiagram(['A', [1,2]])
            sage: Dp = D.relabel({-1:4, 0:-3, 1:3, 2:2})
            sage: Dp
            O---X---O---O
            4   -3  3   2
            A1|2 relabelled by {-1: 4, 0: -3, 1: 3, 2: 2}
            sage: Dp.odd_isotropic_roots()
            (-3,)

            sage: D = DynkinDiagram(['D', 5])
            sage: G, perm = D.relabel(range(5), return_map=True)
            sage: G
                    O 4
                    |
                    |
            O---O---O---O
            0   1   2   3
            D5 relabelled by {1: 0, 2: 1, 3: 2, 4: 3, 5: 4}
            sage: perm
            {1: 0, 2: 1, 3: 2, 4: 3, 5: 4}

            sage: perm = D.relabel(range(5), return_map=True, inplace=True)
            sage: D
                    O 4
                    |
                    |
            O---O---O---O
            0   1   2   3
            D5 relabelled by {1: 0, 2: 1, 3: 2, 4: 3, 5: 4}
            sage: perm
            {1: 0, 2: 1, 3: 2, 4: 3, 5: 4}
        """
        return_map = kwds.pop("return_map", False)
        inplace = kwds.pop("inplace", False)
        if inplace:
            G = self
        else:
            # We need to copy self because we want to return the
            # permutation and that works when relabelling in place.
            G = self.copy()

        perm = DiGraph.relabel(G, *args, inplace=True, return_map=True, **kwds)
        new_odds = [perm[i] for i in self._odd_isotropic_roots]
        G._odd_isotropic_roots = tuple(new_odds)
        if self._cartan_type is not None:
            G._cartan_type = self._cartan_type.relabel(perm.__getitem__)
        if return_map:
            if inplace:
                return perm
            else:
                return G, perm
        else:
            return G
开发者ID:sagemath,项目名称:sage,代码行数:82,代码来源:dynkin_diagram.py

示例6: RandomPoset

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
    def RandomPoset(n, p):
        r"""
        Generate a random poset on ``n`` elements according to a
        probability ``p``.

        INPUT:

        - ``n`` - number of elements, a non-negative integer

        - ``p`` - a probability, a real number between 0 and 1 (inclusive)

        OUTPUT:

        A poset on `n` elements. The probability `p` roughly measures
        width/height of the output: `p=0` always generates an antichain,
        `p=1` will return a chain. To create interesting examples,
        keep the probability small, perhaps on the order of `1/n`.

        EXAMPLES::

            sage: set_random_seed(0)  # Results are reproducible
            sage: P = Posets.RandomPoset(5, 0.3)
            sage: P.cover_relations()
            [[5, 4], [4, 2], [1, 2]]

        TESTS::

            sage: Posets.RandomPoset('junk', 0.5)
            Traceback (most recent call last):
            ...
            TypeError: number of elements must be an integer, not junk

            sage: Posets.RandomPoset(-6, 0.5)
            Traceback (most recent call last):
            ...
            ValueError: number of elements must be non-negative, not -6

            sage: Posets.RandomPoset(6, 'garbage')
            Traceback (most recent call last):
            ...
            TypeError: probability must be a real number, not garbage

            sage: Posets.RandomPoset(6, -0.5)
            Traceback (most recent call last):
            ...
            ValueError: probability must be between 0 and 1, not -0.5

            sage: Posets.RandomPoset(0, 0.5)
            Finite poset containing 0 elements
        """
        from sage.misc.prandom import random

        try:
            n = Integer(n)
        except TypeError:
            raise TypeError("number of elements must be an integer, not {0}".format(n))
        if n < 0:
            raise ValueError("number of elements must be non-negative, not {0}".format(n))
        try:
            p = float(p)
        except Exception:
            raise TypeError("probability must be a real number, not {0}".format(p))
        if p < 0 or p> 1:
            raise ValueError("probability must be between 0 and 1, not {0}".format(p))

        D = DiGraph(loops=False, multiedges=False)
        D.add_vertices(range(n))
        for i in range(n):
            for j in range(i+1, n):
                if random() < p:
                    D.add_edge(i, j)
        D.relabel(list(Permutations(n).random_element()))
        return Poset(D, cover_relations=False)
开发者ID:Babyll,项目名称:sage,代码行数:75,代码来源:poset_examples.py

示例7: Hasse_diagram_from_incidences

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]

#.........这里部分代码省略.........
    and we can compute the Hasse diagram as ::

        sage: L = sage.geometry.cone.Hasse_diagram_from_incidences(
        ...                       atom_to_coatoms, coatom_to_atoms)
        sage: L
        Finite poset containing 8 elements with distinguished linear extension
        sage: for level in L.level_sets(): print(level)
        [((), (0, 1, 2))]
        [((0,), (0, 1)), ((1,), (0, 2)), ((2,), (1, 2))]
        [((0, 1), (0,)), ((0, 2), (1,)), ((1, 2), (2,))]
        [((0, 1, 2), ())]

    For more involved examples see the *source code* of
    :meth:`sage.geometry.cone.ConvexRationalPolyhedralCone.face_lattice` and
    :meth:`sage.geometry.fan.RationalPolyhedralFan._compute_cone_lattice`.
    """
    from sage.graphs.digraph import DiGraph
    from sage.combinat.posets.posets import FinitePoset
    def default_face_constructor(atoms, coatoms, **kwds):
        return (atoms, coatoms)
    if face_constructor is None:
        face_constructor = default_face_constructor
    atom_to_coatoms = [frozenset(atc) for atc in atom_to_coatoms]
    A = frozenset(range(len(atom_to_coatoms)))  # All atoms
    coatom_to_atoms = [frozenset(cta) for cta in coatom_to_atoms]
    C = frozenset(range(len(coatom_to_atoms)))  # All coatoms
    # Comments with numbers correspond to steps in Section 2.5 of the article
    L = DiGraph(1)       # 3: initialize L
    faces = dict()
    atoms = frozenset()
    coatoms = C
    faces[atoms, coatoms] = 0
    next_index = 1
    Q = [(atoms, coatoms)]              # 4: initialize Q with the empty face
    while Q:                            # 5
        q_atoms, q_coatoms = Q.pop()    # 6: remove some q from Q
        q = faces[q_atoms, q_coatoms]
        # 7: compute H = {closure(q+atom) : atom not in atoms of q}
        H = dict()
        candidates = set(A.difference(q_atoms))
        for atom in candidates:
            coatoms = q_coatoms.intersection(atom_to_coatoms[atom])
            atoms = A
            for coatom in coatoms:
                atoms = atoms.intersection(coatom_to_atoms[coatom])
            H[atom] = (atoms, coatoms)
        # 8: compute the set G of minimal sets in H
        minimals = set([])
        while candidates:
            candidate = candidates.pop()
            atoms = H[candidate][0]
            if atoms.isdisjoint(candidates) and atoms.isdisjoint(minimals):
                minimals.add(candidate)
        # Now G == {H[atom] : atom in minimals}
        for atom in minimals:   # 9: for g in G:
            g_atoms, g_coatoms = H[atom]
            if not required_atoms is None:
                if g_atoms.isdisjoint(required_atoms):
                    continue
            if (g_atoms, g_coatoms) in faces:
                g = faces[g_atoms, g_coatoms]
            else:               # 11: if g was newly created
                g = next_index
                faces[g_atoms, g_coatoms] = g
                next_index += 1
                Q.append((g_atoms, g_coatoms))  # 12
            L.add_edge(q, g)                    # 14
    # End of algorithm, now construct a FinitePoset.
    # In principle, it is recommended to use Poset or in this case perhaps
    # even LatticePoset, but it seems to take several times more time
    # than the above computation, makes unnecessary copies, and crashes.
    # So for now we will mimic the relevant code from Poset.

    # Enumeration of graph vertices must be a linear extension of the poset
    new_order = L.topological_sort()
    # Make sure that coatoms are in the end in proper order
    tail = [faces[atoms, frozenset([coatom])]
            for coatom, atoms in enumerate(coatom_to_atoms)]
    tail.append(faces[A, frozenset()])
    new_order = [n for n in new_order if n not in tail] + tail
    # Make sure that atoms are in the beginning in proper order
    head = [0] # We know that the empty face has index 0
    head.extend(faces[frozenset([atom]), coatoms]
                for atom, coatoms in enumerate(atom_to_coatoms)
                if required_atoms is None or atom in required_atoms)
    new_order = head + [n for n in new_order if n not in head]
    # "Invert" this list to a dictionary
    labels = dict()
    for new, old in enumerate(new_order):
        labels[old] = new
    L.relabel(labels)
    # Construct the actual poset elements
    elements = [None] * next_index
    for face, index in faces.items():
        atoms, coatoms = face
        elements[labels[index]] = face_constructor(
                        tuple(sorted(atoms)), tuple(sorted(coatoms)), **kwds)
    D = {i:f for i,f in enumerate(elements)}
    L.relabel(D)
    return FinitePoset(L, elements, key = key)
开发者ID:drupel,项目名称:sage,代码行数:104,代码来源:hasse_diagram.py

示例8: ParentBigOh

# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import relabel [as 别名]
class ParentBigOh(Parent,UniqueRepresentation):
    def __init__(self,ambiant):
        try:
            self._uniformizer = ambiant.uniformizer_name()
        except NotImplementedError:
            raise TypeError("Impossible to determine the name of the uniformizer")
        self._ambiant_space = ambiant
        self._models = DiGraph(loops=False)
        self._default_model = None
        Parent.__init__(self,ambiant.base_ring())
        if self.base_ring() is None:
            self._base_precision = None
        else:
            if self.base_ring() == ambiant:
                self._base_precision = self
            else:
                self._base_precision = ParentBigOh(self.base_ring())

    def __hash__(self):
        return id(self)

    def base_precision(self):
        return self._base_precision

    def precision(self):
        return self._precision

    def default_model(self):
        if self._default_mode is None:
            self.set_default_model()
        return self._default_model
    
    def set_default_model(self,model=None):
        if model is None:
            self._default_model = self._models.topological_sort()[-1]
        else:
            if self._models.has_vertex(model):
                self._default_model = model
            else:
                raise ValueError

    def add_model(self,model):
        from bigoh import BigOh
        if not isinstance(model,list):
            model = [model]
        for m in model:
            if not issubclass(m,BigOh):
                raise TypeError("A precision model must derive from BigOh but '%s' is not"%m)
            self._models.add_vertex(m)

    def delete_model(self,model):
        if isinstance(model,list):
            model = [model]
        for m in model:
            if self._models.has_vertex(m):
                self._models.delete_vertex(m)

    def update_model(self,old,new):
        from bigoh import BigOh
        if self._models.has_vertex(old):
            if not issubclass(new,BigOh):
                raise TypeError("A precision model must derive from BigOh but '%s' is not"%new)
            self._models.relabel({old:new})
        else:
            raise ValueError("Model '%m' does not exist"%old)

    def add_modelconversion(self,domain,codomain,constructor=None,safemode=False):
        if not self._models.has_vertex(domain):
            if safemode: return
            raise ValueError("Model '%s' does not exist"%domain)
        if not self._models.has_vertex(codomain):
            if safemode: return
            raise ValueError("Model '%s' does not exist"%codomain)
        path = self._models.shortest_path(codomain,domain)
        if len(path) > 0:
            raise ValueError("Adding this conversion creates a cycle")
        self._models.add_edge(domain,codomain,constructor)

    def delete_modelconversion(self,domain,codomain):
        if not self._models.has_vertex(domain):
            raise ValueError("Model '%s' does not exist"%domain)
        if not self._models.has_vertex(codomain):
            raise ValueError("Model '%s' does not exist"%codomain)
        if not self._models_has_edge(domain,codomain):
            raise ValueError("No conversion from %s to %s"%(domain,codomain))
        self._modelfs.delete_edge(domain,codomain)

    def uniformizer_name(self):
        return self._uniformizer

    def ambiant_space(self):
        return self._ambiant_space

    # ?!?
    def __call__(self,*args,**kwargs):
        return self._element_constructor_(*args,**kwargs)
    
    def _element_constructor_(self, *args, **kwargs):
        if kwargs.has_key('model'):
            del kwargs['model']
#.........这里部分代码省略.........
开发者ID:roed314,项目名称:padicprec,代码行数:103,代码来源:parent_precision.py


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