| 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 |