Ticket #13067: trac_13067-new.patch

File trac_13067-new.patch, 4.0 KB (added by chapoton, 7 years ago)
  • sage/graphs/graph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1343836685 -7200
    # Node ID f0dac422c592fc0dcd4ffc31ab64643845ed45c5
    # Parent  59c0bbefac391d2e0a0eba49172ca75aceeb56ce
    trac #13067 Graph.is_strongly_regular method
    
    diff --git a/sage/graphs/graph.py b/sage/graphs/graph.py
    a b graphs. 
    5252    :meth:`~Graph.is_long_hole_free` | Tests whether ``self`` contains an induced cycle of length at least 5.
    5353    :meth:`~Graph.is_long_antihole_free` | Tests whether ``self`` contains an induced anticycle of length at least 5.
    5454    :meth:`~Graph.is_weakly_chordal` | Tests whether ``self`` is weakly chordal.
    55 
     55    :meth:`~Graph.is_strongly_regular` | Tests whether ``self`` is strongly regular.
    5656
    5757**Connectivity and orientations:**
    5858
    class Graph(GenericGraph): 
    21622162        else:
    21632163            return counter_example is None
    21642164
     2165    def is_strongly_regular(self, return_parameters=False):
     2166        r"""
     2167        Tests whether ``self`` is strongly regular.
     2168
     2169        A graph `G` is said to be strongly regular with parameters `(k, \lambda,
     2170        \mu)` if and only if:
     2171
     2172            * `G` is `k`-regular
     2173
     2174            * Any two adjacent vertices of `G` have `\lambda` common neighbors.
     2175
     2176            * Any two non-adjacent vertices of `G` have `\mu` common neighbors.
     2177
     2178        INPUT:
     2179
     2180        - ``return_parameters`` (boolean) -- whether to return the triple
     2181          `(k,\lambda,\mu)`. If ``return_parameters = False`` (default), this
     2182          method only returns ``True`` and ``False`` answers. If
     2183          ``return_parameters=True``, the ``True`` answers are replaced by
     2184          triples `(k,\lambda,\mu)`. See definition above.
     2185
     2186        EXAMPLES:
     2187
     2188        Petersen's graph is strongly regular::
     2189
     2190            sage: g = graphs.PetersenGraph()
     2191            sage: g.is_strongly_regular()
     2192            True
     2193            sage: g.is_strongly_regular(return_parameters = True)
     2194            (3, 0, 1)
     2195
     2196        And Clebsch's graph is too::
     2197
     2198            sage: g = graphs.ClebschGraph()
     2199            sage: g.is_strongly_regular()
     2200            True
     2201            sage: g.is_strongly_regular(return_parameters = True)
     2202            (5, 0, 2)
     2203
     2204        But Chvatal's graph is not::
     2205
     2206            sage: g = graphs.ChvatalGraph()
     2207            sage: g.is_strongly_regular()
     2208            False
     2209        """
     2210        degree = self.degree()
     2211        k = degree[0]
     2212        if not all(d == k for d in degree):
     2213            return False
     2214
     2215        if self.is_clique():
     2216            l = self.order()-2
     2217            m = 0
     2218        elif self.size() == 0:
     2219            l = 0
     2220            m = 0
     2221        else:
     2222            l = m = None
     2223            for u in self:
     2224                nu = set(self.neighbors(u))
     2225                for v in self:
     2226                    if u == v:
     2227                        continue
     2228                    nv = set(self.neighbors(v))
     2229                    inter = len(nu&nv)
     2230
     2231                    if v in nu:
     2232                        if l is None:
     2233                            l = inter
     2234                        else:
     2235                            if l != inter:
     2236                                return False
     2237                    else:
     2238                        if m is None:
     2239                            m = inter
     2240                        else:
     2241                            if m != inter:
     2242                                return False
     2243
     2244            if return_parameters:
     2245                return (k,l,m)
     2246            else:
     2247                return True
    21652248
    21662249    def degree_constrained_subgraph(self, bounds=None, solver=None, verbose=0):
    21672250        r"""
    21682251        Returns a degree-constrained subgraph.
    21692252
    21702253        Given a graph `G` and two functions `f, g:V(G)\rightarrow \mathbb Z`
    2171         such that `f \leq g`, a degree-constrained subgraph in `G` is 
     2254        such that `f \leq g`, a degree-constrained subgraph in `G` is
    21722255        a subgraph `G' \subseteq G` such that for any vertex `v \in G`,
    21732256        `f(v) \leq d_{G'}(v) \leq g(v)`.
    21742257